aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/ComponentManager.hpp
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-11-22 11:14:13 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-11-22 11:14:13 +0100
commit08fee6eff251337dd4dca2b514a9c06d57ede0af (patch)
treeead93ad5594e1254a66a6429a600f080880f4d90 /src/crepe/ComponentManager.hpp
parent07bca38a27f794ed6a2f74536f7a909530ce7df0 (diff)
Implemented persistent objects
Diffstat (limited to 'src/crepe/ComponentManager.hpp')
-rw-r--r--src/crepe/ComponentManager.hpp13
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>