Преглед изворни кода

entity:
* drop utility.hpp
* turn get_t/exclude_t into aliases for type_list
* updated api for basic_registry<...>::group/group_if_exists
* doc review to reflect all the changes above

Michele Caini пре 3 година
родитељ
комит
803db476bb

+ 0 - 1
CMakeLists.txt

@@ -146,7 +146,6 @@ if(ENTT_INCLUDE_HEADERS)
             $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/snapshot.hpp>
             $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/sparse_set.hpp>
             $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/storage.hpp>
-            $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/utility.hpp>
             $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/view.hpp>
             $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/locator/locator.hpp>
             $<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/adl_pointer.hpp>

+ 2 - 2
docs/md/entity.md

@@ -1732,7 +1732,7 @@ auto group = registry.group<position, velocity>();
 Filtering entities by components is also supported:
 
 ```cpp
-auto group = registry.group<position, velocity>(entt::exclude<renderable>);
+auto group = registry.group<position, velocity>({}, entt::exclude<renderable>);
 ```
 
 Once created, the group gets the ownership of all the components specified in
@@ -1841,7 +1841,7 @@ nested groups, an excluded component type `T` is treated as being an observed
 type `not_T`. Therefore, consider these two definitions:
 
 * `registry.group<sprite, transform>()`.
-* `registry.group<sprite, transform>(entt::exclude<rotation>)`.
+* `registry.group<sprite, transform>({}, entt::exclude<rotation>)`.
 
 They are treated as if users were defining the following groups:
 

+ 43 - 1
src/entt/entity/fwd.hpp

@@ -3,7 +3,7 @@
 
 #include <memory>
 #include "../core/fwd.hpp"
