Michele Caini 1 год назад
Родитель
Сommit
7a7695e603
3 измененных файлов с 23 добавлено и 3 удалено
  1. 0 1
      TODO
  2. 21 0
      src/entt/entity/organizer.hpp
  3. 2 2
      test/entt/entity/organizer.cpp

+ 0 - 1
TODO

@@ -28,7 +28,6 @@ TODO:
 * review cmake warning about FetchContent_Populate (need .28 and EXCLUDE_FROM_ALL for FetchContent)
 * suppress -Wself-move on CI with g++13
 * view specializations for multi, single and filtered elements
-* organizer support to groups
 * meta range: move id to meta objects and return plain types (?), then remove id from meta base and meta ctor too
 * don't pass reactive storage by default to callback
 * runtime types support for meta for types that aren't backed by C++ types

+ 21 - 0
src/entt/entity/organizer.hpp

@@ -27,6 +27,15 @@ struct is_view<basic_view<Args...>>: std::true_type {};
 template<typename Type>
 inline constexpr bool is_view_v = is_view<Type>::value;
 
+template<typename>
+struct is_group: std::false_type {};
+
+template<typename... Args>
+struct is_group<basic_group<Args...>>: std::true_type {};
+
+template<typename Type>
+inline constexpr bool is_group_v = is_group<Type>::value;
+
 template<typename Type, typename Override>
 struct unpack_type {
     using ro = std::conditional_t<
@@ -60,6 +69,16 @@ template<typename... Get, typename... Exclude, typename... Override>
 struct unpack_type<const basic_view<get_t<Get...>, exclude_t<Exclude...>>, type_list<Override...>>
     : unpack_type<basic_view<get_t<Get...>, exclude_t<Exclude...>>, type_list<Override...>> {};
 
+template<typename... Owned, typename... Get, typename... Exclude, typename... Override>
+struct unpack_type<basic_group<owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>>, type_list<Override...>> {
+    using ro = type_list_cat_t<type_list<typename Exclude::element_type...>, typename unpack_type<constness_as_t<typename Get::element_type, Get>, type_list<Override...>>::ro..., typename unpack_type<constness_as_t<typename Owned::element_type, Owned>, type_list<Override...>>::ro...>;
+    using rw = type_list_cat_t<typename unpack_type<constness_as_t<typename Get::element_type, Get>, type_list<Override...>>::rw..., typename unpack_type<constness_as_t<typename Owned::element_type, Owned>, type_list<Override...>>::rw...>;
+};
+
+template<typename... Owned, typename... Get, typename... Exclude, typename... Override>
+struct unpack_type<const basic_group<owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>>, type_list<Override...>>
+    : unpack_type<basic_group<owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>>, type_list<Override...>> {};
+
 template<typename, typename>
 struct resource_traits;
 
@@ -119,6 +138,8 @@ class basic_organizer final {
             return reg;
         } else if constexpr(internal::is_view_v<Type>) {
             return static_cast<Type>(as_view{reg});
+        } else if constexpr(internal::is_group_v<Type>) {
+            return static_cast<Type>(as_group{reg});
         } else {
             return reg.ctx().template emplace<std::remove_reference_t<Type>>();
         }

+ 2 - 2
test/entt/entity/organizer.cpp

@@ -7,7 +7,7 @@
 #include <entt/entity/registry.hpp>
 
 void ro_int_rw_char_double(entt::view<entt::get_t<const int, char>>, double &) {}
-void ro_char_rw_int(entt::view<entt::get_t<int, const char>>) {}
+void ro_char_rw_int(entt::group<entt::owned_t<int>, entt::get_t<const char>>) {}
 void ro_char_rw_double(entt::view<entt::get_t<const char>>, double &) {}
 void ro_int_double(entt::view<entt::get_t<const int>>, const double &) {}
 void sync_point(entt::registry &, entt::view<entt::get_t<const int>>) {}
@@ -19,7 +19,7 @@ struct clazz {
     void rw_int_char_double(entt::view<entt::get_t<int, char>>, double &) {}
 
     static void ro_int_with_payload(const clazz &, entt::view<entt::get_t<const int>>) {}
-    static void ro_char_with_payload(const clazz &, entt::view<entt::get_t<const char>>) {}
+    static void ro_char_with_payload(const clazz &, entt::group<entt::owned_t<const char>>) {}
     static void ro_int_char_with_payload(clazz &, entt::view<entt::get_t<const int, const char>>) {}
 };