aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlec Thomas <alec@swapoff.org>2014-05-15 12:56:25 -0400
committerAlec Thomas <alec@swapoff.org>2014-05-15 12:56:25 -0400
commit99cae200fa62af1a2a6695129413691698f27184 (patch)
tree2675b5fc256a3be6da60122a827a535475cc66da
parent60497ad23b6abb01e76693c39ce079a0d0df5b3b (diff)
Only delete assigned components.
Fixes #31.
-rw-r--r--entityx/Entity.h7
-rw-r--r--entityx/Entity_test.cc7
2 files changed, 12 insertions, 2 deletions
diff --git a/entityx/Entity.h b/entityx/Entity.h
index 7362f69..5f51b50 100644
--- a/entityx/Entity.h
+++ b/entityx/Entity.h
@@ -456,9 +456,12 @@ class EntityManager : entityx::help::NonCopyable {
void destroy(Entity::Id entity) {
assert_valid(entity);
int index = entity.index();
+ auto mask = entity_component_mask_[entity.index()];
event_manager_.emit<EntityDestroyedEvent>(Entity(this, entity));
- for (BasePool *pool : component_pools_) {
- if (pool) pool->destroy(index);
+ for (size_t i = 0; i < component_pools_.size(); i++) {
+ BasePool *pool = component_pools_[i];
+ if (pool && mask.test(i))
+ pool->destroy(index);
}
entity_component_mask_[index] = 0;
entity_version_[index]++;
diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc
index f40a9bc..1f87473 100644
--- a/entityx/Entity_test.cc
+++ b/entityx/Entity_test.cc
@@ -449,3 +449,10 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestComponentHandleInvalidatedWhenCompon
a.remove<Position>();
REQUIRE(!position);
}
+
+TEST_CASE_METHOD(EntityManagerFixture, "TestDeleteEntityWithNoComponents") {
+ Entity a = em.create();
+ a.assign<Position>(1, 2);
+ Entity b = em.create();
+ b.destroy();
+}