aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--entityx/Entity.h6
-rw-r--r--entityx/EntityClass.h1
-rw-r--r--entityx/help/Pool.h7
-rw-r--r--entityx/help/Pool_test.cc3
4 files changed, 14 insertions, 3 deletions
diff --git a/entityx/Entity.h b/entityx/Entity.h
index 8e1e93e..2ef01f7 100644
--- a/entityx/Entity.h
+++ b/entityx/Entity.h
@@ -381,12 +381,14 @@ 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))
+ if (pool && mask.test(i)) {
+ pool->removeComponent(Entity(this, entity));
pool->destroy(index);
+ }
}
+ event_manager_.emit<EntityDestroyedEvent>(Entity(this, entity));
entity_component_mask_[index].reset();
entity_version_[index]++;
free_list_.push_back(index);
diff --git a/entityx/EntityClass.h b/entityx/EntityClass.h
index 444e494..94a2a02 100644
--- a/entityx/EntityClass.h
+++ b/entityx/EntityClass.h
@@ -10,6 +10,7 @@
#pragma once
+#include <bitset>
#include "entityx/config.h"
namespace entityx {
diff --git a/entityx/help/Pool.h b/entityx/help/Pool.h
index f217ec2..c4b7d83 100644
--- a/entityx/help/Pool.h
+++ b/entityx/help/Pool.h
@@ -14,6 +14,8 @@
#include <cassert>
#include <vector>
+#include "entityx/EntityClass.h"
+
namespace entityx {
/**
@@ -63,6 +65,7 @@ class BasePool {
}
virtual void destroy(std::size_t n) = 0;
+ virtual void removeComponent(Entity entity) = 0;
protected:
std::vector<char *> blocks_;
@@ -90,6 +93,10 @@ class Pool : public BasePool {
T *ptr = static_cast<T*>(get(n));
ptr->~T();
}
+
+ virtual void removeComponent(Entity entity) override {
+ entity.remove<T>();
+ }
};
} // namespace entityx
diff --git a/entityx/help/Pool_test.cc b/entityx/help/Pool_test.cc
index 56ca85a..08ef1d2 100644
--- a/entityx/help/Pool_test.cc
+++ b/entityx/help/Pool_test.cc
@@ -13,8 +13,9 @@
#include <vector>
#include "entityx/3rdparty/catch.hpp"
#include "entityx/help/Pool.h"
+#include "entityx/Entity.h"
-struct Position {
+struct Position : public entityx::Component<Position> {
explicit Position(int *ptr = nullptr) : ptr(ptr) {
if (ptr) (*ptr)++;
}