Преглед изворни кода

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

Ryan C. Gordon пре 8 месеци
родитељ
комит
6a25e94472

+ 14 - 0
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);

+ 5 - 0
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.

+ 0 - 3
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! */
 }
 

+ 5 - 0
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.

+ 0 - 3
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! */
 }
 

+ 5 - 0
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.
+

+ 0 - 3
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! */
 }
 

+ 3 - 0
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.

+ 3 - 0
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.
+

+ 2 - 2
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!
  */

+ 1 - 0
examples/template.html

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