From 945dc409372f04e6545ddcbfc6223aaa1156dbab Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 15 Mar 2023 09:39:50 +0100 Subject: [PATCH] group: split group handler functions --- src/entt/entity/group.hpp | 30 ++++++++++++++++++++++-------- src/entt/entity/registry.hpp | 30 +++++++++++++++--------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index 2ad807162..537a13939 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -126,16 +126,23 @@ public: +[]([[maybe_unused]] const id_type ctype) noexcept { return ((ctype == entt::type_hash::value()) || ...); }}, pools{&opool..., &gpool...}, filter{&epool...}, len{} {} - template - void push_if(const entity_type entt) { + void push_on_construct(const entity_type entt) { if(std::apply([entt](auto *...cpool) { return (cpool->contains(entt) && ...); }, pools) - && std::apply([entt](auto *...cpool) { return (Expected == (0u + ... + cpool->contains(entt))); }, filter) + && std::apply([entt](auto *...cpool) { return (!cpool->contains(entt) && ...); }, filter) && !(std::get<0>(pools)->index(entt) < len)) { swap_elements(std::index_sequence_for{}, len++, entt); } } - void remove_if(const entity_type entt) { + void push_on_destroy(const entity_type entt) { + if(std::apply([entt](auto *...cpool) { return (cpool->contains(entt) && ...); }, pools) + && std::apply([entt](auto *...cpool) { return (0u + ... + cpool->contains(entt)) == 1u; }, filter) + && !(std::get<0>(pools)->index(entt) < len)) { + swap_elements(std::index_sequence_for{}, len++, entt); + } + } + + void remove(const entity_type entt) { if(std::get<0>(pools)->contains(entt) && (std::get<0>(pools)->index(entt) < len)) { swap_elements(std::index_sequence_for{}, --len, entt); } @@ -169,16 +176,23 @@ public: +[]([[maybe_unused]] const id_type ctype) noexcept { return ((ctype == entt::type_hash::value()) || ...); }}, pools{&gpool...}, filter{&epool...}, elem{alloc} {} - template - void push_if(const entity_type entt) { + void push_on_construct(const entity_type entt) { if(std::apply([entt](auto *...cpool) { return (cpool->contains(entt) && ...); }, pools) - && std::apply([entt](auto *...cpool) { return (Expected == (0u + ... + cpool->contains(entt))); }, filter) + && std::apply([entt](auto *...cpool) { return (!cpool->contains(entt) && ...); }, filter) && !elem.contains(entt)) { elem.push(entt); } } - void remove_if(const entity_type entt) { + void push_on_destroy(const entity_type entt) { + if(std::apply([entt](auto *...cpool) { return (cpool->contains(entt) && ...); }, pools) + && std::apply([entt](auto *...cpool) { return (0u + ... + cpool->contains(entt)) == 1u; }, filter) + && !elem.contains(entt)) { + elem.push(entt); + } + } + + void remove(const entity_type entt) { elem.remove(entt); } diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 993981f1a..8213d1a67 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -1240,21 +1240,21 @@ public: } } - on_construct>().before(next).template connect<&handler_type::template push_if<0u>>(*handler); - (on_construct>().before(next).template connect<&handler_type::template push_if<0u>>(*handler), ...); - (on_construct>().before(next).template connect<&handler_type::template push_if<0u>>(*handler), ...); - (on_destroy>().before(next).template connect<&handler_type::template push_if<1u>>(*handler), ...); + on_construct>().before(next).template connect<&handler_type::push_on_construct>(*handler); + (on_construct>().before(next).template connect<&handler_type::push_on_construct>(*handler), ...); + (on_construct>().before(next).template connect<&handler_type::push_on_construct>(*handler), ...); + (on_destroy>().before(next).template connect<&handler_type::push_on_destroy>(*handler), ...); - on_destroy>().before(prev).template connect<&handler_type::remove_if>(*handler); - (on_destroy>().before(prev).template connect<&handler_type::remove_if>(*handler), ...); - (on_destroy>().before(prev).template connect<&handler_type::remove_if>(*handler), ...); - (on_construct>().before(prev).template connect<&handler_type::remove_if>(*handler), ...); + on_destroy>().before(prev).template connect<&handler_type::remove>(*handler); + (on_destroy>().before(prev).template connect<&handler_type::remove>(*handler), ...); + (on_destroy>().before(prev).template connect<&handler_type::remove>(*handler), ...); + (on_construct>().before(prev).template connect<&handler_type::remove>(*handler), ...); auto &cpool = assure>(); // we cannot iterate backwards because we want to leave behind valid entities in case of owned types for(auto *first = cpool.data(), *last = first + cpool.size(); first != last; ++first) { - handler->template push_if<0u>(*first); + handler->push_on_construct(*first); } } @@ -1281,13 +1281,13 @@ public: groups.emplace(type_hash::value(), elem); handler = static_cast(elem.get()); - on_construct>().template connect<&handler_type::template push_if<0u>>(*handler); - (on_construct>().template connect<&handler_type::template push_if<0u>>(*handler), ...); - (on_destroy>().template connect<&handler_type::template push_if<1u>>(*handler), ...); + on_construct>().template connect<&handler_type::push_on_construct>(*handler); + (on_construct>().template connect<&handler_type::push_on_construct>(*handler), ...); + (on_destroy>().template connect<&handler_type::push_on_destroy>(*handler), ...); - on_destroy>().template connect<&handler_type::remove_if>(*handler); - (on_destroy>().template connect<&handler_type::remove_if>(*handler), ...); - (on_construct>().template connect<&handler_type::remove_if>(*handler), ...); + on_destroy>().template connect<&handler_type::remove>(*handler); + (on_destroy>().template connect<&handler_type::remove>(*handler), ...); + (on_construct>().template connect<&handler_type::remove>(*handler), ...); for(const auto entity: view(exclude)) { handler->group().push(entity);