diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 974d2a411..a1dabaefb 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -76,9 +76,6 @@ int gNetPlayers; int gChokeCounter = 0; -double g_gameUpdateTime, g_gameUpdateAndDrawTime; -double g_gameUpdateAvgTime = 0.001; - bool gQuitGame; int gQuitRequest; @@ -572,11 +569,19 @@ void ProcessFrame(void) if (paused || gEndGameMgr.at0 || (gGameOptions.nGameType == 0 && M_Active())) return; } + + thinktime.Reset(); + thinktime.Clock(); + + actortime.Reset(); + actortime.Clock(); for (int i = connecthead; i >= 0; i = connectpoint2[i]) { viewBackupView(i); playerProcess(&gPlayer[i]); } + actortime.Unclock(); + trProcessBusy(); evProcess(gFrameClock); seqProcess(4); @@ -602,6 +607,9 @@ void ProcessFrame(void) gChokeCounter -= COUNTRATE; } } + + thinktime.Unclock(); + gLevelTime++; gFrameCount++; gFrameClock += 4; @@ -792,6 +800,9 @@ static void gameTicker() int const currentTic = I_GetTime(); gameclock = I_GetBuildTime(); + gameupdatetime.Reset(); + gameupdatetime.Clock(); + while (currentTic - lastTic >= 1 && ready2send) { gNetInput = gInput; @@ -810,21 +821,19 @@ static void gameTicker() gameUpdate = true; } } - if (gameUpdate) - { - 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); - } + + gameupdatetime.Unclock(); + if (gQuitRequest && gQuitGame) videoClearScreen(0); else { netCheckSync(); - auto beforeSwapTime = I_msTimeF(); + + drawtime.Reset(); + drawtime.Clock(); viewDrawScreen(); - g_gameUpdateAndDrawTime = beforeSwapTime/* I_msTimeF()*/ - gameUpdateStartTime; + drawtime.Unclock(); } } diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index f610508be..766c71826 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -84,9 +84,6 @@ extern INICHAIN *pINIChain; extern short BloodVersion; extern int gNetPlayers; extern bool gRestartGame; -#define GAMEUPDATEAVGTIMENUMSAMPLES 100 -extern double g_gameUpdateTime, g_gameUpdateAndDrawTime; -extern double g_gameUpdateAvgTime; extern int blood_globalflags; extern bool gSavingGame; @@ -110,7 +107,6 @@ struct GameInterface : ::GameInterface void RunGameFrame() override; bool GenerateSavePic() override; void FreeGameData() override; - FString statFPS() override; FSavegameInfo GetSaveSig() override; void MenuOpened() override; void MenuClosed() override; diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index 6160c986d..22f19e76d 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -1089,86 +1089,6 @@ bool GameInterface::GenerateSavePic() # define FPS_YOFFSET 0 #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() { return "Player pos is unknown"; // todo: output at least something useful. diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index a357c2171..a63182837 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -927,6 +927,12 @@ static void updatePauseStatus() 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() { @@ -944,6 +950,7 @@ void app_loop() handleevents(); updatePauseStatus(); D_ProcessEvents(); + checkTimerActive(); gi->RunGameFrame(); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 7ae7977b7..0fc3b2281 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -5,6 +5,7 @@ bool System_WantGuiCapture(); // During playing this tells us whether the game m #include #include "vectors.h" #include "engineerrors.h" +#include "stats.h" struct GameStats { @@ -53,6 +54,8 @@ struct ReservedSpace enum EMenuSounds : int; +extern glcycle_t drawtime, actortime, thinktime, gameupdatetime; + struct GameInterface { virtual const char* Name() { return "$"; } @@ -64,7 +67,6 @@ struct GameInterface virtual void UpdateScreenSize() {} virtual void FreeGameData() {} virtual void PlayHudSound() {} - virtual FString statFPS() { return "FPS display not available"; } virtual GameStats getStats() { return {}; } virtual void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) {} virtual void MainMenuOpened() {} @@ -91,6 +93,17 @@ struct GameInterface virtual void ExitFromMenu() { throw CExitEvent(0); } virtual ReservedSpace GetReservedScreenSpace(int viewsize) { return { 0, 0 }; } 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; + } }; diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 0b7958f24..8024536d8 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -382,36 +382,6 @@ double calc_smoothratio() 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::max(), maxFPS; - //static double minGameUpdate = std::numeric_limits::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) { FixPalette(); @@ -477,6 +447,9 @@ void GameTicker() } else { + gameupdatetime.Reset(); + gameupdatetime.Clock(); + while (!EndLevel && currentTic - lastTic >= 1) { lastTic = currentTic; @@ -487,8 +460,7 @@ void GameTicker() nPlayerDAng = fix16_sadd(nPlayerDAng, localInput.q16avel); inita &= kAngleMask; - int i; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { lPlayerXVel += localInput.fvel * Cos(inita) + localInput.svel * Sin(inita); lPlayerYVel += localInput.fvel * Sin(inita) - localInput.svel * Cos(inita); @@ -510,9 +482,12 @@ void GameTicker() sPlayerInput[nLocalPlayer].horizon = PlayerList[nLocalPlayer].q16horiz; - leveltime++; - GameMove(); - } + leveltime++; + GameMove(); + } + + gameupdatetime.Unclock(); + if (nPlayerLives[nLocalPlayer] <= 0) { startmainmenu(); } diff --git a/source/exhumed/src/exhumed.h b/source/exhumed/src/exhumed.h index 765d2ab66..a905528e6 100644 --- a/source/exhumed/src/exhumed.h +++ b/source/exhumed/src/exhumed.h @@ -291,7 +291,6 @@ struct GameInterface : ::GameInterface void clearlocalinputstate() override; void QuitToTitle() override; - FString statFPS() override; ::GameStats getStats() override; }; diff --git a/source/exhumed/src/gameloop.cpp b/source/exhumed/src/gameloop.cpp index 7491d2af4..3021838dc 100644 --- a/source/exhumed/src/gameloop.cpp +++ b/source/exhumed/src/gameloop.cpp @@ -114,6 +114,9 @@ static void showmap(short nLevel, short nLevelNew, short nLevelBest, TArraylevelNumber == kMap20) { DoEnergyTile(); @@ -128,6 +131,8 @@ static void GameDisplay(void) int nStringWidth = SmallFont->StringWidth(tex); DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - nStringWidth / 2, 100, tex, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE); } + + drawtime.Unclock(); } //--------------------------------------------------------------------------- diff --git a/source/exhumed/src/move.cpp b/source/exhumed/src/move.cpp index 4ef9b57cf..596fd90e6 100644 --- a/source/exhumed/src/move.cpp +++ b/source/exhumed/src/move.cpp @@ -160,6 +160,9 @@ signed int lsqrt(int a1) void MoveThings() { + thinktime.Reset(); + thinktime.Clock(); + UndoFlashes(); DoLights(); @@ -171,8 +174,11 @@ void MoveThings() } else { + actortime.Reset(); + actortime.Clock(); runlist_ExecObjects(); runlist_CleanRunRecs(); + actortime.Unclock(); } MoveStatus(); @@ -190,6 +196,8 @@ void MoveThings() BendAmbientSound(); } } + + thinktime.Unclock(); } void ResetMoveFifo() diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 4ebde4370..bf3137675 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -19,11 +19,8 @@ #include "rts.h" #include "sounds.h" #include "soundefs.h" -#include "stats.h" #include "binaryangle.h" -extern glcycle_t drawtime, actortime, thinktime, gameupdatetime; - BEGIN_DUKE_NS extern FFont* IndexFont; @@ -37,7 +34,6 @@ struct GameInterface : public ::GameInterface void clearlocalinputstate() override; bool GenerateSavePic() override; void PlayHudSound() override; - FString statFPS() override; GameStats getStats() override; void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) override; void MenuOpened() override; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 8c5b57b4d..efb0e21ed 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -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; -} - //--------------------------------------------------------------------------- // // diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 0b1b096a9..ea607a1fb 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -296,18 +296,6 @@ int moveloop() // //--------------------------------------------------------------------------- -static void checkTimerActive() -{ - FStat *stat = FStat::FindStat("fps"); - glcycle_t::active = (stat != NULL && stat->isActive()); -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - bool GameTicker() { if (ps[myconnectindex].gm == MODE_DEMO) @@ -319,7 +307,6 @@ bool GameTicker() //Net_GetPackets(); nonsharedkeys(); - checkTimerActive(); gameupdatetime.Reset(); gameupdatetime.Clock(); @@ -353,8 +340,6 @@ bool GameTicker() } } - double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio; - gameupdatetime.Unclock(); if (ps[myconnectindex].gm & (MODE_EOL | MODE_RESTART)) @@ -367,9 +352,11 @@ bool GameTicker() GetInput(); } + S_Update(); + drawtime.Reset(); drawtime.Clock(); - S_Update(); + double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio; displayrooms(screenpeek, smoothRatio); displayrest(smoothRatio); drawtime.Unclock(); diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index a282b4d45..b372c055c 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1189,28 +1189,6 @@ CircleCamera(int *nx, int *ny, int *nz, short *vsect, int *nq16ang, short horiz) *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() { PLAYERp pp = Player + myconnectindex; diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index eb7bc6f29..7264017ca 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -776,6 +776,9 @@ void GameTicker(void) } else { + gameupdatetime.Reset(); + gameupdatetime.Clock(); + while (ready2send && currentTic - lastTic >= 1) { lastTic = currentTic; @@ -784,14 +787,20 @@ void GameTicker(void) MoveTicker(); } - smoothratio = I_GetTimeFrac() * MaxSmoothRatio; + gameupdatetime.Unclock(); // Get input again to update q16ang/q16horiz. if (!PedanticMode) getinput(&loc, TRUE); + + smoothratio = I_GetTimeFrac() * MaxSmoothRatio; } + drawtime.Reset(); + drawtime.Clock(); drawscreen(Player + screenpeek, smoothratio); + drawtime.Unclock(); + ready2send = 0; } if (ExitLevel) diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 21a158999..8ea013d32 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -2308,7 +2308,6 @@ struct GameInterface : ::GameInterface void QuitToTitle() override; void ResetFollowPos(bool message) override; - FString statFPS() override; GameStats getStats() override; }; diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index a186c6695..5da73c90a 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -7666,6 +7666,9 @@ domovethings(void) PlayClock += synctics; + thinktime.Reset(); + thinktime.Clock(); + DoAnim(synctics); // should pass pnum and use syncbits @@ -7681,6 +7684,8 @@ domovethings(void) SpriteControl(); + actortime.Reset(); + actortime.Clock(); TRAVERSE_CONNECT(pnum) { extern short screenpeek; @@ -7743,13 +7748,15 @@ domovethings(void) DoPlayerSectorUpdatePostMove(pp); PlayerGlobal(pp); } - + actortime.Unclock(); MultiPlayLimits(); //if (MoveSkip8 == 0) // 8=5x 4=10x, 2=20x, 0=40x per second DoUpdateSounds(); + thinktime.Unclock(); + CorrectPrediction(movefifoplc - 1); if (FinishTimer)