diff options
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; |