diff options
author | Ryan C. Gordon <icculus@icculus.org> | 2014-12-18 00:19:52 -0500 |
---|---|---|
committer | Ryan C. Gordon <icculus@icculus.org> | 2014-12-18 00:19:52 -0500 |
commit | a9626cb76ed66437d49650941bf4a407929d92ba (patch) | |
tree | e56028e303856804a8bf85f64ce541515738bd8a /test/testsprite2.c | |
parent | 9168cf2eccd605281f8882f7b80ed782046bad0a (diff) |
Initial merge of Emscripten port!
With this commit, you can compile SDL2 with Emscripten
( http://emscripten.org/ ), and make your SDL-based C/C++ program
into a web app.
This port was due to the efforts of several people, including: Charlie Birks,
Sathyanarayanan Gunasekaran, Jukka Jylänki, Alon Zakai, Edward Rudd,
Bruce Mitchener, and Martin Gerhardy. (Thanks, everyone!)
Diffstat (limited to 'test/testsprite2.c')
-rw-r--r-- | test/testsprite2.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/test/testsprite2.c b/test/testsprite2.c index 945280f9fb..17a9cd5f4f 100644 --- a/test/testsprite2.c +++ b/test/testsprite2.c @@ -15,6 +15,10 @@ #include <stdio.h> #include <time.h> +#ifdef __EMSCRIPTEN__ +#include <emscripten/emscripten.h> +#endif + #include "SDL_test.h" #include "SDL_test_common.h" @@ -38,6 +42,8 @@ static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND; /* -1: infinite random moves (default); >=0: enables N deterministic moves */ static int iterations = -1; +int done; + /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ static void quit(int rc) @@ -230,11 +236,27 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite) SDL_RenderPresent(renderer); } +void +loop() +{ + int i; + SDL_Event event; + + /* Check for events */ + while (SDL_PollEvent(&event)) { + SDLTest_CommonEvent(state, &event, &done); + } + for (i = 0; i < state->num_windows; ++i) { + if (state->windows[i] == NULL) + continue; + MoveSprites(state->renderers[i], sprites[i]); + } +} + int main(int argc, char *argv[]) { - int i, done; - SDL_Event event; + int i; Uint32 then, now, frames; Uint64 seed; const char *icon = "icon.bmp"; @@ -351,18 +373,15 @@ main(int argc, char *argv[]) frames = 0; then = SDL_GetTicks(); done = 0; + +#ifdef __EMSCRIPTEN__ + emscripten_set_main_loop(loop, 0, 1); +#else while (!done) { - /* Check for events */ ++frames; - while (SDL_PollEvent(&event)) { - SDLTest_CommonEvent(state, &event, &done); - } - for (i = 0; i < state->num_windows; ++i) { - if (state->windows[i] == NULL) - continue; - MoveSprites(state->renderers[i], sprites[i]); - } + loop(); } +#endif /* Print out some timing information */ now = SDL_GetTicks(); |