From 2018ba27aef26c5f389772a49a4f051ea5d95ee5 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Sun, 13 Dec 2015 19:59:25 +0100 Subject: [PATCH] Added KnowsEntity function to ComponentPool to query whether an entity has a component attached --- include/Engine/Core/ComponentPool.h | 2 ++ src/Engine/Core/ComponentPool.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/Engine/Core/ComponentPool.h b/include/Engine/Core/ComponentPool.h index f0d53864..8dd8dc29 100644 --- a/include/Engine/Core/ComponentPool.h +++ b/include/Engine/Core/ComponentPool.h @@ -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); diff --git a/src/Engine/Core/ComponentPool.cpp b/src/Engine/Core/ComponentPool.cpp index 146b33f6..ef7f9740 100644 --- a/src/Engine/Core/ComponentPool.cpp +++ b/src/Engine/Core/ComponentPool.cpp @@ -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);