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.
This commit is contained in:
Stephen Seo 2017-12-01 19:20:59 +09:00
parent f8d27d65d3
commit 6f0b7cb65b
2 changed files with 39 additions and 15 deletions

View file

@ -123,7 +123,6 @@ namespace EC
} }
std::get<bool>(entities[currentSize]) = true; std::get<bool>(entities[currentSize]) = true;
std::get<BitsetType>(entities[currentSize]).reset();
return currentSize++; return currentSize++;
} }
@ -136,7 +135,6 @@ namespace EC
deletedSet.erase(iter); deletedSet.erase(iter);
} }
std::get<bool>(entities[id]) = true; std::get<bool>(entities[id]) = true;
std::get<BitsetType>(entities[id]).reset();
return id; return id;
} }
} }
@ -153,6 +151,7 @@ namespace EC
if(hasEntity(index)) if(hasEntity(index))
{ {
std::get<bool>(entities.at(index)) = false; std::get<bool>(entities.at(index)) = false;
std::get<BitsetType>(entities.at(index)).reset();
deletedSet.insert(index); deletedSet.insert(index);
} }
} }
@ -775,7 +774,10 @@ namespace EC
{ {
for(auto eid : matching) for(auto eid : matching)
{ {
helper.callInstancePtr(eid, *this, &function); if(isAlive(eid))
{
helper.callInstancePtr(eid, *this, &function);
}
} }
} }
else else
@ -800,7 +802,10 @@ namespace EC
std::size_t end) { std::size_t end) {
for(std::size_t i = begin; i < end; ++i) for(std::size_t i = begin; i < end; ++i)
{ {
helper.callInstancePtr(i, *this, &function); if(isAlive(i))
{
helper.callInstancePtr(i, *this, &function);
}
} }
}, },
begin, end); begin, end);
@ -1251,7 +1256,10 @@ namespace EC
{ {
for(const auto& id : multiMatchingEntities[index]) for(const auto& id : multiMatchingEntities[index])
{ {
Helper::call(id, *this, func); if(isAlive(id))
{
Helper::call(id, *this, func);
}
} }
} }
else else
@ -1278,10 +1286,13 @@ namespace EC
for(std::size_t j = begin; j < end; for(std::size_t j = begin; j < end;
++j) ++j)
{ {
Helper::call( if(isAlive(multiMatchingEntities[index][j]))
multiMatchingEntities[index][j], {
*this, Helper::call(
func); multiMatchingEntities[index][j],
*this,
func);
}
} }
}, begin, end); }, begin, end);
} }
@ -1435,7 +1446,10 @@ namespace EC
{ {
for(const auto& id : multiMatchingEntities[index]) for(const auto& id : multiMatchingEntities[index])
{ {
Helper::callPtr(id, *this, func); if(isAlive(id))
{
Helper::callPtr(id, *this, func);
}
} }
} }
else else
@ -1462,10 +1476,13 @@ namespace EC
for(std::size_t j = begin; j < end; for(std::size_t j = begin; j < end;
++j) ++j)
{ {
Helper::callPtr( if(isAlive(multiMatchingEntities[index][j]))
multiMatchingEntities[index][j], {
*this, Helper::callPtr(
func); multiMatchingEntities[index][j],
*this,
func);
}
} }
}, begin, end); }, begin, end);
} }

View file

@ -218,7 +218,14 @@ TEST(EC, DeletedEntities)
for(unsigned int i = 0; i < 4; ++i) for(unsigned int i = 0; i < 4; ++i)
{ {
EXPECT_TRUE(manager.hasComponent<C0>(i)); if(i < 2)
{
EXPECT_TRUE(manager.hasComponent<C0>(i));
}
else
{
EXPECT_FALSE(manager.hasComponent<C0>(i));
}
} }
for(unsigned int i = 0; i < 2; ++i) for(unsigned int i = 0; i < 2; ++i)