-#include "utility.hpp"
+#include "../core/type_traits.hpp"
 
 namespace entt {
 
@@ -43,6 +43,48 @@ class basic_snapshot_loader;
 template<typename>
 class basic_continuous_loader;
 
+/**
+ * @brief Alias for exclusion lists.
+ * @tparam Type List of types.
+ */
+template<typename... Type>
+using exclude_t = type_list<Type...>;
+
+/**
+ * @brief Variable template for exclusion lists.
+ * @tparam Type List of types.
+ */
+template<typename... Type>
+inline constexpr exclude_t<Type...> exclude{};
+
+/**
+ * @brief Alias for lists of observed components.
+ * @tparam Type List of types.
+ */
+template<typename... Type>
+using get_t = type_list<Type...>;
+
+/**
+ * @brief Variable template for lists of observed components.
+ * @tparam Type List of types.
+ */
+template<typename... Type>
+inline constexpr get_t<Type...> get{};
+
+/**
+ * @brief Alias for lists of owned components.
+ * @tparam Type List of types.
+ */
+template<typename... Type>
+using owned_t = type_list<Type...>;
+
+/**
+ * @brief Variable template for lists of owned components.
+ * @tparam Type List of types.
+ */
+template<typename... Type>
+inline constexpr owned_t<Type...> owned{};
+
 /*! @brief Default entity identifier. */
 enum class entity : id_type {};
 

+ 0 - 1
src/entt/entity/group.hpp

@@ -12,7 +12,6 @@
 #include "fwd.hpp"
 #include "sparse_set.hpp"
 #include "storage.hpp"
-#include "utility.hpp"
 
 namespace entt {
 

+ 0 - 1
src/entt/entity/observer.hpp

@@ -13,7 +13,6 @@
 #include "fwd.hpp"
 #include "registry.hpp"
 #include "storage.hpp"
-#include "utility.hpp"
 
 namespace entt {
 

+ 2 - 15
src/entt/entity/registry.hpp

@@ -25,7 +25,6 @@
 #include "runtime_view.hpp"
 #include "sparse_set.hpp"
 #include "storage.hpp"
-#include "utility.hpp"
 #include "view.hpp"
 
 namespace entt {
@@ -1261,7 +1260,7 @@ public:
      * @return A newly created group.
      */
     template<typename... Owned, typename... Get, typename... Exclude>
-    [[nodiscard]] basic_group<entity_type, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> group(get_t<Get...>, exclude_t<Exclude...> = {}) {
+    [[nodiscard]] basic_group<entity_type, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> group(get_t<Get...> = {}, exclude_t<Exclude...> = {}) {
         static_assert(sizeof...(Owned) + sizeof...(Get) > 0, "Exclusion-only groups are not supported");
         static_assert(sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude) > 1, "Single component groups are not allowed");
 
@@ -1343,7 +1342,7 @@ public:
 
     /*! @copydoc group */
     template<typename... Owned, typename... Get, typename... Exclude>
-    [[nodiscard]] basic_group<entity_type, owned_t<std::add_const_t<Owned>...>, get_t<std::add_const_t<Get>...>, exclude_t<Exclude...>> group_if_exists(get_t<Get...>, exclude_t<Exclude...> = {}) const {
+    [[nodiscard]] basic_group<entity_type, owned_t<std::add_const_t<Owned>...>, get_t<std::add_const_t<Get>...>, exclude_t<Exclude...>> group_if_exists(get_t<Get...> = {}, exclude_t<Exclude...> = {}) const {
         auto it = std::find_if(groups.cbegin(), groups.cend(), [](const auto &gdata) {
             return gdata.size == (sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude))
                    && (gdata.owned(type_hash<std::remove_const_t<Owned>>::value()) && ...)
@@ -1359,18 +1358,6 @@ public:
         }
     }
 
-    /*! @copydoc group */
-    template<typename... Owned, typename... Exclude>
-    [[nodiscard]] basic_group<entity_type, owned_t<Owned...>, get_t<>, exclude_t<Exclude...>> group(exclude_t<Exclude...> = {}) {
-        return group<Owned...>(get_t<>{}, exclude<Exclude...>);
-    }
-
-    /*! @copydoc group */
-    template<typename... Owned, typename... Exclude>
-    [[nodiscard]] basic_group<entity_type, owned_t<std::add_const_t<Owned>...>, get_t<>, exclude_t<Exclude...>> group_if_exists(exclude_t<Exclude...> = {}) const {
-        return group_if_exists<std::add_const_t<Owned>...>(get_t<>{}, exclude<Exclude...>);
-    }
-
     /**
      * @brief Checks whether the given components belong to any group.
      * @tparam Component Types of components in which one is interested.

+ 0 - 52
src/entt/entity/utility.hpp

@@ -1,52 +0,0 @@
-#ifndef ENTT_ENTITY_UTILITY_HPP
-#define ENTT_ENTITY_UTILITY_HPP
-
-#include "../core/type_traits.hpp"
-
-namespace entt {
-
-/**
- * @brief Alias for exclusion lists.
- * @tparam Type List of types.
- */
-template<typename... Type>
-struct exclude_t: type_list<Type...> {};
-
-/**
- * @brief Variable template for exclusion lists.
- * @tparam Type List of types.
- */
-template<typename... Type>
-inline constexpr exclude_t<Type...> exclude{};
-
-/**
- * @brief Alias for lists of observed components.
- * @tparam Type List of types.
- */
-template<typename... Type>
-struct get_t: type_list<Type...> {};
-
-/**
- * @brief Variable template for lists of observed components.
- * @tparam Type List of types.
- */
-template<typename... Type>
-inline constexpr get_t<Type...> get{};
-
-/**
- * @brief Alias for lists of owned components.
- * @tparam Type List of types.
- */
-template<typename... Type>
-struct owned_t: type_list<Type...> {};
-
-/**
- * @brief Variable template for lists of owned components.
- * @tparam Type List of types.
- */
-template<typename... Type>
-inline constexpr owned_t<Type...> owned{};
-
-} // namespace entt
-
-#endif

+ 0 - 1
src/entt/entity/view.hpp

@@ -15,7 +15,6 @@
 #include "fwd.hpp"
 #include "sparse_set.hpp"
 #include "storage.hpp"
-#include "utility.hpp"
 
 namespace entt {
 

+ 0 - 1
src/entt/entt.hpp

@@ -31,7 +31,6 @@
 #include "entity/snapshot.hpp"
 #include "entity/sparse_set.hpp"
 #include "entity/storage.hpp"
-#include "entity/utility.hpp"
 #include "entity/view.hpp"
 #include "locator/locator.hpp"
 #include "meta/adl_pointer.hpp"

+ 4 - 4
test/entt/entity/group.cpp

@@ -1026,7 +1026,7 @@ TEST(OwningGroup, SortUnordered) {
 
 TEST(OwningGroup, SortWithExclusionList) {
     entt::registry registry;
-    auto group = registry.group<boxed_int>(entt::exclude<char>);
+    auto group = registry.group<boxed_int>({}, entt::exclude<char>);
 
     entt::entity entities[5]{};
     registry.create(std::begin(entities), std::end(entities));
@@ -1192,7 +1192,7 @@ TEST(OwningGroup, ExcludedComponents) {
     registry.emplace<int>(e1, 1);
     registry.emplace<char>(e1);
 
-    const auto group = registry.group<int>(entt::exclude<char, double>);
+    const auto group = registry.group<int>({}, entt::exclude<char, double>);
 
     const auto e2 = registry.create();
     registry.emplace<int>(e2, 2);
@@ -1263,8 +1263,8 @@ TEST(OwningGroup, EmptyAndNonEmptyTypes) {
 
 TEST(OwningGroup, TrackEntitiesOnComponentDestruction) {
     entt::registry registry;
-    const auto group = registry.group<int>(entt::exclude<char>);
-    const auto cgroup = std::as_const(registry).group_if_exists<const int>(entt::exclude<char>);
+    const auto group = registry.group<int>({}, entt::exclude<char>);
+    const auto cgroup = std::as_const(registry).group_if_exists<const int>({}, entt::exclude<char>);
 
     const auto entity = registry.create();
     registry.emplace<int>(entity);