mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-08 17:32:09 +00:00
Improve vid_fps stats
This commit is contained in:
parent
795c0d90de
commit
e4578a7626
3 changed files with 30 additions and 16 deletions
|
@ -276,8 +276,8 @@ public:
|
||||||
static float GetZNear() { return 5.f; }
|
static float GetZNear() { return 5.f; }
|
||||||
static float GetZFar() { return 65536.f; }
|
static float GetZFar() { return 65536.f; }
|
||||||
|
|
||||||
// The original size of the framebuffer as selected in the video menu.
|
|
||||||
uint64_t FrameTime = 0;
|
uint64_t FrameTime = 0;
|
||||||
|
uint64_t FrameTimeNS = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t fpsLimitTime = 0;
|
uint64_t fpsLimitTime = 0;
|
||||||
|
|
|
@ -659,6 +659,7 @@ void FStartScreen::Render(bool force)
|
||||||
if (nowtime - screen->FrameTime > 30 || force)
|
if (nowtime - screen->FrameTime > 30 || force)
|
||||||
{
|
{
|
||||||
screen->FrameTime = nowtime;
|
screen->FrameTime = nowtime;
|
||||||
|
screen->FrameTimeNS = I_nsTime();
|
||||||
screen->BeginFrame();
|
screen->BeginFrame();
|
||||||
twod->ClearClipRect();
|
twod->ClearClipRect();
|
||||||
I_GetEvent();
|
I_GetEvent();
|
||||||
|
|
|
@ -773,33 +773,45 @@ static void DrawPaletteTester(int paletteno)
|
||||||
// Draws the fps counter, dot ticker, and palette debug.
|
// Draws the fps counter, dot ticker, and palette debug.
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
uint64_t LastFPS, LastMSCount;
|
uint64_t LastFPS, LastAvgNSCount, LastMaxNSCount, LastMinNSCount;
|
||||||
|
|
||||||
void CalcFps()
|
void CalcFps()
|
||||||
{
|
{
|
||||||
static uint64_t LastMS = 0, LastSec = 0, FrameCount = 0, LastTic = 0;
|
static uint64_t LastNS = 0, LastStart = 0, FrameCount = 0, AccumNS = 0, MaxNS = 0, MinNS = 0xffff'ffff'ffffULL;
|
||||||
|
|
||||||
uint64_t ms = screen->FrameTime;
|
uint64_t ns = screen->FrameTimeNS;
|
||||||
uint64_t howlong = ms - LastMS;
|
uint64_t howlong = ns - LastNS;
|
||||||
if ((signed)howlong > 0) // do this only once per frame.
|
if ((signed)howlong > 0) // do this only once per frame.
|
||||||
{
|
{
|
||||||
uint32_t thisSec = (uint32_t)(ms / 1000);
|
|
||||||
if (LastSec < thisSec)
|
|
||||||
{
|
|
||||||
LastFPS = FrameCount / (thisSec - LastSec);
|
|
||||||
LastSec = thisSec;
|
|
||||||
FrameCount = 0;
|
|
||||||
}
|
|
||||||
FrameCount++;
|
FrameCount++;
|
||||||
LastMS = ms;
|
|
||||||
LastMSCount = howlong;
|
// Wait until at least a second has elapsed
|
||||||
|
if (LastStart / 1'000'000'000ULL < ns / 1'000'000'000ULL)
|
||||||
|
{
|
||||||
|
LastFPS = (FrameCount * 1'000'000'000ULL + 100'000'000ULL) / (ns - LastStart);
|
||||||
|
LastStart = ns;
|
||||||
|
LastAvgNSCount = AccumNS / FrameCount;
|
||||||
|
LastMaxNSCount = MaxNS;
|
||||||
|
LastMinNSCount = MinNS;
|
||||||
|
FrameCount = 0;
|
||||||
|
AccumNS = 0;
|
||||||
|
MaxNS = 0;
|
||||||
|
MinNS = 0xffff'ffff'ffffULL;
|
||||||
|
}
|
||||||
|
LastNS = ns;
|
||||||
|
AccumNS += howlong;
|
||||||
|
MaxNS = std::max(MaxNS, howlong);
|
||||||
|
MinNS = std::min(MinNS, howlong);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ADD_STAT(fps)
|
ADD_STAT(fps)
|
||||||
{
|
{
|
||||||
CalcFps();
|
CalcFps();
|
||||||
return FStringf("%2llu ms (%3llu fps)", (unsigned long long)LastMSCount , (unsigned long long)LastFPS);
|
return FStringf("%2llu.%llu ms avg (%4llu fps), %2llu.%llu ms max, %2llu.%llu ms min",
|
||||||
|
(unsigned long long)(LastAvgNSCount / 1'000'000ULL), (unsigned long long)(LastAvgNSCount / 100'000ULL % 10), (unsigned long long)LastFPS,
|
||||||
|
(unsigned long long)(LastMaxNSCount / 1'000'000ULL), (unsigned long long)(LastMaxNSCount / 100'000ULL % 10),
|
||||||
|
(unsigned long long)(LastMinNSCount / 1'000'000ULL), (unsigned long long)(LastMinNSCount / 100'000ULL % 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawRateStuff()
|
static void DrawRateStuff()
|
||||||
|
@ -815,7 +827,7 @@ static void DrawRateStuff()
|
||||||
int rate_x;
|
int rate_x;
|
||||||
int textScale = active_con_scale(twod);
|
int textScale = active_con_scale(twod);
|
||||||
|
|
||||||
chars = mysnprintf(fpsbuff, countof(fpsbuff), "%2llu ms (%3llu fps)", (unsigned long long)LastMSCount, (unsigned long long)LastFPS);
|
chars = mysnprintf(fpsbuff, countof(fpsbuff), "%2llu.%llu ms (%4llu fps)", (unsigned long long)(LastAvgNSCount / 1'000'000ULL), (unsigned long long)(LastAvgNSCount / 100'000ULL % 10), (unsigned long long)LastFPS);
|
||||||
rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]);
|
rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]);
|
||||||
ClearRect(twod, rate_x * textScale, 0, screen->GetWidth(), NewConsoleFont->GetHeight() * textScale, GPalette.BlackIndex, 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],
|
DrawText(twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char*)&fpsbuff[0],
|
||||||
|
@ -977,6 +989,7 @@ void D_Display ()
|
||||||
}
|
}
|
||||||
|
|
||||||
screen->FrameTime = I_msTimeFS();
|
screen->FrameTime = I_msTimeFS();
|
||||||
|
screen->FrameTimeNS = I_nsTime();
|
||||||
TexAnim.UpdateAnimations(screen->FrameTime);
|
TexAnim.UpdateAnimations(screen->FrameTime);
|
||||||
R_UpdateSky(screen->FrameTime);
|
R_UpdateSky(screen->FrameTime);
|
||||||
screen->BeginFrame();
|
screen->BeginFrame();
|
||||||
|
|
Loading…
Reference in a new issue