diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-14 11:26:12 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-14 11:26:12 +0100 |
commit | 01c09a196c3f3e5cefaa4119a95a1cdeb7b9c263 (patch) | |
tree | 5667369a85bd06b683c67de42bf0311c2647912b /src/crepe/ComponentManager.h | |
parent | 6e13510f3c6d4155707f748d237bb1fa05243450 (diff) | |
parent | 8600b8a29351aae26ec7b22f84aeeef92d8cb421 (diff) |
merge `loek/cleanup` into `loek/audio`
Diffstat (limited to 'src/crepe/ComponentManager.h')
-rw-r--r-- | src/crepe/ComponentManager.h | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h index c8c196c..51c84a4 100644 --- a/src/crepe/ComponentManager.h +++ b/src/crepe/ComponentManager.h @@ -1,15 +1,18 @@ #pragma once -#include <cstdint> +#include <forward_list> #include <memory> #include <typeindex> #include <unordered_map> #include <vector> #include "Component.h" +#include "api/Vector2.h" namespace crepe { +class GameObject; + /** * \brief Manages all components * @@ -18,18 +21,10 @@ namespace crepe { */ class ComponentManager { public: - /** - * \brief Get the instance of the ComponentManager - * - * \return The instance of the ComponentManager - */ - static ComponentManager & get_instance(); - ComponentManager(const ComponentManager &) = delete; - ComponentManager(ComponentManager &&) = delete; - ComponentManager & operator=(const ComponentManager &) = delete; - ComponentManager & operator=(ComponentManager &&) = delete; - ~ComponentManager(); + ComponentManager(); // dbg_trace + ~ComponentManager(); // dbg_trace +protected: /** * \brief Add a component to the ComponentManager * @@ -44,6 +39,11 @@ public: */ template <typename T, typename... Args> T & add_component(game_object_id_t id, Args &&... args); + //! GameObject is used as an interface to add components instead of the + // component manager directly + friend class GameObject; + +public: /** * \brief Delete all components of a specific type and id * @@ -100,8 +100,11 @@ public: template <typename T> std::vector<std::reference_wrapper<T>> get_components_by_type() const; -private: - ComponentManager(); + // TODO: doxygen + GameObject new_object(const std::string & name, + const std::string & tag = "", + const Vector2 & position = {0, 0}, + double rotation = 0, double scale = 0); private: /** @@ -118,6 +121,10 @@ private: std::unordered_map<std::type_index, std::vector<std::vector<std::unique_ptr<Component>>>> components; + + //! ID of next GameObject + game_object_id_t next_id = 0; + std::forward_list<std::unique_ptr<GameObject>> objects; }; } // namespace crepe |