From 6a25e94472291e77d3b00d32899f21fdd1f1c9d7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 30 Jul 2024 12:22:39 -0400 Subject: [PATCH] examples: Print a description of the program to the console on startup. --- build-scripts/build-web-examples.pl | 14 ++++++++++++++ examples/audio/01-simple-playback/README.txt | 5 +++++ .../audio/01-simple-playback/simple-playback.c | 3 --- .../audio/02-simple-playback-callback/README.txt | 5 +++++ .../simple-playback-callback.c | 3 --- examples/audio/03-load-wav/README.txt | 5 +++++ examples/audio/03-load-wav/load-wav.c | 3 --- examples/renderer/01-clear/README.txt | 3 +++ examples/renderer/02-primitives/README.txt | 3 +++ .../renderer/02-primitives/renderer-primitives.c | 4 ++-- examples/template.html | 1 + 11 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 examples/audio/01-simple-playback/README.txt create mode 100644 examples/audio/02-simple-playback-callback/README.txt create mode 100644 examples/audio/03-load-wav/README.txt create mode 100644 examples/renderer/01-clear/README.txt create mode 100644 examples/renderer/02-primitives/README.txt diff --git a/build-scripts/build-web-examples.pl b/build-scripts/build-web-examples.pl index ebed3fab7..6f4351b32 100755 --- a/build-scripts/build-web-examples.pl +++ b/build-scripts/build-web-examples.pl @@ -103,6 +103,19 @@ sub handle_example_dir { my $jsdst = "$dst/$jsfname"; my $wasmdst = "$dst/$wasmfname"; + my $print_description = ''; + if (open(my $readmetxth, '<', "$examples_dir/$category/$example/README.txt")) { + my $spc = ''; + while (<$readmetxth>) { + chomp; + s/\"/\\"/g; + $print_description .= "${spc}Module.print(\"$_\");"; + $spc = ' '; + } + $print_description .= "${spc}Module.print(\"\");"; + close($readmetxth); + } + do_mkdir($dst); do_copy($jssrc, $jsdst); do_copy($wasmsrc, $wasmdst); @@ -142,6 +155,7 @@ sub handle_example_dir { s/\@example_name\@/$example/g; s/\@javascript_file\@/$jsfname/g; s/\@htmlified_source_code\@/$htmlified_source_code/g; + s/\@print_description\@/$print_description/g; $html .= $_; } close($htmltemplate); diff --git a/examples/audio/01-simple-playback/README.txt b/examples/audio/01-simple-playback/README.txt new file mode 100644 index 000000000..9b3c07dd0 --- /dev/null +++ b/examples/audio/01-simple-playback/README.txt @@ -0,0 +1,5 @@ +If you're running this in a web browser, you need to click the window before you'll hear anything! + +This example code creates an simple audio stream for playing sound, and +generates a sine wave sound effect for it to play as time goes on. This is the +simplest way to get up and running with procedural sound. diff --git a/examples/audio/01-simple-playback/simple-playback.c b/examples/audio/01-simple-playback/simple-playback.c index 464d760d4..ecf0c2dba 100644 --- a/examples/audio/01-simple-playback/simple-playback.c +++ b/examples/audio/01-simple-playback/simple-playback.c @@ -47,9 +47,6 @@ int SDL_AppInit(void **appstate, int argc, char *argv[]) /* SDL_OpenAudioDeviceStream starts the device paused. You have to tell it to start! */ SDL_ResumeAudioStreamDevice(stream); - /* (this is a web browser requirement, not an SDL thing.) */ - SDL_Log("If you're running this in a web browser, you need to click the window before you'll hear anything."); - return SDL_APP_CONTINUE; /* carry on with the program! */ } diff --git a/examples/audio/02-simple-playback-callback/README.txt b/examples/audio/02-simple-playback-callback/README.txt new file mode 100644 index 000000000..e719256d8 --- /dev/null +++ b/examples/audio/02-simple-playback-callback/README.txt @@ -0,0 +1,5 @@ +If you're running this in a web browser, you need to click the window before you'll hear anything! + +This example code creates an simple audio stream for playing sound, and +generates a sine wave sound effect for it to play as time goes on. Unlike +the previous example, this uses a callback to generate sound. diff --git a/examples/audio/02-simple-playback-callback/simple-playback-callback.c b/examples/audio/02-simple-playback-callback/simple-playback-callback.c index 4d21296ec..1fa1e0b02 100644 --- a/examples/audio/02-simple-playback-callback/simple-playback-callback.c +++ b/examples/audio/02-simple-playback-callback/simple-playback-callback.c @@ -79,9 +79,6 @@ int SDL_AppInit(void **appstate, int argc, char *argv[]) /* SDL_OpenAudioDeviceStream starts the device paused. You have to tell it to start! */ SDL_ResumeAudioStreamDevice(stream); - /* (this is a web browser requirement, not an SDL thing.) */ - SDL_Log("If you're running this in a web browser, you need to click the window before you'll hear anything."); - return SDL_APP_CONTINUE; /* carry on with the program! */ } diff --git a/examples/audio/03-load-wav/README.txt b/examples/audio/03-load-wav/README.txt new file mode 100644 index 000000000..5a6894c76 --- /dev/null +++ b/examples/audio/03-load-wav/README.txt @@ -0,0 +1,5 @@ +If you're running this in a web browser, you need to click the window before you'll hear anything! + +This example code creates an simple audio stream for playing sound, and +loads a .wav file that is pushed through the stream in a loop. + diff --git a/examples/audio/03-load-wav/load-wav.c b/examples/audio/03-load-wav/load-wav.c index 0a24a15eb..d8d74cd51 100644 --- a/examples/audio/03-load-wav/load-wav.c +++ b/examples/audio/03-load-wav/load-wav.c @@ -61,9 +61,6 @@ int SDL_AppInit(void **appstate, int argc, char *argv[]) /* SDL_OpenAudioDeviceStream starts the device paused. You have to tell it to start! */ SDL_ResumeAudioStreamDevice(stream); - /* (this is a web browser requirement, not an SDL thing.) */ - SDL_Log("If you're running this in a web browser, you need to click the window before you'll hear anything."); - return SDL_APP_CONTINUE; /* carry on with the program! */ } diff --git a/examples/renderer/01-clear/README.txt b/examples/renderer/01-clear/README.txt new file mode 100644 index 000000000..ce9ef8131 --- /dev/null +++ b/examples/renderer/01-clear/README.txt @@ -0,0 +1,3 @@ +This example code creates an SDL window and renderer, and then clears the +window to a different color every frame, so you'll effectively get a window +that's smoothly fading between colors. diff --git a/examples/renderer/02-primitives/README.txt b/examples/renderer/02-primitives/README.txt new file mode 100644 index 000000000..1e2bfce8b --- /dev/null +++ b/examples/renderer/02-primitives/README.txt @@ -0,0 +1,3 @@ +This example creates an SDL window and renderer, and then draws some lines, +rectangles and points to it every frame. + diff --git a/examples/renderer/02-primitives/renderer-primitives.c b/examples/renderer/02-primitives/renderer-primitives.c index 9bb8f079f..e2021e885 100644 --- a/examples/renderer/02-primitives/renderer-primitives.c +++ b/examples/renderer/02-primitives/renderer-primitives.c @@ -1,6 +1,6 @@ /* - * This example code creates an SDL window and renderer, and then draws a few - * lines and rectangles to it every frame. + * This example creates an SDL window and renderer, and then draws some lines, + * rectangles and points to it every frame. * * This code is public domain. Feel free to use it for any purpose! */ diff --git a/examples/template.html b/examples/template.html index 902f0ff49..c1284e2b7 100644 --- a/examples/template.html +++ b/examples/template.html @@ -201,6 +201,7 @@ if (text) console.error('[post-exception status] ' + text); }; }; + @print_description@