Delayed removal of entities.

This commit is contained in:
2014-03-13 21:40:12 +01:00
parent d6a0cdca58
commit ebd54f0833
2 changed files with 28 additions and 14 deletions
+10
View File
@@ -36,6 +36,8 @@ void World::Update(double dt)
system->Update(dt); system->Update(dt);
RecursiveUpdate(system, dt, 0); RecursiveUpdate(system, dt, 0);
} }
ProcessEntityRemovals();
} }
//std::vector<EntityID> GetEntityChildren(EntityID entity); //std::vector<EntityID> GetEntityChildren(EntityID entity);
@@ -60,6 +62,12 @@ bool World::ValidEntity(EntityID entity)
void World::RemoveEntity(EntityID entity) void World::RemoveEntity(EntityID entity)
{ {
m_EntitiesToRemove.push_back(entity);
}
void World::ProcessEntityRemovals()
{
for (auto entity : m_EntitiesToRemove) {
m_EntityParents.erase(entity); m_EntityParents.erase(entity);
// Remove components // Remove components
for (auto pair : m_EntityComponents[entity]) { for (auto pair : m_EntityComponents[entity]) {
@@ -76,6 +84,8 @@ void World::RemoveEntity(EntityID entity)
RecycleEntityID(entity); RecycleEntityID(entity);
} }
m_EntitiesToRemove.clear();
}
EntityID World::CreateEntity(EntityID parent /*= 0*/) EntityID World::CreateEntity(EntityID parent /*= 0*/)
{ {
+4
View File
@@ -85,9 +85,13 @@ protected:
std::unordered_map<std::string, std::list<std::shared_ptr<Component>>> m_ComponentsOfType; std::unordered_map<std::string, std::list<std::shared_ptr<Component>>> m_ComponentsOfType;
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents; std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
std::list<EntityID> m_EntitiesToRemove;
void ProcessEntityRemovals();
EntityID GenerateEntityID(); EntityID GenerateEntityID();
void RecycleEntityID(EntityID id); void RecycleEntityID(EntityID id);
}; };
template <class T> template <class T>