From f1bd90127ed054c8dae094b4eb8d691176bd7839 Mon Sep 17 00:00:00 2001 From: pongo1231 Date: Sun, 19 Jan 2025 00:46:38 +0000 Subject: [PATCH] ChaosMod/EffectDispatcher: Fix broken effect timer logic --- ChaosMod/Components/EffectDispatchTimer.cpp | 14 +++++++------- ChaosMod/Components/EffectDispatcher.cpp | 12 ++++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ChaosMod/Components/EffectDispatchTimer.cpp b/ChaosMod/Components/EffectDispatchTimer.cpp index 2f954a2c7..fe29425e6 100644 --- a/ChaosMod/Components/EffectDispatchTimer.cpp +++ b/ChaosMod/Components/EffectDispatchTimer.cpp @@ -27,8 +27,8 @@ void EffectDispatchTimer::UpdateTimer(int deltaTime) return; m_TimerPercentage += deltaTime - * (ComponentExists() ? GetComponent()->TimerSpeedModifier : 1.f) - / m_EffectSpawnTime / 1000; + * (!ComponentExists() ? 1.f : GetComponent()->TimerSpeedModifier) + / m_EffectSpawnTime / 1000.f; if (m_TimerPercentage >= 1.f && m_DispatchEffectsOnTimer && ComponentExists()) { @@ -135,8 +135,8 @@ void EffectDispatchTimer::ResetTimer() int EffectDispatchTimer::GetRemainingTimerTime() const { return std::ceil(m_EffectSpawnTime - / (ComponentExists() ? GetComponent()->TimerSpeedModifier : 1.f) - * (1 - m_TimerPercentage)); + / (!ComponentExists() ? 1.f : GetComponent()->TimerSpeedModifier) + * (1.f - m_TimerPercentage)); } bool EffectDispatchTimer::ShouldDispatchEffectNow() const @@ -161,7 +161,7 @@ void EffectDispatchTimer::ResetFakeTimerPercentage() void EffectDispatchTimer::OnRun() { - auto currentUpdateTime = GetTickCount64(); + auto curTime = GetTickCount64(); if (m_EnableTimer && m_DrawTimerBar && (!ComponentExists() || !GetComponent()->HideChaosUI) @@ -180,7 +180,7 @@ void EffectDispatchTimer::OnRun() false); } - int deltaTime = currentUpdateTime - m_Timer; + int deltaTime = curTime - m_Timer; // The game was paused if (deltaTime > 1000) @@ -194,5 +194,5 @@ void EffectDispatchTimer::OnRun() UpdateTimer(deltaTime); } - m_Timer = currentUpdateTime; + m_Timer = curTime; } \ No newline at end of file diff --git a/ChaosMod/Components/EffectDispatcher.cpp b/ChaosMod/Components/EffectDispatcher.cpp index b71c53213..c8652c88c 100644 --- a/ChaosMod/Components/EffectDispatcher.cpp +++ b/ChaosMod/Components/EffectDispatcher.cpp @@ -192,14 +192,22 @@ static void _DispatchEffect(EffectDispatcher *effectDispatcher, const EffectDisp static void _OnRunEffects(LPVOID data) { auto effectDispatcher = reinterpret_cast(data); + auto lastTime = GetTickCount64(); while (true) { - int deltaTime = GetTickCount64() - - (!ComponentExists() ? 0 : GetComponent()->GetTimer()); + auto curTime = GetTickCount64(); + int deltaTime = + !ComponentExists() + ? 0 + : (curTime - lastTime) + * (ComponentExists() ? GetComponent()->EffectDurationModifier + : 1.f); // The game was paused if (deltaTime > 1000) deltaTime = 0; + lastTime = curTime; + while (!effectDispatcher->EffectDispatchQueue.empty()) { _DispatchEffect(effectDispatcher, effectDispatcher->EffectDispatchQueue.front());