diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index fd20f49ef..2ad807162 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -5,7 +5,9 @@ #include #include #include "../config/config.h" +#include "../core/fwd.hpp" #include "../core/iterator.hpp" +#include "../core/type_info.hpp" #include "../core/type_traits.hpp" #include "entity.hpp" #include "fwd.hpp" @@ -91,8 +93,10 @@ template } struct basic_group_handler { - using size_type = std::size_t; - const size_type size; + const std::size_t size; + bool (*const owned)(const id_type) noexcept; + bool (*const get)(const id_type) noexcept; + bool (*const exclude)(const id_type) noexcept; }; template @@ -115,10 +119,12 @@ public: using entity_type = underlying_type; group_handler(Owned &...opool, Get &...gpool, Exclude &...epool) - : basic_group_handler{sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude)}, - pools{&opool..., &gpool...}, - filter{&epool...}, - len{} {} + : basic_group_handler{ + sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude), + +[](const id_type ctype) noexcept { return ((ctype == entt::type_hash::value()) || ...); }, + +[]([[maybe_unused]] const id_type ctype) noexcept { return ((ctype == entt::type_hash::value()) || ...); }, + +[]([[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) { @@ -156,10 +162,12 @@ public: template group_handler(const Alloc &alloc, Get &...gpool, Exclude &...epool) - : basic_group_handler{sizeof...(Get) + sizeof...(Exclude)}, - pools{&gpool...}, - filter{&epool...}, - elem{alloc} {} + : basic_group_handler{ + sizeof...(Get) + sizeof...(Exclude), + +[](const id_type) noexcept { return false; }, + +[](const id_type ctype) noexcept { return ((ctype == entt::type_hash::value()) || ...); }, + +[]([[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) { diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index df58a21f5..ebe0b8b51 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -248,9 +248,6 @@ class basic_registry { struct group_data { std::shared_ptr handler; - bool (*owned)(const id_type) noexcept; - bool (*get)(const id_type) noexcept; - bool (*exclude)(const id_type) noexcept; }; // std::shared_ptr because of its type erased allocator which is useful here @@ -1217,18 +1214,14 @@ public: handler = static_cast(it->second.handler.get()); } else { group_data candidate = { - std::allocate_shared(get_allocator(), assure>(), assure>()..., assure>()..., assure>()...), - []([[maybe_unused]] const id_type ctype) noexcept { return ((ctype == type_hash>::value()) || ... || (ctype == type_hash>::value())); }, - []([[maybe_unused]] const id_type ctype) noexcept { return ((ctype == type_hash>::value()) || ...); }, - []([[maybe_unused]] const id_type ctype) noexcept { return ((ctype == type_hash>::value()) || ...); }, - }; + std::allocate_shared(get_allocator(), assure>(), assure>()..., assure>()..., assure>()...)}; handler = static_cast(candidate.handler.get()); groups.emplace(type_hash::value(), std::move(candidate)); ENTT_ASSERT(std::all_of(groups.cbegin(), groups.cend(), [size = handler->size](const auto &data) { - const auto overlapping = (data.second.owned(type_hash>::value()) + ... + data.second.owned(type_hash>::value())); - const auto sz = overlapping + (0u + ... + data.second.get(type_hash>::value())) + (0u + ... + data.second.exclude(type_hash>::value())); + const auto overlapping = (data.second.handler->owned(type_hash>::value()) + ... + data.second.handler->owned(type_hash>::value())); + const auto sz = overlapping + (0u + ... + data.second.handler->get(type_hash>::value())) + (0u + ... + data.second.handler->exclude(type_hash>::value())); return !overlapping || ((sz == size) || (sz == data.second.handler->size)); }), "Conflicting groups"); @@ -1240,7 +1233,7 @@ public: size_type next_len{}; for(auto &&data: groups) { - if((data.second.owned(type_hash>::value()) || ... || data.second.owned(type_hash>::value()))) { + if((data.second.handler->owned(type_hash>::value()) || ... || data.second.handler->owned(type_hash>::value()))) { if(const auto sz = data.second.handler->size; sz < handler->size && (prev == nullptr || prev_len < sz)) { prev = data.second.handler.get(); prev_len = sz; @@ -1291,11 +1284,7 @@ public: handler = static_cast(it->second.handler.get()); } else { group_data candidate = { - std::allocate_shared(get_allocator(), get_allocator(), assure>(), assure>()..., assure>()...), - []([[maybe_unused]] const id_type ctype) noexcept { return false; }, - []([[maybe_unused]] const id_type ctype) noexcept { return ((ctype == type_hash>::value()) || ... || (ctype == type_hash>::value())); }, - []([[maybe_unused]] const id_type ctype) noexcept { return ((ctype == type_hash>::value()) || ...); }, - }; + std::allocate_shared(get_allocator(), get_allocator(), assure>(), assure>()..., assure>()...)}; handler = static_cast(candidate.handler.get()); groups.emplace(type_hash::value(), std::move(candidate)); @@ -1337,7 +1326,7 @@ public: */ template [[nodiscard]] bool owned() const { - return std::any_of(groups.cbegin(), groups.cend(), [](auto &&data) { return (data.second.owned(type_hash>::value()) || ...); }); + return std::any_of(groups.cbegin(), groups.cend(), [](auto &&data) { return (data.second.handler->owned(type_hash>::value()) || ...); }); } /** @@ -1350,7 +1339,7 @@ public: template [[nodiscard]] bool sortable(const basic_group, get_t, exclude_t> &) noexcept { constexpr auto size = sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude); - auto pred = [size](const auto &data) { return (data.second.owned(type_hash::value()) || ...) && (size < data.second.handler->size); }; + auto pred = [size](const auto &data) { return (data.second.handler->owned(type_hash::value()) || ...) && (size < data.second.handler->size); }; return std::find_if(groups.cbegin(), groups.cend(), std::move(pred)) == groups.cend(); }