summary refs log tree commit diff stats
path: root/src/entity_manager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/entity_manager.h')
-rw-r--r--src/entity_manager.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/entity_manager.h b/src/entity_manager.h index 65fa6ca..1e8d31c 100644 --- a/src/entity_manager.h +++ b/src/entity_manager.h
@@ -26,6 +26,7 @@ private:
26 26
27 database_type entities; 27 database_type entities;
28 std::vector<bool> slotAvailable; 28 std::vector<bool> slotAvailable;
29 std::set<id_type> allEntities;
29 std::map<std::set<std::type_index>, std::set<id_type>> cachedComponents; 30 std::map<std::set<std::type_index>, std::set<id_type>> cachedComponents;
30 31
31 id_type nextEntityID = 0; 32 id_type nextEntityID = 0;
@@ -59,12 +60,14 @@ public:
59 // If the database is saturated, add a new element for the new entity. 60 // If the database is saturated, add a new element for the new entity.
60 entities.emplace_back(); 61 entities.emplace_back();
61 slotAvailable.push_back(false); 62 slotAvailable.push_back(false);
63 allEntities.insert(nextEntityID);
62 64
63 return nextEntityID++; 65 return nextEntityID++;
64 } else { 66 } else {
65 // If there is an available slot in the database, use it. 67 // If there is an available slot in the database, use it.
66 id_type id = nextEntityID++; 68 id_type id = nextEntityID++;
67 slotAvailable[id] = false; 69 slotAvailable[id] = false;
70 allEntities.insert(id);
68 71
69 // Fast forward the next available slot pointer to an available slot. 72 // Fast forward the next available slot pointer to an available slot.
70 while ((nextEntityID < entities.size()) && !slotAvailable[nextEntityID]) 73 while ((nextEntityID < entities.size()) && !slotAvailable[nextEntityID])
@@ -89,6 +92,8 @@ public:
89 cache.second.erase(entity); 92 cache.second.erase(entity);
90 } 93 }
91 94
95 allEntities.erase(entity);
96
92 // Destroy the data 97 // Destroy the data
93 entities[entity].components.clear(); 98 entities[entity].components.clear();
94 99
@@ -202,6 +207,11 @@ public:
202 207
203 return getEntitiesWithComponentsHelper<R...>(componentTypes); 208 return getEntitiesWithComponentsHelper<R...>(componentTypes);
204 } 209 }
210
211 const std::set<id_type>& getEntities() const
212 {
213 return allEntities;
214 }
205}; 215};
206 216
207template <> 217template <>