Bladeren bron

group: simplify non-critical virtual function

skypjack 1 jaar geleden
bovenliggende
commit
7431d93691
3 gewijzigde bestanden met toevoegingen van 10 en 15 verwijderingen
  1. 1 2
      TODO
  2. 7 9
      src/entt/entity/group.hpp
  3. 2 4
      src/entt/entity/registry.hpp

+ 1 - 2
TODO

@@ -36,9 +36,8 @@ TODO:
 * improve front (no multiple checks) and back (ie no contains) for multi-type view
 * 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
 * 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
 * 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<void> for meta properties
 * entity based component_traits
 * entity based component_traits
-* investigate using any rather than shared<void> for meta properties
 * copy-and-swap for any and meta_any
 * copy-and-swap for any and meta_any
 * improve seek function for overloaded meta functions
 * improve seek function for overloaded meta functions
 * fix cmake warning about FetchContent_Populate
 * fix cmake warning about FetchContent_Populate

+ 7 - 9
src/entt/entity/group.hpp

@@ -94,8 +94,8 @@ template<typename... Lhs, typename... Rhs>
 struct group_descriptor {
 struct group_descriptor {
     using size_type = std::size_t;
     using size_type = std::size_t;
     virtual ~group_descriptor() noexcept = default;
     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();
         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 {
     [[nodiscard]] size_type length() const noexcept {

+ 2 - 4
src/entt/entity/registry.hpp

@@ -1099,8 +1099,7 @@ public:
             handler = std::allocate_shared<handler_type>(get_allocator(), get_allocator(), std::forward_as_tuple(assure<std::remove_const_t<Get>>()...), std::forward_as_tuple(assure<std::remove_const_t<Exclude>>()...));
             handler = std::allocate_shared<handler_type>(get_allocator(), get_allocator(), std::forward_as_tuple(assure<std::remove_const_t<Get>>()...), std::forward_as_tuple(assure<std::remove_const_t<Exclude>>()...));
         } else {
         } else {
             handler = std::allocate_shared<handler_type>(get_allocator(), std::forward_as_tuple(assure<std::remove_const_t<Owned>>()..., assure<std::remove_const_t<Get>>()...), std::forward_as_tuple(assure<std::remove_const_t<Exclude>>()...));
             handler = std::allocate_shared<handler_type>(get_allocator(), std::forward_as_tuple(assure<std::remove_const_t<Owned>>()..., assure<std::remove_const_t<Get>>()...), std::forward_as_tuple(assure<std::remove_const_t<Exclude>>()...));
-            [[maybe_unused]] const std::array elem{type_hash<std::remove_const_t<Owned>>::value()..., type_hash<std::remove_const_t<Get>>::value()..., type_hash<std::remove_const_t<Exclude>>::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<Owned>().hash()) || ...); }), "Conflicting groups");
         }
         }
 
 
         groups.emplace(group_type::group_id(), handler);
         groups.emplace(group_type::group_id(), handler);
@@ -1130,8 +1129,7 @@ public:
      */
      */
     template<typename Type, typename... Other>
     template<typename Type, typename... Other>
     [[nodiscard]] bool owned() const {
     [[nodiscard]] bool owned() const {
-        const std::array elem{type_hash<std::remove_const_t<Type>>::value(), type_hash<std::remove_const_t<Other>>::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<Type>().hash()) || ... || data.second->owned(type_id<Other>().hash())); });
     }
     }
 
 
     /**
     /**