diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-11 21:04:30 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-11 21:04:30 +0100 |
commit | 359ad8db97305856f4cfdade1cd1dada78a7a635 (patch) | |
tree | a6d5dce34c2aa5406744c414baccf6a2450dd8a5 /src/crepe/api | |
parent | 313da47b72aafa0b40ac2cd2b586d525ed17fbd4 (diff) |
more replay system WIP
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/GameObject.cpp | 10 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 13 | ||||
-rw-r--r-- | src/crepe/api/LoopManager.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Transform.cpp | 10 | ||||
-rw-r--r-- | src/crepe/api/Transform.h | 7 |
5 files changed, 31 insertions, 11 deletions
diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index ea9c425..68b074e 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -11,13 +11,9 @@ GameObject::GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, const std::string & tag, const vec2 & position, double rotation, double scale) : id(id), - mediator(mediator) { - - // Add Transform and Metadata components - ComponentManager & mgr = this->mediator.component_manager; - mgr.add_component<Transform>(this->id, position, rotation, scale); - mgr.add_component<Metadata>(this->id, name, tag); -} + mediator(mediator), + transform(mediator.component_manager->add_component<Transform>(this->id, position, rotation, scale)), + metadata(mediator.component_manager->add_component<Metadata>(this->id, name, tag)) { } void GameObject::set_parent(const GameObject & parent) { ComponentManager & mgr = this->mediator.component_manager; diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index a311c21..6203f81 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -7,6 +7,8 @@ namespace crepe { class Mediator; +class Transform; +class Metadata; /** * \brief Represents a GameObject @@ -35,6 +37,13 @@ private: friend class ComponentManager; public: + //! The id of the GameObject + const game_object_id_t id; + + Transform & transform; + Metadata & metadata; + +public: /** * \brief Set the parent of this GameObject * @@ -68,10 +77,6 @@ public: */ void set_persistent(bool persistent = true); -public: - //! The id of the GameObject - const game_object_id_t id; - protected: Mediator & mediator; }; diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index 3511bca..2855455 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -25,6 +25,8 @@ LoopManager::LoopManager() { this->load_system<InputSystem>(); this->load_system<EventSystem>(); this->load_system<AudioSystem>(); + + this->mediator.loop_manager = *this; } void LoopManager::start() { diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index a85b792..5fc886b 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -3,6 +3,7 @@ #include "Transform.h" using namespace crepe; +using namespace std; Transform::Transform(game_object_id_t id, const vec2 & point, double rotation, double scale) : Component(id), @@ -11,3 +12,12 @@ Transform::Transform(game_object_id_t id, const vec2 & point, double rotation, d scale(scale) { dbg_trace(); } + +unique_ptr<Component> Transform::save() const { + return unique_ptr<Component>{new Transform(*this)}; +} + +void Transform::restore(const Component & snapshot) { + *this = static_cast<const Transform &>(snapshot); +} + diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h index 7ee6d65..bbd23e0 100644 --- a/src/crepe/api/Transform.h +++ b/src/crepe/api/Transform.h @@ -35,6 +35,13 @@ protected: virtual int get_instances_max() const { return 1; } //! ComponentManager instantiates all components friend class ComponentManager; + +protected: + virtual std::unique_ptr<Component> save() const; + Transform(const Transform &) = default; + virtual void restore(const Component & snapshot); + virtual Transform & operator=(const Transform &) = default; + }; } // namespace crepe |