From fdb4c99e139a264d4e15e6913a3756fc6cccb2f2 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 6 Dec 2024 20:07:24 +0100 Subject: nitpick #59 --- src/crepe/api/Scene.h | 4 ++-- 1 file changed, 2 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 9f1e8ce..ba9bb76 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -12,7 +12,7 @@ class ComponentManager; /** * \brief Represents a Scene - * + * * This class represents a Scene. The Scene class is only used as an interface for the game * programmer. */ @@ -41,7 +41,7 @@ public: 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 -- cgit v1.2.3 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 ++++++++++ src/example/game.cpp | 8 +++--- 4 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/crepe/api/Scene.hpp (limited to 'src/crepe/api/Scene.h') 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)...); +} + +} diff --git a/src/example/game.cpp b/src/example/game.cpp index 5361f3a..16fe18f 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -160,15 +160,13 @@ public: void load_scene() { - Mediator & m = this->mediator; - ComponentManager & mgr = m.component_manager; Color color(0, 0, 0, 255); float screen_size_width = 320; float screen_size_height = 240; float world_collider = 1000; //define playable world - GameObject world = mgr.new_object( + GameObject world = new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); world.add_component(Rigidbody::Data{ .mass = 0, @@ -196,7 +194,7 @@ public: .zoom = 1, }); - GameObject game_object1 = mgr.new_object( + GameObject game_object1 = new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); game_object1.add_component(Rigidbody::Data{ .mass = 1, @@ -228,7 +226,7 @@ public: .active = false; - GameObject game_object2 = mgr.new_object( + GameObject game_object2 = new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); game_object2.add_component(Rigidbody::Data{ .mass = 1, -- 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/Scene.h') 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/Scene.h') 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 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/Scene.h') 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/Scene.h') 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 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/Scene.h') 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/Scene.h') 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