]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Add ComponentHelper and base class, no functionality
authorZack Mulgrew <zmulgrew@linkedin.com>
Sat, 27 Feb 2016 09:51:08 +0000 (01:51 -0800)
committerZack Mulgrew <zmulgrew@linkedin.com>
Sat, 27 Feb 2016 23:32:04 +0000 (15:32 -0800)
entityx/Entity.cc
entityx/Entity.h

index 5461ca725cf0fec834d7f60592045238f2ba617b..ddb8df7f35ec1bcb590f1c5d19188f197c4fb92b 100644 (file)
@@ -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();
index 3d0b96f72ff64c8b05e88040878c28c5a2ed5d48..c4e4ac587f1990a34ee47f339c49ad9ff995d60b 100644 (file)
@@ -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