Skip to content

Commit

Permalink
- removed all vid_fps offsetting.
Browse files Browse the repository at this point in the history
To compensate there is now also a "stat fps" which displays the FPS rate in the lower left corner. This had to go because unconditionally altering positions was causing problems with custom HUDs.
  • Loading branch information
coelckers committed Jun 5, 2022
1 parent 24a2758 commit e266fb1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 55 deletions.
1 change: 0 additions & 1 deletion src/common/rendering/hwrenderer/data/hw_clock.cpp
Expand Up @@ -153,7 +153,6 @@ ADD_STAT(lightstats)
static int printstats;
static bool switchfps;
static uint64_t waitstart;
extern uint64_t LastCount;
EXTERN_CVAR(Bool, vid_fps)

void CheckBench()
Expand Down
13 changes: 0 additions & 13 deletions src/common/statusbar/base_sbar.cpp
Expand Up @@ -59,7 +59,6 @@ CVAR(Color, crosshaircolor, 0xff0000, CVAR_ARCHIVE);
CVAR(Int, crosshairhealth, 2, CVAR_ARCHIVE);
CVARD(Float, crosshairscale, 0.5, CVAR_ARCHIVE, "changes the size of the crosshair");
CVAR(Bool, crosshairgrow, false, CVAR_ARCHIVE);
EXTERN_CVAR(Bool, vid_fps)

EXTERN_CVAR(Float, hud_scalefactor)
EXTERN_CVAR(Bool, hud_aspectscale)
Expand Down Expand Up @@ -568,9 +567,6 @@ void DStatusBarCore::DrawGraphic(FGameTexture* tex, double x, double y, int flag
case DI_SCREEN_BOTTOM: orgy = twod->GetHeight(); break;
}

// move stuff in the top right corner a bit down if the fps counter is on.
if ((flags & (DI_SCREEN_HMASK | DI_SCREEN_VMASK)) == DI_SCREEN_RIGHT_TOP && vid_fps) y += 10;

DVector2 Scale = GetHUDScale();

x *= Scale.X;
Expand Down Expand Up @@ -662,9 +658,6 @@ void DStatusBarCore::DrawRotated(FGameTexture* tex, double x, double y, int flag
case DI_SCREEN_BOTTOM: orgy = twod->GetHeight(); break;
}

// move stuff in the top right corner a bit down if the fps counter is on.
if ((flags & (DI_SCREEN_HMASK | DI_SCREEN_VMASK)) == DI_SCREEN_RIGHT_TOP && vid_fps) y += 10;

x *= Scale.X;
y *= Scale.Y;
scaleX *= Scale.X;
Expand Down Expand Up @@ -742,9 +735,6 @@ void DStatusBarCore::DrawString(FFont* font, const FString& cstring, double x, d
case DI_SCREEN_VCENTER: orgy = twod->GetHeight() / 2; break;
case DI_SCREEN_BOTTOM: orgy = twod->GetHeight(); break;
}

// move stuff in the top right corner a bit down if the fps counter is on.
if ((flags & (DI_SCREEN_HMASK | DI_SCREEN_VMASK)) == DI_SCREEN_RIGHT_TOP && vid_fps) y += 10;
}
else
{
Expand Down Expand Up @@ -907,9 +897,6 @@ void DStatusBarCore::TransformRect(double& x, double& y, double& w, double& h, i
case DI_SCREEN_BOTTOM: orgy = twod->GetHeight(); break;
}

// move stuff in the top right corner a bit down if the fps counter is on.
if ((flags & (DI_SCREEN_HMASK | DI_SCREEN_VMASK)) == DI_SCREEN_RIGHT_TOP && vid_fps) y += 10;

DVector2 Scale = GetHUDScale();

x *= Scale.X;
Expand Down
81 changes: 47 additions & 34 deletions src/d_main.cpp
Expand Up @@ -293,13 +293,14 @@ CUSTOM_CVAR (String, vid_cursor, "None", CVAR_ARCHIVE | CVAR_NOINITCALL)
}

