- Unify stat fps for all games.

This commit is contained in:
Mitchell Richters 2020-08-28 17:07:36 +10:00 committed by Christoph Oelckers
parent 59a964bb83
commit e32cd81cc7
16 changed files with 86 additions and 196 deletions

View file

@ -76,9 +76,6 @@ int gNetPlayers;
int gChokeCounter = 0; int gChokeCounter = 0;
double g_gameUpdateTime, g_gameUpdateAndDrawTime;
double g_gameUpdateAvgTime = 0.001;
bool gQuitGame; bool gQuitGame;
int gQuitRequest; int gQuitRequest;
@ -572,11 +569,19 @@ void ProcessFrame(void)
if (paused || gEndGameMgr.at0 || (gGameOptions.nGameType == 0 && M_Active())) if (paused || gEndGameMgr.at0 || (gGameOptions.nGameType == 0 && M_Active()))
return; return;
} }
thinktime.Reset();
thinktime.Clock();
actortime.Reset();
actortime.Clock();
for (int i = connecthead; i >= 0; i = connectpoint2[i]) for (int i = connecthead; i >= 0; i = connectpoint2[i])
{ {
viewBackupView(i); viewBackupView(i);
playerProcess(&gPlayer[i]); playerProcess(&gPlayer[i]);
} }
actortime.Unclock();
trProcessBusy(); trProcessBusy();
evProcess(gFrameClock); evProcess(gFrameClock);
seqProcess(4); seqProcess(4);
@ -602,6 +607,9 @@ void ProcessFrame(void)
gChokeCounter -= COUNTRATE; gChokeCounter -= COUNTRATE;
} }
} }
thinktime.Unclock();
gLevelTime++; gLevelTime++;
gFrameCount++; gFrameCount++;
gFrameClock += 4; gFrameClock += 4;
@ -792,6 +800,9 @@ static void gameTicker()
int const currentTic = I_GetTime(); int const currentTic = I_GetTime();
gameclock = I_GetBuildTime(); gameclock = I_GetBuildTime();
gameupdatetime.Reset();
gameupdatetime.Clock();
while (currentTic - lastTic >= 1 && ready2send) while (currentTic - lastTic >= 1 && ready2send)
{ {
gNetInput = gInput; gNetInput = gInput;
@ -810,21 +821,19 @@ static void gameTicker()
gameUpdate = true; gameUpdate = true;
} }
} }
if (gameUpdate)
{ gameupdatetime.Unclock();
g_gameUpdateTime = I_msTimeF() - gameUpdateStartTime;
if (g_gameUpdateAvgTime < 0.f)
g_gameUpdateAvgTime = g_gameUpdateTime;
g_gameUpdateAvgTime = ((GAMEUPDATEAVGTIMENUMSAMPLES - 1.f) * g_gameUpdateAvgTime + g_gameUpdateTime) / ((float)GAMEUPDATEAVGTIMENUMSAMPLES);
}
if (gQuitRequest && gQuitGame) if (gQuitRequest && gQuitGame)
videoClearScreen(0); videoClearScreen(0);
else else
{ {
netCheckSync(); netCheckSync();
auto beforeSwapTime = I_msTimeF();
drawtime.Reset();
drawtime.Clock();
viewDrawScreen(); viewDrawScreen();
g_gameUpdateAndDrawTime = beforeSwapTime/* I_msTimeF()*/ - gameUpdateStartTime; drawtime.Unclock();
} }
} }

View file

@ -84,9 +84,6 @@ extern INICHAIN *pINIChain;
extern short BloodVersion; extern short BloodVersion;
extern int gNetPlayers; extern int gNetPlayers;
extern bool gRestartGame; extern bool gRestartGame;
#define GAMEUPDATEAVGTIMENUMSAMPLES 100
extern double g_gameUpdateTime, g_gameUpdateAndDrawTime;
extern double g_gameUpdateAvgTime;
extern int blood_globalflags; extern int blood_globalflags;
extern bool gSavingGame; extern bool gSavingGame;
@ -110,7 +107,6 @@ struct GameInterface : ::GameInterface
void RunGameFrame() override; void RunGameFrame() override;
bool GenerateSavePic() override; bool GenerateSavePic() override;
void FreeGameData() override; void FreeGameData() override;
FString statFPS() override;
FSavegameInfo GetSaveSig() override; FSavegameInfo GetSaveSig() override;
void MenuOpened() override; void MenuOpened() override;
void MenuClosed() override; void MenuClosed() override;

