aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/ComponentManager.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-13 16:26:38 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-13 16:26:38 +0100
commitb63f4700f7bda696afb14cc3111be0f8b0eed458 (patch)
tree08c4b00b249a4fa672d97a5bc79927adac0a0257 /src/crepe/ComponentManager.h
parent2933655dea64f11f200f42fe51e58dacc5f160eb (diff)
parent9e87a556a5f68c5f9bb04bef9a66880536ccd6e8 (diff)
merge `loek/tests` into `loek/cleanup` (close #32)
Diffstat (limited to 'src/crepe/ComponentManager.h')
-rw-r--r--src/crepe/ComponentManager.h35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h
index c8c196c..75606e0 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