aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZack Mulgrew <zmulgrew@linkedin.com>2016-02-27 01:51:08 -0800
committerZack Mulgrew <zmulgrew@linkedin.com>2016-02-27 15:32:04 -0800
commit769db20f9a9f6655aeca8167470c5301dbfb16ed (patch)
tree85adc451051785e52f19bf0c30a7b9a8ed3cc263
parentd6128e0eb9c7b91df09dff2861f99045da77f7a3 (diff)
Add ComponentHelper and base class, no functionality
-rw-r--r--entityx/Entity.cc4
-rw-r--r--entityx/Entity.h21
2 files changed, 25 insertions, 0 deletions
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<ComponentRemovedEvent<C>> {
ComponentHandle<C> component;
};
+/**
+ * Helper class to perform component operations in a typed manner.
+ */
+class BaseComponentHelper {
+public:
+ virtual ~BaseComponentHelper() {}
+};
+
+template <typename C>
+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<C> *helper = new ComponentHelper<C>();
+ component_helpers_[family] = helper;
+ }
return static_cast<Pool<C>*>(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<BasePool*> 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<BaseComponentHelper*> component_helpers_;
// Bitmask of components associated with each entity. Index into the vector is the Entity::Id.
std::vector<ComponentMask> entity_component_mask_;
// Vector of entity version numbers. Incremented each time an entity is destroyed