Browse Source

view: avoid using storage, further prepare for empty safe views

Michele Caini 2 years ago
parent
commit
34f4403864
1 changed files with 12 additions and 12 deletions
  1. 12 12
      src/entt/entity/view.hpp

+ 12 - 12
src/entt/entity/view.hpp

@@ -228,14 +228,14 @@ class basic_view<get_t<Get...>, exclude_t<Exclude...>> {
         if constexpr(Curr == Other) {
             return std::forward_as_tuple(std::get<Args>(curr)...);
         } else {
-            return storage<Other>()->get_as_tuple(std::get<0>(curr));
+            return std::get<Other>(pools)->get_as_tuple(std::get<0>(curr));
         }
     }
 
     template<std::size_t Curr, typename Func, std::size_t... Index>
     void each(Func &func, std::index_sequence<Index...>) const {
-        for(const auto curr: storage<Curr>()->each()) {
-            if(const auto entt = std::get<0>(curr); ((sizeof...(Get) != 1u) || (entt != tombstone)) && ((Curr == Index || storage<Index>()->contains(entt)) && ...) && internal::none_of(filter, entt)) {
+        for(const auto curr: std::get<Curr>(pools)->each()) {
+            if(const auto entt = std::get<0>(curr); ((sizeof...(Get) != 1u) || (entt != tombstone)) && ((Curr == Index || std::get<Index>(pools)->contains(entt)) && ...) && internal::none_of(filter, entt)) {
                 if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_view>().get({})))>) {
                     std::apply(func, std::tuple_cat(std::make_tuple(entt), dispatch_get<Curr, Index>(curr)...));
                 } else {
@@ -247,7 +247,7 @@ class basic_view<get_t<Get...>, exclude_t<Exclude...>> {
 
     template<typename Func, std::size_t... Index>
     void pick_and_each(Func &func, std::index_sequence<Index...> seq) const {
-        ((storage<Index>() == view ? each<Index>(func, seq) : void()), ...);
+        ((std::get<Index>(pools) == view ? each<Index>(func, seq) : void()), ...);
     }
 
 public:
@@ -303,7 +303,7 @@ public:
      */
     template<std::size_t Index>
     void use() noexcept {
-        view = storage<Index>();
+        view = std::get<Index>(pools);
     }
 
     /*! @brief Updates the internal leading view if required. */
@@ -496,9 +496,9 @@ public:
         if constexpr(sizeof...(Index) == 0) {
             return std::apply([entt](auto *...curr) { return std::tuple_cat(curr->get_as_tuple(entt)...); }, pools);
         } else if constexpr(sizeof...(Index) == 1) {
-            return (storage<Index>()->get(entt), ...);
+            return (std::get<Index>(pools)->get(entt), ...);
         } else {
-            return std::tuple_cat(storage<Index>()->get_as_tuple(entt)...);
+            return std::tuple_cat(std::get<Index>(pools)->get_as_tuple(entt)...);
         }
     }
 
@@ -780,7 +780,7 @@ public:
      * @return The component assigned to the given entity.
      */
     [[nodiscard]] decltype(auto) operator[](const entity_type entt) const {
-        return storage()->get(entt);
+        return std::get<0>(pools)->get(entt);
     }
 
     /**
@@ -821,9 +821,9 @@ public:
     template<std::size_t... Elem>
     [[nodiscard]] decltype(auto) get(const entity_type entt) const {
         if constexpr(sizeof...(Elem) == 0) {
-            return storage()->get_as_tuple(entt);
+            return std::get<0>(pools)->get_as_tuple(entt);
         } else {
-            return storage<Elem...>()->get(entt);
+            return std::get<Elem...>(pools)->get(entt);
         }
     }
 
@@ -860,7 +860,7 @@ public:
                 func();
             }
         } else {
-            for(auto &&component: *storage()) {
+            for(auto &&component: *std::get<0>(pools)) {
                 func(component);
             }
         }
@@ -876,7 +876,7 @@ public:
      * @return An iterable object to use to _visit_ the view.
      */
     [[nodiscard]] iterable each() const noexcept {
-        return storage()->each();
+        return std::get<0>(pools)->each();
     }
 
     /**