examples: Print a description of the program to the console on startup.

This commit is contained in:
Ryan C. Gordon 2024-07-30 12:22:39 -04:00
parent a6407e88da
commit 6a25e94472
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
11 changed files with 38 additions and 11 deletions

View File

@ -103,6 +103,19 @@ sub handle_example_dir {
my $jsdst = "$dst/$jsfname"; my $jsdst = "$dst/$jsfname";
my $wasmdst = "$dst/$wasmfname"; 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_mkdir($dst);
do_copy($jssrc, $jsdst); do_copy($jssrc, $jsdst);
do_copy($wasmsrc, $wasmdst); do_copy($wasmsrc, $wasmdst);
@ -142,6 +155,7 @@ sub handle_example_dir {
s/\@example_name\@/$example/g; s/\@example_name\@/$example/g;
s/\@javascript_file\@/$jsfname/g; s/\@javascript_file\@/$jsfname/g;
s/\@htmlified_source_code\@/$htmlified_source_code/g; s/\@htmlified_source_code\@/$htmlified_source_code/g;
s/\@print_description\@/$print_description/g;
$html .= $_; $html .= $_;
} }
close($htmltemplate); close($htmltemplate);

View File

@ -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.

View File

@ -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_OpenAudioDeviceStream starts the device paused. You have to tell it to start! */
SDL_ResumeAudioStreamDevice(stream); 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! */ return SDL_APP_CONTINUE; /* carry on with the program! */
} }

View File

@ -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.

View File

@ -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_OpenAudioDeviceStream starts the device paused. You have to tell it to start! */
SDL_ResumeAudioStreamDevice(stream); 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! */ return SDL_APP_CONTINUE; /* carry on with the program! */
} }

View File

@ -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.

View File

@ -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_OpenAudioDeviceStream starts the device paused. You have to tell it to start! */
SDL_ResumeAudioStreamDevice(stream); 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! */ return SDL_APP_CONTINUE; /* carry on with the program! */
} }

View File

@ -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.

View File

@ -0,0 +1,3 @@
This example creates an SDL window and renderer, and then draws some lines,
rectangles and points to it every frame.

View File

@ -1,6 +1,6 @@
/* /*
* This example code creates an SDL window and renderer, and then draws a few * This example creates an SDL window and renderer, and then draws some lines,
* lines and rectangles to it every frame. * rectangles and points to it every frame.
* *
* This code is public domain. Feel free to use it for any purpose! * This code is public domain. Feel free to use it for any purpose!
*/ */

View File

@ -201,6 +201,7 @@
if (text) console.error('[post-exception status] ' + text); if (text) console.error('[post-exception status] ' + text);
}; };
}; };
@print_description@
</script> </script>
<script async type="text/javascript" src="@javascript_file@"></script> <script async type="text/javascript" src="@javascript_file@"></script>
</body> </body>