From e585e01b625fcdbc00709c1bbade1b542b1f6139 Mon Sep 17 00:00:00 2001 From: max-001 Date: Wed, 20 Nov 2024 11:42:23 +0100 Subject: Added Doxygen comments/explanation for GameObjects and Scenes --- src/crepe/api/Scene.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/crepe/api/Scene.h') diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 0e516b6..6647135 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -7,19 +7,33 @@ namespace crepe { class SceneManager; class ComponentManager; +/** + * \brief Represents a Scene + * + * This class represents a Scene. The Scene class is only used as an interface for the game + * programmer. + */ class Scene { protected: + /** + * \param mgr Reference to the ComponentManager + * \param name Name of the scene + */ Scene(ComponentManager & mgr, const std::string & name); + //! SceneManager instances Scene friend class SceneManager; public: virtual ~Scene() = default; public: + //! Load the scene virtual void load_scene() = 0; + //! The scene name const std::string name; protected: + //! Reference to the ComponentManager ComponentManager & component_manager; }; -- cgit v1.2.3 From 801be9bd006a5f9f24a76067113bf1fd756aabbd Mon Sep 17 00:00:00 2001 From: max-001 Date: Thu, 21 Nov 2024 08:47:36 +0100 Subject: Replaced Scene's name variable with get_name() method --- src/crepe/api/Scene.cpp | 4 +--- src/crepe/api/Scene.h | 9 ++++++--- src/crepe/api/SceneManager.cpp | 2 +- src/crepe/api/SceneManager.h | 2 +- src/crepe/api/SceneManager.hpp | 6 +++--- src/example/scene_manager.cpp | 8 ++++++-- 6 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src/crepe/api/Scene.h') diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp index 88aa82d..849945e 100644 --- a/src/crepe/api/Scene.cpp +++ b/src/crepe/api/Scene.cpp @@ -2,6 +2,4 @@ using namespace crepe; -Scene::Scene(ComponentManager & mgr, const std::string & name) - : component_manager(mgr), - name(name) {} +Scene::Scene(ComponentManager & mgr) : component_manager(mgr) {} diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 6647135..45595c7 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -19,7 +19,7 @@ protected: * \param mgr Reference to the ComponentManager * \param name Name of the scene */ - Scene(ComponentManager & mgr, const std::string & name); + Scene(ComponentManager & mgr); //! SceneManager instances Scene friend class SceneManager; @@ -29,8 +29,11 @@ public: public: //! Load the scene virtual void load_scene() = 0; - //! The scene name - const std::string name; + /** + * \brief Get the scene's name + * \return The scene's name + */ + virtual std::string get_name() = 0; protected: //! Reference to the ComponentManager diff --git a/src/crepe/api/SceneManager.cpp b/src/crepe/api/SceneManager.cpp index 7fb5cb0..1f783ad 100644 --- a/src/crepe/api/SceneManager.cpp +++ b/src/crepe/api/SceneManager.cpp @@ -18,7 +18,7 @@ void SceneManager::load_next_scene() { auto it = find_if(this->scenes.begin(), this->scenes.end(), [&next_scene = this->next_scene](unique_ptr & scene) { - return scene->name == next_scene; + return scene.get()->get_name() == next_scene; }); // next scene not found diff --git a/src/crepe/api/SceneManager.h b/src/crepe/api/SceneManager.h index 16d6004..ebf77e7 100644 --- a/src/crepe/api/SceneManager.h +++ b/src/crepe/api/SceneManager.h @@ -29,7 +29,7 @@ public: * \param name Name of new scene */ template - void add_scene(const std::string & name); + void add_scene(); /** * \brief Set the next scene * diff --git a/src/crepe/api/SceneManager.hpp b/src/crepe/api/SceneManager.hpp index 714f690..94e5946 100644 --- a/src/crepe/api/SceneManager.hpp +++ b/src/crepe/api/SceneManager.hpp @@ -5,16 +5,16 @@ namespace crepe { template -void SceneManager::add_scene(const std::string & name) { +void SceneManager::add_scene() { using namespace std; static_assert(is_base_of::value, "T must be derived from Scene"); - Scene * scene = new T(this->component_manager, name); + Scene * scene = new T(this->component_manager); this->scenes.emplace_back(unique_ptr(scene)); // The first scene added, is the one that will be loaded at the beginning if (next_scene.empty()) { - next_scene = name; + next_scene = scene->get_name(); } } diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp index accec7d..ac7f439 100644 --- a/src/example/scene_manager.cpp +++ b/src/example/scene_manager.cpp @@ -20,6 +20,8 @@ public: GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); } + + string get_name() { return "scene1"; } }; class ConcreteScene2 : public Scene { @@ -33,6 +35,8 @@ public: GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); } + + string get_name() { return "scene2"; } }; int main() { @@ -40,8 +44,8 @@ int main() { SceneManager scene_mgr{component_mgr}; // Add the scenes to the scene manager - scene_mgr.add_scene("scene1"); - scene_mgr.add_scene("scene2"); + scene_mgr.add_scene(); + scene_mgr.add_scene(); // There is no need to call set_next_scene() at the beginnen, because the first scene will be // automatically set as the next scene -- cgit v1.2.3 From a3512cfa329d50fb72d22a39d4c134d39763815f Mon Sep 17 00:00:00 2001 From: max-001 Date: Thu, 21 Nov 2024 08:49:23 +0100 Subject: Added TODO --- src/crepe/api/Scene.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/crepe/api/Scene.h') diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 45595c7..74cfac3 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -15,9 +15,9 @@ 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 - * \param name Name of the scene */ Scene(ComponentManager & mgr); //! SceneManager instances Scene -- cgit v1.2.3 From ba93a8deaf7ba4e68c25d74c58637450cbe0e056 Mon Sep 17 00:00:00 2001 From: max-001 Date: Thu, 21 Nov 2024 09:30:23 +0100 Subject: Added const --- src/crepe/api/Scene.h | 2 +- src/example/scene_manager.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/crepe/api/Scene.h') diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 74cfac3..869bf6f 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -33,7 +33,7 @@ public: * \brief Get the scene's name * \return The scene's name */ - virtual std::string get_name() = 0; + virtual std::string get_name() const = 0; protected: //! Reference to the ComponentManager diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp index 7277afa..2ab45f9 100644 --- a/src/example/scene_manager.cpp +++ b/src/example/scene_manager.cpp @@ -1,6 +1,6 @@ #define private public -#include "api/LoopManager.h" +#include #include #include @@ -24,7 +24,7 @@ public: GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); } - string get_name() { return "scene1"; } + string get_name() const { return "scene1"; } }; class ConcreteScene2 : public Scene { @@ -39,7 +39,7 @@ public: GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); } - string get_name() { return "scene2"; } + string get_name() const { return "scene2"; } }; int main() { -- cgit v1.2.3