From a1a9770b4440ffb9c6e726d063add9b32c85259c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 10 Nov 2019 11:42:25 +0100 Subject: [PATCH] - reworked the FPS display to use ZDoom's fstat class to get rid of the microscopic font it used. - changed time display for rendering to exclude VSync and playsim times to get more meaningful information. --- source/blood/src/blood.cpp | 2 +- source/blood/src/blood.h | 1 + source/blood/src/view.cpp | 65 +++++++------------------------- source/blood/src/view.h | 1 - source/build/include/baselayer.h | 4 ++ source/build/src/engine.cpp | 2 + source/build/src/sdlayer.cpp | 10 +---- source/common/gamecvars.cpp | 7 ++++ source/common/utility/stats.cpp | 9 +++++ source/common/utility/stats.h | 1 + source/duke3d/src/cheats.cpp | 5 +-- source/duke3d/src/duke3d.h | 1 + source/duke3d/src/game.cpp | 4 +- source/duke3d/src/screens.cpp | 61 +++++++----------------------- source/rr/src/cheats.cpp | 5 +-- source/rr/src/duke3d.h | 1 + source/rr/src/game.cpp | 2 +- source/rr/src/screens.cpp | 63 +++++++------------------------ 18 files changed, 75 insertions(+), 169 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index f397ffaec..8c9c4167a 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -1422,7 +1422,7 @@ RESTART: if (bDraw) { viewDrawScreen(); - g_gameUpdateAndDrawTime = timerGetHiTicks() - gameUpdateStartTime; + g_gameUpdateAndDrawTime = g_beforeSwapTime/* timerGetHiTicks()*/ - gameUpdateStartTime; } } } diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index bc4241c53..166f05f61 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -91,6 +91,7 @@ struct GameInterface : ::GameInterface void set_hud_layout(int size) override; void set_hud_scale(int size) override; bool mouseInactiveConditional(bool condition) override; + FString statFPS() override; }; END_BLD_NS diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index e96e1e693..0b63656b2 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -60,6 +60,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "view.h" #include "warp.h" #include "weapon.h" +#include "zstring.h" CVARD(Bool, hud_powerupduration, true, CVAR_ARCHIVE|CVAR_FRONTEND_BLOOD, "enable/disable displaying the remaining seconds for power-ups") @@ -3569,7 +3570,6 @@ RORHACK: #endif viewDrawMapTitle(); viewDrawAimedPlayerName(); - viewPrintFPS(); if (gPaused) { viewDrawText(1, "PAUSED", 160, 10, 0, 0, 1, 0); @@ -3740,9 +3740,9 @@ void viewResetCrosshairToDefault(void) #define FPS_COLOR(x) ((x) ? COLOR_RED : COLOR_WHITE) -void viewPrintFPS(void) +FString GameInterface::statFPS(void) { - char tempbuf[128]; + FString output; static int32_t frameCount; static double cumulativeFrameDelay; static double lastFrameTime; @@ -3757,73 +3757,35 @@ void viewPrintFPS(void) { int32_t x = (xdim <= 640); - if (r_showfps) + //if (r_showfps) { - int32_t chars = Bsprintf(tempbuf, "%.1f ms, %5.1f fps", frameDelay, lastFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+1+FPS_YOFFSET, - FPS_COLOR(lastFPS < LOW_FPS), -1, tempbuf, x); + output.AppendFormat("%.1f ms, %5.1f fps\n", frameDelay, lastFPS); if (r_showfps > 1) { - chars = Bsprintf(tempbuf, "max: %5.1f fps", maxFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+10+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+10+FPS_YOFFSET, - FPS_COLOR(maxFPS < LOW_FPS), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "min: %5.1f fps", minFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+20+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+20+FPS_YOFFSET, - FPS_COLOR(minFPS < LOW_FPS), -1, tempbuf, x); + output.AppendFormat("max: %5.1f fps\n", maxFPS); + output.AppendFormat("min: %5.1f fps\n", minFPS); } if (r_showfps > 2) { if (g_gameUpdateTime > maxGameUpdate) maxGameUpdate = g_gameUpdateTime; if (g_gameUpdateTime < minGameUpdate) minGameUpdate = g_gameUpdateTime; - chars = Bsprintf(tempbuf, "Game Update: %2.2f ms + draw: %2.2f ms", g_gameUpdateTime, g_gameUpdateAndDrawTime); + output.AppendFormat("Game Update: %2.2f ms + draw: %2.2f ms\n", g_gameUpdateTime, g_gameUpdateAndDrawTime - g_gameUpdateTime); + output.AppendFormat("GU min/max/avg: %5.2f/%5.2f/%5.2f ms\n", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime); - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+30+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+30+FPS_YOFFSET, - FPS_COLOR(g_gameUpdateAndDrawTime >= SLOW_FRAME_TIME), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "GU min/max/avg: %5.2f/%5.2f/%5.2f ms", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+40+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+40+FPS_YOFFSET, - FPS_COLOR(maxGameUpdate >= SLOW_FRAME_TIME), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "bufferjitter: %i", gBufferJitter); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+50+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+50+FPS_YOFFSET, - COLOR_WHITE, -1, tempbuf, x); + output.AppendFormat("bufferjitter: %i\n", gBufferJitter); #if 0 - chars = Bsprintf(tempbuf, "G_MoveActors(): %.3e ms", g_moveActorsTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+50+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+50+FPS_YOFFSET, - COLOR_WHITE, -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "G_MoveWorld(): %.3e ms", g_moveWorldTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+60+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+60+FPS_YOFFSET, - COLOR_WHITE, -1, tempbuf, x); + output.AppendFormat("G_MoveActors(): %.3f ms\n", g_moveActorsTime); + output.AppendFormat("G_MoveWorld(): %.3f ms\n", g_moveWorldTime); #endif } #if 0 // lag meter if (g_netClientPeer) { - chars = Bsprintf(tempbuf, "%d +- %d ms", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2, + output.AppendFormat("%d +- %d ms\n", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2, (g_netClientPeer->lastRoundTripTimeVariance + g_netClientPeer->roundTripTimeVariance)/2); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+30+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+30+1+FPS_YOFFSET, FPS_COLOR(g_netClientPeer->lastRoundTripTime > 200), -1, tempbuf, x); } #endif } @@ -3855,6 +3817,7 @@ void viewPrintFPS(void) frameCount++; } lastFrameTime = frameTime; + return output; } #undef FPS_COLOR diff --git a/source/blood/src/view.h b/source/blood/src/view.h index 4f8f10892..c6dd3995d 100644 --- a/source/blood/src/view.h +++ b/source/blood/src/view.h @@ -151,7 +151,6 @@ void viewUpdateDelirium(void); void viewUpdateShake(void); void viewSetCrosshairColor(int32_t r, int32_t g, int32_t b); void viewResetCrosshairToDefault(void); -void viewPrintFPS(void); void viewSetSystemMessage(const char* pMessage, ...); inline void viewInterpolateSector(int nSector, sectortype *pSector) diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index e509faa69..094bf2b49 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -13,6 +13,7 @@ #include "c_cvars.h" #include "inputstate.h" #include "printf.h" +#include "zstring.h" #ifdef DEBUGGINGAIDS @@ -170,9 +171,12 @@ struct GameInterface virtual void set_hud_layout(int size) = 0; virtual void set_hud_scale(int size) = 0; virtual bool mouseInactiveConditional(bool condition) { return condition; } + virtual FString statFPS() { return "FPS display not available"; } }; extern GameInterface* gi; +extern double g_beforeSwapTime; + void ImGui_Begin_Frame(); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 03bccbb43..a7104f269 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -10230,6 +10230,8 @@ void videoNextPage(void) } videoEndDrawing(); //}}} + g_beforeSwapTime = timerGetHiTicks(); + // Draw the ImGui menu on top of the game content, but below the console (if open.) if (GUICapture & 6) { diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 4190246d5..0fc5534a8 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -70,6 +70,7 @@ CVAR(Int, windowy, -1, CVAR_ARCHIVE | CVAR_VIDEOCONFIG) static SDL_version linked; #endif +double g_beforeSwapTime; GameInterface* gi; FArgs* Args; @@ -1536,16 +1537,7 @@ void videoShowFrame(int32_t w) } static uint32_t lastSwapTime = 0; -#ifdef TIMING - cycle_t clock; - clock.Reset(); - clock.Clock(); -#endif glFinish(); -#ifdef TIMING - clock.Unclock(); - OSD_Printf("glfinish time: %2.3f\n", clock.TimeMS()); -#endif SDL_GL_SwapWindow(sdl_window); lastSwapTime = SDL_GetTicks(); diff --git a/source/common/gamecvars.cpp b/source/common/gamecvars.cpp index 33f591620..af0250045 100644 --- a/source/common/gamecvars.cpp +++ b/source/common/gamecvars.cpp @@ -45,6 +45,7 @@ #include "gamecontrol.h" #include "m_argv.h" #include "rts.h" +#include "stats.h" /* Notes @@ -337,9 +338,15 @@ CUSTOM_CVARD(Int, r_drawweapon, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enable/disab if (self < 0 || self > 2) self = 1; } +ADD_STAT(fps) +{ + return gi->statFPS(); +} + CUSTOM_CVARD(Int, r_showfps, 0, 0, "show the frame rate counter") { if (self < 0 || self > 3) self = 1; + FStat::EnableStat("fps", self != 0); } CUSTOM_CVARD(Int, r_showfpsperiod, 0, 0, "time in seconds before averaging min and max stats for r_showfps 2+") diff --git a/source/common/utility/stats.cpp b/source/common/utility/stats.cpp index bda6e7ec0..8ab7b407b 100644 --- a/source/common/utility/stats.cpp +++ b/source/common/utility/stats.cpp @@ -80,6 +80,15 @@ void FStat::ToggleStat (const char *name) Printf ("Unknown stat: %s\n", name); } +void FStat::EnableStat(const char* name, bool on) +{ + FStat* stat = FindStat(name); + if (stat) + stat->m_Active = on; + else + Printf("Unknown stat: %s\n", name); +} + void FStat::ToggleStat () { m_Active = !m_Active; diff --git a/source/common/utility/stats.h b/source/common/utility/stats.h index ede0424c6..32a12251a 100644 --- a/source/common/utility/stats.h +++ b/source/common/utility/stats.h @@ -226,6 +226,7 @@ public: static void PrintStat (); static FStat *FindStat (const char *name); static void ToggleStat (const char *name); + static void EnableStat(const char* name, bool on); static void DumpRegisteredStats (); private: diff --git a/source/duke3d/src/cheats.cpp b/source/duke3d/src/cheats.cpp index 7b317e6a6..13feb226d 100644 --- a/source/duke3d/src/cheats.cpp +++ b/source/duke3d/src/cheats.cpp @@ -666,10 +666,7 @@ void G_DoCheats(void) return; case CHEAT_RATE: - r_showfps = r_showfps+1; - if (r_showfps > 3) - r_showfps = 0; - + r_showfps = clamp(*r_showfps+1, 0, 3); end_cheat(pPlayer); return; diff --git a/source/duke3d/src/duke3d.h b/source/duke3d/src/duke3d.h index 6d8b28a94..d3be7d5e5 100644 --- a/source/duke3d/src/duke3d.h +++ b/source/duke3d/src/duke3d.h @@ -152,6 +152,7 @@ struct GameInterface : ::GameInterface void set_hud_layout(int size) override; void set_hud_scale(int size) override; bool mouseInactiveConditional(bool condition) override; + FString statFPS() override; }; END_DUKE_NS diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 41f2c7f29..e7eef2813 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -6432,6 +6432,8 @@ MAIN_LOOP_RESTART: bool gameUpdate = false; double gameUpdateStartTime = timerGetHiTicks(); + auto beforeMoveClock = ototalclock; + if (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU|MODE_DEMO)) == 0) && totalclock >= ototalclock+TICSPERFRAME) { do @@ -6509,7 +6511,7 @@ MAIN_LOOP_RESTART: videoNextPage(); if (gameUpdate) - g_gameUpdateAndDrawTime = timerGetHiTicks()-gameUpdateStartTime; + g_gameUpdateAndDrawTime = g_beforeSwapTime/* timerGetHiTicks()*/ - gameUpdateStartTime; frameJustDrawn = true; } diff --git a/source/duke3d/src/screens.cpp b/source/duke3d/src/screens.cpp index f4798af6f..c57072127 100644 --- a/source/duke3d/src/screens.cpp +++ b/source/duke3d/src/screens.cpp @@ -680,9 +680,10 @@ static void G_PrintCoords(int32_t snum) #define FPS_COLOR(x) ((x) ? COLOR_RED : COLOR_WHITE) -static void G_PrintFPS(void) +FString GameInterface::statFPS(void) { - static int32_t frameCount; + FString output; + static int32_t frameCount; static double cumulativeFrameDelay; static double lastFrameTime; static float lastFPS, minFPS = std::numeric_limits::max(), maxFPS; @@ -696,66 +697,31 @@ static void G_PrintFPS(void) { int32_t x = (xdim <= 640); - if (r_showfps) + //if (r_showfps) { - int32_t chars = Bsprintf(tempbuf, "%.1f ms, %5.1f fps", frameDelay, lastFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+1+FPS_YOFFSET, - FPS_COLOR(lastFPS < LOW_FPS), -1, tempbuf, x); + output.AppendFormat("%.1f ms, %5.1f fps\n", frameDelay, lastFPS); if (r_showfps > 1) { - chars = Bsprintf(tempbuf, "max: %5.1f fps", maxFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+10+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+10+FPS_YOFFSET, - FPS_COLOR(maxFPS < LOW_FPS), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "min: %5.1f fps", minFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+20+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+20+FPS_YOFFSET, - FPS_COLOR(minFPS < LOW_FPS), -1, tempbuf, x); + output.AppendFormat("max: %5.1f fps\n", maxFPS); + output.AppendFormat("min: %5.1f fps\n", minFPS); } if (r_showfps > 2) { if (g_gameUpdateTime > maxGameUpdate) maxGameUpdate = g_gameUpdateTime; if (g_gameUpdateTime < minGameUpdate) minGameUpdate = g_gameUpdateTime; - chars = Bsprintf(tempbuf, "Game Update: %2.2f ms + draw: %2.2f ms", g_gameUpdateTime, g_gameUpdateAndDrawTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+30+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+30+FPS_YOFFSET, - FPS_COLOR(g_gameUpdateAndDrawTime >= SLOW_FRAME_TIME), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "GU min/max/avg: %5.2f/%5.2f/%5.2f ms", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+40+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+40+FPS_YOFFSET, - FPS_COLOR(maxGameUpdate >= SLOW_FRAME_TIME), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "G_MoveActors(): %.3e ms", g_moveActorsTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+50+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+50+FPS_YOFFSET, - COLOR_WHITE, -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "G_MoveWorld(): %.3e ms", g_moveWorldTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+60+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+60+FPS_YOFFSET, - COLOR_WHITE, -1, tempbuf, x); + output.AppendFormat("Game Update: %2.2f ms + draw: %2.2f ms\n", g_gameUpdateTime, g_gameUpdateAndDrawTime - g_gameUpdateTime); + output.AppendFormat("GU min/max/avg: %5.2f/%5.2f/%5.2f ms\n", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime); + output.AppendFormat("G_MoveActors(): %.3f ms\n", g_moveActorsTime); + output.AppendFormat("G_MoveWorld(): %.3f ms\n", g_moveWorldTime); } // lag meter if (g_netClientPeer) { - chars = Bsprintf(tempbuf, "%d +- %d ms", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2, + output.AppendFormat("%d +- %d ms\n", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2, (g_netClientPeer->lastRoundTripTimeVariance + g_netClientPeer->roundTripTimeVariance)/2); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+30+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+30+1+FPS_YOFFSET, FPS_COLOR(g_netClientPeer->lastRoundTripTime > 200), -1, tempbuf, x); } } @@ -786,6 +752,7 @@ static void G_PrintFPS(void) frameCount++; } lastFrameTime = frameTime; + return output; } #undef FPS_COLOR @@ -1119,8 +1086,6 @@ void G_DisplayRest(int32_t smoothratio) mdpause = (ud.pause_on || (ud.recstat==2 && (g_demo_paused && g_demo_goalCnt==0)) || (g_player[myconnectindex].ps->gm&MODE_MENU && numplayers < 2)); #endif - G_PrintFPS(); - // JBF 20040124: display level stats in screen corner if (ud.overhead_on != 2 && hud_stats && VM_OnEvent(EVENT_DISPLAYLEVELSTATS, g_player[screenpeek].ps->i, screenpeek) == 0) { diff --git a/source/rr/src/cheats.cpp b/source/rr/src/cheats.cpp index 603b364bb..d2e315636 100644 --- a/source/rr/src/cheats.cpp +++ b/source/rr/src/cheats.cpp @@ -673,10 +673,7 @@ void G_DoCheats(void) return; case CHEAT_RATE: - r_showfps = r_showfps+1; - if (r_showfps > 3) - r_showfps = 0; - + r_showfps = clamp(*r_showfps+1, 0, 3); end_cheat(pPlayer); return; diff --git a/source/rr/src/duke3d.h b/source/rr/src/duke3d.h index f5568d8cb..e9ab843cf 100644 --- a/source/rr/src/duke3d.h +++ b/source/rr/src/duke3d.h @@ -156,6 +156,7 @@ struct GameInterface : ::GameInterface void set_hud_layout(int size) override; void set_hud_scale(int size) override; bool mouseInactiveConditional(bool condition) override; + FString statFPS() override; }; END_RR_NS diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index d257d1a51..57e80f5bb 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -7942,7 +7942,7 @@ MAIN_LOOP_RESTART: if (gameUpdate) { - g_gameUpdateAndDrawTime = timerGetHiTicks()-gameUpdateStartTime; + g_gameUpdateAndDrawTime = g_beforeSwapTime/* timerGetHiTicks()*/ - gameUpdateStartTime; } } diff --git a/source/rr/src/screens.cpp b/source/rr/src/screens.cpp index ccaf81157..91214bd32 100644 --- a/source/rr/src/screens.cpp +++ b/source/rr/src/screens.cpp @@ -676,8 +676,9 @@ static void G_PrintCoords(int32_t snum) #define FPS_COLOR(x) ((x) ? COLOR_RED : COLOR_WHITE) -static void G_PrintFPS(void) +FString GameInterface::statFPS() { + FString output; static int32_t frameCount; static double cumulativeFrameDelay; static double lastFrameTime; @@ -692,67 +693,32 @@ static void G_PrintFPS(void) { int32_t x = (xdim <= 640); - if (r_showfps) + //if (r_showfps) { - int32_t chars = Bsprintf(tempbuf, "%.1f ms, %5.1f fps", frameDelay, lastFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+1+FPS_YOFFSET, - FPS_COLOR(lastFPS < LOW_FPS), -1, tempbuf, x); + output.AppendFormat("%.1f ms, %5.1f fps\n", frameDelay, lastFPS); if (r_showfps > 1) { - chars = Bsprintf(tempbuf, "max: %5.1f fps", maxFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+10+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+10+FPS_YOFFSET, - FPS_COLOR(maxFPS < LOW_FPS), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "min: %5.1f fps", minFPS); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+20+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+20+FPS_YOFFSET, - FPS_COLOR(minFPS < LOW_FPS), -1, tempbuf, x); + output.AppendFormat("max: %5.1f fps\n", maxFPS); + output.AppendFormat("min: %5.1f fps\n", minFPS); } if (r_showfps > 2) { if (g_gameUpdateTime > maxGameUpdate) maxGameUpdate = g_gameUpdateTime; if (g_gameUpdateTime < minGameUpdate) minGameUpdate = g_gameUpdateTime; - chars = Bsprintf(tempbuf, "Game Update: %2.2f ms + draw: %2.2f ms", g_gameUpdateTime, g_gameUpdateAndDrawTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+30+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+30+FPS_YOFFSET, - FPS_COLOR(g_gameUpdateAndDrawTime >= SLOW_FRAME_TIME), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "GU min/max/avg: %5.2f/%5.2f/%5.2f ms", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+40+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+40+FPS_YOFFSET, - FPS_COLOR(maxGameUpdate >= SLOW_FRAME_TIME), -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "G_MoveActors(): %.3e ms", g_moveActorsTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+50+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+50+FPS_YOFFSET, - COLOR_WHITE, -1, tempbuf, x); - - chars = Bsprintf(tempbuf, "G_MoveWorld(): %.3e ms", g_moveWorldTime); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+60+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+60+FPS_YOFFSET, - COLOR_WHITE, -1, tempbuf, x); + output.AppendFormat("Game Update: %2.2f ms + draw: %2.2f ms\n", g_gameUpdateTime, g_gameUpdateAndDrawTime - g_gameUpdateTime); + output.AppendFormat("GU min/max/avg: %5.2f/%5.2f/%5.2f ms\n", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime); + output.AppendFormat("G_MoveActors(): %.3f ms\n", g_moveActorsTime); + output.AppendFormat("G_MoveWorld(): %.3f ms\n", g_moveWorldTime); } // lag meter if (g_netClientPeer) { - chars = Bsprintf(tempbuf, "%d +- %d ms", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2, - (g_netClientPeer->lastRoundTripTimeVariance + g_netClientPeer->roundTripTimeVariance)/2); - - printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+30+2+FPS_YOFFSET, 0, -1, tempbuf, x); - printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+30+1+FPS_YOFFSET, FPS_COLOR(g_netClientPeer->lastRoundTripTime > 200), -1, tempbuf, x); - } + output.AppendFormat("%d +- %d ms\n", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2, + (g_netClientPeer->lastRoundTripTimeVariance + g_netClientPeer->roundTripTimeVariance) / 2); + } } if (cumulativeFrameDelay >= 1000.0) @@ -782,6 +748,7 @@ static void G_PrintFPS(void) frameCount++; } lastFrameTime = frameTime; + return output; } #undef FPS_COLOR @@ -1123,8 +1090,6 @@ void G_DisplayRest(int32_t smoothratio) mdpause = (ud.pause_on || (ud.recstat==2 && (g_demo_paused && g_demo_goalCnt==0)) || (g_player[myconnectindex].ps->gm&MODE_MENU && numplayers < 2)); #endif - G_PrintFPS(); - // JBF 20040124: display level stats in screen corner if (ud.overhead_on != 2 && hud_stats) {