test/testscale.c
changeset 9278 8900afb78a19
parent 8149 681eb46b8ac4
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 #define WINDOW_WIDTH    640
    24 #define WINDOW_WIDTH    640
    21 #define WINDOW_HEIGHT   480
    25 #define WINDOW_HEIGHT   480
    28     SDL_Texture *background;
    32     SDL_Texture *background;
    29     SDL_Texture *sprite;
    33     SDL_Texture *sprite;
    30     SDL_Rect sprite_rect;
    34     SDL_Rect sprite_rect;
    31     int scale_direction;
    35     int scale_direction;
    32 } DrawState;
    36 } DrawState;
       
    37 
       
    38 DrawState *drawstates;
       
    39 int done;
    33 
    40 
    34 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    41 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    35 static void
    42 static void
    36 quit(int rc)
    43 quit(int rc)
    37 {
    44 {
   118 
   125 
   119     /* Update the screen! */
   126     /* Update the screen! */
   120     SDL_RenderPresent(s->renderer);
   127     SDL_RenderPresent(s->renderer);
   121 }
   128 }
   122 
   129 
       
   130 void
       
   131 loop()
       
   132 {
       
   133     int i;
       
   134     SDL_Event event;
       
   135 
       
   136     /* Check for events */
       
   137     while (SDL_PollEvent(&event)) {
       
   138         SDLTest_CommonEvent(state, &event, &done);
       
   139     }
       
   140     for (i = 0; i < state->num_windows; ++i) {
       
   141         if (state->windows[i] == NULL)
       
   142             continue;
       
   143         Draw(&drawstates[i]);
       
   144     }
       
   145 }
       
   146 
   123 int
   147 int
   124 main(int argc, char *argv[])
   148 main(int argc, char *argv[])
   125 {
   149 {
   126     DrawState *drawstates;
   150     int i;
   127     int i, done;
       
   128     SDL_Event event;
       
   129     int frames;
   151     int frames;
   130     Uint32 then, now;
   152     Uint32 then, now;
   131 
   153 
   132     /* Enable standard application logging */
   154     /* Enable standard application logging */
   133     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   155     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   169 
   191 
   170     /* Main render loop */
   192     /* Main render loop */
   171     frames = 0;
   193     frames = 0;
   172     then = SDL_GetTicks();
   194     then = SDL_GetTicks();
   173     done = 0;
   195     done = 0;
       
   196 
       
   197 #ifdef __EMSCRIPTEN__
       
   198     emscripten_set_main_loop(loop, 0, 1);
       
   199 #else
   174     while (!done) {
   200     while (!done) {
   175         /* Check for events */
       
   176         ++frames;
   201         ++frames;
   177         while (SDL_PollEvent(&event)) {
   202         loop();
   178             SDLTest_CommonEvent(state, &event, &done);
   203     }
   179         }
   204 #endif
   180         for (i = 0; i < state->num_windows; ++i) {
       
   181             if (state->windows[i] == NULL)
       
   182                 continue;
       
   183             Draw(&drawstates[i]);
       
   184         }
       
   185     }
       
   186 
   205 
   187     /* Print out some timing information */
   206     /* Print out some timing information */
   188     now = SDL_GetTicks();
   207     now = SDL_GetTicks();
   189     if (now > then) {
   208     if (now > then) {
   190         double fps = ((double) frames * 1000) / (now - then);
   209         double fps = ((double) frames * 1000) / (now - then);