From 803dc1309a3effd4c9a868e8b569c37a7636fcd1 Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Mon, 12 Aug 2024 07:59:49 -0700 Subject: [PATCH] Optimize avoiding CheckGameLoopTimerSkips Implements a static boolean to track the CheckGameLoopTimerSkips preference, so that it isn't calling PREFSMAN via CheckGameLoopTimerSkips in a tight loop. Since this setting is rarely used, and isn't expected to be changed while the game is open, it doesn't need to be continuously checked. --- src/GameLoop.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp index f4d3fd590b..cf5a1d9552 100644 --- a/src/GameLoop.cpp +++ b/src/GameLoop.cpp @@ -42,9 +42,6 @@ void GameLoop::SetUpdateRate( float fUpdateRate ) static void CheckGameLoopTimerSkips( float fDeltaTime ) { - if( !PREFSMAN->m_bLogSkips ) - return; - static int iLastFPS = 0; int iThisFPS = DISPLAY->GetFPS(); @@ -273,7 +270,13 @@ void GameLoop::UpdateAllButDraw(bool bRunningFromVBLANK) ? g_fConstantUpdateDeltaSeconds : g_GameplayTimer.GetDeltaTime(); - CheckGameLoopTimerSkips(fDeltaTime); + // Use a static boolean to check the preference once per game launch. + // This is a rarely used debug feature, so we try to skip it if possible. + static bool bLogSkips = PREFSMAN->m_bLogSkips; + if (bLogSkips) + { + CheckGameLoopTimerSkips(fDeltaTime); + } fDeltaTime *= g_fUpdateRate;