diff options
author | Zack Mulgrew <zmulgrew@linkedin.com> | 2016-02-27 02:03:50 -0800 |
---|---|---|
committer | Zack Mulgrew <zmulgrew@linkedin.com> | 2016-02-27 15:32:04 -0800 |
commit | 88e85573ed8f9a9b6605ccdaaf84d353379a9e63 (patch) | |
tree | c397d61334962029a8d1cba7b157a723dc593f32 | |
parent | 769db20f9a9f6655aeca8167470c5301dbfb16ed (diff) |
Trigger ComponentRemovedEvent on Entity::destroy
-rw-r--r-- | entityx/Entity.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/entityx/Entity.h b/entityx/Entity.h index c4e4ac5..06854e3 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -331,10 +331,15 @@ struct ComponentRemovedEvent : public Event<ComponentRemovedEvent<C>> { class BaseComponentHelper { public: virtual ~BaseComponentHelper() {} + virtual void remove_component(Entity e) = 0; }; template <typename C> class ComponentHelper : public BaseComponentHelper { +public: + void remove_component(Entity e) override { + e.remove<C>(); + } }; /** @@ -569,12 +574,12 @@ class EntityManager : entityx::help::NonCopyable { assert_valid(entity); uint32_t index = entity.index(); auto mask = entity_component_mask_[entity.index()]; - event_manager_.emit<EntityDestroyedEvent>(Entity(this, entity)); - for (size_t i = 0; i < component_pools_.size(); i++) { - BasePool *pool = component_pools_[i]; - if (pool && mask.test(i)) - pool->destroy(index); + for (size_t i = 0; i < component_helpers_.size(); i++) { + BaseComponentHelper *helper = component_helpers_[i]; + if (helper && mask.test(i)) + helper->remove_component(Entity(this, entity)); } + event_manager_.emit<EntityDestroyedEvent>(Entity(this, entity)); entity_component_mask_[index].reset(); entity_version_[index]++; free_list_.push_back(index); |