From d9f23fc1563a6ff05b57354ef91d393f556556a8 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Wed, 4 Aug 2021 19:15:25 +0200 Subject: [PATCH] Show FPS counter in its own top-right widget --- README | 1 - cgdoom/hu_stuff.c | 25 +++++++++++++++++++++++++ cgdoom/i_system.c | 15 +++++---------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/README b/README index 4e62d46..6e546b8 100644 --- a/README +++ b/README @@ -14,7 +14,6 @@ sources (GPL) and nDoom (GPLv2). See LICENSE. UI improvements TODO: -> Better keyboard layout (including more keys, eg. Run) => Edit messages accordingly ("press y"/etc) --> Figure out why blue key looks yellow in status bar WAD support TODO: -> Unmodified 1.9 shareware WAD works all the way through? diff --git a/cgdoom/hu_stuff.c b/cgdoom/hu_stuff.c index c719757..4f6917a 100644 --- a/cgdoom/hu_stuff.c +++ b/cgdoom/hu_stuff.c @@ -95,6 +95,12 @@ extern boolean automapactive; static boolean headsupactive = false; +/* CGDoom */ +static hu_stext_t w_fpscounter; +static boolean fpscounter_on; +int fpscounter_data = 0; +boolean fpscounteractive = false; + // // Builtin map names. // The actual names can be found in DStrings.h. @@ -222,6 +228,12 @@ void HU_Start(void) hu_font, HU_FONTSTART); + /* CGDoom: Create the FPS counter widget */ + HUlib_initSText(&w_fpscounter, + SCREENWIDTH-48, HU_MSGY, HU_MSGHEIGHT, + hu_font, + HU_FONTSTART, &fpscounter_on); + switch ( gamemode ) { case shareware: @@ -274,6 +286,8 @@ void HU_Drawer(void) { HUlib_drawSText(&w_message); + if (fpscounteractive) + HUlib_drawSText(&w_fpscounter); HUlib_drawIText(&w_chat); if (automapactive) HUlib_drawTextLine(&w_title, false); @@ -283,6 +297,8 @@ void HU_Drawer(void) void HU_Erase(void) { HUlib_eraseSText(&w_message); + if (fpscounteractive) + HUlib_eraseSText(&w_fpscounter); HUlib_eraseIText(&w_chat); HUlib_eraseTextLine(&w_title); @@ -316,6 +332,15 @@ void HU_Ticker(void) } } // else message_on = false; + + if (fpscounteractive) + { + /* Update FPS counter text */ + static char text[10]; + sprintf(text, "%d FPS", fpscounter_data); + HUlib_addMessageToSText(&w_fpscounter, 0, text); + fpscounter_on = true; + } } #define QUEUESIZE 128 diff --git a/cgdoom/i_system.c b/cgdoom/i_system.c index 3680089..d6f8366 100644 --- a/cgdoom/i_system.c +++ b/cgdoom/i_system.c @@ -329,7 +329,9 @@ void I_StartTic (void) { static KeyboardState st = { 0 }; - static int fps_show = 0; + extern boolean fpscounteractive; + extern int fpscounter_data; + /* Number of frames since FPS count started */ static int fps_frames = 0; /* Time when the FPS count started */ @@ -341,14 +343,7 @@ void I_StartTic (void) if(++fps_frames >= 16) { int now = RTC_GetTicks(); - int fps = (now == fps_ticks) ? -1 : 128 * fps_frames / (now - fps_ticks); - - if (fps_show) - { - static char message[16]; - sprintf(message, "%d FPS", fps); - players[consoleplayer].message = message; - } + fpscounter_data = (now == fps_ticks) ? -1 : 128 * fps_frames / (now - fps_ticks); fps_ticks = now; fps_frames = 0; @@ -373,7 +368,7 @@ void I_StartTic (void) if (KeycodePressed(st, next_st, KEYCODE_FD)) CGFreeMem(); if (KeycodePressed(st, next_st, KEYCODE_LEFTP)) - fps_show ^= 1; + fpscounteractive = !fpscounteractive; if (KeycodePressed(st, next_st, KEYCODE_VARS)) CGRefreshSwitch();