From f34daa492c30a0d28b747817a9f2d6fb0186cf80 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 12 Dec 2024 18:46:34 +0100 Subject: clean up ReplayManager API --- src/crepe/manager/ReplayManager.cpp | 28 ++++++++++++++++++++++++++++ src/crepe/manager/ReplayManager.h | 33 +++++++++++++++++---------------- 2 files changed, 45 insertions(+), 16 deletions(-) (limited to 'src/crepe/manager') diff --git a/src/crepe/manager/ReplayManager.cpp b/src/crepe/manager/ReplayManager.cpp index 81ff114..ab8a5a0 100644 --- a/src/crepe/manager/ReplayManager.cpp +++ b/src/crepe/manager/ReplayManager.cpp @@ -37,3 +37,31 @@ void ReplayManager::release(recording_t handle) { this->memory.erase(handle); } +void ReplayManager::frame_record() { + ComponentManager & components = this->mediator.component_manager; + Recording & recording = this->recording; + + recording.frames.push_back(components.save()); + recording.frame++; +} + +bool ReplayManager::frame_step() { + ComponentManager & components = this->mediator.component_manager; + Recording & recording = this->recording; + + ComponentManager::Snapshot & frame = recording.frames.at(recording.frame); + + components.restore(frame); + recording.frame++; + + if (recording.frame < recording.frames.size()) return false; + // end of recording + recording.frame = 0; + this->state = IDLE; + return true; +} + +ReplayManager::State ReplayManager::get_state() const { + return this->state; +} + diff --git a/src/crepe/manager/ReplayManager.h b/src/crepe/manager/ReplayManager.h index 672d093..5794761 100644 --- a/src/crepe/manager/ReplayManager.h +++ b/src/crepe/manager/ReplayManager.h @@ -15,33 +15,34 @@ typedef size_t recording_t; class ReplayManager : public Manager { public: ReplayManager(Mediator & mediator); - friend class ReplaySystem; - -protected: - void record_frame(); - -private: - struct Recording { - size_t frame = 0; - std::vector frames; - }; +public: + void record_start(); + recording_t record_end(); + void play(recording_t handle); + void release(recording_t handle); + +public: enum State { IDLE, RECORDING, PLAYING, }; + State get_state() const; +public: + void frame_record(); + bool frame_step(); + +private: + struct Recording { + size_t frame = 0; + std::vector frames; + }; State state = IDLE; OptionalRef recording; recording_t id = -1; - std::unordered_map> memory; -public: - void record_start(); - recording_t record_end(); - void play(recording_t handle); - void release(recording_t handle); }; } // namespace crepe -- cgit v1.2.3