From 7431d936914cf14ecadd28e665f042efcd14ae72 Mon Sep 17 00:00:00 2001 From: skypjack Date: Fri, 19 Jul 2024 10:31:30 +0200 Subject: [PATCH] group: simplify non-critical virtual function --- TODO | 3 +-- src/entt/entity/group.hpp | 16 +++++++--------- src/entt/entity/registry.hpp | 6 ++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index 3d7e4e814..ff4fe8da9 100644 --- a/TODO +++ b/TODO @@ -36,9 +36,8 @@ TODO: * improve front (no multiple checks) and back (ie no contains) for multi-type view * cleanup common view from tricks to handle single swap-only and in-place, if constexpr branches * exploit ref/cref in any to avoid invoking the vtable if possible -* review meta properties and details, maybe a dense map is too much +* review meta properties and details: maybe a dense map is too much, investigate using any rather than shared for meta properties * entity based component_traits -* investigate using any rather than shared for meta properties * copy-and-swap for any and meta_any * improve seek function for overloaded meta functions * fix cmake warning about FetchContent_Populate diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index 0c5a238eb..2ecbecbe7 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -94,8 +94,8 @@ template struct group_descriptor { using size_type = std::size_t; virtual ~group_descriptor() noexcept = default; - virtual size_type owned(const id_type *, const size_type) const noexcept { - return 0u; + virtual bool owned(const id_type) const noexcept { + return false; } }; @@ -149,16 +149,14 @@ public: common_setup(); } - size_type owned(const id_type *elem, const size_type length) const noexcept final { - size_type cnt = 0u; - - for(auto pos = 0u; pos < length; ++pos) { - for(auto next = 0u; next < Owned; ++next) { - cnt += (elem[pos] == pools[next]->type().hash()); + virtual bool owned(const id_type hash) const noexcept { + for(size_type pos{}; pos < Owned; ++pos) { + if(pools[pos]->type().hash() == hash) { + return true; } } - return cnt; + return false; } [[nodiscard]] size_type length() const noexcept { diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 40fc96389..a54e2ebf7 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -1099,8 +1099,7 @@ public: handler = std::allocate_shared(get_allocator(), get_allocator(), std::forward_as_tuple(assure>()...), std::forward_as_tuple(assure>()...)); } else { handler = std::allocate_shared(get_allocator(), std::forward_as_tuple(assure>()..., assure>()...), std::forward_as_tuple(assure>()...)); - [[maybe_unused]] const std::array elem{type_hash>::value()..., type_hash>::value()..., type_hash>::value()...}; - ENTT_ASSERT(std::all_of(groups.cbegin(), groups.cend(), [&elem](const auto &data) { return data.second->owned(elem.data(), sizeof...(Owned)) == 0u; }), "Conflicting groups"); + ENTT_ASSERT(std::all_of(groups.cbegin(), groups.cend(), [](const auto &data) { return !(data.second->owned(type_id().hash()) || ...); }), "Conflicting groups"); } groups.emplace(group_type::group_id(), handler); @@ -1130,8 +1129,7 @@ public: */ template [[nodiscard]] bool owned() const { - const std::array elem{type_hash>::value(), type_hash>::value()...}; - return std::any_of(groups.cbegin(), groups.cend(), [&elem](auto &&data) { return data.second->owned(elem.data(), 1u + sizeof...(Other)); }); + return std::any_of(groups.cbegin(), groups.cend(), [](auto &&data) { return (data.second->owned(type_id().hash()) || ... || data.second->owned(type_id().hash())); }); } /**