From 0927b0b21189df130292cc59bda92cf51348b7c6 Mon Sep 17 00:00:00 2001 From: max-001 Date: Tue, 26 Nov 2024 09:38:44 +0100 Subject: Improved delete_all_components() --- src/crepe/ComponentManager.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/crepe/ComponentManager.cpp') diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp index af4b9f4..68b5edb 100644 --- a/src/crepe/ComponentManager.cpp +++ b/src/crepe/ComponentManager.cpp @@ -27,10 +27,18 @@ void ComponentManager::delete_all_components_of_id(game_object_id_t id) { } void ComponentManager::delete_all_components() { - // Loop through all the ids and delete all components of each id - for (game_object_id_t id = 0; id < next_id; id++) { - delete_all_components_of_id(id); + // Loop through all the types (in the unordered_map<>) + for (auto & [type, component_array] : this->components) { + // Loop through all the ids (in the vector<>) + for (game_object_id_t id = 0; id < component_array.size(); id++) { + // Do not delete persistent objects + if (!this->persistent[id]) { + // Clear the components at this specific id + component_array[id].clear(); + } + } } + this->next_id = 0; } -- cgit v1.2.3