From ab2209b69813a54a9f034a2137566a09e56f1b4e Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 30 Aug 2016 17:34:34 +0900 Subject: [PATCH] Fixed bug where deleted entities retain info --- src/EC/Manager.hpp | 4 +--- src/test/ECTest.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) 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)); + } +} +