aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-11-26 09:38:44 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-11-26 09:38:44 +0100
commit0927b0b21189df130292cc59bda92cf51348b7c6 (patch)
tree7279e336939790a5535686990b4a38ace9197963
parent07ac07ce4cafe8ec454a1e53b1541dcaab10cf40 (diff)
Improved delete_all_components()
-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;
}