From 7c21e34ae1898fce8c8051b5f1380e268da32140 Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 22 Nov 2024 09:36:35 +0100 Subject: Replaced ComponentManager reference by OptionalRef for late binding --- src/crepe/api/Scene.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/crepe/api/Scene.h') diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 869bf6f..22aadab 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -1,5 +1,6 @@ #pragma once +#include "util/OptionalRef.h" #include namespace crepe { @@ -15,11 +16,8 @@ class ComponentManager; */ class Scene { protected: - //TODO: Use Loek's custom reference class to set ComponentManger via SceneManager instead of via constructor - /** - * \param mgr Reference to the ComponentManager - */ - Scene(ComponentManager & mgr); + // NOTE: This must be the only constructor on Scene, see "Late references" below + Scene() = default; //! SceneManager instances Scene friend class SceneManager; @@ -36,8 +34,20 @@ public: virtual std::string get_name() const = 0; protected: + /** + * \name Late references + * + * These references are set by SceneManager immediately after calling the constructor of Scene. + * + * \note Scene must have a constructor without arguments so the game programmer doesn't need to + * manually add `using Scene::Scene` to their concrete scene class, if they want to add a + * constructor with arguments (e.g. for passing references to their own concrete Scene classes). + * + * \{ + */ //! Reference to the ComponentManager - ComponentManager & component_manager; + OptionalRef component_manager; + //! \} }; } // namespace crepe -- cgit v1.2.3 From be5ccbe24086d5d4fb407f268c649dcbc36eda6b Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 24 Nov 2024 19:03:06 +0100 Subject: nitpick #50 --- src/crepe/api/Scene.h | 3 ++- src/doc/feature/scene.dox | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/crepe/api/Scene.h') diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 22aadab..f6fdb2a 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -1,8 +1,9 @@ #pragma once -#include "util/OptionalRef.h" #include +#include "../util/OptionalRef.h" + namespace crepe { class SceneManager; diff --git a/src/doc/feature/scene.dox b/src/doc/feature/scene.dox index bac1c87..d81df4c 100644 --- a/src/doc/feature/scene.dox +++ b/src/doc/feature/scene.dox @@ -36,7 +36,7 @@ concrete scene to be added. #include #include #include -#include +#include using namespace crepe; -- cgit v1.2.3