// Controlled by startup dialog
CVAR (Bool, disableautoload, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR (Bool, autoloadbrightmaps, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR (Bool, autoloadlights, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR (Bool, autoloadwidescreen, true, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR (Bool, r_debug_disable_vis_filter, false, 0)
CVAR(Bool, disableautoload, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR(Bool, autoloadbrightmaps, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR(Bool, autoloadlights, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR(Bool, autoloadwidescreen, true, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG)
CVAR(Bool, r_debug_disable_vis_filter, false, 0)
CVAR(Bool, vid_fps, false, 0)
CVAR(Int, vid_showpalette, 0, 0)

CUSTOM_CVAR (Bool, i_discordrpc, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
I_UpdateWindowTitle();
Expand Down Expand Up @@ -765,43 +766,55 @@ static void DrawPaletteTester(int paletteno)
// Draws the fps counter, dot ticker, and palette debug.
//
//==========================================================================
uint64_t LastCount;
uint64_t LastFPS, LastMSCount;

static void DrawRateStuff()
void CalcFps()
{
static uint64_t LastMS = 0, LastSec = 0, FrameCount = 0, LastTic = 0;

// Draws frame time and cumulative fps
if (vid_fps)
uint64_t ms = screen->FrameTime;
uint64_t howlong = ms - LastMS;
if ((signed)howlong > 0) // do this only once per frame.
{
uint64_t ms = screen->FrameTime;
uint64_t howlong = ms - LastMS;
if ((signed)howlong >= 0)
uint32_t thisSec = (uint32_t)(ms / 1000);
if (LastSec < thisSec)
{
char fpsbuff[40];
int chars;
int rate_x;
LastFPS = FrameCount / (thisSec - LastSec);
LastSec = thisSec;
FrameCount = 0;
}
FrameCount++;
LastMS = ms;
LastMSCount = howlong;
}
}

int textScale = active_con_scale(twod);
ADD_STAT(fps)
{
CalcFps();
return FStringf("%2llu ms (%3llu fps)", (unsigned long long)LastMSCount , (unsigned long long)LastFPS);
}

chars = mysnprintf(fpsbuff, countof(fpsbuff), "%2llu ms (%3llu fps)", (unsigned long long)howlong, (unsigned long long)LastCount);
rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]);
ClearRect(twod, rate_x * textScale, 0, screen->GetWidth(), NewConsoleFont->GetHeight() * textScale, GPalette.BlackIndex, 0);
DrawText(twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char*)&fpsbuff[0],
DTA_VirtualWidth, screen->GetWidth() / textScale,
DTA_VirtualHeight, screen->GetHeight() / textScale,
DTA_KeepRatio, true, TAG_DONE);
static void DrawRateStuff()
{
static uint64_t LastMS = 0, LastSec = 0, FrameCount = 0, LastTic = 0;

uint32_t thisSec = (uint32_t)(ms / 1000);
if (LastSec < thisSec)
{
LastCount = FrameCount / (thisSec - LastSec);
LastSec = thisSec;
FrameCount = 0;
}
FrameCount++;
}
LastMS = ms;
// Draws frame time and cumulative fps
if (vid_fps)
{
CalcFps();
char fpsbuff[40];
int chars;
int rate_x;
int textScale = active_con_scale(twod);

chars = mysnprintf(fpsbuff, countof(fpsbuff), "%2llu ms (%3llu fps)", (unsigned long long)LastMSCount, (unsigned long long)LastFPS);
rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]);
ClearRect(twod, rate_x * textScale, 0, screen->GetWidth(), NewConsoleFont->GetHeight() * textScale, GPalette.BlackIndex, 0);
DrawText(twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char*)&fpsbuff[0],
DTA_VirtualWidth, screen->GetWidth() / textScale,
DTA_VirtualHeight, screen->GetHeight() / textScale,
DTA_KeepRatio, true, TAG_DONE);
}

int Height = screen->GetHeight();
Expand Down Expand Up @@ -2740,7 +2753,7 @@ FString System_GetLocationDescription()
auto& vp = r_viewpoint;
auto Level = vp.ViewLevel;
return Level == nullptr ? FString() : FStringf("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n%llu fps\n\n",
Level->MapName.GetChars(), Level->LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees, (unsigned long long)LastCount);
Level->MapName.GetChars(), Level->LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees, (unsigned long long)LastFPS);

}

Expand Down
5 changes: 0 additions & 5 deletions src/g_statusbar/sbarinfo.cpp
Expand Up @@ -66,7 +66,6 @@ enum

EXTERN_CVAR(Int, fraglimit)
EXTERN_CVAR(Int, screenblocks)
EXTERN_CVAR(Bool, vid_fps)

class DSBarInfo;
static double nulclip[] = { 0,0,0,0 };
Expand Down Expand Up @@ -1287,8 +1286,6 @@ class DSBarInfo

w = (forceWidth < 0 ? texture->GetDisplayWidth() : forceWidth);
h = (forceHeight < 0 ? texture->GetDisplayHeight() : forceHeight);
if(vid_fps && rx < 0 && ry >= 0)
ry += 10;

rx *= Scale.X;
ry *= Scale.Y;
Expand Down Expand Up @@ -1432,8 +1429,6 @@ class DSBarInfo
}
else
{
if(vid_fps && ax < 0 && ay >= 0)
ry += 10;

bool xright = rx < 0;
bool ybot = ry < 0;
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/swrenderer/scene/r_scene.cpp
Expand Up @@ -421,7 +421,7 @@ namespace swrenderer

/////////////////////////////////////////////////////////////////////////

ADD_STAT(fps)
ADD_STAT(swfps)
{
FString out;
out.Format("frame=%04.1f ms walls=%04.1f ms planes=%04.1f ms masked=%04.1f ms",
Expand All @@ -432,7 +432,7 @@ namespace swrenderer
static double f_acc, w_acc, p_acc, m_acc;
static int acc_c;

ADD_STAT(fps_accumulated)
ADD_STAT(swfps_accumulated)
{
f_acc += FrameCycles.TimeMS();
w_acc += WallCycles.TimeMS();
Expand Down

0 comments on commit e266fb1

Please sign in to comment.