aboutsummaryrefslogtreecommitdiff
path: root/Museum.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-25 19:14:53 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-25 19:14:53 +0200
commit11a1e4e6c416dc160d1864f12fdf104bdf799146 (patch)
tree4a908642fd5d8aeb10c96e69adb3abebae2e5eec /Museum.cpp
parentb8d946a4f14f7e32df9f3ddc325931283b771d8e (diff)
fix silly bugHEADmaster
Diffstat (limited to 'Museum.cpp')
-rw-r--r--Museum.cpp36
1 files changed, 22 insertions, 14 deletions
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<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;