From de5cdcfa0cf004254cd7dd32b7da57fa57fa0ab2 Mon Sep 17 00:00:00 2001 From: AMJ <69196954+ThisAMJ@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:36:07 +1000 Subject: [PATCH] feat: wait to apply `sar_speedrun_time_pauses` Fixes #281 --- src/Features/Speedrun/SpeedrunTimer.cpp | 6 ++++-- src/Features/Speedrun/SpeedrunTimer.hpp | 2 ++ src/Features/Timer/PauseTimer.cpp | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Features/Speedrun/SpeedrunTimer.cpp b/src/Features/Speedrun/SpeedrunTimer.cpp index 8c0941d0b..49ec00cf6 100644 --- a/src/Features/Speedrun/SpeedrunTimer.cpp +++ b/src/Features/Speedrun/SpeedrunTimer.cpp @@ -123,6 +123,8 @@ static struct static std::map g_activeRun; static std::vector> g_runs; +bool g_timePauses = false; + static void handleCoopPacket(const void *data, size_t size); ON_INIT { @@ -392,7 +394,7 @@ void SpeedrunTimer::Update() { std::string map = getEffectiveMapName(); - if (engine->IsCoop() && !engine->IsOrange() && SpeedrunTimer::IsRunning() && !sar_speedrun_time_pauses.GetBool()) { + if (engine->IsCoop() && !engine->IsOrange() && SpeedrunTimer::IsRunning() && !g_timePauses) { if (pauseTimer->IsActive() && !g_speedrun.inCoopPause) { // I don't understand how any of this works but I think we're off-by-one here g_speedrun.saved = SpeedrunTimer::GetSplitTicks() + 1; @@ -455,7 +457,7 @@ ON_EVENT(PRE_TICK) { return; } - if (!g_speedrun.isRunning || g_speedrun.isPaused || !sar_speedrun_time_pauses.GetBool()) { + if (!g_speedrun.isRunning || g_speedrun.isPaused || !g_timePauses) { return; } diff --git a/src/Features/Speedrun/SpeedrunTimer.hpp b/src/Features/Speedrun/SpeedrunTimer.hpp index bba7d27c7..4d6b2205a 100644 --- a/src/Features/Speedrun/SpeedrunTimer.hpp +++ b/src/Features/Speedrun/SpeedrunTimer.hpp @@ -57,3 +57,5 @@ extern Command sar_speedrun_resume; extern Command sar_speedrun_reset; extern Command sar_speedrun_result; extern Command sar_speedrun_export; + +extern bool g_timePauses; diff --git a/src/Features/Timer/PauseTimer.cpp b/src/Features/Timer/PauseTimer.cpp index 7c0137f5f..f1db0ae74 100644 --- a/src/Features/Timer/PauseTimer.cpp +++ b/src/Features/Timer/PauseTimer.cpp @@ -3,6 +3,7 @@ #include "Event.hpp" #include "Features/Hud/Hud.hpp" #include "Features/Session.hpp" +#include "Features/Speedrun/SpeedrunTimer.hpp" #include "Modules/Engine.hpp" #include "Modules/Server.hpp" @@ -23,9 +24,10 @@ void PauseTimer::Increment() { void PauseTimer::Stop() { this->isActive = false; if (engine->demorecorder->isRecordingDemo && session->GetTick() != 0) { // HACKHACK: pause timer currently gets triggered on every load, before session start. we gotta make that not happen - char data[5]; + char data[6]; data[0] = 0x08; *(int *)(data + 1) = this->ticks; + *(bool *)(data + 5) = g_timePauses; engine->demorecorder->RecordData(data, sizeof data); } } @@ -52,9 +54,11 @@ ON_EVENT(PRE_TICK) { if (!server->IsRestoring()) { if (!event.simulating && !pauseTimer->IsActive()) { pauseTimer->Start(); + g_timePauses = sar_speedrun_time_pauses.GetBool(); } else if (event.simulating && pauseTimer->IsActive()) { pauseTimer->Stop(); console->DevMsg("Paused for %d non-simulated ticks.\n", pauseTimer->GetTotal()); + g_timePauses = sar_speedrun_time_pauses.GetBool(); } }