Skip to content

Commit

Permalink
feat: wait to apply sar_speedrun_time_pauses
Browse files Browse the repository at this point in the history
Fixes #281
  • Loading branch information
ThisAMJ committed Sep 24, 2024
1 parent 59db773 commit de5cdcf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Features/Speedrun/SpeedrunTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ static struct
static std::map<std::string, int> g_activeRun;
static std::vector<std::map<std::string, int>> g_runs;

bool g_timePauses = false;

static void handleCoopPacket(const void *data, size_t size);

ON_INIT {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Features/Speedrun/SpeedrunTimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 5 additions & 1 deletion src/Features/Timer/PauseTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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);
}
}
Expand All @@ -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();
}
}

Expand Down

0 comments on commit de5cdcf

Please sign in to comment.