From 7ef00851153a6d579f178b151cf3ce584d644bdf Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 14 Mar 2023 15:45:13 +0100 Subject: [PATCH] registry: drop group_data --- src/entt/entity/registry.hpp | 48 +++++++++++++++--------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index ebe0b8b51..993981f1a 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -246,13 +246,9 @@ class basic_registry { template using storage_for_type = typename storage_for>>::type; - struct group_data { - std::shared_ptr handler; - }; - // std::shared_ptr because of its type erased allocator which is useful here using pool_container_type = dense_map, identity, std::equal_to, typename alloc_traits::template rebind_alloc>>>; - using group_container_type = dense_map, typename alloc_traits::template rebind_alloc>>; + using group_container_type = dense_map, identity, std::equal_to, typename alloc_traits::template rebind_alloc>>>; template [[nodiscard]] auto &assure(const id_type id = type_hash::value()) { @@ -1211,18 +1207,16 @@ public: handler_type *handler = nullptr; if(auto it = groups.find(type_hash::value()); it != groups.cend()) { - handler = static_cast(it->second.handler.get()); + handler = static_cast(it->second.get()); } else { - group_data candidate = { - std::allocate_shared(get_allocator(), assure>(), assure>()..., assure>()..., assure>()...)}; - - handler = static_cast(candidate.handler.get()); - groups.emplace(type_hash::value(), std::move(candidate)); + const auto elem = std::allocate_shared(get_allocator(), assure>(), assure>()..., assure>()..., assure>()...); + groups.emplace(type_hash::value(), elem); + handler = static_cast(elem.get()); ENTT_ASSERT(std::all_of(groups.cbegin(), groups.cend(), [size = handler->size](const auto &data) { - 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)); + 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())); + return !overlapping || ((sz == size) || (sz == data.second->size)); }), "Conflicting groups"); @@ -1233,14 +1227,14 @@ public: size_type next_len{}; for(auto &&data: groups) { - 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(); + if((data.second->owned(type_hash>::value()) || ... || data.second->owned(type_hash>::value()))) { + if(const auto sz = data.second->size; sz < handler->size && (prev == nullptr || prev_len < sz)) { + prev = data.second.get(); prev_len = sz; } - if(const auto sz = data.second.handler->size; sz > handler->size && (next == nullptr || next_len > sz)) { - next = data.second.handler.get(); + if(const auto sz = data.second->size; sz > handler->size && (next == nullptr || next_len > sz)) { + next = data.second.get(); next_len = sz; } } @@ -1281,13 +1275,11 @@ public: handler_type *handler = nullptr; if(auto it = groups.find(type_hash::value()); it != groups.cend()) { - handler = static_cast(it->second.handler.get()); + handler = static_cast(it->second.get()); } else { - group_data candidate = { - std::allocate_shared(get_allocator(), get_allocator(), assure>(), assure>()..., assure>()...)}; - - handler = static_cast(candidate.handler.get()); - groups.emplace(type_hash::value(), std::move(candidate)); + const auto elem = std::allocate_shared(get_allocator(), get_allocator(), assure>(), assure>()..., assure>()...); + 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), ...); @@ -1314,7 +1306,7 @@ public: if(auto it = groups.find(type_hash::value()); it == groups.cend()) { return {}; } else { - return {*static_cast(it->second.handler.get()), assure>()..., assure>()..., assure>()...}; + return {*static_cast(it->second.get()), assure>()..., assure>()..., assure>()...}; } } @@ -1326,7 +1318,7 @@ public: */ template [[nodiscard]] bool owned() const { - return std::any_of(groups.cbegin(), groups.cend(), [](auto &&data) { return (data.second.handler->owned(type_hash>::value()) || ...); }); + return std::any_of(groups.cbegin(), groups.cend(), [](auto &&data) { return (data.second->owned(type_hash>::value()) || ...); }); } /** @@ -1339,7 +1331,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.handler->owned(type_hash::value()) || ...) && (size < data.second.handler->size); }; + auto pred = [size](const auto &data) { return (data.second->owned(type_hash::value()) || ...) && (size < data.second->size); }; return std::find_if(groups.cbegin(), groups.cend(), std::move(pred)) == groups.cend(); }