registry: slightly better destroy (yet not quite there though)

This commit is contained in:
Michele Caini
2023-01-11 11:54:29 +01:00
parent d0854646c7
commit 7a05a16c54

View File

@@ -801,8 +801,31 @@ public:
*/
template<typename It>
void destroy(It first, It last) {
for(; first != last; ++first) {
destroy(*first);
if constexpr(std::is_same_v<It, typename basic_common_type::iterator>) {
basic_common_type *owner = nullptr;
for(size_type pos = pools.size(); pos; --pos) {
if(pools.begin()[pos - 1u].second->data() == first.data()) {
owner = pools.begin()[pos - 1u].second.get();
} else {
pools.begin()[pos - 1u].second->remove(first, last);
}
}
if(owner) {
// waiting to further/completely optimize this with the entity storage
for(; first != last; ++first) {
const auto entt = *first;
owner->remove(entt);
release(entt);
}
} else {
release(std::move(first), std::move(last));
}
} else {
for(; first != last; ++first) {
destroy(*first);
}
}
}