Explorar el Código

view: internal changes

Michele Caini hace 1 año
padre
commit
f1356db111
Se han modificado 1 ficheros con 20 adiciones y 19 borrados
  1. 20 19
      src/entt/entity/view.hpp

+ 20 - 19
src/entt/entity/view.hpp

@@ -270,27 +270,19 @@ protected:
         return pools[pos];
         return pools[pos];
     }
     }
 
 
-    [[nodiscard]] const Type *storage(const std::size_t pos) const noexcept {
-        if(pos < Get) {
-            return pools[pos];
-        }
-
-        if(const auto idx = pos - Get; filter[idx] != internal::view_placeholder<Type>()) {
-            return filter[idx];
-        }
+    void pool_at(const std::size_t pos, const Type *elem) noexcept {
+        ENTT_ASSERT(elem != nullptr, "Unexpected element");
+        pools[pos] = elem;
+        refresh();
+    }
 
 
-        return nullptr;
+    [[nodiscard]] const Type *filter_at(const std::size_t pos) const noexcept {
+        return (filter[pos] == internal::view_placeholder<Type>()) ? nullptr : filter[pos];
     }
     }
 
 
-    void storage(const std::size_t pos, const Type *elem) noexcept {
+    void filter_at(const std::size_t pos, const Type *elem) noexcept {
         ENTT_ASSERT(elem != nullptr, "Unexpected element");
         ENTT_ASSERT(elem != nullptr, "Unexpected element");
-
-        if(pos < Get) {
-            pools[pos] = elem;
-            refresh();
-        } else {
-            filter[pos - Get] = elem;
-        }
+        filter[pos] = elem;
     }
     }
 
 
     [[nodiscard]] bool none_of(const typename Type::entity_type entt) const noexcept {
     [[nodiscard]] bool none_of(const typename Type::entity_type entt) const noexcept {
@@ -544,7 +536,11 @@ public:
      */
      */
     template<std::size_t Index>
     template<std::size_t Index>
     [[nodiscard]] auto *storage() const noexcept {
     [[nodiscard]] auto *storage() const noexcept {
-        return static_cast<element_at<Index> *>(const_cast<constness_as_t<common_type, element_at<Index>> *>(base_type::storage(Index)));
+        if constexpr(Index < sizeof...(Get)) {
+            return static_cast<element_at<Index> *>(const_cast<constness_as_t<common_type, element_at<Index>> *>(base_type::pool_at(Index)));
+        } else {
+            return static_cast<element_at<Index> *>(const_cast<constness_as_t<common_type, element_at<Index>> *>(base_type::filter_at(Index - sizeof...(Get))));
+        }
     }
     }
 
 
     /**
     /**
@@ -566,7 +562,12 @@ public:
     template<std::size_t Index, typename Type>
     template<std::size_t Index, typename Type>
     void storage(Type &elem) noexcept {
     void storage(Type &elem) noexcept {
         static_assert(std::is_convertible_v<Type &, element_at<Index> &>, "Unexpected type");
         static_assert(std::is_convertible_v<Type &, element_at<Index> &>, "Unexpected type");
-        base_type::storage(Index, &elem);
+
+        if constexpr(Index < sizeof...(Get)) {
+            base_type::pool_at(Index, &elem);
+        } else {
+            base_type::filter_at(Index - sizeof...(Get), &elem);
+        }
     }
     }
 
 
     /**
     /**