From 11a1e4e6c416dc160d1864f12fdf104bdf799146 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 25 Oct 2024 19:14:53 +0200 Subject: fix silly bug --- Museum.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'Museum.cpp') diff --git a/Museum.cpp b/Museum.cpp index bf000e2..346acb7 100644 --- a/Museum.cpp +++ b/Museum.cpp @@ -29,30 +29,38 @@ void Museum::update() { } void Museum::skip_forward() { + lock_guard guard(this->jump_mutex); this->jump++; } void Museum::skip_backward() { + lock_guard guard(this->jump_mutex); this->paused = true; this->jump--; } +void Museum::process_jump() { + lock_guard guard(this->jump_mutex); + + if (this->jump > 0) { + // forward jump + for (; this->jump != 0; this->jump--) { + for (size_t i = 0; i < this->snapshot_ticks; i++) + this->update(); + } + } else if (this->jump < 0) { + // backward jump + for (; this->jump != 0; this->jump++) { + if (this->history.empty()) continue; + this->restore_snapshot(this->history.top()); + if (this->tick > 0) this->history.pop(); + } + } +} + void Museum::work() { while (this->working) { // immediately process jumps, even if paused - if (this->jump > 0) { - // forward jump - for (; this->jump != 0; this->jump--) { - for (size_t i = 0; i < this->snapshot_ticks; i++) - this->update(); - } - } else if (this->jump < 0) { - // backward jump - for (; this->jump != 0; this->jump++) { - if (this->history.empty()) continue; - this->restore_snapshot(this->history.top()); - if (this->tick > 0) this->history.pop(); - } - } + this->process_jump(); // wait with regular update if paused if (this->paused) continue; -- cgit v1.2.3