testsprite2: report average FPS in blocks of five seconds.

This makes the reporting more accurate, vs startup inefficiencies and other
scheduling burps.
This commit is contained in:
Ryan C. Gordon 2018-09-20 15:41:57 -04:00
parent a2f7af9a47
commit e0cc19f2d8

View file

@ -37,6 +37,8 @@ static SDL_Rect *positions;
static SDL_Rect *velocities; static SDL_Rect *velocities;
static int sprite_w, sprite_h; static int sprite_w, sprite_h;
static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND; static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
static Uint32 next_fps_check, frames;
static const Uint32 fps_check_delay = 5000;
/* Number of iterations to move sprites - used for visual tests. */ /* Number of iterations to move sprites - used for visual tests. */
/* -1: infinite random moves (default); >=0: enables N deterministic moves */ /* -1: infinite random moves (default); >=0: enables N deterministic moves */
@ -244,6 +246,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
void void
loop() loop()
{ {
Uint32 now;
int i; int i;
SDL_Event event; SDL_Event event;
@ -261,13 +264,24 @@ 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;
Uint64 seed; Uint64 seed;
const char *icon = "icon.bmp"; const char *icon = "icon.bmp";
@ -384,24 +398,17 @@ 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
/* 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);
}
quit(0); quit(0);
return 0; return 0;
} }