From 2969fe8c0fca4826ca129fe12d2e125bb7955c78 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 6 Oct 2024 17:39:15 +0200 Subject: WIP ScriptSystem --- src/crepe/ComponentManager.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/crepe/ComponentManager.hpp') 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 + #include "ComponentManager.h" namespace crepe { -template +template void ComponentManager::add_component(uint32_t id, Args &&... args) { using namespace std; + static_assert(is_base_of::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(forward(args)...)); + // Create a new component of type T (arguments directly forwarded). The + // constructor must be called by ComponentManager. + T * instance = new T(forward(args)...); + // store its unique_ptr in the vector<> + components[type][id].push_back(unique_ptr(instance)); } template -- cgit v1.2.3