Skip to content

Commit

Permalink
hud_debug: Update GetFrametime()
Browse files Browse the repository at this point in the history
  • Loading branch information
Elinsrc committed Nov 2, 2024
1 parent b82215c commit aa64b53
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions cl_dll/ui/hud/hud_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<int>(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);
}

Expand Down

0 comments on commit aa64b53

Please sign in to comment.