diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-25 19:14:53 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-25 19:14:53 +0200 |
commit | 11a1e4e6c416dc160d1864f12fdf104bdf799146 (patch) | |
tree | 4a908642fd5d8aeb10c96e69adb3abebae2e5eec /Museum.cpp | |
parent | b8d946a4f14f7e32df9f3ddc325931283b771d8e (diff) |
Diffstat (limited to 'Museum.cpp')
-rw-r--r-- | Museum.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -29,30 +29,38 @@ void Museum::update() { } void Museum::skip_forward() { + lock_guard<mutex> guard(this->jump_mutex); this->jump++; } void Museum::skip_backward() { + lock_guard<mutex> guard(this->jump_mutex); this->paused = true; this->jump--; } +void Museum::process_jump() { + lock_guard<mutex> 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; |