From 769db20f9a9f6655aeca8167470c5301dbfb16ed Mon Sep 17 00:00:00 2001 From: Zack Mulgrew Date: Sat, 27 Feb 2016 01:51:08 -0800 Subject: Add ComponentHelper and base class, no functionality --- entityx/Entity.cc | 4 ++++ entityx/Entity.h | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/entityx/Entity.cc b/entityx/Entity.cc index 5461ca7..ddb8df7 100644 --- a/entityx/Entity.cc +++ b/entityx/Entity.cc @@ -43,7 +43,11 @@ void EntityManager::reset() { for (BasePool *pool : component_pools_) { if (pool) delete pool; } + for (BaseComponentHelper *helper : component_helpers_) { + if (helper) delete helper; + } component_pools_.clear(); + component_helpers_.clear(); entity_component_mask_.clear(); entity_version_.clear(); free_list_.clear(); diff --git a/entityx/Entity.h b/entityx/Entity.h index 3d0b96f..c4e4ac5 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -325,6 +325,17 @@ struct ComponentRemovedEvent : public Event> { ComponentHandle component; }; +/** + * Helper class to perform component operations in a typed manner. + */ +class BaseComponentHelper { +public: + virtual ~BaseComponentHelper() {} +}; + +template +class ComponentHelper : public BaseComponentHelper { +}; /** * Manages Entity::Id creation and component assignment. @@ -860,6 +871,13 @@ class EntityManager : entityx::help::NonCopyable { pool->expand(index_counter_); component_pools_[family] = pool; } + if (component_helpers_.size() <= family) { + component_helpers_.resize(family + 1, nullptr); + } + if (!component_helpers_[family]) { + ComponentHelper *helper = new ComponentHelper(); + component_helpers_[family] = helper; + } return static_cast*>(component_pools_[family]); } @@ -870,6 +888,9 @@ class EntityManager : entityx::help::NonCopyable { // Each element in component_pools_ corresponds to a Pool for a Component. // The index into the vector is the Component::family(). std::vector component_pools_; + // Each element in component_helpers_ corresponds to a ComponentHelper for a Component type. + // The index into the vector is the Component::family(). + std::vector component_helpers_; // Bitmask of components associated with each entity. Index into the vector is the Entity::Id. std::vector entity_component_mask_; // Vector of entity version numbers. Incremented each time an entity is destroyed -- cgit v1.2.3