View file

@ -1089,86 +1089,6 @@ bool GameInterface::GenerateSavePic()
# define FPS_YOFFSET 0 # define FPS_YOFFSET 0
#endif #endif
FString GameInterface::statFPS(void)
{
FString output;
static int32_t frameCount;
static double cumulativeFrameDelay;
static double lastFrameTime;
static float lastFPS, minFPS = FLT_MAX, maxFPS;
static double minGameUpdate = DBL_MAX, maxGameUpdate;
double frameTime = I_msTimeF();
double frameDelay = frameTime - lastFrameTime;
cumulativeFrameDelay += frameDelay;
if (frameDelay >= 0)
{
int32_t x = (xdim <= 640);
//if (r_showfps)
{
output.AppendFormat("%.1f ms, %5.1f fps\n", frameDelay, lastFPS);
if (r_showfps > 1)
{
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;
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("bufferjitter: %i\n", gBufferJitter);
#if 0
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)
{
output.AppendFormat("%d +- %d ms\n", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2,
(g_netClientPeer->lastRoundTripTimeVariance + g_netClientPeer->roundTripTimeVariance)/2);
}
#endif
}
if (cumulativeFrameDelay >= 1000.0)
{
lastFPS = 1000.f * frameCount / cumulativeFrameDelay;
g_frameRate = Blrintf(lastFPS);
frameCount = 0;
cumulativeFrameDelay = 0.0;
if (r_showfps > 1)
{
if (lastFPS > maxFPS) maxFPS = lastFPS;
if (lastFPS < minFPS) minFPS = lastFPS;
static int secondCounter;
if (++secondCounter >= r_showfpsperiod)
{
maxFPS = (lastFPS + maxFPS) * .5f;
minFPS = (lastFPS + minFPS) * .5f;
maxGameUpdate = (g_gameUpdateTime + maxGameUpdate) * 0.5;
minGameUpdate = (g_gameUpdateTime + minGameUpdate) * 0.5;
secondCounter = 0;
}
}
}
frameCount++;
}
lastFrameTime = frameTime;
return output;
}
FString GameInterface::GetCoordString() FString GameInterface::GetCoordString()
{ {
return "Player pos is unknown"; // todo: output at least something useful. return "Player pos is unknown"; // todo: output at least something useful.

View file

@ -927,6 +927,12 @@ static void updatePauseStatus()
paused ? S_PauseSound(!pausedWithKey, !paused) : S_ResumeSound(paused); paused ? S_PauseSound(!pausedWithKey, !paused) : S_ResumeSound(paused);
} }
static void checkTimerActive()
{
FStat *stat = FStat::FindStat("fps");
glcycle_t::active = (stat != NULL && stat->isActive());
}
void app_loop() void app_loop()
{ {
@ -944,6 +950,7 @@ void app_loop()
handleevents(); handleevents();
updatePauseStatus(); updatePauseStatus();
D_ProcessEvents(); D_ProcessEvents();
checkTimerActive();
gi->RunGameFrame(); gi->RunGameFrame();

View file

@ -5,6 +5,7 @@ bool System_WantGuiCapture(); // During playing this tells us whether the game m
#include <stdint.h> #include <stdint.h>
#include "vectors.h" #include "vectors.h"
#include "engineerrors.h" #include "engineerrors.h"
#include "stats.h"
struct GameStats struct GameStats
{ {
@ -53,6 +54,8 @@ struct ReservedSpace
enum EMenuSounds : int; enum EMenuSounds : int;
extern glcycle_t drawtime, actortime, thinktime, gameupdatetime;
struct GameInterface struct GameInterface
{ {
virtual const char* Name() { return "$"; } virtual const char* Name() { return "$"; }
@ -64,7 +67,6 @@ struct GameInterface
virtual void UpdateScreenSize() {} virtual void UpdateScreenSize() {}
virtual void FreeGameData() {} virtual void FreeGameData() {}
virtual void PlayHudSound() {} virtual void PlayHudSound() {}
virtual FString statFPS() { return "FPS display not available"; }
virtual GameStats getStats() { return {}; } virtual GameStats getStats() { return {}; }
virtual void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) {} virtual void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) {}
virtual void MainMenuOpened() {} virtual void MainMenuOpened() {}
@ -91,6 +93,17 @@ struct GameInterface
virtual void ExitFromMenu() { throw CExitEvent(0); } virtual void ExitFromMenu() { throw CExitEvent(0); }
virtual ReservedSpace GetReservedScreenSpace(int viewsize) { return { 0, 0 }; } virtual ReservedSpace GetReservedScreenSpace(int viewsize) { return { 0, 0 }; }
virtual void ResetFollowPos(bool) {} virtual void ResetFollowPos(bool) {}
virtual FString statFPS()
{
FString output;
output.AppendFormat("Actor think time: %.3f ms\n", actortime.TimeMS());
output.AppendFormat("Total think time: %.3f ms\n", thinktime.TimeMS());
output.AppendFormat("Game Update: %.3f ms\n", gameupdatetime.TimeMS());
output.AppendFormat("Draw time: %.3f ms\n", drawtime.TimeMS());
return output;
}
}; };

View file

@ -382,36 +382,6 @@ double calc_smoothratio()
return I_GetTimeFrac() * MaxSmoothRatio; return I_GetTimeFrac() * MaxSmoothRatio;
} }
FString GameInterface::statFPS()
{
FString out;
static int32_t frameCount;
static double cumulativeFrameDelay;
static double lastFrameTime;
static float lastFPS; // , minFPS = std::numeric_limits<float>::max(), maxFPS;
//static double minGameUpdate = std::numeric_limits<double>::max(), maxGameUpdate;
double frameTime = I_msTimeF();
double frameDelay = frameTime - lastFrameTime;
cumulativeFrameDelay += frameDelay;
if (frameDelay >= 0)
{
out.Format("%.1f ms, %5.1f fps", frameDelay, lastFPS);
if (cumulativeFrameDelay >= 1000.0)
{
lastFPS = 1000.f * frameCount / cumulativeFrameDelay;
// g_frameRate = Blrintf(lastFPS);
frameCount = 0;
cumulativeFrameDelay = 0.0;
}
frameCount++;
}
lastFrameTime = frameTime;
return out;
}
void GameMove(void) void GameMove(void)
{ {
FixPalette(); FixPalette();
@ -477,6 +447,9 @@ void GameTicker()
} }
else else
{ {
gameupdatetime.Reset();
gameupdatetime.Clock();
while (!EndLevel && currentTic - lastTic >= 1) while (!EndLevel && currentTic - lastTic >= 1)
{ {
lastTic = currentTic; lastTic = currentTic;
@ -487,8 +460,7 @@ void GameTicker()
nPlayerDAng = fix16_sadd(nPlayerDAng, localInput.q16avel); nPlayerDAng = fix16_sadd(nPlayerDAng, localInput.q16avel);
inita &= kAngleMask; inita &= kAngleMask;
int i; for (int i = 0; i < 4; i++)
for (i = 0; i < 4; i++)
{ {
lPlayerXVel += localInput.fvel * Cos(inita) + localInput.svel * Sin(inita); lPlayerXVel += localInput.fvel * Cos(inita) + localInput.svel * Sin(inita);
lPlayerYVel += localInput.fvel * Sin(inita) - localInput.svel * Cos(inita); lPlayerYVel += localInput.fvel * Sin(inita) - localInput.svel * Cos(inita);
@ -510,9 +482,12 @@ void GameTicker()
sPlayerInput[nLocalPlayer].horizon = PlayerList[nLocalPlayer].q16horiz; sPlayerInput[nLocalPlayer].horizon = PlayerList[nLocalPlayer].q16horiz;
leveltime++; leveltime++;
GameMove(); GameMove();
} }
gameupdatetime.Unclock();
if (nPlayerLives[nLocalPlayer] <= 0) { if (nPlayerLives[nLocalPlayer] <= 0) {
startmainmenu(); startmainmenu();
} }

View file

@ -291,7 +291,6 @@ struct GameInterface : ::GameInterface
void clearlocalinputstate() override; void clearlocalinputstate() override;
void QuitToTitle() override; void QuitToTitle() override;
FString statFPS() override;
::GameStats getStats() override; ::GameStats getStats() override;
}; };

View file

@ -114,6 +114,9 @@ static void showmap(short nLevel, short nLevelNew, short nLevelBest, TArray<JobD
static void GameDisplay(void) static void GameDisplay(void)
{ {
drawtime.Reset();
drawtime.Clock();
if (currentLevel->levelNumber == kMap20) if (currentLevel->levelNumber == kMap20)
{ {
DoEnergyTile(); DoEnergyTile();
@ -128,6 +131,8 @@ static void GameDisplay(void)
int nStringWidth = SmallFont->StringWidth(tex); int nStringWidth = SmallFont->StringWidth(tex);
DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - nStringWidth / 2, 100, tex, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE); DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - nStringWidth / 2, 100, tex, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
} }
drawtime.Unclock();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View file

@ -160,6 +160,9 @@ signed int lsqrt(int a1)
void MoveThings() void MoveThings()
{ {
thinktime.Reset();
thinktime.Clock();
UndoFlashes(); UndoFlashes();
DoLights(); DoLights();
@ -171,8 +174,11 @@ void MoveThings()
} }
else else
{ {
actortime.Reset();
actortime.Clock();
runlist_ExecObjects(); runlist_ExecObjects();
runlist_CleanRunRecs(); runlist_CleanRunRecs();
actortime.Unclock();
} }
MoveStatus(); MoveStatus();
@ -190,6 +196,8 @@ void MoveThings()
BendAmbientSound(); BendAmbientSound();
} }
} }
thinktime.Unclock();
} }
void ResetMoveFifo() void ResetMoveFifo()

