diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-28 08:23:04 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-28 08:23:04 +0100 |
commit | 87c147dde61e2534d4e66c159a711b0f1ab68b8b (patch) | |
tree | 4316ebe9fe8e9abad55d5b0309bda06cd4f01b77 /src/crepe/ComponentManager.hpp | |
parent | 80836bce1294898f3d115ed363edd6d921aa15d5 (diff) | |
parent | d1eed940b8119e95a14f1d08bf26184c7f0a0d8f (diff) |
Merge branch 'master' into niels/decoupling_pixel_and_pos
Diffstat (limited to 'src/crepe/ComponentManager.hpp')
-rw-r--r-- | src/crepe/ComponentManager.hpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp index 4d5eaf4..ffb38ec 100644 --- a/src/crepe/ComponentManager.hpp +++ b/src/crepe/ComponentManager.hpp @@ -54,6 +54,11 @@ template <typename T> void ComponentManager::delete_components_by_id(game_object_id_t id) { using namespace std; + // Do not delete persistent objects + if (this->persistent[id]) { + return; + } + // Determine the type of T (this is used as the key of the unordered_map<>) type_index type = typeid(T); @@ -77,7 +82,13 @@ void ComponentManager::delete_components() { if (this->components.find(type) == this->components.end()) return; - this->components[type].clear(); + // Loop through the whole vector<> of this specific type + for (game_object_id_t i = 0; i < this->components[type].size(); ++i) { + // Do not delete persistent objects + if (!this->persistent[i]) { + this->components[type][i].clear(); + } + } } template <typename T> |