From 6f0b7cb65b9faabca7f11174f832f523ef7245cd Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 1 Dec 2017 19:20:59 +0900 Subject: [PATCH] Fix bug with multiple sig/func call Fixed bug where if an entity is deleted during a multiple signature/function call but matched a later signature/function, it would still be called in that later function. Minor fixes as well. --- src/EC/Manager.hpp | 45 +++++++++++++++++++++++++++++++-------------- src/test/ECTest.cpp | 9 ++++++++- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/EC/Manager.hpp b/src/EC/Manager.hpp index 259d2b4..5454a57 100644 --- a/src/EC/Manager.hpp +++ b/src/EC/Manager.hpp @@ -123,7 +123,6 @@ namespace EC } std::get(entities[currentSize]) = true; - std::get(entities[currentSize]).reset(); return currentSize++; } @@ -136,7 +135,6 @@ namespace EC deletedSet.erase(iter); } std::get(entities[id]) = true; - std::get(entities[id]).reset(); return id; } } @@ -153,6 +151,7 @@ namespace EC if(hasEntity(index)) { std::get(entities.at(index)) = false; + std::get(entities.at(index)).reset(); deletedSet.insert(index); } } @@ -775,7 +774,10 @@ namespace EC { for(auto eid : matching) { - helper.callInstancePtr(eid, *this, &function); + if(isAlive(eid)) + { + helper.callInstancePtr(eid, *this, &function); + } } } else @@ -800,7 +802,10 @@ namespace EC std::size_t end) { for(std::size_t i = begin; i < end; ++i) { - helper.callInstancePtr(i, *this, &function); + if(isAlive(i)) + { + helper.callInstancePtr(i, *this, &function); + } } }, begin, end); @@ -1251,7 +1256,10 @@ namespace EC { for(const auto& id : multiMatchingEntities[index]) { - Helper::call(id, *this, func); + if(isAlive(id)) + { + Helper::call(id, *this, func); + } } } else @@ -1278,10 +1286,13 @@ namespace EC for(std::size_t j = begin; j < end; ++j) { - Helper::call( - multiMatchingEntities[index][j], - *this, - func); + if(isAlive(multiMatchingEntities[index][j])) + { + Helper::call( + multiMatchingEntities[index][j], + *this, + func); + } } }, begin, end); } @@ -1435,7 +1446,10 @@ namespace EC { for(const auto& id : multiMatchingEntities[index]) { - Helper::callPtr(id, *this, func); + if(isAlive(id)) + { + Helper::callPtr(id, *this, func); + } } } else @@ -1462,10 +1476,13 @@ namespace EC for(std::size_t j = begin; j < end; ++j) { - Helper::callPtr( - multiMatchingEntities[index][j], - *this, - func); + if(isAlive(multiMatchingEntities[index][j])) + { + Helper::callPtr( + multiMatchingEntities[index][j], + *this, + func); + } } }, begin, end); } diff --git a/src/test/ECTest.cpp b/src/test/ECTest.cpp index ad61c88..fc5e59a 100644 --- a/src/test/ECTest.cpp +++ b/src/test/ECTest.cpp @@ -218,7 +218,14 @@ TEST(EC, DeletedEntities) for(unsigned int i = 0; i < 4; ++i) { - EXPECT_TRUE(manager.hasComponent(i)); + if(i < 2) + { + EXPECT_TRUE(manager.hasComponent(i)); + } + else + { + EXPECT_FALSE(manager.hasComponent(i)); + } } for(unsigned int i = 0; i < 2; ++i)