Michele Caini 4 лет назад
Родитель
Сommit
61c5f8ae22
4 измененных файлов с 30 добавлено и 46 удалено
  1. 6 6
      src/entt/entity/group.hpp
  2. 1 1
      src/entt/entity/helper.hpp
  3. 5 9
      src/entt/entity/registry.hpp
  4. 18 30
      src/entt/entity/view.hpp

+ 6 - 6
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<typename Comp>
-    [[nodiscard]] storage_type<Comp> &storage() const ENTT_NOEXCEPT {
+    [[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
         return *std::get<storage_type<Comp> *>(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<typename Comp>
-    [[nodiscard]] storage_type<Comp> &storage() const ENTT_NOEXCEPT {
+    [[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
         return *std::get<storage_type<Comp> *>(pools);
     }
 

+ 1 - 1
src/entt/entity/helper.hpp

@@ -139,7 +139,7 @@ void invoke(basic_registry<Entity> &reg, const Entity entt) {
 template<typename Entity, typename Component>
 Entity to_entity(const basic_registry<Entity> &reg, const Component &instance) {
     const auto &storage = reg.template storage<Component>();
-    const typename basic_registry<Entity>::template storage_type<Component>::base_type &base = storage;
+    const typename basic_registry<Entity>::base_type &base = storage;
     const auto *addr = std::addressof(instance);
 
     for(auto it = base.rbegin(), last = base.rend(); it < last; it += ENTT_PACKED_PAGE) {

+ 5 - 9
src/entt/entity/registry.hpp

@@ -38,6 +38,9 @@ class basic_registry {
     using entity_traits = entt_traits<Entity>;
     using basic_common_type = basic_sparse_set<Entity>;
 
+    template<typename Component>
+    using storage_type = typename storage_traits<Entity, Component>::storage_type;
+
     template<typename...>
     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<typename Component>
-    using storage_type = typename storage_traits<Entity, Component>::storage_type;
-
     /*! @brief Default constructor. */
     basic_registry() = default;
 
@@ -192,7 +188,7 @@ public:
      * @return The storage for the given component type.
      */
     template<typename Component>
-    [[nodiscard]] storage_type<Component> &storage(const id_type id = type_hash<Component>::value()) {
+    [[nodiscard]] decltype(auto) storage(const id_type id = type_hash<Component>::value()) {
         return assure<Component>(id);
     }
 
@@ -208,7 +204,7 @@ public:
      * @return The storage for the given component type.
      */
     template<typename Component>
-    [[nodiscard]] const storage_type<Component> &storage(const id_type id = type_hash<Component>::value()) const {
+    [[nodiscard]] decltype(auto) storage(const id_type id = type_hash<Component>::value()) const {
         return assure<Component>(id);
     }
 

+ 18 - 30
src/entt/entity/view.hpp

@@ -33,7 +33,7 @@ auto storage_tuple(const View &view, std::index_sequence<Index...>) {
 
 template<typename Storage>
 class iterable_storage final {
-    using basic_common_type = typename Storage::base_type;
+    using base_type = typename Storage::base_type;
 
     template<typename... It>
     struct iterable_storage_iterator final {
@@ -79,18 +79,18 @@ class iterable_storage final {
 public:
     using iterator = std::conditional_t<
         ignore_as_empty_v<typename Storage::value_type>,
-        iterable_storage_iterator<typename basic_common_type::iterator>,
-        iterable_storage_iterator<typename basic_common_type::iterator, decltype(std::declval<Storage>().begin())>>;
+        iterable_storage_iterator<typename base_type::iterator>,
+        iterable_storage_iterator<typename base_type::iterator, decltype(std::declval<Storage>().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<Entity, get_t<Component...>, exclude_t<Exclude...>> {
     friend class basic_view;
 
     template<typename Comp>
-    using basic_storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
-
-    using basic_common_type = std::common_type_t<typename basic_storage_type<Component>::base_type...>;
+    using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
 
     template<std::size_t... Index>
     [[nodiscard]] auto pools_to_array(std::index_sequence<Index...>) 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<typename storage_type<Component>::base_type...>;
     /*! @brief Bidirectional iterator type. */
-    using iterator = internal::view_iterator<basic_common_type, sizeof...(Component) - 1u, sizeof...(Exclude)>;
+    using iterator = internal::view_iterator<base_type, sizeof...(Component) - 1u, sizeof...(Exclude)>;
     /*! @brief Iterable view type. */
     using iterable_view = internal::iterable_view<basic_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<typename Comp>
-    using storage_type = basic_storage_type<Comp>;
 
     /*! @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<typename Comp>
-    [[nodiscard]] storage_type<Comp> &storage() const ENTT_NOEXCEPT {
+    [[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
         return *std::get<storage_type<Comp> *>(pools);
     }
 
@@ -623,24 +614,21 @@ class basic_view<Entity, get_t<Component>, exclude_t<>, std::void_t<std::enable_
     template<typename, typename, typename, typename>
     friend class basic_view;
 
-    using basic_storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
-    using basic_common_type = typename basic_storage_type::base_type;
+    using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
 
 public:
     /*! @brief Underlying entity identifier. */
     using entity_type = Entity;
     /*! @brief Unsigned integer type. */
     using size_type = std::size_t;
+    /*! @brief Common type among all storage types. */
+    using base_type = typename storage_type::base_type;
     /*! @brief Random access iterator type. */
-    using iterator = typename basic_common_type::iterator;
+    using iterator = typename base_type::iterator;
     /*! @brief Reversed iterator type. */
-    using reverse_iterator = typename basic_common_type::reverse_iterator;
+    using reverse_iterator = typename base_type::reverse_iterator;
     /*! @brief Iterable view type. */
-    using iterable_view = internal::iterable_storage<basic_storage_type>;
-    /*! @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 iterable_view = internal::iterable_storage<storage_type>;
 
     /*! @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<typename... Comp>
-    [[nodiscard]] storage_type &storage() const ENTT_NOEXCEPT {
+    [[nodiscard]] decltype(auto) storage() const ENTT_NOEXCEPT {
         static_assert((std::is_same_v<Comp, Component> && ...), "Invalid component type");
         return *view;
     }
@@ -919,7 +907,7 @@ public:
     }
 
 private:
-    std::array<const basic_common_type *, 0u> filter;
+    std::array<const base_type *, 0u> filter;
     storage_type *view;
 };