#include "Museum.h" using namespace std; Museum::Museum() : people(*this), canvas(*this) { this->worker = new std::thread(&Museum::work, this); } Museum::~Museum() { this->working = false; this->worker->join(); if (this->worker != nullptr) { delete this->worker; this->worker = nullptr; } } void Museum::update() { this->people.update(); this->canvas.update(); this->tick++; } void Museum::skip_forward() { this->jump += this->snapshot_ticks; } void Museum::skip_backward() { } void Museum::work() { while (this->working) { // immediately process forward jumps, even if paused if (this->jump > 0) { while (--this->jump > 0) this->update(); } // wait with regular update if paused if (this->paused) continue; // regular update auto next = chrono::steady_clock::now() + this->tick_interval; this->update(); this_thread::sleep_until(next); } } void Museum::set_pause(bool paused) { this->paused = paused; }