View file

@ -19,11 +19,8 @@
#include "rts.h" #include "rts.h"
#include "sounds.h" #include "sounds.h"
#include "soundefs.h" #include "soundefs.h"
#include "stats.h"
#include "binaryangle.h" #include "binaryangle.h"
extern glcycle_t drawtime, actortime, thinktime, gameupdatetime;
BEGIN_DUKE_NS BEGIN_DUKE_NS
extern FFont* IndexFont; extern FFont* IndexFont;
@ -37,7 +34,6 @@ struct GameInterface : public ::GameInterface
void clearlocalinputstate() override; void clearlocalinputstate() override;
bool GenerateSavePic() override; bool GenerateSavePic() override;
void PlayHudSound() override; void PlayHudSound() override;
FString statFPS() override;
GameStats getStats() override; GameStats getStats() override;
void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) override; void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) override;
void MenuOpened() override; void MenuOpened() override;

View file

@ -74,24 +74,6 @@ GameStats GameInterface::getStats()
} }
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
FString GameInterface::statFPS()
{
FString output;
output.AppendFormat("Actor think time: %.3f ms\n", actortime.TimeMS());
output.AppendFormat("Total think time: %.3f ms\n", thinktime.TimeMS());
output.AppendFormat("Game Update: %.3f ms\n", gameupdatetime.TimeMS());
output.AppendFormat("Draw time: %.3f ms\n", drawtime.TimeMS());
return output;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// //

View file

@ -296,18 +296,6 @@ int moveloop()
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static void checkTimerActive()
{
FStat *stat = FStat::FindStat("fps");
glcycle_t::active = (stat != NULL && stat->isActive());
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
bool GameTicker() bool GameTicker()
{ {
if (ps[myconnectindex].gm == MODE_DEMO) if (ps[myconnectindex].gm == MODE_DEMO)
@ -319,7 +307,6 @@ bool GameTicker()
//Net_GetPackets(); //Net_GetPackets();
nonsharedkeys(); nonsharedkeys();
checkTimerActive();
gameupdatetime.Reset(); gameupdatetime.Reset();
gameupdatetime.Clock(); gameupdatetime.Clock();
@ -353,8 +340,6 @@ bool GameTicker()
} }
} }
double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio;
gameupdatetime.Unclock(); gameupdatetime.Unclock();
if (ps[myconnectindex].gm & (MODE_EOL | MODE_RESTART)) if (ps[myconnectindex].gm & (MODE_EOL | MODE_RESTART))
@ -367,9 +352,11 @@ bool GameTicker()
GetInput(); GetInput();
} }
S_Update();
drawtime.Reset(); drawtime.Reset();
drawtime.Clock(); drawtime.Clock();
S_Update(); double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio;
displayrooms(screenpeek, smoothRatio); displayrooms(screenpeek, smoothRatio);
displayrest(smoothRatio); displayrest(smoothRatio);
drawtime.Unclock(); drawtime.Unclock();

