From 1bfd582b7b7f762011f5f4b7f84e180cf20e9046 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 12 Dec 2024 19:35:19 +0100 Subject: shielded mediator --- src/crepe/api/CMakeLists.txt | 1 + src/crepe/api/Scene.h | 62 ++++++++++++++++++++++++++++++++++++++++++-- src/crepe/api/Scene.hpp | 13 ++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/crepe/api/Scene.hpp (limited to 'src/crepe/api') diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index fb11c8d..eb7b042 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -36,6 +36,7 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Vector2.hpp Color.h Scene.h + Scene.hpp Metadata.h Camera.h Animator.h diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index ba9bb76..a1e5cfe 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -3,12 +3,16 @@ #include #include "../manager/Mediator.h" +#include "../manager/ResourceManager.h" +#include "../manager/ComponentManager.h" #include "../util/OptionalRef.h" +#include "GameObject.h" namespace crepe { class SceneManager; class ComponentManager; +class Asset; /** * \brief Represents a Scene @@ -38,7 +42,7 @@ public: // TODO: Late references should ALWAYS be private! This is currently kept as-is so unit tests // keep passing, but this reference should not be directly accessible by the user!!! -protected: +private: /** * \name Late references * @@ -51,8 +55,62 @@ protected: * \{ */ //! Mediator reference - OptionalRef mediator; //! \} + OptionalRef mediator; + +protected: + + /** + * \brief Retrieve the reference to the SaveManager instance + * + * \returns A reference to the SaveManager instance held by the Mediator. + */ + SaveManager& get_save_manager() const{ + return mediator->save_manager; + } + + /** + * \brief Create a new game object using the component manager + * + * \param name Metadata::name (required) + * \param tag Metadata::tag (optional, empty by default) + * \param position Transform::position (optional, origin by default) + * \param rotation Transform::rotation (optional, 0 by default) + * \param scale Transform::scale (optional, 1 by default) + * + * \returns GameObject interface + * + * \note This method automatically assigns a new entity ID + */ + GameObject new_object(const std::string & name, const std::string & tag = "", + const vec2 & position = {0, 0}, double rotation = 0, + double scale = 1) { + // Forward the call to ComponentManager's new_object method + return mediator->component_manager->new_object(name, tag, position, rotation, scale); + } + + /** + * \brief Mark a resource as persistent (i.e. used across multiple scenes) + * + * \param asset Asset the concrete resource is instantiated from + * \param persistent Whether this resource is persistent (true=keep, false=destroy) + */ + void set_persistent(const Asset & asset, bool persistent){ + mediator->resource_manager->set_persistent(asset, persistent); + } + + /** + * \brief Log a message using Log::logf + * + * \tparam Args Log::logf parameters + * \param args Log::logf parameters + */ + template + void logf(Args &&... args); + }; } // namespace crepe + + +#include "Scene.hpp" diff --git a/src/crepe/api/Scene.hpp b/src/crepe/api/Scene.hpp new file mode 100644 index 0000000..d0ada65 --- /dev/null +++ b/src/crepe/api/Scene.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "Scene.h" +#include "../util/Log.h" + +namespace crepe { + +template +void Scene::logf(Args &&... args) { + Log::logf(std::forward(args)...); +} + +} -- cgit v1.2.3 From c9a093dfb670e29fb92cfd75938aa8f293a0767a Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 12 Dec 2024 19:37:10 +0100 Subject: format --- src/crepe/api/Scene.h | 15 +++++---------- src/crepe/api/Scene.hpp | 4 ++-- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index a1e5cfe..6ee1f68 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -2,9 +2,9 @@ #include +#include "../manager/ComponentManager.h" #include "../manager/Mediator.h" #include "../manager/ResourceManager.h" -#include "../manager/ComponentManager.h" #include "../util/OptionalRef.h" #include "GameObject.h" @@ -59,15 +59,12 @@ private: OptionalRef mediator; protected: - /** * \brief Retrieve the reference to the SaveManager instance * * \returns A reference to the SaveManager instance held by the Mediator. */ - SaveManager& get_save_manager() const{ - return mediator->save_manager; - } + SaveManager & get_save_manager() const { return mediator->save_manager; } /** * \brief Create a new game object using the component manager @@ -83,8 +80,8 @@ protected: * \note This method automatically assigns a new entity ID */ GameObject new_object(const std::string & name, const std::string & tag = "", - const vec2 & position = {0, 0}, double rotation = 0, - double scale = 1) { + const vec2 & position = {0, 0}, double rotation = 0, + double scale = 1) { // Forward the call to ComponentManager's new_object method return mediator->component_manager->new_object(name, tag, position, rotation, scale); } @@ -95,7 +92,7 @@ protected: * \param asset Asset the concrete resource is instantiated from * \param persistent Whether this resource is persistent (true=keep, false=destroy) */ - void set_persistent(const Asset & asset, bool persistent){ + void set_persistent(const Asset & asset, bool persistent) { mediator->resource_manager->set_persistent(asset, persistent); } @@ -107,10 +104,8 @@ protected: */ template void logf(Args &&... args); - }; } // namespace crepe - #include "Scene.hpp" diff --git a/src/crepe/api/Scene.hpp b/src/crepe/api/Scene.hpp index d0ada65..58aacb6 100644 --- a/src/crepe/api/Scene.hpp +++ b/src/crepe/api/Scene.hpp @@ -1,7 +1,7 @@ #pragma once -#include "Scene.h" #include "../util/Log.h" +#include "Scene.h" namespace crepe { @@ -10,4 +10,4 @@ void Scene::logf(Args &&... args) { Log::logf(std::forward(args)...); } -} +} // namespace crepe -- cgit v1.2.3 From 5f09a71b433e01a9dc17f93c5d9f79117cef618e Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 12 Dec 2024 19:38:17 +0100 Subject: fixed includes --- src/crepe/api/Scene.h | 1 + src/crepe/api/Scene.hpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index a1e5cfe..cb8147f 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -6,6 +6,7 @@ #include "../manager/ResourceManager.h" #include "../manager/ComponentManager.h" #include "../util/OptionalRef.h" + #include "GameObject.h" namespace crepe { diff --git a/src/crepe/api/Scene.hpp b/src/crepe/api/Scene.hpp index d0ada65..b0ef392 100644 --- a/src/crepe/api/Scene.hpp +++ b/src/crepe/api/Scene.hpp @@ -1,8 +1,9 @@ #pragma once -#include "Scene.h" #include "../util/Log.h" +#include "Scene.h" + namespace crepe { template -- cgit v1.2.3 From 1cce3f1456f9df143d700d3ac37fcfd318577a36 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 12 Dec 2024 19:39:01 +0100 Subject: removed merge include --- src/crepe/api/Scene.hpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Scene.hpp b/src/crepe/api/Scene.hpp index ee89981..ecb21ed 100644 --- a/src/crepe/api/Scene.hpp +++ b/src/crepe/api/Scene.hpp @@ -1,7 +1,6 @@ #pragma once #include "../util/Log.h" -#include "Scene.h" #include "Scene.h" -- cgit v1.2.3 From 5a8ae8b82019afbb5aa40f4fbcf45a9df82d43f3 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 13 Dec 2024 17:56:35 +0100 Subject: moved mediator up --- src/crepe/api/Scene.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 9ef75b5..1203612 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -56,8 +56,8 @@ private: * \{ */ //! Mediator reference - //! \} OptionalRef mediator; + //! \} protected: /** -- cgit v1.2.3 From 128e7975eb6417438fcf6f51224b6067554a2004 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 13 Dec 2024 18:43:12 +0100 Subject: added feedback --- src/crepe/api/Scene.cpp | 5 +++++ src/crepe/api/Scene.h | 38 +++++++++++++++----------------------- src/crepe/api/Scene.hpp | 11 ++++++++--- 3 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 src/crepe/api/Scene.cpp (limited to 'src/crepe/api') diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp new file mode 100644 index 0000000..5117766 --- /dev/null +++ b/src/crepe/api/Scene.cpp @@ -0,0 +1,5 @@ +#include "Scene.h" + +using namespace crepe; + +SaveManager & Scene::get_save_manager() const { return mediator->save_manager; } diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index 1203612..cba4e10 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -6,6 +6,7 @@ #include "../manager/Mediator.h" #include "../manager/ResourceManager.h" #include "../util/OptionalRef.h" +#include "../util/Log.h" #include "GameObject.h" @@ -65,20 +66,10 @@ protected: * * \returns A reference to the SaveManager instance held by the Mediator. */ - SaveManager & get_save_manager() const { return mediator->save_manager; } + SaveManager & get_save_manager() const; /** - * \brief Create a new game object using the component manager - * - * \param name Metadata::name (required) - * \param tag Metadata::tag (optional, empty by default) - * \param position Transform::position (optional, origin by default) - * \param rotation Transform::rotation (optional, 0 by default) - * \param scale Transform::scale (optional, 1 by default) - * - * \returns GameObject interface - * - * \note This method automatically assigns a new entity ID + * \copydoc ComponentManager::new_object */ GameObject new_object(const std::string & name, const std::string & tag = "", const vec2 & position = {0, 0}, double rotation = 0, @@ -88,23 +79,24 @@ protected: } /** - * \brief Mark a resource as persistent (i.e. used across multiple scenes) - * - * \param asset Asset the concrete resource is instantiated from - * \param persistent Whether this resource is persistent (true=keep, false=destroy) + * \copydoc ResourceManager::set_persistent */ void set_persistent(const Asset & asset, bool persistent) { mediator->resource_manager->set_persistent(asset, persistent); } /** - * \brief Log a message using Log::logf - * - * \tparam Args Log::logf parameters - * \param args Log::logf parameters - */ - template - void logf(Args &&... args); + * \name Logging functions + * \see Log + * \{ + */ + //! \copydoc Log::logf + template + void logf(const Log::Level & level, std::format_string fmt, Args &&... args); + //! \copydoc Log::logf + template + void logf(std::format_string fmt, Args &&... args); + //! \} }; } // namespace crepe diff --git a/src/crepe/api/Scene.hpp b/src/crepe/api/Scene.hpp index ecb21ed..14635df 100644 --- a/src/crepe/api/Scene.hpp +++ b/src/crepe/api/Scene.hpp @@ -6,9 +6,14 @@ namespace crepe { -template -void Scene::logf(Args &&... args) { - Log::logf(std::forward(args)...); +template +void Scene::logf(const Log::Level & level, std::format_string fmt, Args &&... args) { + Log::logf(level, fmt, std::forward(args)...); +} + +template +void Scene::logf(std::format_string fmt, Args &&... args) { + Log::logf(fmt, std::forward(args)...); } } // namespace crepe -- cgit v1.2.3 From 374cdf9b14e372e85c7a88c0b994146b34977193 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 13 Dec 2024 18:45:12 +0100 Subject: added scene to cmake --- src/crepe/api/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'src/crepe/api') diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index eb7b042..8f84f06 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -20,6 +20,7 @@ target_sources(crepe PUBLIC Button.cpp UIObject.cpp AI.cpp + Scene.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES -- cgit v1.2.3 From c4c5758061c817784743af07271445905d62dfdd Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 13 Dec 2024 20:47:57 +0100 Subject: moved code to cpp --- src/crepe/api/Scene.cpp | 10 ++++++++++ src/crepe/api/Scene.h | 19 ++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp index 5117766..9a2a1bc 100644 --- a/src/crepe/api/Scene.cpp +++ b/src/crepe/api/Scene.cpp @@ -3,3 +3,13 @@ using namespace crepe; SaveManager & Scene::get_save_manager() const { return mediator->save_manager; } + +GameObject Scene::new_object(const std::string & name, const std::string & tag, const vec2 & position, double rotation, double scale) { + // Forward the call to ComponentManager's new_object method + return mediator->component_manager->new_object(name, tag, position, rotation, scale); +} + + +void Scene::set_persistent(const Asset & asset, bool persistent) { + mediator->resource_manager->set_persistent(asset, persistent); +} diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index cba4e10..e70d9ba 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -68,23 +68,12 @@ protected: */ SaveManager & get_save_manager() const; - /** - * \copydoc ComponentManager::new_object - */ - GameObject new_object(const std::string & name, const std::string & tag = "", - const vec2 & position = {0, 0}, double rotation = 0, - double scale = 1) { - // Forward the call to ComponentManager's new_object method - return mediator->component_manager->new_object(name, tag, position, rotation, scale); - } + //! \copydoc ComponentManager::new_object + GameObject new_object(const std::string & name, const std::string & tag = "", const vec2 & position = {0, 0}, double rotation = 0, double scale = 1); - /** - * \copydoc ResourceManager::set_persistent - */ - void set_persistent(const Asset & asset, bool persistent) { - mediator->resource_manager->set_persistent(asset, persistent); - } + //! \copydoc ResourceManager::set_persistent + void set_persistent(const Asset & asset, bool persistent); /** * \name Logging functions * \see Log -- cgit v1.2.3 From ded2f0d56d95edffb97830f406bce9e1ec4293d1 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 13 Dec 2024 20:48:44 +0100 Subject: make format --- src/crepe/api/Scene.cpp | 10 +++++----- src/crepe/api/Scene.h | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp index 9a2a1bc..ad729d2 100644 --- a/src/crepe/api/Scene.cpp +++ b/src/crepe/api/Scene.cpp @@ -4,12 +4,12 @@ using namespace crepe; SaveManager & Scene::get_save_manager() const { return mediator->save_manager; } -GameObject Scene::new_object(const std::string & name, const std::string & tag, const vec2 & position, double rotation, double scale) { - // Forward the call to ComponentManager's new_object method - return mediator->component_manager->new_object(name, tag, position, rotation, scale); +GameObject Scene::new_object(const std::string & name, const std::string & tag, + const vec2 & position, double rotation, double scale) { + // Forward the call to ComponentManager's new_object method + return mediator->component_manager->new_object(name, tag, position, rotation, scale); } - void Scene::set_persistent(const Asset & asset, bool persistent) { - mediator->resource_manager->set_persistent(asset, persistent); + mediator->resource_manager->set_persistent(asset, persistent); } diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index e70d9ba..dcca9d4 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -5,8 +5,8 @@ #include "../manager/ComponentManager.h" #include "../manager/Mediator.h" #include "../manager/ResourceManager.h" -#include "../util/OptionalRef.h" #include "../util/Log.h" +#include "../util/OptionalRef.h" #include "GameObject.h" @@ -69,10 +69,11 @@ protected: SaveManager & get_save_manager() const; //! \copydoc ComponentManager::new_object - GameObject new_object(const std::string & name, const std::string & tag = "", const vec2 & position = {0, 0}, double rotation = 0, double scale = 1); - + GameObject new_object(const std::string & name, const std::string & tag = "", + const vec2 & position = {0, 0}, double rotation = 0, + double scale = 1); - //! \copydoc ResourceManager::set_persistent + //! \copydoc ResourceManager::set_persistent void set_persistent(const Asset & asset, bool persistent); /** * \name Logging functions -- cgit v1.2.3