(World) Fixed entity killing

Former-commit-id: 180cd3c163cb2c6595a6710ce9302bcb83923870
This commit is contained in:
Lynix 2015-02-08 15:43:27 +01:00
parent 5067767074
commit 12824deba2
1 changed files with 10 additions and 9 deletions

View File

@ -52,6 +52,7 @@ namespace Ndk
void World::KillEntity(Entity& entity) void World::KillEntity(Entity& entity)
{ {
if (IsEntityValid(entity))
m_killedEntities.push_back(entity); m_killedEntities.push_back(entity);
} }
@ -87,12 +88,11 @@ namespace Ndk
{ {
if (!m_killedEntities.empty()) if (!m_killedEntities.empty())
{ {
///FIXME: Inverser les deux boucles ? for (unsigned int i = 0; i < m_killedEntities.size(); ++i)
for (unsigned int i = 0; i < m_aliveEntities.size(); ++i)
{ {
Entity::Id e1 = m_aliveEntities[i].GetId(); Entity::Id e1 = m_aliveEntities[i].GetId();
for (unsigned int j = 0; j < m_killedEntities.size(); ++j) for (unsigned int j = 0; j < m_aliveEntities.size(); ++j)
{ {
Entity::Id e2 = m_killedEntities[j].GetId(); Entity::Id e2 = m_killedEntities[j].GetId();
if (e1 == e2) if (e1 == e2)
@ -105,15 +105,16 @@ namespace Ndk
m_freeIdList.push_back(e1); m_freeIdList.push_back(e1);
// Suppression de l'entité des deux tableaux // Suppression de l'entité des deux tableaux
m_aliveEntities.erase(m_aliveEntities.begin() + i); m_aliveEntities.erase(m_aliveEntities.begin() + j);
m_killedEntities.erase(m_killedEntities.begin() + j); m_killedEntities.erase(m_killedEntities.begin() + i);
break;
}
}
if (m_killedEntities.empty()) // Correction des indices (pour ne pas sauter une case)
i--;
j--;
break; break;
} }
} }
} }
} }
}
}