test/testwm2.c
changeset 9278 8900afb78a19
parent 8149 681eb46b8ac4
child 9607 7746ab058d12
     1.1 --- a/test/testwm2.c	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/test/testwm2.c	Thu Dec 18 00:19:52 2014 -0500
     1.3 @@ -13,22 +13,16 @@
     1.4  #include <stdlib.h>
     1.5  #include <stdio.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  static SDLTest_CommonState *state;
    1.14 +int done;
    1.15  
    1.16 -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.17 -static void
    1.18 -quit(int rc)
    1.19 -{
    1.20 -    SDLTest_CommonQuit(state);
    1.21 -    exit(rc);
    1.22 -}
    1.23 -
    1.24 -int
    1.25 -main(int argc, char *argv[])
    1.26 -{
    1.27 -    static const char *cursorNames[] = {
    1.28 +static const char *cursorNames[] = {
    1.29          "arrow",
    1.30          "ibeam",
    1.31          "wait",
    1.32 @@ -41,44 +35,22 @@
    1.33          "sizeALL",
    1.34          "NO",
    1.35          "hand",
    1.36 -    };
    1.37 +};
    1.38 +int system_cursor = -1;
    1.39 +SDL_Cursor *cursor = NULL;
    1.40  
    1.41 -    int i, done;
    1.42 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.43 +static void
    1.44 +quit(int rc)
    1.45 +{
    1.46 +    SDLTest_CommonQuit(state);
    1.47 +    exit(rc);
    1.48 +}
    1.49 +
    1.50 +void
    1.51 +loop()
    1.52 +{
    1.53      SDL_Event event;
    1.54 -    int system_cursor = -1;
    1.55 -    SDL_Cursor *cursor = NULL;
    1.56 -
    1.57 -	/* Enable standard application logging */
    1.58 -    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.59 -
    1.60 -    SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
    1.61 -
    1.62 -    /* Initialize test framework */
    1.63 -    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    1.64 -    if (!state) {
    1.65 -        return 1;
    1.66 -    }
    1.67 -    state->skip_renderer = SDL_TRUE;
    1.68 -    for (i = 1; i < argc;) {
    1.69 -        int consumed;
    1.70 -
    1.71 -        consumed = SDLTest_CommonArg(state, i);
    1.72 -        if (consumed == 0) {
    1.73 -            consumed = -1;
    1.74 -        }
    1.75 -        if (consumed < 0) {
    1.76 -            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
    1.77 -            quit(1);
    1.78 -        }
    1.79 -        i += consumed;
    1.80 -    }
    1.81 -    if (!SDLTest_CommonInit(state)) {
    1.82 -        quit(2);
    1.83 -    }
    1.84 -
    1.85 -    /* Main render loop */
    1.86 -    done = 0;
    1.87 -    while (!done) {
    1.88          /* Check for events */
    1.89          while (SDL_PollEvent(&event)) {
    1.90              SDLTest_CommonEvent(state, &event, &done);
    1.91 @@ -128,7 +100,50 @@
    1.92                  }
    1.93              }
    1.94          }
    1.95 +}
    1.96 +
    1.97 +int
    1.98 +main(int argc, char *argv[])
    1.99 +{
   1.100 +    int i;
   1.101 +
   1.102 +	/* Enable standard application logging */
   1.103 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   1.104 +
   1.105 +    SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
   1.106 +
   1.107 +    /* Initialize test framework */
   1.108 +    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
   1.109 +    if (!state) {
   1.110 +        return 1;
   1.111      }
   1.112 +    state->skip_renderer = SDL_TRUE;
   1.113 +    for (i = 1; i < argc;) {
   1.114 +        int consumed;
   1.115 +
   1.116 +        consumed = SDLTest_CommonArg(state, i);
   1.117 +        if (consumed == 0) {
   1.118 +            consumed = -1;
   1.119 +        }
   1.120 +        if (consumed < 0) {
   1.121 +            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
   1.122 +            quit(1);
   1.123 +        }
   1.124 +        i += consumed;
   1.125 +    }
   1.126 +    if (!SDLTest_CommonInit(state)) {
   1.127 +        quit(2);
   1.128 +    }
   1.129 +
   1.130 +    /* Main render loop */
   1.131 +    done = 0;
   1.132 +#ifdef __EMSCRIPTEN__
   1.133 +    emscripten_set_main_loop(loop, 0, 1);
   1.134 +#else
   1.135 +    while (!done) {
   1.136 +        loop();
   1.137 +    }
   1.138 +#endif
   1.139      SDL_FreeCursor(cursor);
   1.140  
   1.141      quit(0);