aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crepe/ComponentManager.cpp14
1 files changed, 11 insertions, 3 deletions
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;
}