Browse Source

added the excluded components to the list of template parameters of a group

Michele Caini 6 years ago
parent
commit
84d1fa54ec
4 changed files with 34 additions and 34 deletions
  1. 22 4
      src/entt/entity/group.hpp
  2. 4 3
      src/entt/entity/helper.hpp
  3. 4 20
      src/entt/entity/registry.hpp
  4. 4 7
      test/entt/entity/helper.cpp

+ 22 - 4
src/entt/entity/group.hpp

@@ -15,6 +15,22 @@
 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>
+constexpr exclude_t<Type...> exclude{};
+
+
 /**
  * @brief Alias for lists of observed components.
  * @tparam Type List of types.
@@ -76,10 +92,11 @@ class basic_group;
  * In any other case, attempting to use a group results in undefined behavior.
  *
  * @tparam Entity A valid entity type (see entt_traits for more details).
+ * @tparam Exclude Types of components used to filter the group.
  * @tparam Get Types of components observed by the group.
  */
-template<typename Entity, typename... Get>
-class basic_group<Entity, get_t<Get...>> {
+template<typename Entity, typename... Exclude, typename... Get>
+class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> {
     static_assert(sizeof...(Get) > 0);
 
     /*! @brief A registry is allowed to create groups. */
@@ -435,11 +452,12 @@ private:
  * In any other case, attempting to use a group results in undefined behavior.
  *
  * @tparam Entity A valid entity type (see entt_traits for more details).
+ * @tparam Exclude Types of components used to filter the group.
  * @tparam Get Types of components observed by the group.
  * @tparam Owned Types of components owned by the group.
  */
-template<typename Entity, typename... Get, typename... Owned>
-class basic_group<Entity, get_t<Get...>, Owned...> {
+template<typename Entity, typename... Exclude, typename... Get, typename... Owned>
+class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> {
     static_assert(sizeof...(Get) + sizeof...(Owned) > 0);
 
     /*! @brief A registry is allowed to create groups. */

+ 4 - 3
src/entt/entity/helper.hpp

@@ -77,13 +77,14 @@ struct as_group {
 
     /**
      * @brief Conversion function from a registry to a group.
+     * @tparam Exclude Types of components used to filter the group.
      * @tparam Get Types of components observed by the group.
      * @tparam Owned Types of components owned by the group.
      * @return A newly created group.
      */
-    template<typename Get, typename... Owned>
-    operator entt::basic_group<Entity, Get, Owned...>() const {
-        return reg.template group<Owned...>(Get{});
+    template<typename Exclude, typename Get, typename... Owned>
+    operator entt::basic_group<Entity, Exclude, Get, Owned...>() const {
+        return reg.template group<Owned...>(Get{}, Exclude{});
     }
 
 private:

+ 4 - 20
src/entt/entity/registry.hpp

@@ -29,22 +29,6 @@
 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>
-constexpr exclude_t<Type...> exclude{};
-
-
 /**
  * @brief Fast and reliable entity-component system.
  *
@@ -1319,7 +1303,7 @@ public:
      * @return A newly created group.
      */
     template<typename... Owned, typename... Get, typename... Exclude>
-    entt::basic_group<Entity, get_t<Get...>, Owned...> group(get_t<Get...>, exclude_t<Exclude...> = {}) {
+    entt::basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> group(get_t<Get...>, exclude_t<Exclude...> = {}) {
         static_assert(sizeof...(Owned) + sizeof...(Get) > 0);
         static_assert(sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude) > 1);
 
@@ -1394,20 +1378,20 @@ public:
 
     /*! @copydoc group */
     template<typename... Owned, typename... Get, typename... Exclude>
-    entt::basic_group<Entity, get_t<Get...>, Owned...> group(get_t<Get...>, exclude_t<Exclude...> = {}) const {
+    entt::basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> group(get_t<Get...>, exclude_t<Exclude...> = {}) const {
         static_assert(std::conjunction_v<std::is_const<Owned>..., std::is_const<Get>...>);
         return const_cast<basic_registry *>(this)->group<Owned...>(entt::get<Get...>, exclude<Exclude...>);
     }
 
     /*! @copydoc group */
     template<typename... Owned, typename... Exclude>
-    entt::basic_group<Entity, get_t<>, Owned...> group(exclude_t<Exclude...> = {}) {
+    entt::basic_group<Entity, exclude_t<Exclude...>, get_t<>, Owned...> group(exclude_t<Exclude...> = {}) {
         return group<Owned...>(entt::get<>, exclude<Exclude...>);
     }
 
     /*! @copydoc group */
     template<typename... Owned, typename... Exclude>
-    entt::basic_group<Entity, get_t<>, Owned...> group(exclude_t<Exclude...> = {}) const {
+    entt::basic_group<Entity, exclude_t<Exclude...>, get_t<>, Owned...> group(exclude_t<Exclude...> = {}) const {
         static_assert(std::conjunction_v<std::is_const<Owned>...>);
         return const_cast<basic_registry *>(this)->group<Owned...>(exclude<Exclude...>);
     }

+ 4 - 7
test/entt/entity/helper.cpp

@@ -17,13 +17,10 @@ TEST(Helper, AsGroup) {
     entt::registry registry;
     const entt::registry cregistry;
 
-    ([](entt::group<entt::get_t<>, double, float>) {})(entt::as_group{registry});
-    ([](entt::group<entt::get_t<>, const double, float>) {})(entt::as_group{registry});
-    ([](entt::group<entt::get_t<>, const double, const float>) {})(entt::as_group{cregistry});
-
-    ([](entt::group<entt::get_t<int>, char>) {})(entt::as_group{registry});
-    ([](entt::group<entt::get_t<const int>, char>) {})(entt::as_group{registry});
-    ([](entt::group<entt::get_t<const int>, const char>) {})(entt::as_group{cregistry});
+    ([](entt::group<entt::exclude_t<int>, entt::get_t<char>, double>) {})(entt::as_group{registry});
+    ([](entt::group<entt::exclude_t<const int>, entt::get_t<char>, double>) {})(entt::as_group{registry});
+    ([](entt::group<entt::exclude_t<const int>, entt::get_t<const char>, double>) {})(entt::as_group{registry});
+    ([](entt::group<entt::exclude_t<const int>, entt::get_t<const char>, const double>) {})(entt::as_group{registry});
 }
 
 TEST(Helper, Dependency) {