diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-12 18:46:34 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-12 18:46:34 +0100 |
commit | f34daa492c30a0d28b747817a9f2d6fb0186cf80 (patch) | |
tree | 2c2501968f12e379ac196abb4161527d86a351e5 /src/crepe/system/ReplaySystem.cpp | |
parent | b9694e8cc6b85a0089f97ff3c21862adc75a7ee5 (diff) |
clean up ReplayManager API
Diffstat (limited to 'src/crepe/system/ReplaySystem.cpp')
-rw-r--r-- | src/crepe/system/ReplaySystem.cpp | 49 |
1 files changed, 8 insertions, 41 deletions
diff --git a/src/crepe/system/ReplaySystem.cpp b/src/crepe/system/ReplaySystem.cpp index a6b8fb1..39b5c14 100644 --- a/src/crepe/system/ReplaySystem.cpp +++ b/src/crepe/system/ReplaySystem.cpp @@ -1,4 +1,3 @@ -#include "../util/Log.h" #include "../manager/ReplayManager.h" #include "../manager/SystemManager.h" @@ -10,52 +9,23 @@ using namespace std; void ReplaySystem::fixed_update() { ReplayManager & replay = this->mediator.replay_manager; + ReplayManager::State state = replay.get_state(); + ReplayManager::State last_state = this->last_state; + this->last_state = state; - switch (replay.state) { + switch (state) { case ReplayManager::IDLE: break; case ReplayManager::RECORDING: { - this->update_recording(); + replay.frame_record(); break; } case ReplayManager::PLAYING: { - this->update_playing(); + if (last_state != ReplayManager::PLAYING) this->playback_begin(); + bool last = replay.frame_step(); + if (last) this->playback_end(); break; } } - - this->last_state = replay.state; -} - -void ReplaySystem::update_recording() { - ReplayManager & replay = this->mediator.replay_manager; - ComponentManager & components = this->mediator.component_manager; - - ReplayManager::Recording & recording = replay.recording; - recording.frames.push_back(components.save()); - recording.frame++; -} - -void ReplaySystem::update_playing() { - ReplayManager & replay = this->mediator.replay_manager; - - if (this->last_state != ReplayManager::PLAYING) { - this->playback_begin(); - } - - ReplayManager::Recording & recording = replay.recording; - - if (recording.frames.size() == recording.frame) { - dbg_log("Finished playback"); - this->playback_end(); - return; - } - - ComponentManager & components = this->mediator.component_manager; - ComponentManager::Snapshot & frame = recording.frames.at(recording.frame); - - dbg_logf("Playing recording frame {}", recording.frame); - components.restore(frame); - recording.frame++; } void ReplaySystem::playback_begin() { @@ -78,8 +48,5 @@ void ReplaySystem::playback_end() { components.restore(this->playback.components); systems.restore(this->playback.systems); - - ReplayManager & replay = this->mediator.replay_manager; - replay.state = ReplayManager::IDLE; } |