test/testspriteminimal.c
changeset 9278 8900afb78a19
parent 8149 681eb46b8ac4
child 9607 7746ab058d12
--- a/test/testspriteminimal.c	Sat Dec 13 02:33:52 2014 -0500
+++ b/test/testspriteminimal.c	Thu Dec 18 00:19:52 2014 -0500
@@ -15,6 +15,10 @@
 #include <stdio.h>
 #include <time.h>
 
+#ifdef __EMSCRIPTEN__
+#include <emscripten/emscripten.h>
+#endif
+
 #include "SDL.h"
 
 #define WINDOW_WIDTH    640
@@ -27,6 +31,9 @@
 static SDL_Rect velocities[NUM_SPRITES];
 static int sprite_w, sprite_h;
 
+SDL_Renderer *renderer;
+int done;
+
 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
 static void
 quit(int rc)
@@ -118,13 +125,25 @@
     SDL_RenderPresent(renderer);
 }
 
+void loop()
+{
+    SDL_Event event;
+
+    /* Check for events */
+    while (SDL_PollEvent(&event)) {
+        if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN) {
+            done = 1;
+        }
+    }
+    MoveSprites(renderer, sprite);
+}
+
 int
 main(int argc, char *argv[])
 {
     SDL_Window *window;
-    SDL_Renderer *renderer;
-    int i, done;
-    SDL_Event event;
+    int i;
+
 
 	/* Enable standard application logging */
     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -154,16 +173,14 @@
 
     /* Main render loop */
     done = 0;
+
+#ifdef __EMSCRIPTEN__
+    emscripten_set_main_loop(loop, 0, 1);
+#else
     while (!done) {
-        /* Check for events */
-        while (SDL_PollEvent(&event)) {
-            if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN) {
-                done = 1;
-            }
+        loop();
         }
-        MoveSprites(renderer, sprite);
-    }
-
+#endif
     quit(0);
 
     return 0; /* to prevent compiler warning */