test/teststreaming.c
changeset 9278 8900afb78a19
parent 9101 f0c55792deed
child 9607 7746ab058d12
     1.1 --- a/test/teststreaming.c	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/test/teststreaming.c	Thu Dec 18 00:19:52 2014 -0500
     1.3 @@ -18,6 +18,10 @@
     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.h"
    1.12  
    1.13  #define MOOSEPIC_W 64
    1.14 @@ -52,6 +56,11 @@
    1.15  
    1.16  Uint8 MooseFrames[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE];
    1.17  
    1.18 +SDL_Renderer *renderer;
    1.19 +int frame;
    1.20 +SDL_Texture *MooseTexture;
    1.21 +SDL_bool done = SDL_FALSE;
    1.22 +
    1.23  void quit(int rc)
    1.24  {
    1.25      SDL_Quit();
    1.26 @@ -82,16 +91,37 @@
    1.27      SDL_UnlockTexture(texture);
    1.28  }
    1.29  
    1.30 +void
    1.31 +loop()
    1.32 +{
    1.33 +    SDL_Event event;
    1.34 +
    1.35 +    while (SDL_PollEvent(&event)) {
    1.36 +        switch (event.type) {
    1.37 +        case SDL_KEYDOWN:
    1.38 +            if (event.key.keysym.sym == SDLK_ESCAPE) {
    1.39 +                done = SDL_TRUE;
    1.40 +            }
    1.41 +            break;
    1.42 +        case SDL_QUIT:
    1.43 +            done = SDL_TRUE;
    1.44 +            break;
    1.45 +        }
    1.46 +    }
    1.47 +
    1.48 +    frame = (frame + 1) % MOOSEFRAMES_COUNT;
    1.49 +    UpdateTexture(MooseTexture, frame);
    1.50 +
    1.51 +    SDL_RenderClear(renderer);
    1.52 +    SDL_RenderCopy(renderer, MooseTexture, NULL, NULL);
    1.53 +    SDL_RenderPresent(renderer);
    1.54 +}
    1.55 +
    1.56  int
    1.57  main(int argc, char **argv)
    1.58  {
    1.59      SDL_Window *window;
    1.60 -    SDL_Renderer *renderer;
    1.61      SDL_RWops *handle;
    1.62 -    SDL_Texture *MooseTexture;
    1.63 -    SDL_Event event;
    1.64 -    SDL_bool done = SDL_FALSE;
    1.65 -    int frame;
    1.66  
    1.67  	/* Enable standard application logging */
    1.68      SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.69 @@ -136,27 +166,15 @@
    1.70  
    1.71      /* Loop, waiting for QUIT or the escape key */
    1.72      frame = 0;
    1.73 +
    1.74 +#ifdef __EMSCRIPTEN__
    1.75 +    emscripten_set_main_loop(loop, 0, 1);
    1.76 +#else
    1.77      while (!done) {
    1.78 -        while (SDL_PollEvent(&event)) {
    1.79 -            switch (event.type) {
    1.80 -            case SDL_KEYDOWN:
    1.81 -                if (event.key.keysym.sym == SDLK_ESCAPE) {
    1.82 -                    done = SDL_TRUE;
    1.83 -                }
    1.84 -                break;
    1.85 -            case SDL_QUIT:
    1.86 -                done = SDL_TRUE;
    1.87 -                break;
    1.88 -            }
    1.89 +        loop();
    1.90          }
    1.91 -
    1.92 -        frame = (frame + 1) % MOOSEFRAMES_COUNT;
    1.93 -        UpdateTexture(MooseTexture, frame);
    1.94 +#endif
    1.95  
    1.96 -        SDL_RenderClear(renderer);
    1.97 -        SDL_RenderCopy(renderer, MooseTexture, NULL, NULL);
    1.98 -        SDL_RenderPresent(renderer);
    1.99 -    }
   1.100      SDL_DestroyRenderer(renderer);
   1.101  
   1.102      quit(0);