aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/ComponentManager.hpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-06 17:39:15 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-06 17:39:15 +0200
commit2969fe8c0fca4826ca129fe12d2e125bb7955c78 (patch)
treeb7514048a8894cc5c64657e817765eb4e860187c /src/crepe/ComponentManager.hpp
parent8a509ad4c5e15fbf7eaade1c8bf4834f0d0069c5 (diff)
WIP ScriptSystem
Diffstat (limited to 'src/crepe/ComponentManager.hpp')
-rw-r--r--src/crepe/ComponentManager.hpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp
index 999cdcf..084cd33 100644
--- a/src/crepe/ComponentManager.hpp
+++ b/src/crepe/ComponentManager.hpp
@@ -1,13 +1,17 @@
#pragma once
+#include <type_traits>
+
#include "ComponentManager.h"
namespace crepe {
-template <typename T, typename... Args>
+template <class T, typename... Args>
void ComponentManager::add_component(uint32_t id, Args &&... args) {
using namespace std;
+ static_assert(is_base_of<Component, T>::value, "add_component must recieve a derivative class of Component");
+
// Determine the type of T (this is used as the key of the unordered_map<>)
type_index type = typeid(T);
@@ -23,9 +27,11 @@ void ComponentManager::add_component(uint32_t id, Args &&... args) {
components[type].resize(id + 1);
}
- // Create a new component of type T using perfect forwarding and store its
- // unique_ptr in the vector<>
- components[type][id].push_back(make_unique<T>(forward<Args>(args)...));
+ // Create a new component of type T (arguments directly forwarded). The
+ // constructor must be called by ComponentManager.
+ T * instance = new T(forward<Args>(args)...);
+ // store its unique_ptr in the vector<>
+ components[type][id].push_back(unique_ptr<T>(instance));
}
template <typename T>