Added KnowsEntity function to ComponentPool to query whether an entity has a component attached

This commit is contained in:
2015-12-13 19:59:25 +01:00
parent b66cf47ff0
commit 2018ba27ae
2 changed files with 8 additions and 0 deletions
+2
View File
@@ -54,6 +54,8 @@ public:
ComponentWrapper Allocate(EntityID entity);
// Get the component belonging to a specific entity
ComponentWrapper GetByEntity(EntityID ent);
// Returns true if the pool contains a component for the specified entity
bool KnowsEntity(EntityID ent);
// Delete a component and free its memory
void Delete(ComponentWrapper& wrapper);
+6
View File
@@ -50,6 +50,12 @@ ComponentWrapper ComponentPool::GetByEntity(EntityID ent)
return ComponentWrapper(m_ComponentInfo, m_EntityToComponent.at(ent));
}
bool ComponentPool::KnowsEntity(EntityID ent)
{
return m_EntityToComponent.find(ent) != m_EntityToComponent.end();
}
void ComponentPool::Delete(ComponentWrapper& wrapper)
{
m_EntityToComponent.erase(wrapper.EntityID);