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<BitsetType>(entities[currentSize]).reset();
return currentSize++;
}
@ -136,7 +135,6 @@ namespace EC
deletedSet.erase(iter);
}
std::get<bool>(entities[id]) = true;
std::get<BitsetType>(entities[id]).reset();
return id;
}
}
@ -153,6 +151,7 @@ namespace EC
if(hasEntity(index))
{
std::get<bool>(entities.at(index)) = false;
std::get<BitsetType>(entities.at(index)).reset();
deletedSet.insert(index);
}
}
@ -774,10 +773,13 @@ namespace EC
if(threadCount <= 1)
{
for(auto eid : matching)
{
if(isAlive(eid))
{
helper.callInstancePtr(eid, *this, &function);
}
}
}
else
{
std::vector<std::thread> threads(threadCount);
@ -799,9 +801,12 @@ namespace EC
(std::size_t begin,
std::size_t end) {
for(std::size_t i = begin; i < end; ++i)
{
if(isAlive(i))
{
helper.callInstancePtr(i, *this, &function);
}
}
},
begin, end);
}
@ -1250,10 +1255,13 @@ namespace EC
if(threadCount <= 1)
{
for(const auto& id : multiMatchingEntities[index])
{
if(isAlive(id))
{
Helper::call(id, *this, func);
}
}
}
else
{
std::vector<std::thread> threads(threadCount);
@ -1277,12 +1285,15 @@ namespace EC
{
for(std::size_t j = begin; j < end;
++j)
{
if(isAlive(multiMatchingEntities[index][j]))
{
Helper::call(
multiMatchingEntities[index][j],
*this,
func);
}
}
}, begin, end);
}
for(std::size_t i = 0; i < threadCount; ++i)
@ -1434,10 +1445,13 @@ namespace EC
if(threadCount <= 1)
{
for(const auto& id : multiMatchingEntities[index])
{
if(isAlive(id))
{
Helper::callPtr(id, *this, func);
}
}
}
else
{
std::vector<std::thread> threads(threadCount);
@ -1461,12 +1475,15 @@ namespace EC
{
for(std::size_t j = begin; j < end;
++j)
{
if(isAlive(multiMatchingEntities[index][j]))
{
Helper::callPtr(
multiMatchingEntities[index][j],
*this,
func);
}
}
}, begin, end);
}
for(std::size_t i = 0; i < threadCount; ++i)

View file

@ -217,9 +217,16 @@ TEST(EC, DeletedEntities)
manager.deleteEntity(3);
for(unsigned int i = 0; i < 4; ++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)
{