Clean up messy GameLoop function

This commit is contained in:
sukibaby
2024-08-06 18:07:21 -07:00
committed by teejusb
parent e34450fbe8
commit beecd2bd47
+29 -15
View File
@@ -242,25 +242,36 @@ namespace
g_NewTheme= RString(); g_NewTheme= RString();
} }
} }
static bool m_bUpdatedDuringVBLANK = false;
void GameLoop::UpdateAllButDraw(bool bRunningFromVBLANK) void GameLoop::UpdateAllButDraw(bool bRunningFromVBLANK)
{ {
//if we are running our once per frame routine and we were already run from VBLANK, we did the work already // Flag to indicate whether an update has been processed during the VBLANK period.
static bool m_bUpdatedDuringVBLANK = false;
// If we're running from VBLANK, and we've already updated during the VBLANK period,
// don't update again. This is to prevent multiple updates during the same VBLANK period.
if (!bRunningFromVBLANK && m_bUpdatedDuringVBLANK) if (!bRunningFromVBLANK && m_bUpdatedDuringVBLANK)
{ {
m_bUpdatedDuringVBLANK = false; m_bUpdatedDuringVBLANK = false;
return; //would it kill us to run it again or do we want to draw asap? return;
} }
//if vblank called us, we will tell the game loop we received an update for the frame it wants to process // If we're running from VBLANK, indicate we've updated during the VBLANK period.
if (bRunningFromVBLANK) m_bUpdatedDuringVBLANK = true; // Otherwise, make sure the flag is cleared.
else m_bUpdatedDuringVBLANK = false; if (bRunningFromVBLANK)
{
m_bUpdatedDuringVBLANK = true;
}
else
{
m_bUpdatedDuringVBLANK = false;
}
// Update our stuff // If the constant update delta is set, use that value. Otherwise, use the delta
float fDeltaTime = g_GameplayTimer.GetDeltaTime(); // time from the gameplay timer.
float fDeltaTime = (g_fConstantUpdateDeltaSeconds > 0)
if (g_fConstantUpdateDeltaSeconds > 0) ? g_fConstantUpdateDeltaSeconds
fDeltaTime = g_fConstantUpdateDeltaSeconds; : g_GameplayTimer.GetDeltaTime();
CheckGameLoopTimerSkips(fDeltaTime); CheckGameLoopTimerSkips(fDeltaTime);
@@ -282,14 +293,17 @@ void GameLoop::UpdateAllButDraw(bool bRunningFromVBLANK)
* acting on song beat from last frame */ * acting on song beat from last frame */
HandleInputEvents(fDeltaTime); HandleInputEvents(fDeltaTime);
//bandaid for low max audio sample counter // Legacy hack to work around low sample count in some sound drivers.
// This is a workaround for a bug in the Windows sound system that causes
// the sound to be cut off if the sample count is too low. This is a
// workaround for the bug, but it's not a fix. It should probably be
// removed or localized to the DirectSound driver. --sukibaby
SOUNDMAN->low_sample_count_workaround(); SOUNDMAN->low_sample_count_workaround();
// Update the lights
LIGHTSMAN->Update(fDeltaTime); LIGHTSMAN->Update(fDeltaTime);
} }
void GameLoop::RunGameLoop() void GameLoop::RunGameLoop()
{ {
static int CheckInputDevicesCounter = 0; static int CheckInputDevicesCounter = 0;