test/testrendercopyex.c
changeset 9278 8900afb78a19
parent 8851 a7cfe554d337
child 9607 7746ab058d12
     1.1 --- a/test/testrendercopyex.c	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/test/testrendercopyex.c	Thu Dec 18 00:19:52 2014 -0500
     1.3 @@ -15,6 +15,10 @@
     1.4  #include <stdio.h>
     1.5  #include <time.h>
     1.6  
     1.7 +#ifdef __EMSCRIPTEN__
     1.8 +#include <emscripten/emscripten.h>
     1.9 +#endif
    1.10 +
    1.11  #include "SDL_test_common.h"
    1.12  
    1.13  
    1.14 @@ -29,6 +33,9 @@
    1.15      int scale_direction;
    1.16  } DrawState;
    1.17  
    1.18 +DrawState *drawstates;
    1.19 +int done;
    1.20 +
    1.21  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.22  static void
    1.23  quit(int rc)
    1.24 @@ -130,12 +137,27 @@
    1.25      /* SDL_Delay(10); */
    1.26  }
    1.27  
    1.28 +void loop()
    1.29 +{
    1.30 +    int i;
    1.31 +    SDL_Event event;
    1.32 +
    1.33 +    /* Check for events */
    1.34 +
    1.35 +    while (SDL_PollEvent(&event)) {
    1.36 +        SDLTest_CommonEvent(state, &event, &done);
    1.37 +    }
    1.38 +    for (i = 0; i < state->num_windows; ++i) {
    1.39 +        if (state->windows[i] == NULL)
    1.40 +            continue;
    1.41 +        Draw(&drawstates[i]);
    1.42 +    }
    1.43 +}
    1.44 +
    1.45  int
    1.46  main(int argc, char *argv[])
    1.47  {
    1.48 -    DrawState *drawstates;
    1.49 -    int i, done;
    1.50 -    SDL_Event event;
    1.51 +    int i;
    1.52      int frames;
    1.53      Uint32 then, now;
    1.54  
    1.55 @@ -181,19 +203,15 @@
    1.56      frames = 0;
    1.57      then = SDL_GetTicks();
    1.58      done = 0;
    1.59 +
    1.60 +#ifdef __EMSCRIPTEN__
    1.61 +    emscripten_set_main_loop(loop, 0, 1);
    1.62 +#else
    1.63      while (!done) {
    1.64 -        /* Check for events */
    1.65          ++frames;
    1.66 -        while (SDL_PollEvent(&event)) {
    1.67 -            SDLTest_CommonEvent(state, &event, &done);
    1.68 +        loop();
    1.69          }
    1.70 -        for (i = 0; i < state->num_windows; ++i) {
    1.71 -            if (state->windows[i] == NULL)
    1.72 -                continue;
    1.73 -            Draw(&drawstates[i]);
    1.74 -        }
    1.75 -    }
    1.76 -
    1.77 +#endif
    1.78      /* Print out some timing information */
    1.79      now = SDL_GetTicks();
    1.80      if (now > then) {