From 45f1f18c78e73280a8a861df2db6237bae6f6d80 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 12 Dec 2024 19:02:40 +0100 Subject: add script api for replaymanager --- src/crepe/Component.cpp | 3 ++- src/crepe/api/Script.cpp | 21 +++++++++++++++++++++ src/crepe/api/Script.h | 18 ++++++++++++++++++ src/crepe/manager/ReplayManager.h | 5 +++++ src/crepe/system/ReplaySystem.h | 2 -- src/example/replay.cpp | 35 ++++++++--------------------------- 6 files changed, 54 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp index 8086492..1aed507 100644 --- a/src/crepe/Component.cpp +++ b/src/crepe/Component.cpp @@ -5,7 +5,8 @@ using namespace std; Component::Component(game_object_id_t id) : game_object_id(id) {} -Component & Component::operator=(const Component &) { +Component & Component::operator=(const Component & other) { + this->active = other.active; return *this; } diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp index 753a9e3..8b95cc9 100644 --- a/src/crepe/api/Script.cpp +++ b/src/crepe/api/Script.cpp @@ -25,3 +25,24 @@ void Script::set_next_scene(const string & name) { } SaveManager & Script::get_save_manager() const { return this->mediator->save_manager; } + +void Script::replay::record_start() { + ReplayManager & mgr = this->mediator->replay_manager; + return mgr.record_start(); +} + +recording_t Script::replay::record_end() { + ReplayManager & mgr = this->mediator->replay_manager; + return mgr.record_end(); +} + +void Script::replay::play(recording_t recording) { + ReplayManager & mgr = this->mediator->replay_manager; + return mgr.play(recording); +} + +void Script::replay::release(recording_t recording) { + ReplayManager & mgr = this->mediator->replay_manager; + return mgr.release(recording); +} + diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 668e5d1..c797db0 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -2,6 +2,7 @@ #include +#include "../manager/ReplayManager.h" #include "../manager/EventManager.h" #include "../manager/Mediator.h" #include "../system/CollisionSystem.h" @@ -135,6 +136,23 @@ protected: //! Retrieve SaveManager reference SaveManager & get_save_manager() const; + //! Replay management functions + struct replay { // NOLINT + //! \copydoc ReplayManager::record_start + void record_start(); + //! \copydoc ReplayManager::record_end + recording_t record_end(); + //! \copydoc ReplayManager::play + void play(recording_t); + //! \copydoc ReplayManager::release + void release(recording_t); + + private: + OptionalRef & mediator; + replay(OptionalRef & mediator) : mediator(mediator) {} + friend class Script; + } replay{mediator}; + //! \} private: diff --git a/src/crepe/manager/ReplayManager.h b/src/crepe/manager/ReplayManager.h index 5794761..7be18f3 100644 --- a/src/crepe/manager/ReplayManager.h +++ b/src/crepe/manager/ReplayManager.h @@ -12,7 +12,12 @@ class ReplaySystem; typedef size_t recording_t; +/** + * \brief Replay manager + * + */ class ReplayManager : public Manager { + // TODO: Delete recordings at end of scene public: ReplayManager(Mediator & mediator); diff --git a/src/crepe/system/ReplaySystem.h b/src/crepe/system/ReplaySystem.h index 6f6fce4..919c554 100644 --- a/src/crepe/system/ReplaySystem.h +++ b/src/crepe/system/ReplaySystem.h @@ -15,8 +15,6 @@ public: private: ReplayManager::State last_state = ReplayManager::IDLE; - void update_recording(); - void update_playing(); struct Snapshot { ComponentManager::Snapshot components; diff --git a/src/example/replay.cpp b/src/example/replay.cpp index e7f4e6d..4c606d7 100644 --- a/src/example/replay.cpp +++ b/src/example/replay.cpp @@ -1,19 +1,6 @@ -#include -#include -#include -#include -#include -#include -#include #include -#include -#include #include -#include -#include -#include -#include -#include +#include using namespace crepe; using namespace std; @@ -34,27 +21,20 @@ class AnimationScript : public Script { class Timeline : public Script { unsigned i = 0; - ReplayManager & mgr; recording_t recording; -public: - Timeline(ReplayManager & mgr) - : mgr(mgr) {} - void update() { switch (i++) { default: break; case 10: - mgr.record_start(); + replay.record_start(); break; case 60: - this->recording = mgr.record_end(); - break; - case 70: - mgr.play(this->recording); + this->recording = replay.record_end(); + replay.play(this->recording); break; - case 71: - mgr.release(this->recording); + case 61: + replay.release(this->recording); break; case 72: throw; @@ -86,7 +66,7 @@ public: square.add_component().set_script(); GameObject scapegoat = mgr.new_object(""); - scapegoat.add_component().set_script(mediator.replay_manager); + scapegoat.add_component().set_script(); } string get_name() const { return "scene1"; } @@ -100,5 +80,6 @@ int main(int argc, char * argv[]) { engine.add_scene(); engine.start(); + return 0; } -- cgit v1.2.3