From a5da1900d0c4991827a210b126bd9ee667b5e088 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Tue, 14 Apr 2020 11:31:11 +0200 Subject: [PATCH] add an FPS counter widget and the SHOWFPS cheat to enable it (only if not in automap) --- Source/d_player.h | 4 +++- Source/hu_stuff.c | 22 ++++++++++++++++++++++ Source/i_video.c | 22 ++++++++++++++++++++++ Source/m_cheat.c | 11 +++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Source/d_player.h b/Source/d_player.h index de1222b8..1a766fa4 100644 --- a/Source/d_player.h +++ b/Source/d_player.h @@ -70,7 +70,9 @@ typedef enum // No damage, no health loss. CF_GODMODE = 2, // Not really a cheat, just a debug aid. - CF_NOMOMENTUM = 4 + CF_NOMOMENTUM = 4, + // [FG] FPS counter widget + CF_SHOWFPS = 8 } cheat_t; diff --git a/Source/hu_stuff.c b/Source/hu_stuff.c index a1582a82..49afbba4 100644 --- a/Source/hu_stuff.c +++ b/Source/hu_stuff.c @@ -173,6 +173,7 @@ static hu_textline_t w_keys; //jff 2/16/98 new keys widget for hud static hu_textline_t w_gkeys; //jff 3/7/98 graphic keys widget for hud static hu_textline_t w_monsec; //jff 2/16/98 new kill/secret widget for hud static hu_mtext_t w_rtext; //jff 2/26/98 text message refresh widget +static hu_textline_t w_fps; // [FG] FPS counter widget static boolean always_off = false; static char chat_dest[MAXPLAYERS]; @@ -222,6 +223,7 @@ static char hud_weapstr[80]; static char hud_keysstr[80]; static char hud_gkeysstr[80]; //jff 3/7/98 add support for graphic key display static char hud_monsecstr[80]; +static char hud_fpsstr[32]; // [FG] FPS counter widget // // Builtin map names. @@ -527,6 +529,9 @@ void HU_Start(void) HU_FONTSTART, colrngs[hudcolor_xyco]); HUlib_initTextLine(&w_coordz, HU_COORDX, HU_COORDZ_Y, hu_font, HU_FONTSTART, colrngs[hudcolor_xyco]); + // [FG] FPS counter widget + HUlib_initTextLine(&w_fps, HU_COORDX, HU_COORDX_Y, hu_font, + HU_FONTSTART, colrngs[hudcolor_xyco]); // initialize the automaps coordinate widget //jff 3/3/98 split coordstr widget into 3 parts @@ -542,6 +547,11 @@ void HU_Start(void) s = hud_coordstrz; while (*s) HUlib_addCharToTextLine(&w_coordz, *s++); + // [FG] FPS counter widget + sprintf(hud_fpsstr,"%-5d FPS",0); + s = hud_fpsstr; + while (*s) + HUlib_addCharToTextLine(&w_fps, *s++); //jff 2/16/98 initialize ammo widget sprintf(hud_ammostr,"AMM "); @@ -719,6 +729,18 @@ void HU_Drawer(void) HUlib_addCharToTextLine(&w_coordz, *s++); HUlib_drawTextLine(&w_coordz, false); } + // [FG] FPS counter widget + else if (plr->cheats & CF_SHOWFPS) + { + extern int fps; + + sprintf(hud_fpsstr,"%-5d FPS", fps); // killough 10/98 + HUlib_clearTextLine(&w_fps); + s = hud_fpsstr; + while (*s) + HUlib_addCharToTextLine(&w_fps, *s++); + HUlib_drawTextLine(&w_fps, false); + } // draw the weapon/health/ammo/armor/kills/keys displays if optioned //jff 2/17/98 allow new hud stuff to be turned off diff --git a/Source/i_video.c b/Source/i_video.c index bd017b26..fbc9b504 100644 --- a/Source/i_video.c +++ b/Source/i_video.c @@ -682,6 +682,8 @@ static int in_page_flip, in_hires; static void I_DrawDiskIcon(), I_RestoreDiskBackground(); static unsigned int disk_to_draw, disk_to_restore; +int fps; // [FG] FPS counter widget + void I_FinishUpdate(void) { if (noblit || !in_graphics_mode) @@ -726,6 +728,26 @@ void I_FinishUpdate(void) } } + // [crispy] [AM] Real FPS counter + { + static int lastmili; + static int fpscount; + int i, mili; + + fpscount++; + + i = SDL_GetTicks(); + mili = i - lastmili; + + // Update FPS counter every second + if (mili >= 1000) + { + fps = (fpscount * 1000) / mili; + fpscount = 0; + lastmili = i; + } + } + I_DrawDiskIcon(); SDL_LowerBlit(sdlscreen, &blit_rect, argbbuffer, &blit_rect); diff --git a/Source/m_cheat.c b/Source/m_cheat.c index f88259a0..ba7cec2c 100644 --- a/Source/m_cheat.c +++ b/Source/m_cheat.c @@ -83,6 +83,7 @@ static void cheat_printstats(); // killough 8/23/98 static void cheat_autoaim(); // killough 7/19/98 static void cheat_tst(); +static void cheat_showfps(); // [FG] FPS counter widget //----------------------------------------------------------------------------- // @@ -256,6 +257,10 @@ struct cheat_s cheat[] = { cheat_printstats}, #endif +// [FG] FPS counter widget + {"showfps", NULL, always, + cheat_showfps}, + {NULL} // end-of-list marker }; @@ -269,6 +274,12 @@ static void cheat_printstats() // killough 8/23/98 } #endif +// [FG] FPS counter widget +static void cheat_showfps() +{ + plyr->cheats ^= CF_SHOWFPS; +} + // killough 7/19/98: Autoaiming optional in beta emulation mode static void cheat_autoaim() {