From 61c5f8ae229a615d75fac0cd2e763ba5cce01423 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sun, 12 Dec 2021 16:51:48 +0100 Subject: [PATCH] registry/view/group: cleanup --- src/entt/entity/group.hpp | 12 ++++----- src/entt/entity/helper.hpp | 2 +- src/entt/entity/registry.hpp | 14 ++++------ src/entt/entity/view.hpp | 52 ++++++++++++++---------------------- 4 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index 309e17a83..260762364 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -154,14 +154,14 @@ public: using entity_type = Entity; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Common type among all storage types. */ + using base_type = basic_common_type; /*! @brief Random access iterator type. */ using iterator = typename basic_common_type::iterator; /*! @brief Reversed iterator type. */ using reverse_iterator = typename basic_common_type::reverse_iterator; /*! @brief Iterable group type. */ using iterable_group = iterable; - /*! @brief Common type among all storage types. */ - using base_type = basic_common_type; /*! @brief Default constructor to use to create empty, invalid groups. */ basic_group() ENTT_NOEXCEPT @@ -181,7 +181,7 @@ public: * @return The storage for the given component type. */ template - [[nodiscard]] storage_type &storage() const ENTT_NOEXCEPT { + [[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT { return *std::get *>(pools); } @@ -653,14 +653,14 @@ public: using entity_type = Entity; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Common type among all storage types. */ + using base_type = basic_common_type; /*! @brief Random access iterator type. */ using iterator = typename basic_common_type::iterator; /*! @brief Reversed iterator type. */ using reverse_iterator = typename basic_common_type::reverse_iterator; /*! @brief Iterable group type. */ using iterable_group = iterable; - /*! @brief Common type among all storage types. */ - using base_type = basic_common_type; /*! @brief Default constructor to use to create empty, invalid groups. */ basic_group() ENTT_NOEXCEPT @@ -672,7 +672,7 @@ public: * @return The storage for the given component type. */ template - [[nodiscard]] storage_type &storage() const ENTT_NOEXCEPT { + [[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT { return *std::get *>(pools); } diff --git a/src/entt/entity/helper.hpp b/src/entt/entity/helper.hpp index baf5dabc4..2170ac21c 100644 --- a/src/entt/entity/helper.hpp +++ b/src/entt/entity/helper.hpp @@ -139,7 +139,7 @@ void invoke(basic_registry ®, const Entity entt) { template Entity to_entity(const basic_registry ®, const Component &instance) { const auto &storage = reg.template storage(); - const typename basic_registry::template storage_type::base_type &base = storage; + const typename basic_registry::base_type &base = storage; const auto *addr = std::addressof(instance); for(auto it = base.rbegin(), last = base.rend(); it < last; it += ENTT_PACKED_PAGE) { diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 88d238c4b..eead1635b 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -38,6 +38,9 @@ class basic_registry { using entity_traits = entt_traits; using basic_common_type = basic_sparse_set; + template + using storage_type = typename storage_traits::storage_type; + template struct group_handler; @@ -141,13 +144,6 @@ public: /*! @brief Common type among all storage types. */ using base_type = basic_common_type; - /** - * @brief Storage type associated with a given component. - * @tparam Type Type of component. - */ - template - using storage_type = typename storage_traits::storage_type; - /*! @brief Default constructor. */ basic_registry() = default; @@ -192,7 +188,7 @@ public: * @return The storage for the given component type. */ template - [[nodiscard]] storage_type &storage(const id_type id = type_hash::value()) { + [[nodiscard]] decltype(auto) storage(const id_type id = type_hash::value()) { return assure(id); } @@ -208,7 +204,7 @@ public: * @return The storage for the given component type. */ template - [[nodiscard]] const storage_type &storage(const id_type id = type_hash::value()) const { + [[nodiscard]] decltype(auto) storage(const id_type id = type_hash::value()) const { return assure(id); } diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 65f09565c..b8976097f 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -33,7 +33,7 @@ auto storage_tuple(const View &view, std::index_sequence) { template class iterable_storage final { - using basic_common_type = typename Storage::base_type; + using base_type = typename Storage::base_type; template struct iterable_storage_iterator final { @@ -79,18 +79,18 @@ class iterable_storage final { public: using iterator = std::conditional_t< ignore_as_empty_v, - iterable_storage_iterator, - iterable_storage_iterator().begin())>>; + iterable_storage_iterator, + iterable_storage_iterator().begin())>>; iterable_storage(Storage &ref) : pool{&ref} {} [[nodiscard]] iterator begin() const ENTT_NOEXCEPT { - return iterator{pool->basic_common_type::begin(), pool->begin()}; + return iterator{pool->base_type::begin(), pool->begin()}; } [[nodiscard]] iterator end() const ENTT_NOEXCEPT { - return iterator{pool->basic_common_type::end(), pool->end()}; + return iterator{pool->base_type::end(), pool->end()}; } private: @@ -269,9 +269,7 @@ class basic_view, exclude_t> { friend class basic_view; template - using basic_storage_type = constness_as_t>::storage_type, Comp>; - - using basic_common_type = std::common_type_t::base_type...>; + using storage_type = constness_as_t>::storage_type, Comp>; template [[nodiscard]] auto pools_to_array(std::index_sequence) const ENTT_NOEXCEPT { @@ -317,19 +315,12 @@ public: using entity_type = Entity; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Common type among all storage types. */ + using base_type = std::common_type_t::base_type...>; /*! @brief Bidirectional iterator type. */ - using iterator = internal::view_iterator; + using iterator = internal::view_iterator; /*! @brief Iterable view type. */ using iterable_view = internal::iterable_view; - /*! @brief Common type among all storage types. */ - using base_type = basic_common_type; - - /** - * @brief Storage type associated with a given component. - * @tparam Type Type of component. - */ - template - using storage_type = basic_storage_type; /*! @brief Default constructor to use to create empty, invalid views. */ basic_view() ENTT_NOEXCEPT @@ -385,7 +376,7 @@ public: * @return The storage for the given component type. */ template - [[nodiscard]] storage_type &storage() const ENTT_NOEXCEPT { + [[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT { return *std::get *>(pools); } @@ -623,24 +614,21 @@ class basic_view, exclude_t<>, std::void_t friend class basic_view; - using basic_storage_type = constness_as_t>::storage_type, Component>; - using basic_common_type = typename basic_storage_type::base_type; + using storage_type = constness_as_t>::storage_type, Component>; public: /*! @brief Underlying entity identifier. */ using entity_type = Entity; /*! @brief Unsigned integer type. */ using size_type = std::size_t; - /*! @brief Random access iterator type. */ - using iterator = typename basic_common_type::iterator; - /*! @brief Reversed iterator type. */ - using reverse_iterator = typename basic_common_type::reverse_iterator; - /*! @brief Iterable view type. */ - using iterable_view = internal::iterable_storage; /*! @brief Common type among all storage types. */ - using base_type = basic_common_type; - /*! @brief Storage type associated with the view component. */ - using storage_type = basic_storage_type; + using base_type = typename storage_type::base_type; + /*! @brief Random access iterator type. */ + using iterator = typename base_type::iterator; + /*! @brief Reversed iterator type. */ + using reverse_iterator = typename base_type::reverse_iterator; + /*! @brief Iterable view type. */ + using iterable_view = internal::iterable_storage; /*! @brief Default constructor to use to create empty, invalid views. */ basic_view() ENTT_NOEXCEPT @@ -669,7 +657,7 @@ public: * @return The storage for the given component type. */ template - [[nodiscard]] storage_type &storage() const ENTT_NOEXCEPT { + [[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT { static_assert((std::is_same_v && ...), "Invalid component type"); return *view; } @@ -919,7 +907,7 @@ public: } private: - std::array filter; + std::array filter; storage_type *view; };