test/testscale.c
changeset 9278 8900afb78a19
parent 8149 681eb46b8ac4
child 9607 7746ab058d12
     1.1 --- a/test/testscale.c	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/test/testscale.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  #define WINDOW_WIDTH    640
    1.14 @@ -31,6 +35,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 @@ -120,12 +127,27 @@
    1.25      SDL_RenderPresent(s->renderer);
    1.26  }
    1.27  
    1.28 +void
    1.29 +loop()
    1.30 +{
    1.31 +    int i;
    1.32 +    SDL_Event event;
    1.33 +
    1.34 +    /* Check for events */
    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 @@ -171,18 +193,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 -        }
    1.69 -        for (i = 0; i < state->num_windows; ++i) {
    1.70 -            if (state->windows[i] == NULL)
    1.71 -                continue;
    1.72 -            Draw(&drawstates[i]);
    1.73 -        }
    1.74 +        loop();
    1.75      }
    1.76 +#endif
    1.77  
    1.78      /* Print out some timing information */
    1.79      now = SDL_GetTicks();