From aa64b53fbcacd05386d0696ebe6df0400f70c096 Mon Sep 17 00:00:00 2001 From: Elinsrc Date: Sat, 2 Nov 2024 19:11:41 +0500 Subject: [PATCH] hud_debug: Update GetFrametime() --- cl_dll/ui/hud/hud_debug.cpp | 40 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/cl_dll/ui/hud/hud_debug.cpp b/cl_dll/ui/hud/hud_debug.cpp index 698f843..b22a615 100644 --- a/cl_dll/ui/hud/hud_debug.cpp +++ b/cl_dll/ui/hud/hud_debug.cpp @@ -70,18 +70,24 @@ static float GetCurrentSysTime() float CHudDebug::GetFrametime() { - const float smoothFactor = 0.24f; - const float diffThreshold = 0.13f; - float currSysTime = GetCurrentSysTime(); - float timeDelta = currSysTime - m_lastSysTime; - - if ((timeDelta - m_lastFrameTime) > diffThreshold) - timeDelta = m_lastFrameTime; - - m_frameTime += (timeDelta - m_frameTime) * smoothFactor; - m_lastFrameTime = m_frameTime; - m_lastSysTime = currSysTime; - return m_frameTime; + float calc; + double newtime = GetCurrentSysTime(); + static double nexttime = 0, lasttime = 0; + static double framerate = 0; + static int framecount = 0; + + if( newtime >= nexttime ) + { + framerate = framecount / (newtime - lasttime); + lasttime = newtime; + nexttime = Q_max( nexttime + 1.0, lasttime - 1.0 ); + framecount = 0; + } + + calc = framerate; + framecount++; + + return calc; } const char *CHudDebug::GetMovetypeName(int moveType) @@ -488,20 +494,20 @@ int CHudDebug::Draw(float flTime) int DebugMode = cl_debug->value; - float timeDelta = GetFrametime(); - float fps = 1.f / timeDelta; - char str[256]; + float fps = GetFrametime(); const unsigned char* color = getColorForFPS(static_cast(fps)); int r = color[0]; int g = color[1]; int b = color[2]; + char str[256]; + if (DebugMode > 0.0f || cl_debug_showfps->value > 0.0f) { - sprintf(str, "FPS: %.1f", fps); + sprintf(str, "FPS: %.0f", fps); gHUD.DrawHudText(ScreenWidth / 1.5, gHUD.m_scrinfo.iCharHeight, str, r, g, b); - sprintf(str, "Frame Time: %.1f ms\n", timeDelta * 1000.f); + sprintf(str, "Frame Time: %.0f ms\n", 1000.f / fps); gHUD.DrawHudText(ScreenWidth / 1.5, gHUD.m_scrinfo.iCharHeight * 2, str, r, g, b); }