test/testrendercopyex.c
changeset 9278 8900afb78a19
parent 8851 a7cfe554d337
child 9607 7746ab058d12
equal deleted inserted replaced
9277:f0bd40782fc7 9278:8900afb78a19
    12 /* Simple program:  Move N sprites around on the screen as fast as possible */
    12 /* Simple program:  Move N sprites around on the screen as fast as possible */
    13 
    13 
    14 #include <stdlib.h>
    14 #include <stdlib.h>
    15 #include <stdio.h>
    15 #include <stdio.h>
    16 #include <time.h>
    16 #include <time.h>
       
    17 
       
    18 #ifdef __EMSCRIPTEN__
       
    19 #include <emscripten/emscripten.h>
       
    20 #endif
    17 
    21 
    18 #include "SDL_test_common.h"
    22 #include "SDL_test_common.h"
    19 
    23 
    20 
    24 
    21 static SDLTest_CommonState *state;
    25 static SDLTest_CommonState *state;
    26     SDL_Texture *background;
    30     SDL_Texture *background;
    27     SDL_Texture *sprite;
    31     SDL_Texture *sprite;
    28     SDL_Rect sprite_rect;
    32     SDL_Rect sprite_rect;
    29     int scale_direction;
    33     int scale_direction;
    30 } DrawState;
    34 } DrawState;
       
    35 
       
    36 DrawState *drawstates;
       
    37 int done;
    31 
    38 
    32 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    39 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    33 static void
    40 static void
    34 quit(int rc)
    41 quit(int rc)
    35 {
    42 {
   128     /* Update the screen! */
   135     /* Update the screen! */
   129     SDL_RenderPresent(s->renderer);
   136     SDL_RenderPresent(s->renderer);
   130     /* SDL_Delay(10); */
   137     /* SDL_Delay(10); */
   131 }
   138 }
   132 
   139 
       
   140 void loop()
       
   141 {
       
   142     int i;
       
   143     SDL_Event event;
       
   144 
       
   145     /* Check for events */
       
   146 
       
   147     while (SDL_PollEvent(&event)) {
       
   148         SDLTest_CommonEvent(state, &event, &done);
       
   149     }
       
   150     for (i = 0; i < state->num_windows; ++i) {
       
   151         if (state->windows[i] == NULL)
       
   152             continue;
       
   153         Draw(&drawstates[i]);
       
   154     }
       
   155 }
       
   156 
   133 int
   157 int
   134 main(int argc, char *argv[])
   158 main(int argc, char *argv[])
   135 {
   159 {
   136     DrawState *drawstates;
   160     int i;
   137     int i, done;
       
   138     SDL_Event event;
       
   139     int frames;
   161     int frames;
   140     Uint32 then, now;
   162     Uint32 then, now;
   141 
   163 
   142 	/* Enable standard application logging */
   164 	/* Enable standard application logging */
   143     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   165     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   179 
   201 
   180     /* Main render loop */
   202     /* Main render loop */
   181     frames = 0;
   203     frames = 0;
   182     then = SDL_GetTicks();
   204     then = SDL_GetTicks();
   183     done = 0;
   205     done = 0;
       
   206 
       
   207 #ifdef __EMSCRIPTEN__
       
   208     emscripten_set_main_loop(loop, 0, 1);
       
   209 #else
   184     while (!done) {
   210     while (!done) {
   185         /* Check for events */
       
   186         ++frames;
   211         ++frames;
   187         while (SDL_PollEvent(&event)) {
   212         loop();
   188             SDLTest_CommonEvent(state, &event, &done);
   213         }
   189         }
   214 #endif
   190         for (i = 0; i < state->num_windows; ++i) {
       
   191             if (state->windows[i] == NULL)
       
   192                 continue;
       
   193             Draw(&drawstates[i]);
       
   194         }
       
   195     }
       
   196 
       
   197     /* Print out some timing information */
   215     /* Print out some timing information */
   198     now = SDL_GetTicks();
   216     now = SDL_GetTicks();
   199     if (now > then) {
   217     if (now > then) {
   200         double fps = ((double) frames * 1000) / (now - then);
   218         double fps = ((double) frames * 1000) / (now - then);
   201         SDL_Log("%2.2f frames per second\n", fps);
   219         SDL_Log("%2.2f frames per second\n", fps);