test/testsprite2.c
branchSDL-ryan-batching-renderer
changeset 12210 9f9dbcce30b3
parent 11811 5d94cb6b24d3
child 12503 806492103856
equal deleted inserted replaced
12209:042096b6e332 12210:9f9dbcce30b3
    35 static int current_color = 0;
    35 static int current_color = 0;
    36 static SDL_Rect *positions;
    36 static SDL_Rect *positions;
    37 static SDL_Rect *velocities;
    37 static SDL_Rect *velocities;
    38 static int sprite_w, sprite_h;
    38 static int sprite_w, sprite_h;
    39 static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
    39 static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
       
    40 static Uint32 next_fps_check, frames;
       
    41 static const Uint32 fps_check_delay = 5000;
    40 
    42 
    41 /* Number of iterations to move sprites - used for visual tests. */
    43 /* Number of iterations to move sprites - used for visual tests. */
    42 /* -1: infinite random moves (default); >=0: enables N deterministic moves */
    44 /* -1: infinite random moves (default); >=0: enables N deterministic moves */
    43 static int iterations = -1;
    45 static int iterations = -1;
    44 
    46 
   242 }
   244 }
   243 
   245 
   244 void
   246 void
   245 loop()
   247 loop()
   246 {
   248 {
       
   249     Uint32 now;
   247     int i;
   250     int i;
   248     SDL_Event event;
   251     SDL_Event event;
   249 
   252 
   250     /* Check for events */
   253     /* Check for events */
   251     while (SDL_PollEvent(&event)) {
   254     while (SDL_PollEvent(&event)) {
   259 #ifdef __EMSCRIPTEN__
   262 #ifdef __EMSCRIPTEN__
   260     if (done) {
   263     if (done) {
   261         emscripten_cancel_main_loop();
   264         emscripten_cancel_main_loop();
   262     }
   265     }
   263 #endif
   266 #endif
       
   267 
       
   268     frames++;
       
   269     now = SDL_GetTicks();
       
   270     if (SDL_TICKS_PASSED(now, next_fps_check)) {
       
   271         /* Print out some timing information */
       
   272         const Uint32 then = next_fps_check - fps_check_delay;
       
   273         const double fps = ((double) frames * 1000) / (now - then);
       
   274         SDL_Log("%2.2f frames per second\n", fps);
       
   275         next_fps_check = now + fps_check_delay;
       
   276         frames = 0;
       
   277     }
       
   278 
   264 }
   279 }
   265 
   280 
   266 int
   281 int
   267 main(int argc, char *argv[])
   282 main(int argc, char *argv[])
   268 {
   283 {
   269     int i;
   284     int i;
   270     Uint32 then, now, frames;
       
   271     Uint64 seed;
   285     Uint64 seed;
   272     const char *icon = "icon.bmp";
   286     const char *icon = "icon.bmp";
   273 
   287 
   274     /* Initialize parameters */
   288     /* Initialize parameters */
   275     num_sprites = NUM_SPRITES;
   289     num_sprites = NUM_SPRITES;
   382         }
   396         }
   383     }
   397     }
   384 
   398 
   385     /* Main render loop */
   399     /* Main render loop */
   386     frames = 0;
   400     frames = 0;
   387     then = SDL_GetTicks();
   401     next_fps_check = SDL_GetTicks() + fps_check_delay;
   388     done = 0;
   402     done = 0;
   389 
   403 
   390 #ifdef __EMSCRIPTEN__
   404 #ifdef __EMSCRIPTEN__
   391     emscripten_set_main_loop(loop, 0, 1);
   405     emscripten_set_main_loop(loop, 0, 1);
   392 #else
   406 #else
   393     while (!done) {
   407     while (!done) {
   394         ++frames;
       
   395         loop();
   408         loop();
   396     }
   409     }
   397 #endif
   410 #endif
   398 
   411 
   399     /* Print out some timing information */
       
   400     now = SDL_GetTicks();
       
   401     if (now > then) {
       
   402         double fps = ((double) frames * 1000) / (now - then);
       
   403         SDL_Log("%2.2f frames per second\n", fps);
       
   404     }
       
   405     quit(0);
   412     quit(0);
   406     return 0;
   413     return 0;
   407 }
   414 }
   408 
   415 
   409 /* vi: set ts=4 sw=4 expandtab: */
   416 /* vi: set ts=4 sw=4 expandtab: */