diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-11-07 12:44:27 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-11-07 12:44:27 +0100 |
commit | 41c0ea36b025f0c15c7d14db8d88eb9558085b74 (patch) | |
tree | 7960787822f4bea96b29af1d81db855edf039759 /src | |
parent | d7b17796943e2cc09bf4de853a9c1a19d3cb6786 (diff) | |
parent | ce8debc03d2ed291285535462cbf4411bf298278 (diff) |
Merge remote-tracking branch 'origin/master' into max/big-cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/ComponentManager.hpp | 13 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.h | 5 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp index 7616f92..489e188 100644 --- a/src/crepe/ComponentManager.hpp +++ b/src/crepe/ComponentManager.hpp @@ -30,11 +30,16 @@ T & ComponentManager::add_component(uint32_t id, Args &&... args) { // Create a new component of type T (arguments directly forwarded). The // constructor must be called by ComponentManager. - unique_ptr<T> instance = unique_ptr<T>(new T(id, forward<Args>(args)...)); + T * instance_ptr = new T(id, forward<Args>(args)...); + if (instance_ptr == nullptr) + throw std::bad_alloc(); + + T & instance_ref = *instance_ptr; + unique_ptr<T> instance = unique_ptr<T>(instance_ptr); // Check if the vector size is not greater than get_instances_max - if (instance->get_instances_max() != -1 - && this->components[type][id].size() >= instance->get_instances_max()) { + int max_instances = instance->get_instances_max(); + if (max_instances != -1 && components[type][id].size() >= max_instances) { // TODO: Exception throw std::runtime_error( "Exceeded maximum number of instances for this component type"); @@ -43,7 +48,7 @@ T & ComponentManager::add_component(uint32_t id, Args &&... args) { // store its unique_ptr in the vector<> this->components[type][id].push_back(std::move(instance)); - return *instance; + return instance_ref; } template <typename T> diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 21638f4..6b1fec7 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -5,12 +5,9 @@ #include "../Component.h" namespace crepe { + class ScriptSystem; class ComponentManager; -} // namespace crepe - -namespace crepe { - class Script; class BehaviorScript : public Component { |