test/testrelative.c
changeset 9278 8900afb78a19
parent 8724 9fa8abe556d7
child 9333 de02c2d8a06f
     1.1 --- a/test/testrelative.c	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/test/testrelative.c	Thu Dec 18 00:19:52 2014 -0500
     1.3 @@ -18,8 +18,14 @@
     1.4  
     1.5  #include "SDL_test_common.h"
     1.6  
     1.7 +#ifdef __EMSCRIPTEN__
     1.8 +#include <emscripten/emscripten.h>
     1.9 +#endif
    1.10  
    1.11  static SDLTest_CommonState *state;
    1.12 +int i, done;
    1.13 +SDL_Rect rect;
    1.14 +SDL_Event event;
    1.15  
    1.16  static void
    1.17  DrawRects(SDL_Renderer * renderer, SDL_Rect * rect)
    1.18 @@ -28,12 +34,36 @@
    1.19      SDL_RenderFillRect(renderer, rect);
    1.20  }
    1.21  
    1.22 +static void
    1.23 +loop(){
    1.24 +    /* Check for events */
    1.25 +    while (SDL_PollEvent(&event)) {
    1.26 +        SDLTest_CommonEvent(state, &event, &done);
    1.27 +        switch(event.type) {
    1.28 +        case SDL_MOUSEMOTION:
    1.29 +            {
    1.30 +                rect.x += event.motion.xrel;
    1.31 +                rect.y += event.motion.yrel;
    1.32 +            }
    1.33 +            break;
    1.34 +        }
    1.35 +    }
    1.36 +    for (i = 0; i < state->num_windows; ++i) {
    1.37 +        SDL_Renderer *renderer = state->renderers[i];
    1.38 +        if (state->windows[i] == NULL)
    1.39 +            continue;
    1.40 +        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.41 +        SDL_RenderClear(renderer);
    1.42 +
    1.43 +        DrawRects(renderer, &rect);
    1.44 +
    1.45 +        SDL_RenderPresent(renderer);
    1.46 +    }
    1.47 +}
    1.48 +
    1.49  int
    1.50  main(int argc, char *argv[])
    1.51  {
    1.52 -    int i, done;
    1.53 -    SDL_Rect rect;
    1.54 -    SDL_Event event;
    1.55  
    1.56      /* Enable standard application logging */
    1.57      SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.58 @@ -69,32 +99,13 @@
    1.59      rect.h = 10;
    1.60      /* Main render loop */
    1.61      done = 0;
    1.62 +#ifdef __EMSCRIPTEN__
    1.63 +    emscripten_set_main_loop(loop, 0, 1);
    1.64 +#else
    1.65      while (!done) {
    1.66 -        /* Check for events */
    1.67 -        while (SDL_PollEvent(&event)) {
    1.68 -            SDLTest_CommonEvent(state, &event, &done);
    1.69 -            switch(event.type) {
    1.70 -                case SDL_MOUSEMOTION:
    1.71 -                {
    1.72 -                    rect.x += event.motion.xrel;
    1.73 -                    rect.y += event.motion.yrel;
    1.74 -                }
    1.75 -                break;
    1.76 -            }
    1.77 +        loop();
    1.78          }
    1.79 -        for (i = 0; i < state->num_windows; ++i) {
    1.80 -            SDL_Renderer *renderer = state->renderers[i];
    1.81 -            if (state->windows[i] == NULL)
    1.82 -                continue;
    1.83 -            SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.84 -            SDL_RenderClear(renderer);
    1.85 -
    1.86 -            DrawRects(renderer, &rect);
    1.87 -
    1.88 -            SDL_RenderPresent(renderer);
    1.89 -        }
    1.90 -    }
    1.91 -
    1.92 +#endif
    1.93      SDLTest_CommonQuit(state);
    1.94      return 0;
    1.95  }