diff --git a/src/EC/Manager.hpp b/src/EC/Manager.hpp index 6375fc6..b5ffe13 100644 --- a/src/EC/Manager.hpp +++ b/src/EC/Manager.hpp @@ -104,6 +104,7 @@ namespace EC EntitiesType *entities; const BitsetType *signature; void *userData; + std::unordered_set dead; }; /// Temporary struct used internally by ThreadPool template @@ -114,6 +115,7 @@ namespace EC BitsetType *signature; void *userData; Function *fn; + std::unordered_set dead; }; /// Temporary struct used internally by ThreadPool struct TPFnDataStructTwo { @@ -122,6 +124,7 @@ namespace EC EntitiesType *entities; void *userData; const std::vector *matching; + std::unordered_set dead; }; /// Temporary struct used internally by ThreadPool struct TPFnDataStructThree { @@ -131,6 +134,7 @@ namespace EC const std::vector *bitsets; EntitiesType *entities; std::mutex *mutex; + std::unordered_set dead; }; /// Temporary struct used internally by ThreadPool struct TPFnDataStructFour { @@ -140,6 +144,7 @@ namespace EC multiMatchingEntities; BitsetType *signatures; std::mutex *mutex; + std::unordered_set dead; }; /// Temporary struct used internally by ThreadPool struct TPFnDataStructFive { @@ -149,6 +154,7 @@ namespace EC void *userData; std::vector >* multiMatchingEntities; + std::unordered_set dead; }; /// Temporary struct used internally by ThreadPool struct TPFnDataStructSix { @@ -158,6 +164,7 @@ namespace EC multiMatchingEntities; BitsetType *bitsets; std::mutex *mutex; + std::unordered_set dead; }; /// Temporary struct used internally by ThreadPool template @@ -167,6 +174,7 @@ namespace EC EntitiesType *entities; Iterable *iterable; void *userData; + std::unordered_set dead; }; // end section for "temporary" structures }}} @@ -752,12 +760,17 @@ namespace EC fnDataAr[i].entities = &entities; fnDataAr[i].signature = &signatureBitset; fnDataAr[i].userData = userData; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(j)) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([&function] (void *ud) { auto *data = static_cast(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(!data->manager->isAlive(i)) { + if(data->dead.find(i) != data->dead.end()) { continue; } @@ -870,11 +883,16 @@ namespace EC fnDataAr[i].signature = &signatureBitset; fnDataAr[i].userData = userData; fnDataAr[i].fn = function; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(j)) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([] (void *ud) { auto *data = static_cast*>(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(!data->manager->isAlive(i)) { + if(data->dead.find(i) != data->dead.end()) { continue; } @@ -1015,13 +1033,17 @@ namespace EC fnDataAr[i].entities = &entities; fnDataAr[i].userData = userData; fnDataAr[i].matching = &matching; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(matching.at(j))) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([&function, helper] (void* ud) { auto *data = static_cast(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(data->manager->isAlive( - data->matching->at(i))) { + if(data->dead.find(i) == data->dead.end()) { helper.callInstancePtr( data->matching->at(i), *data->manager, @@ -1085,11 +1107,16 @@ namespace EC fnDataAr[i].bitsets = &bitsets; fnDataAr[i].entities = &entities; fnDataAr[i].mutex = &mutex; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(j)) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([] (void *ud) { auto *data = static_cast(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(!data->manager->isAlive(i)) { + if(data->dead.find(i) != data->dead.end()) { continue; } for(std::size_t j = 0; j < data->bitsets->size(); @@ -1457,12 +1484,17 @@ namespace EC fnDataAr[i].multiMatchingEntities = &multiMatchingEntities; fnDataAr[i].signatures = signatureBitsets; fnDataAr[i].mutex = &mutex; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(j)) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([] (void *ud) { auto *data = static_cast(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(!data->manager->isAlive(i)) { + if(data->dead.find(i) != data->dead.end()) { continue; } for(std::size_t j = 0; j < SigList::size; ++j) { @@ -1524,13 +1556,16 @@ namespace EC fnDataAr[i].userData = userData; fnDataAr[i].multiMatchingEntities = &multiMatchingEntities; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(multiMatchingEntities.at(index).at(j))) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([&func] (void *ud) { auto *data = static_cast(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(data->manager->isAlive( - data->multiMatchingEntities - ->at(data->index).at(i))) { + if(data->dead.find(i) == data->dead.end()) { Helper::call( data->multiMatchingEntities ->at(data->index).at(i), @@ -1657,12 +1692,17 @@ namespace EC fnDataAr[i].multiMatchingEntities = &multiMatchingEntities; fnDataAr[i].bitsets = signatureBitsets; fnDataAr[i].mutex = &mutex; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(j)) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([] (void *ud) { auto *data = static_cast(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(!data->manager->isAlive(i)) { + if(data->dead.find(i) != data->dead.end()) { continue; } for(std::size_t j = 0; j < SigList::size; ++j) { @@ -1729,13 +1769,16 @@ namespace EC fnDataAr[i].userData = userData; fnDataAr[i].multiMatchingEntities = &multiMatchingEntities; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(multiMatchingEntities.at(index).at(j))) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([&func] (void *ud) { auto *data = static_cast(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(data->manager->isAlive( - data->multiMatchingEntities - ->at(data->index).at(i))) { + if(data->dead.find(i) == data->dead.end()) { Helper::callPtr( data->multiMatchingEntities ->at(data->index).at(i), @@ -1809,13 +1852,18 @@ namespace EC fnDataAr[i].entities = &entities; fnDataAr[i].signature = &signatureBitset; fnDataAr[i].userData = userData; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(j)) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([&fn] (void *ud) { auto *data = static_cast(ud); for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(!data->manager->isAlive(i)) { + if(data->dead.find(i) != data->dead.end()) { continue; - } else if((*data->signature + } else if((*data->signature & std::get( data->entities->at(i))) == *data->signature) { @@ -1891,12 +1939,17 @@ namespace EC fnDataAr[i].entities = &entities; fnDataAr[i].iterable = &iterable; fnDataAr[i].userData = userData; + for(std::size_t j = begin; j < end; ++j) { + if(!isAlive(j)) { + fnDataAr[i].dead.insert(j); + } + } threadPool->queueFn([&fn] (void *ud) { auto *data = static_cast*>(ud); bool isValid; for(std::size_t i = data->range[0]; i < data->range[1]; ++i) { - if(!data->manager->isAlive(i)) { + if(data->dead.find(i) != data->dead.end()) { continue; } isValid = true;