Added World::ValidEntity for checking if an entity exists or not
This commit is contained in:
@@ -16,7 +16,8 @@ public:
|
|||||||
EntityID CreateEntity(EntityID parent = 0);
|
EntityID CreateEntity(EntityID parent = 0);
|
||||||
// Delete entity and all components within
|
// Delete entity and all components within
|
||||||
void DeleteEntity(EntityID entity);
|
void DeleteEntity(EntityID entity);
|
||||||
|
// Check if an entity exists
|
||||||
|
bool ValidEntity(EntityID entity) const;
|
||||||
// Register a component type and allocate space for it
|
// Register a component type and allocate space for it
|
||||||
void RegisterComponent(ComponentInfo& ci);
|
void RegisterComponent(ComponentInfo& ci);
|
||||||
// Attach a component to an entity and fill it with default values
|
// Attach a component to an entity and fill it with default values
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ void World::DeleteEntity(EntityID entity)
|
|||||||
m_EntityNames.erase(entity);
|
m_EntityNames.erase(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool World::ValidEntity(EntityID entity) const
|
||||||
|
{
|
||||||
|
return m_EntityParents.find(entity) != m_EntityParents.end();
|
||||||
|
}
|
||||||
|
|
||||||
void World::RegisterComponent(ComponentInfo& ci)
|
void World::RegisterComponent(ComponentInfo& ci)
|
||||||
{
|
{
|
||||||
if (m_ComponentPools.find(ci.Name) == m_ComponentPools.end()) {
|
if (m_ComponentPools.find(ci.Name) == m_ComponentPools.end()) {
|
||||||
@@ -75,7 +80,6 @@ ComponentWrapper World::AttachComponent(EntityID entity, std::string componentTy
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool World::HasComponent(EntityID entity, std::string componentType) const
|
bool World::HasComponent(EntityID entity, std::string componentType) const
|
||||||
{
|
{
|
||||||
ComponentPool* pool = m_ComponentPools.at(componentType);
|
ComponentPool* pool = m_ComponentPools.at(componentType);
|
||||||
@@ -88,7 +92,6 @@ ComponentWrapper World::GetComponent(EntityID entity, std::string componentType)
|
|||||||
return pool->GetByEntity(entity);
|
return pool->GetByEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void World::DeleteComponent(EntityID entity, std::string componentType)
|
void World::DeleteComponent(EntityID entity, std::string componentType)
|
||||||
{
|
{
|
||||||
ComponentPool* pool = m_ComponentPools.at(componentType);
|
ComponentPool* pool = m_ComponentPools.at(componentType);
|
||||||
@@ -102,13 +105,11 @@ const ComponentPool* World::GetComponents(std::string componentType)
|
|||||||
return (it != m_ComponentPools.end()) ? it->second : nullptr;
|
return (it != m_ComponentPools.end()) ? it->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EntityID World::GetParent(EntityID entity)
|
EntityID World::GetParent(EntityID entity)
|
||||||
{
|
{
|
||||||
return m_EntityParents.at(entity);
|
return m_EntityParents.at(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void World::SetParent(EntityID entity, EntityID parent)
|
void World::SetParent(EntityID entity, EntityID parent)
|
||||||
{
|
{
|
||||||
EntityID lastParent = m_EntityParents.at(entity);
|
EntityID lastParent = m_EntityParents.at(entity);
|
||||||
|
|||||||
@@ -622,7 +622,7 @@ bool EditorSystem::createEntityNode(World* world, EntityID entity)
|
|||||||
if (ImGui::Button("Delete")) {
|
if (ImGui::Button("Delete")) {
|
||||||
world->DeleteEntity(entity);
|
world->DeleteEntity(entity);
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
if (m_Selection == entity) {
|
if (!world->ValidEntity(m_Selection)) {
|
||||||
m_Selection = EntityID_Invalid;
|
m_Selection = EntityID_Invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user