mirror of
				https://github.com/libsdl-org/SDL.git
				synced 2025-11-04 09:44:35 +00:00 
			
		
		
		
	testdraw2: display FPS similarly to testsprit2. fix helper syntax
This commit is contained in:
		@@ -32,6 +32,8 @@ static int cycle_direction = 1;
 | 
				
			|||||||
static int current_alpha = 255;
 | 
					static int current_alpha = 255;
 | 
				
			||||||
static int current_color = 255;
 | 
					static int current_color = 255;
 | 
				
			||||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
 | 
					static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
 | 
				
			||||||
 | 
					static Uint32 next_fps_check, frames;
 | 
				
			||||||
 | 
					static const Uint32 fps_check_delay = 5000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int done;
 | 
					int done;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -178,6 +180,7 @@ DrawRects(SDL_Renderer * renderer)
 | 
				
			|||||||
void
 | 
					void
 | 
				
			||||||
loop()
 | 
					loop()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    Uint32 now;
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    SDL_Event event;
 | 
					    SDL_Event event;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -203,13 +206,23 @@ loop()
 | 
				
			|||||||
        emscripten_cancel_main_loop();
 | 
					        emscripten_cancel_main_loop();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					    frames++;
 | 
				
			||||||
 | 
					    now = SDL_GetTicks();
 | 
				
			||||||
 | 
					    if (SDL_TICKS_PASSED(now, next_fps_check)) {
 | 
				
			||||||
 | 
					        /* Print out some timing information */
 | 
				
			||||||
 | 
					        const Uint32 then = next_fps_check - fps_check_delay;
 | 
				
			||||||
 | 
					        const double fps = ((double) frames * 1000) / (now - then);
 | 
				
			||||||
 | 
					        SDL_Log("%2.2f frames per second\n", fps);
 | 
				
			||||||
 | 
					        next_fps_check = now + fps_check_delay;
 | 
				
			||||||
 | 
					        frames = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
main(int argc, char *argv[])
 | 
					main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    Uint32 then, now, frames;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Enable standard application logging */
 | 
					    /* Enable standard application logging */
 | 
				
			||||||
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
 | 
					    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
 | 
				
			||||||
@@ -256,7 +269,12 @@ main(int argc, char *argv[])
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (consumed < 0) {
 | 
					        if (consumed < 0) {
 | 
				
			||||||
            static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", NULL };
 | 
					            static const char *options[] = { 
 | 
				
			||||||
 | 
					                "[--blend none|blend|add|mod]", 
 | 
				
			||||||
 | 
					                "[--cyclecolor]",
 | 
				
			||||||
 | 
					                "[--cyclealpha]",
 | 
				
			||||||
 | 
					                "[num_objects]",
 | 
				
			||||||
 | 
					                NULL };
 | 
				
			||||||
            SDLTest_CommonLogUsage(state, argv[0], options);
 | 
					            SDLTest_CommonLogUsage(state, argv[0], options);
 | 
				
			||||||
            return 1;
 | 
					            return 1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -278,14 +296,13 @@ main(int argc, char *argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /* Main render loop */
 | 
					    /* Main render loop */
 | 
				
			||||||
    frames = 0;
 | 
					    frames = 0;
 | 
				
			||||||
    then = SDL_GetTicks();
 | 
					    next_fps_check = SDL_GetTicks() + fps_check_delay;
 | 
				
			||||||
    done = 0;
 | 
					    done = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __EMSCRIPTEN__
 | 
					#ifdef __EMSCRIPTEN__
 | 
				
			||||||
    emscripten_set_main_loop(loop, 0, 1);
 | 
					    emscripten_set_main_loop(loop, 0, 1);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    while (!done) {
 | 
					    while (!done) {
 | 
				
			||||||
        ++frames;
 | 
					 | 
				
			||||||
        loop();
 | 
					        loop();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@@ -293,12 +310,6 @@ main(int argc, char *argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    SDLTest_CommonQuit(state);
 | 
					    SDLTest_CommonQuit(state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Print out some timing information */
 | 
					 | 
				
			||||||
    now = SDL_GetTicks();
 | 
					 | 
				
			||||||
    if (now > then) {
 | 
					 | 
				
			||||||
        double fps = ((double) frames * 1000) / (now - then);
 | 
					 | 
				
			||||||
        SDL_Log("%2.2f frames per second\n", fps);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user