View file

@ -1189,28 +1189,6 @@ CircleCamera(int *nx, int *ny, int *nz, short *vsect, int *nq16ang, short horiz)
*nq16ang = fix16_from_int(ang); *nq16ang = fix16_from_int(ang);
} }
FString GameInterface::statFPS()
{
#define AVERAGEFRAMES 16
static int frameval[AVERAGEFRAMES], framecnt = 0;
int i;
FString out;
//if (LocationInfo)
{
i = gameclock;
if (i != frameval[framecnt])
{
out.AppendFormat("FPS: %d\n", ((120 * AVERAGEFRAMES) / (i - frameval[framecnt])) + f_c);
frameval[framecnt] = i;
}
framecnt = ((framecnt + 1) & (AVERAGEFRAMES - 1));
}
return out;
}
FString GameInterface::GetCoordString() FString GameInterface::GetCoordString()
{ {
PLAYERp pp = Player + myconnectindex; PLAYERp pp = Player + myconnectindex;

View file

@ -776,6 +776,9 @@ void GameTicker(void)
} }
else else
{ {
gameupdatetime.Reset();
gameupdatetime.Clock();
while (ready2send && currentTic - lastTic >= 1) while (ready2send && currentTic - lastTic >= 1)
{ {
lastTic = currentTic; lastTic = currentTic;
@ -784,14 +787,20 @@ void GameTicker(void)
MoveTicker(); MoveTicker();
} }
smoothratio = I_GetTimeFrac() * MaxSmoothRatio; gameupdatetime.Unclock();
// Get input again to update q16ang/q16horiz. // Get input again to update q16ang/q16horiz.
if (!PedanticMode) if (!PedanticMode)
getinput(&loc, TRUE); getinput(&loc, TRUE);
smoothratio = I_GetTimeFrac() * MaxSmoothRatio;
} }
drawtime.Reset();
drawtime.Clock();
drawscreen(Player + screenpeek, smoothratio); drawscreen(Player + screenpeek, smoothratio);
drawtime.Unclock();
ready2send = 0; ready2send = 0;
} }
if (ExitLevel) if (ExitLevel)

