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