Просмотр исходного кода

Revert "entity: minor changes"

This reverts commit af69a0a1fd0569e960a48936048845892983b17d.
Michele Caini 5 лет назад
Родитель
Сommit
05b514b743
3 измененных файлов с 32 добавлено и 22 удалено
  1. 0 3
      TODO
  2. 29 16
      src/entt/entity/group.hpp
  3. 3 3
      src/entt/entity/view.hpp

+ 0 - 3
TODO

@@ -17,10 +17,7 @@
   - ...
   - ...
 
 
 WIP:
 WIP:
-* currently, the erased remove of pdata forces pools to implement a range remove because it uses this one
 * document the handle way for extended operations
 * document the handle way for extended operations
-* runtime, named pools
-* faster destroy
 * make view pack work also with groups, add multi-type iterator (not only input iterators)
 * make view pack work also with groups, add multi-type iterator (not only input iterators)
 * add exclude-only views to combine with packs
 * add exclude-only views to combine with packs
 * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views
 * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views

+ 29 - 16
src/entt/entity/group.hpp

@@ -74,13 +74,17 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
     class iterable_group {
     class iterable_group {
         friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>>;
         friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>>;
 
 
-        template<typename It>
-        class iterable_group_iterator {
+        template<typename, typename>
+        class iterable_group_iterator;
+
+        template<typename It, typename... Type>
+        class iterable_group_iterator<It, type_list<Type...>> {
             friend class iterable_group;
             friend class iterable_group;
 
 
-            iterable_group_iterator(It from, const basic_group &parent) ENTT_NOEXCEPT
+            template<typename... Args>
+            iterable_group_iterator(It from, const std::tuple<pool_type<Get> *...> &args) ENTT_NOEXCEPT
                 : it{from},
                 : it{from},
-                  group{&parent}
+                  pools{std::get<pool_type<Type> *>(args)...}
             {}
             {}
 
 
         public:
         public:
@@ -100,7 +104,8 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
             }
             }
 
 
             [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
             [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
-                return std::tuple_cat(std::make_tuple(*it), group->get(*it));
+                const auto entt = *it;
+                return std::tuple_cat(std::make_tuple(entt), std::forward_as_tuple(std::get<pool_type<Type> *>(pools)->get(entt)...));
             }
             }
 
 
             [[nodiscard]] bool operator==(const iterable_group_iterator &other) const ENTT_NOEXCEPT {
             [[nodiscard]] bool operator==(const iterable_group_iterator &other) const ENTT_NOEXCEPT {
@@ -113,35 +118,43 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
 
 
         private:
         private:
             It it;
             It it;
-            const basic_group *group;
+            const std::tuple<pool_type<Type> *...> pools;
         };
         };
 
 
-        iterable_group(const basic_group &parent)
-            : group{parent}
+        iterable_group(basic_sparse_set<Entity> &ref, const std::tuple<pool_type<Get> *...> &cpools)
+            : handler{&ref},
+              pools{cpools}
         {}
         {}
 
 
     public:
     public:
-        using iterator = iterable_group_iterator<typename basic_sparse_set<Entity>::iterator>;
-        using reverse_iterator = iterable_group_iterator<typename basic_sparse_set<Entity>::reverse_iterator>;
+        using iterator = iterable_group_iterator<
+            typename basic_sparse_set<Entity>::iterator,
+            type_list_cat_t<std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>...>
+        >;
+        using reverse_iterator = iterable_group_iterator<
+            typename basic_sparse_set<Entity>::reverse_iterator,
+            type_list_cat_t<std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>...>
+        >;
 
 
         [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
         [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
-            return { group.begin(), group };
+            return { handler->begin(), pools };
         }
         }
 
 
         [[nodiscard]] iterator end() const ENTT_NOEXCEPT {
         [[nodiscard]] iterator end() const ENTT_NOEXCEPT {
-            return { group.end(), group };
+            return { handler->end(), pools };
         }
         }
 
 
         [[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
         [[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
-            return { group.rbegin(), group };
+            return { handler->rbegin(), pools };
         }
         }
 
 
         [[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
         [[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
-            return { group.rend(), group };
+            return { handler->rend(), pools };
         }
         }
 
 
     private:
     private:
-        const basic_group group;
+        basic_sparse_set<Entity> *handler;
+        const std::tuple<pool_type<Get> *...> pools;
     };
     };
 
 
     basic_group(basic_sparse_set<Entity> &ref, pool_type<Get> &... gpool) ENTT_NOEXCEPT
     basic_group(basic_sparse_set<Entity> &ref, pool_type<Get> &... gpool) ENTT_NOEXCEPT
@@ -449,7 +462,7 @@ public:
      * @return An iterable object to use to _visit_ the group.
      * @return An iterable object to use to _visit_ the group.
      */
      */
     [[nodiscard]] iterable_group each() const ENTT_NOEXCEPT {
     [[nodiscard]] iterable_group each() const ENTT_NOEXCEPT {
-        return *this;
+        return iterable_group{*handler, pools};
     }
     }
 
 
     /**
     /**

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

@@ -159,7 +159,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
 
 
             iterable_view_iterator(It from, const basic_view &parent) ENTT_NOEXCEPT
             iterable_view_iterator(It from, const basic_view &parent) ENTT_NOEXCEPT
                 : it{from},
                 : it{from},
-                  view{&parent}
+                  view{parent}
             {}
             {}
 
 
         public:
         public:
@@ -179,7 +179,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
             }
             }
 
 
             [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
             [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
-                return std::tuple_cat(std::make_tuple(*it), view->get(*it));
+                return std::tuple_cat(std::make_tuple(*it), view.get(*it));
             }
             }
 
 
             [[nodiscard]] bool operator==(const iterable_view_iterator &other) const ENTT_NOEXCEPT {
             [[nodiscard]] bool operator==(const iterable_view_iterator &other) const ENTT_NOEXCEPT {
@@ -192,7 +192,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
 
 
         private:
         private:
             It it;
             It it;
-            const basic_view *view;
+            const basic_view view;
         };
         };
 
 
         iterable_view(const basic_view &parent)
         iterable_view(const basic_view &parent)