From cb202c15a596b8f6ebd5e0467d2ea5025aa37f0e Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 15 Jun 2022 09:01:41 +0200 Subject: [PATCH] group: minor changes --- src/entt/entity/group.hpp | 97 ++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index c39950a5a..183dbaba0 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -129,8 +129,8 @@ class basic_group, get_t, exclude_t> { using underlying_type = std::common_type_t; using basic_common_type = std::common_type_t; - template - static constexpr std::size_t index_of = type_list_index_v, type_list>; + template + static constexpr std::size_t index_of = type_list_index_v, type_list>; /*! @brief A registry is allowed to create groups. */ friend class basic_registry; @@ -167,22 +167,22 @@ public: /** * @brief Returns the storage for a given component type. - * @tparam Comp Type of component of which to return the storage. + * @tparam Type Type of component of which to return the storage. * @return The storage for the given component type. */ - template + template [[nodiscard]] decltype(auto) storage() const noexcept { - return *std::get>(pools); + return *std::get>(pools); } /** - * @brief Returns the storage for a given component type. - * @tparam Comp Index of component of which to return the storage. - * @return The storage for the given component type. + * @brief Returns the storage for a given index. + * @tparam Index Index of the storage to return. + * @return The storage for the given index. */ - template + template [[nodiscard]] decltype(auto) storage() const noexcept { - return *std::get(pools); + return *std::get(pools); } /** @@ -338,20 +338,20 @@ public: * error. Attempting to use an entity that doesn't belong to the group * results in undefined behavior. * - * @tparam Comp Types of components to get. + * @tparam Type Types of components to get. * @param entt A valid identifier. * @return The components assigned to the entity. */ - template + template [[nodiscard]] decltype(auto) get(const entity_type entt) const { ENTT_ASSERT(contains(entt), "Group does not contain entity"); - if constexpr(sizeof...(Comp) == 0) { + if constexpr(sizeof...(Type) == 0) { return std::apply([entt](auto *...curr) { return std::tuple_cat(curr->get_as_tuple(entt)...); }, pools); - } else if constexpr(sizeof...(Comp) == 1) { - return (std::get>(pools)->get(entt), ...); + } else if constexpr(sizeof...(Type) == 1) { + return (std::get>(pools)->get(entt), ...); } else { - return std::tuple_cat(std::get>(pools)->get_as_tuple(entt)...); + return std::tuple_cat(std::get>(pools)->get_as_tuple(entt)...); } } @@ -433,7 +433,7 @@ public: * * An iterator past the last element of the range to sort. * * A comparison function to use to compare the elements. * - * @tparam Comp Optional types of components to compare. + * @tparam Type Optional types of components to compare. * @tparam Compare Type of comparison function object. * @tparam Sort Type of sort function object. * @tparam Args Types of arguments to forward to the sort function object. @@ -441,18 +441,18 @@ public: * @param algo A valid sort function object. * @param args Arguments to forward to the sort function object, if any. */ - template + template void sort(Compare compare, Sort algo = Sort{}, Args &&...args) { if(*this) { - if constexpr(sizeof...(Comp) == 0) { + if constexpr(sizeof...(Type) == 0) { static_assert(std::is_invocable_v, "Invalid comparison function"); handler->sort(std::move(compare), std::move(algo), std::forward(args)...); } else { auto comp = [this, &compare](const entity_type lhs, const entity_type rhs) { - if constexpr(sizeof...(Comp) == 1) { - return compare((std::get>(pools)->get(lhs), ...), (std::get>(pools)->get(rhs), ...)); + if constexpr(sizeof...(Type) == 1) { + return compare((std::get>(pools)->get(lhs), ...), (std::get>(pools)->get(rhs), ...)); } else { - return compare(std::forward_as_tuple(std::get>(pools)->get(lhs)...), std::forward_as_tuple(std::get>(pools)->get(rhs)...)); + return compare(std::forward_as_tuple(std::get>(pools)->get(lhs)...), std::forward_as_tuple(std::get>(pools)->get(rhs)...)); } }; @@ -475,12 +475,12 @@ public: * can quickly ruin the order imposed to the pool of entities shared between * the non-owning groups. * - * @tparam Comp Type of component to use to impose the order. + * @tparam Type Type of component to use to impose the order. */ - template + template void sort() const { if(*this) { - handler->respect(*std::get>(pools)); + handler->respect(*std::get>(pools)); } } @@ -529,8 +529,8 @@ class basic_group, get_t, exclude_t> { /*! @brief A registry is allowed to create groups. */ friend class basic_registry; - template - static constexpr std::size_t index_of = type_list_index_v, type_list>; + template + static constexpr std::size_t index_of = type_list_index_v, type_list>; basic_group(const std::size_t &extent, Owned &...opool, Get &...gpool) noexcept : pools{&opool..., &gpool...}, @@ -556,22 +556,22 @@ public: /** * @brief Returns the storage for a given component type. - * @tparam Comp Type of component of which to return the storage. + * @tparam Type Type of component of which to return the storage. * @return The storage for the given component type. */ - template + template [[nodiscard]] decltype(auto) storage() const noexcept { - return *std::get>(pools); + return *std::get>(pools); } /** - * @brief Returns the storage for a given component type. - * @tparam Comp Index of component of which to return the storage. - * @return The storage for the given component type. + * @brief Returns the storage for a given index. + * @tparam Index Index of the storage to return. + * @return The storage for the given index. */ - template + template [[nodiscard]] decltype(auto) storage() const noexcept { - return *std::get(pools); + return *std::get(pools); } /** @@ -711,20 +711,20 @@ public: * error. Attempting to use an entity that doesn't belong to the group * results in undefined behavior. * - * @tparam Comp Types of components to get. + * @tparam Type Types of components to get. * @param entt A valid identifier. * @return The components assigned to the entity. */ - template + template [[nodiscard]] decltype(auto) get(const entity_type entt) const { ENTT_ASSERT(contains(entt), "Group does not contain entity"); - if constexpr(sizeof...(Comp) == 0) { + if constexpr(sizeof...(Type) == 0) { return std::apply([entt](auto *...curr) { return std::tuple_cat(curr->get_as_tuple(entt)...); }, pools); - } else if constexpr(sizeof...(Comp) == 1) { - return (std::get>(pools)->get(entt), ...); + } else if constexpr(sizeof...(Type) == 1) { + return (std::get>(pools)->get(entt), ...); } else { - return std::tuple_cat(std::get>(pools)->get_as_tuple(entt)...); + return std::tuple_cat(std::get>(pools)->get_as_tuple(entt)...); } } @@ -807,7 +807,7 @@ public: * * An iterator past the last element of the range to sort. * * A comparison function to use to compare the elements. * - * @tparam Comp Optional types of components to compare. + * @tparam Type Optional types of components to compare. * @tparam Compare Type of comparison function object. * @tparam Sort Type of sort function object. * @tparam Args Types of arguments to forward to the sort function object. @@ -815,17 +815,17 @@ public: * @param algo A valid sort function object. * @param args Arguments to forward to the sort function object, if any. */ - template + template void sort(Compare compare, Sort algo = Sort{}, Args &&...args) const { - if constexpr(sizeof...(Comp) == 0) { + if constexpr(sizeof...(Type) == 0) { static_assert(std::is_invocable_v, "Invalid comparison function"); std::get<0>(pools)->sort_n(*length, std::move(compare), std::move(algo), std::forward(args)...); } else { auto comp = [this, &compare](const entity_type lhs, const entity_type rhs) { - if constexpr(sizeof...(Comp) == 1) { - return compare((std::get>(pools)->get(lhs), ...), (std::get>(pools)->get(rhs), ...)); + if constexpr(sizeof...(Type) == 1) { + return compare((std::get>(pools)->get(lhs), ...), (std::get>(pools)->get(rhs), ...)); } else { - return compare(std::forward_as_tuple(std::get>(pools)->get(lhs)...), std::forward_as_tuple(std::get>(pools)->get(rhs)...)); + return compare(std::forward_as_tuple(std::get>(pools)->get(lhs)...), std::forward_as_tuple(std::get>(pools)->get(rhs)...)); } }; @@ -838,7 +838,8 @@ public: [[maybe_unused]] const auto entt = head->data()[pos]; (other->swap_elements(other->data()[pos], entt), ...); } - }, pools); + }, + pools); } private: