diff --git a/src/EC/Manager.hpp b/src/EC/Manager.hpp index fa3fab9..aa44a79 100644 --- a/src/EC/Manager.hpp +++ b/src/EC/Manager.hpp @@ -80,9 +80,6 @@ namespace EC std::get(entities[currentSize]) = true; - // TODO This shouldn't be necessary, but there is a bug - std::get(entities[currentSize]).reset(); - return currentSize++; } @@ -143,6 +140,7 @@ namespace EC currentSize = 0; return; } + std::get(entities[rhs]).reset(); --rhs; } if(lhs >= rhs) diff --git a/src/test/ECTest.cpp b/src/test/ECTest.cpp index f766510..ee72cd2 100644 --- a/src/test/ECTest.cpp +++ b/src/test/ECTest.cpp @@ -207,3 +207,38 @@ TEST(EC, MoveComponentWithUniquePtr) } } +TEST(EC, DeletedEntities) +{ + EC::Manager manager; + + for(unsigned int i = 0; i < 4; ++i) + { + auto eid = manager.addEntity(); + manager.addComponent(eid); + if(i >= 2) + { + manager.deleteEntity(eid); + } + } + + manager.cleanup(); + + for(unsigned int i = 0; i < 4; ++i) + { + if(i < 2) + { + EXPECT_TRUE(manager.hasComponent(i)); + } + else + { + EXPECT_FALSE(manager.hasComponent(i)); + } + } + + for(unsigned int i = 0; i < 2; ++i) + { + auto eid = manager.addEntity(); + EXPECT_FALSE(manager.hasComponent(eid)); + } +} +