editor icon is removed if a component is removed while entity is being removed

This commit is contained in:
Mikulas Florek 2013-11-22 23:24:53 +01:00
parent 9a7dbdd285
commit 8456c274e1
3 changed files with 14 additions and 3 deletions

View file

@ -961,7 +961,7 @@ void EditorServer::onEvent(Event& evt)
} }
else else
{ {
if(e.component.entity.getComponents().empty()) if(e.component.entity.existsInUniverse() && e.component.entity.getComponents().empty())
{ {
EditorIcon* er = new EditorIcon(); EditorIcon* er = new EditorIcon();
er->create(e.component.entity, Component::INVALID); er->create(e.component.entity, Component::INVALID);

View file

@ -47,6 +47,17 @@ Universe::Universe()
} }
bool Entity::existsInUniverse() const
{
for(int i = 0; i < universe->m_free_slots.size(); ++i)
{
if(universe->m_free_slots[i] == index)
return false;
}
return index != -1;
}
const Quat& Entity::getRotation() const const Quat& Entity::getRotation() const
{ {
return universe->m_rotations[index]; return universe->m_rotations[index];
@ -180,9 +191,9 @@ void Universe::destroyEntity(Entity entity)
{ {
if(entity.isValid()) if(entity.isValid())
{ {
m_free_slots.push_back(entity.index);
m_event_manager->emitEvent(EntityDestroyedEvent(entity)); m_event_manager->emitEvent(EntityDestroyedEvent(entity));
m_component_list[entity.index].clear(); m_component_list[entity.index].clear();
m_free_slots.push_back(entity.index);
} }
} }

View file

@ -43,7 +43,7 @@ struct LUX_ENGINE_API Entity LUX_FINAL
bool isValid() const { return index >= 0; } bool isValid() const { return index >= 0; }
const Component& getComponent(unsigned int type); const Component& getComponent(unsigned int type);
const ComponentList& getComponents() const; const ComponentList& getComponents() const;
bool existsInUniverse() const;
bool operator ==(const Entity& rhs) const; bool operator ==(const Entity& rhs) const;