diff options
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/crepe/api/Scene.h | 62 | ||||
-rw-r--r-- | src/crepe/api/Scene.hpp | 13 | ||||
-rw-r--r-- | src/example/game.cpp | 8 |
4 files changed, 77 insertions, 7 deletions
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 <string> #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> mediator; //! \} + OptionalRef<Mediator> 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 <typename... Args> + 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 <typename... Args> +void Scene::logf(Args &&... args) { + Log::logf(std::forward<Args>(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>(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>(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>(Rigidbody::Data{ .mass = 1, |