Browse Source

view: uniform design (prepare for chaining)

Michele Caini 5 years ago
parent
commit
cabcc761c6
1 changed files with 20 additions and 19 deletions
  1. 20 19
      src/entt/entity/view.hpp

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

@@ -669,7 +669,7 @@ public:
 
 
     /*! @brief Default constructor to use to create empty, invalid views. */
     /*! @brief Default constructor to use to create empty, invalid views. */
     basic_view() ENTT_NOEXCEPT
     basic_view() ENTT_NOEXCEPT
-        : pool{}
+        : pools{}
     {}
     {}
 
 
     /**
     /**
@@ -677,7 +677,7 @@ public:
      * @param ref The storage for the type to iterate.
      * @param ref The storage for the type to iterate.
      */
      */
     basic_view(storage_type &ref) ENTT_NOEXCEPT
     basic_view(storage_type &ref) ENTT_NOEXCEPT
-        : pool{&ref}
+        : pools{&ref}
     {}
     {}
 
 
     /**
     /**
@@ -685,7 +685,7 @@ public:
      * @return Number of entities that have the given component.
      * @return Number of entities that have the given component.
      */
      */
     [[nodiscard]] size_type size() const ENTT_NOEXCEPT {
     [[nodiscard]] size_type size() const ENTT_NOEXCEPT {
-        return pool->size();
+        return std::get<0>(pools)->size();
     }
     }
 
 
     /**
     /**
@@ -693,7 +693,7 @@ public:
      * @return True if the view is empty, false otherwise.
      * @return True if the view is empty, false otherwise.
      */
      */
     [[nodiscard]] bool empty() const ENTT_NOEXCEPT {
     [[nodiscard]] bool empty() const ENTT_NOEXCEPT {
-        return pool->empty();
+        return std::get<0>(pools)->empty();
     }
     }
 
 
     /**
     /**
@@ -705,7 +705,7 @@ public:
      * @return A pointer to the array of components.
      * @return A pointer to the array of components.
      */
      */
     [[nodiscard]] raw_type * raw() const ENTT_NOEXCEPT {
     [[nodiscard]] raw_type * raw() const ENTT_NOEXCEPT {
-        return pool->raw();
+        return std::get<0>(pools)->raw();
     }
     }
 
 
     /**
     /**
@@ -717,7 +717,7 @@ public:
      * @return A pointer to the array of entities.
      * @return A pointer to the array of entities.
      */
      */
     [[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
     [[nodiscard]] const entity_type * data() const ENTT_NOEXCEPT {
-        return pool->data();
+        return std::get<0>(pools)->data();
     }
     }
 
 
     /**
     /**
@@ -729,7 +729,7 @@ public:
      * @return An iterator to the first entity of the view.
      * @return An iterator to the first entity of the view.
      */
      */
     [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
     [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
-        return pool->basic_sparse_set<entity_type>::begin();
+        return std::get<0>(pools)->basic_sparse_set<entity_type>::begin();
     }
     }
 
 
     /**
     /**
@@ -742,7 +742,7 @@ public:
      * @return An iterator to the entity following the last entity of the view.
      * @return An iterator to the entity following the last entity of the view.
      */
      */
     [[nodiscard]] iterator end() const ENTT_NOEXCEPT {
     [[nodiscard]] iterator end() const ENTT_NOEXCEPT {
-        return pool->basic_sparse_set<entity_type>::end();
+        return std::get<0>(pools)->basic_sparse_set<entity_type>::end();
     }
     }
 
 
     /**
     /**
@@ -754,7 +754,7 @@ public:
      * @return An iterator to the first entity of the reversed view.
      * @return An iterator to the first entity of the reversed view.
      */
      */
     [[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
     [[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
-        return pool->basic_sparse_set<entity_type>::rbegin();
+        return std::get<0>(pools)->basic_sparse_set<entity_type>::rbegin();
     }
     }
 
 
     /**
     /**
@@ -769,7 +769,7 @@ public:
      * reversed view.
      * reversed view.
      */
      */
     [[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
     [[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
-        return pool->basic_sparse_set<entity_type>::rend();
+        return std::get<0>(pools)->basic_sparse_set<entity_type>::rend();
     }
     }
 
 
     /**
     /**
@@ -799,7 +799,7 @@ public:
      * iterator otherwise.
      * iterator otherwise.
      */
      */
     [[nodiscard]] iterator find(const entity_type entt) const {
     [[nodiscard]] iterator find(const entity_type entt) const {
-        const auto it = pool->find(entt);
+        const auto it = std::get<0>(pools)->find(entt);
         return it != end() && *it == entt ? it : end();
         return it != end() && *it == entt ? it : end();
     }
     }
 
 
@@ -817,7 +817,7 @@ public:
      * @return True if the view is properly initialized, false otherwise.
      * @return True if the view is properly initialized, false otherwise.
      */
      */
     [[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
     [[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
-        return pool != nullptr;
+        return std::get<0>(pools) != nullptr;
     }
     }
 
 
     /**
     /**
@@ -826,7 +826,7 @@ public:
      * @return True if the view contains the given entity, false otherwise.
      * @return True if the view contains the given entity, false otherwise.
      */
      */
     [[nodiscard]] bool contains(const entity_type entt) const {
     [[nodiscard]] bool contains(const entity_type entt) const {
-        return pool->contains(entt);
+        return std::get<0>(pools)->contains(entt);
     }
     }
 
 
     /**
     /**
@@ -849,10 +849,10 @@ public:
         ENTT_ASSERT(contains(entt));
         ENTT_ASSERT(contains(entt));
 
 
         if constexpr(sizeof...(Comp) == 0) {
         if constexpr(sizeof...(Comp) == 0) {
-            return get_as_tuple(*pool, entt);
+            return get_as_tuple(*std::get<0>(pools), entt);
         } else {
         } else {
             static_assert(std::is_same_v<Comp..., Component>, "Invalid component type");
             static_assert(std::is_same_v<Comp..., Component>, "Invalid component type");
-            return pool->get(entt);
+            return std::get<0>(pools)->get(entt);
         }
         }
     }
     }
 
 
@@ -880,7 +880,7 @@ public:
      */
      */
     template<typename Func>
     template<typename Func>
     void each(Func func) const {
     void each(Func func) const {
-        if constexpr(std::is_void_v<decltype(pool->get({}))>) {
+        if constexpr(std::is_void_v<decltype(std::get<0>(pools)->get({}))>) {
             if constexpr(std::is_invocable_v<Func>) {
             if constexpr(std::is_invocable_v<Func>) {
                 for(auto pos = size(); pos; --pos) {
                 for(auto pos = size(); pos; --pos) {
                     func();
                     func();
@@ -896,7 +896,7 @@ public:
                     std::apply(func, pack);
                     std::apply(func, pack);
                 }
                 }
             } else {
             } else {
-                for(auto &&component: *pool) {
+                for(auto &&component: *std::get<0>(pools)) {
                     func(component);
                     func(component);
                 }
                 }
             }
             }
@@ -917,11 +917,12 @@ public:
      * @return An iterable object to use to _visit_ the view.
      * @return An iterable object to use to _visit_ the view.
      */
      */
     [[nodiscard]] iterable_view each() const ENTT_NOEXCEPT {
     [[nodiscard]] iterable_view each() const ENTT_NOEXCEPT {
-        return iterable_view{*pool};
+        return iterable_view{*std::get<0>(pools)};
     }
     }
 
 
 private:
 private:
-    storage_type * const pool;
+    const std::tuple<storage_type *> pools;
+    const std::tuple<> filter;
 };
 };