From 05b514b7434dac29ceb520139f9275bf15c76e9d Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 2 Nov 2020 14:05:07 +0100 Subject: [PATCH] Revert "entity: minor changes" This reverts commit af69a0a1fd0569e960a48936048845892983b17d. --- TODO | 3 --- src/entt/entity/group.hpp | 45 +++++++++++++++++++++++++-------------- src/entt/entity/view.hpp | 6 +++--- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index 0bd67c7d3..da5c7b968 100644 --- a/TODO +++ b/TODO @@ -17,10 +17,7 @@ - ... 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 -* runtime, named pools -* faster destroy * make view pack work also with groups, add multi-type iterator (not only input iterators) * add exclude-only views to combine with packs * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index f43707f3c..f21f5a526 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -74,13 +74,17 @@ class basic_group, get_t> final { class iterable_group { friend class basic_group, get_t>; - template - class iterable_group_iterator { + template + class iterable_group_iterator; + + template + class iterable_group_iterator> { friend class iterable_group; - iterable_group_iterator(It from, const basic_group &parent) ENTT_NOEXCEPT + template + iterable_group_iterator(It from, const std::tuple *...> &args) ENTT_NOEXCEPT : it{from}, - group{&parent} + pools{std::get *>(args)...} {} public: @@ -100,7 +104,8 @@ class basic_group, get_t> final { } [[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 *>(pools)->get(entt)...)); } [[nodiscard]] bool operator==(const iterable_group_iterator &other) const ENTT_NOEXCEPT { @@ -113,35 +118,43 @@ class basic_group, get_t> final { private: It it; - const basic_group *group; + const std::tuple *...> pools; }; - iterable_group(const basic_group &parent) - : group{parent} + iterable_group(basic_sparse_set &ref, const std::tuple *...> &cpools) + : handler{&ref}, + pools{cpools} {} public: - using iterator = iterable_group_iterator::iterator>; - using reverse_iterator = iterable_group_iterator::reverse_iterator>; + using iterator = iterable_group_iterator< + typename basic_sparse_set::iterator, + type_list_cat_t, type_list<>, type_list>...> + >; + using reverse_iterator = iterable_group_iterator< + typename basic_sparse_set::reverse_iterator, + type_list_cat_t, type_list<>, type_list>...> + >; [[nodiscard]] iterator begin() const ENTT_NOEXCEPT { - return { group.begin(), group }; + return { handler->begin(), pools }; } [[nodiscard]] iterator end() const ENTT_NOEXCEPT { - return { group.end(), group }; + return { handler->end(), pools }; } [[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT { - return { group.rbegin(), group }; + return { handler->rbegin(), pools }; } [[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT { - return { group.rend(), group }; + return { handler->rend(), pools }; } private: - const basic_group group; + basic_sparse_set *handler; + const std::tuple *...> pools; }; basic_group(basic_sparse_set &ref, pool_type &... gpool) ENTT_NOEXCEPT @@ -449,7 +462,7 @@ public: * @return An iterable object to use to _visit_ the group. */ [[nodiscard]] iterable_group each() const ENTT_NOEXCEPT { - return *this; + return iterable_group{*handler, pools}; } /** diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 78233955d..255b365be 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -159,7 +159,7 @@ class basic_view, Component...> final { iterable_view_iterator(It from, const basic_view &parent) ENTT_NOEXCEPT : it{from}, - view{&parent} + view{parent} {} public: @@ -179,7 +179,7 @@ class basic_view, Component...> final { } [[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 { @@ -192,7 +192,7 @@ class basic_view, Component...> final { private: It it; - const basic_view *view; + const basic_view view; }; iterable_view(const basic_view &parent)