View file

@ -2308,7 +2308,6 @@ struct GameInterface : ::GameInterface
void QuitToTitle() override; void QuitToTitle() override;
void ResetFollowPos(bool message) override; void ResetFollowPos(bool message) override;
FString statFPS() override;
GameStats getStats() override; GameStats getStats() override;
}; };

View file

@ -7666,6 +7666,9 @@ domovethings(void)
PlayClock += synctics; PlayClock += synctics;
thinktime.Reset();
thinktime.Clock();
DoAnim(synctics); DoAnim(synctics);
// should pass pnum and use syncbits // should pass pnum and use syncbits
@ -7681,6 +7684,8 @@ domovethings(void)
SpriteControl(); SpriteControl();
actortime.Reset();
actortime.Clock();
TRAVERSE_CONNECT(pnum) TRAVERSE_CONNECT(pnum)
{ {
extern short screenpeek; extern short screenpeek;
@ -7743,13 +7748,15 @@ domovethings(void)
DoPlayerSectorUpdatePostMove(pp); DoPlayerSectorUpdatePostMove(pp);
PlayerGlobal(pp); PlayerGlobal(pp);
} }
actortime.Unclock();
MultiPlayLimits(); MultiPlayLimits();
//if (MoveSkip8 == 0) // 8=5x 4=10x, 2=20x, 0=40x per second //if (MoveSkip8 == 0) // 8=5x 4=10x, 2=20x, 0=40x per second
DoUpdateSounds(); DoUpdateSounds();
thinktime.Unclock();
CorrectPrediction(movefifoplc - 1); CorrectPrediction(movefifoplc - 1);
if (FinishTimer) if (FinishTimer)