From 6fd7cec7d4bbf5aeb361b3f1337671bb0f9af61b Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 28 Nov 2024 10:13:11 +0100 Subject: manager mediator refactor --- src/crepe/api/BehaviorScript.cpp | 6 +- src/crepe/api/BehaviorScript.h | 9 +- src/crepe/api/BehaviorScript.hpp | 4 +- src/crepe/api/CMakeLists.txt | 8 -- src/crepe/api/EventManager.cpp | 46 ----------- src/crepe/api/EventManager.h | 161 ------------------------------------ src/crepe/api/EventManager.hpp | 36 -------- src/crepe/api/GameObject.hpp | 2 +- src/crepe/api/IKeyListener.h | 3 +- src/crepe/api/IMouseListener.h | 3 +- src/crepe/api/LoopManager.cpp | 25 +++--- src/crepe/api/LoopManager.h | 19 ++++- src/crepe/api/LoopManager.hpp | 7 +- src/crepe/api/SaveManager.cpp | 173 --------------------------------------- src/crepe/api/SaveManager.h | 114 -------------------------- src/crepe/api/Scene.h | 7 +- src/crepe/api/SceneManager.cpp | 34 -------- src/crepe/api/SceneManager.h | 53 ------------ src/crepe/api/SceneManager.hpp | 25 ------ src/crepe/api/Script.cpp | 17 +++- src/crepe/api/Script.h | 16 ++-- src/crepe/api/Script.hpp | 8 +- 22 files changed, 83 insertions(+), 693 deletions(-) delete mode 100644 src/crepe/api/EventManager.cpp delete mode 100644 src/crepe/api/EventManager.h delete mode 100644 src/crepe/api/EventManager.hpp delete mode 100644 src/crepe/api/SaveManager.cpp delete mode 100644 src/crepe/api/SaveManager.h delete mode 100644 src/crepe/api/SceneManager.cpp delete mode 100644 src/crepe/api/SceneManager.h delete mode 100644 src/crepe/api/SceneManager.hpp (limited to 'src/crepe/api') diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index 7bbace0..d22afdf 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -4,12 +4,12 @@ using namespace crepe; -BehaviorScript::BehaviorScript(game_object_id_t id, ComponentManager & mgr) +BehaviorScript::BehaviorScript(game_object_id_t id, Mediator & mediator) : Component(id), - component_manager(mgr) {} + mediator(mediator) {} template <> BehaviorScript & GameObject::add_component() { ComponentManager & mgr = this->component_manager; - return mgr.add_component(this->id, mgr); + return mgr.add_component(this->id, mgr.mediator); } diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index d556fe5..3909b96 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -23,14 +23,13 @@ class BehaviorScript : public Component { protected: /** * \param id Parent \c GameObject id - * \param component_manager Reference to component manager (passed through to \c Script - * instance) + * \param mediator Mediator reference * * \note Calls to this constructor (should) always pass through \c GameObject::add_component, * which has an exception for this specific component type. This was done so the user does * not have to pass references used within \c Script to each \c BehaviorScript instance. */ - BehaviorScript(game_object_id_t id, ComponentManager & component_manager); + BehaviorScript(game_object_id_t id, Mediator & mediator); //! Only ComponentManager is allowed to instantiate BehaviorScript friend class ComponentManager; @@ -55,8 +54,8 @@ protected: friend class ScriptSystem; protected: - //! Reference to component manager (passed to Script) - ComponentManager & component_manager; + //! Reference mediator + Mediator & mediator; }; /** diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp index bd59337..6de0157 100644 --- a/src/crepe/api/BehaviorScript.hpp +++ b/src/crepe/api/BehaviorScript.hpp @@ -14,11 +14,11 @@ BehaviorScript & BehaviorScript::set_script(Args &&... args) { dbg_trace(); static_assert(std::is_base_of::value); Script * s = new T(std::forward(args)...); + Mediator & mediator = this->mediator; s->game_object_id = this->game_object_id; s->active = this->active; - s->component_manager = this->component_manager; - s->event_manager = EventManager::get_instance(); + s->mediator = mediator; this->script = std::unique_ptr