From 359ad8db97305856f4cfdade1cd1dada78a7a635 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 11 Dec 2024 21:04:30 +0100 Subject: more replay system WIP --- src/crepe/system/ReplaySystem.cpp | 70 +++++++++++++++++++++++++++++++++++++++ src/crepe/system/ReplaySystem.h | 11 ++++++ 2 files changed, 81 insertions(+) (limited to 'src/crepe/system') diff --git a/src/crepe/system/ReplaySystem.cpp b/src/crepe/system/ReplaySystem.cpp index 3aabb58..85595a2 100644 --- a/src/crepe/system/ReplaySystem.cpp +++ b/src/crepe/system/ReplaySystem.cpp @@ -1,7 +1,77 @@ +#include "system/ScriptSystem.h" + +#include "../manager/ReplayManager.h" + #include "ReplaySystem.h" +#include "../api/LoopManager.h" + using namespace crepe; +using namespace std; void ReplaySystem::fixed_update() { + ReplayManager & replay = this->mediator.replay_manager; + + switch (replay.state) { + case ReplayManager::IDLE: break; + case ReplayManager::RECORDING: { + this->update_recording(); + break; + } + case ReplayManager::PLAYING: { + this->update_playing(); + 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) { + this->playback_end(); + return; + } + + ComponentManager & components = this->mediator.component_manager; + ComponentManager::Snapshot & frame = recording.frames.at(recording.frame); + + components.restore(frame); + recording.frame++; +} + +void ReplaySystem::playback_begin() { + LoopManager & loop_manager = this->mediator.loop_manager; + // TODO: store system active state + // TODO: disable most systems + // TODO: store components snapshot +} + +void ReplaySystem::playback_end() { + ReplayManager & replay = this->mediator.replay_manager; + + replay.state = ReplayManager::IDLE; + + LoopManager & loop_manager = this->mediator.loop_manager; + + // TODO: restore system active state snapshot + // TODO: restore components snapshot } diff --git a/src/crepe/system/ReplaySystem.h b/src/crepe/system/ReplaySystem.h index 15ef3fc..fb40176 100644 --- a/src/crepe/system/ReplaySystem.h +++ b/src/crepe/system/ReplaySystem.h @@ -1,5 +1,7 @@ #pragma once +#include "../manager/ReplayManager.h" + #include "System.h" namespace crepe { @@ -9,6 +11,15 @@ public: using System::System; void fixed_update() override; + +private: + ReplayManager::State last_state = ReplayManager::IDLE; + void update_recording(); + void update_playing(); + + std::unordered_map system_active_snapshot; + void playback_begin(); + void playback_end(); }; } -- cgit v1.2.3