From 64f2d5695256ecfd51a6bc183bf806442d0f97ee Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 19 May 2015 09:36:20 +0200 Subject: [PATCH] fixed displaying frames per second (debug mode only) --- src/game.c | 38 +++++++++++++++++++------------------- src/tools.c | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/game.c b/src/game.c index 49acec5b..2be5985f 100644 --- a/src/game.c +++ b/src/game.c @@ -11202,6 +11202,25 @@ void GameActions() CheckLevelTime(); AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */ + + if (options.debug) /* calculate frames per second */ + { + static unsigned int fps_counter = 0; + static int fps_frames = 0; + unsigned int fps_delay_ms = Counter() - fps_counter; + + fps_frames++; + + if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */ + { + global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms; + + fps_frames = 0; + fps_counter = Counter(); + } + + redraw_mask |= REDRAW_FPS; + } } void GameActions_EM_Main() @@ -11735,25 +11754,6 @@ void GameActions_RND() DrawAllPlayers(); PlayAllPlayersSound(); - if (options.debug) /* calculate frames per second */ - { - static unsigned int fps_counter = 0; - static int fps_frames = 0; - unsigned int fps_delay_ms = Counter() - fps_counter; - - fps_frames++; - - if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */ - { - global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms; - - fps_frames = 0; - fps_counter = Counter(); - } - - redraw_mask |= REDRAW_FPS; - } - if (local_player->show_envelope != 0 && local_player->MovPos == 0) { ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1); diff --git a/src/tools.c b/src/tools.c index 39a0d681..0813343d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -419,6 +419,18 @@ void BlitScreenToBitmap(Bitmap *target_bitmap) redraw_mask |= REDRAW_FIELD; } +void DrawFramesPerSecond() +{ + char text[100]; + int font_nr = FONT_TEXT_2; + int font_width = getFontWidth(font_nr); + + sprintf(text, "%04.1f fps", global.frames_per_second); + + DrawTextExt(backbuffer, WIN_XSIZE - font_width * strlen(text), 0, text, + font_nr, BLIT_OPAQUE); +} + void BackToFront() { if (redraw_mask == REDRAW_NONE) @@ -431,6 +443,10 @@ void BackToFront() // draw masked border to all viewports, if defined DrawMaskedBorder(redraw_mask); + // draw frames per second (only if debug mode is enabled) + if (redraw_mask & REDRAW_FPS) + DrawFramesPerSecond(); + // redraw complete window if both playfield and (some) doors need redraw if (redraw_mask & REDRAW_FIELD && redraw_mask & REDRAW_DOORS) redraw_mask = REDRAW_ALL; -- 2.34.1