ソースを参照

use the right family for groups

Michele Caini 7 年 前
コミット
b1d6ba57ad
2 ファイル変更15 行追加14 行削除
  1. 3 2
      TODO
  2. 12 12
      src/entt/entity/registry.hpp

+ 3 - 2
TODO

@@ -21,10 +21,11 @@
 * empty components model allows for shared components and prefabs unity-like
 * provide create with a pack of default constructible components to assign
 * allow to replace std:: with custom implementations
-* allow curried function and lambdas on sigh/dispatcher (mixed approach with sinks that accept also delegates?)
 * allow user to use also uint32 for hashed strings type if possible
 * allow to sort groups (::respect can already work with begin/end instead of a whole sparse set)
-* views' iterators should return a tuple entity+components, not only entities
+...
 * delegate/sigh "benign" UB: memcpy to work around the fact that types don't pop in existence when the storage is copied (even if all the compilers allow it)
   see https://stackoverflow.com/questions/54512451/about-aligned-storage-and-trivially-copyable-destructible-types/54518339?noredirect=1
   see https://stackoverflow.com/questions/54531009/copy-trivially-copyable-types-using-temporary-storage-areas-is-it-allowed
+* allow curried function and lambdas on sigh/dispatcher (mixed approach with sinks that accept also delegates?)
+* remove group/handler family, use "extended signals" and track the pointer instead (required to fully support shared libraries)

+ 12 - 12
src/entt/entity/registry.hpp

@@ -85,7 +85,7 @@ class registry {
     template<auto Has, auto Accept, typename... Owned>
     static void induce_if(registry &reg, const Entity entity) {
         if((reg.*Has)(entity) && (reg.*Accept)(entity)) {
-            const auto curr = reg.descriptors[handler_family::type<Owned...>]->last++;
+            const auto curr = reg.groups[group_family::type<Owned...>]->last++;
             (std::swap(reg.pool<Owned>().get(entity), reg.pool<Owned>().raw()[curr]), ...);
             (reg.pool<Owned>().swap(reg.pools[reg.type<Owned>()]->get(entity), curr), ...);
         }
@@ -94,10 +94,10 @@ class registry {
     template<typename... Owned>
     static void discard_if(registry &reg, const Entity entity) {
         const auto ctype = type<std::tuple_element_t<0, std::tuple<Owned...>>>();
-        const auto dtype = handler_family::type<Owned...>;
+        const auto gtype = group_family::type<Owned...>;
 
-        if(reg.pools[ctype]->has(entity) && reg.pools[ctype]->get(entity) < reg.descriptors[dtype]->last) {
-            const auto curr = --reg.descriptors[dtype]->last;
+        if(reg.pools[ctype]->has(entity) && reg.pools[ctype]->get(entity) < reg.groups[gtype]->last) {
+            const auto curr = --reg.groups[gtype]->last;
             (std::swap(reg.pool<Owned>().get(entity), reg.pool<Owned>().raw()[curr]), ...);
             (reg.pool<Owned>().swap(reg.pools[reg.type<Owned>()]->get(entity), curr), ...);
         }
@@ -1148,7 +1148,7 @@ public:
      */
     template<typename Component>
     bool owned() const ENTT_NOEXCEPT {
-        return std::any_of(descriptors.cbegin(), descriptors.cend(), [](const auto &descriptor) {
+        return std::any_of(groups.cbegin(), groups.cend(), [](const auto &descriptor) {
             return descriptor && descriptor->contains(type<Component>());
         });
     }
@@ -1215,15 +1215,15 @@ public:
 
             return { handlers[htype].get(), &pool<Get>()... };
         } else {
-            const auto dtype = handler_family::type<Owned...>;
+            const auto gtype = group_family::type<Owned...>;
 
-            if(!(dtype < descriptors.size())) {
-                descriptors.resize(dtype + 1);
+            if(!(gtype < groups.size())) {
+                groups.resize(gtype + 1);
             }
 
-            if(!descriptors[dtype]) {
+            if(!groups[gtype]) {
                 assert((!owned<Owned>() && ...));
-                descriptors[dtype] = std::make_unique<descriptor<Owned...>>();
+                groups[gtype] = std::make_unique<descriptor<Owned...>>();
 
                 (sighs[type<Owned>()].construction.sink().template connect<&induce_if<&registry::has<Owned..., Get...>, &registry::accept<0, Exclude...>, Owned...>>(), ...);
                 (sighs[type<Get>()].construction.sink().template connect<&induce_if<&registry::has<Owned..., Get...>, &registry::accept<0, Exclude...>, Owned...>>(), ...);
@@ -1243,7 +1243,7 @@ public:
                 });
             }
 
-            return { &descriptors[dtype]->last, &pool<Owned>()..., &pool<Get>()... };
+            return { &groups[gtype]->last, &pool<Owned>()..., &pool<Get>()... };
         }
     }
 
@@ -1422,8 +1422,8 @@ public:
     }
 
 private:
+    std::vector<std::unique_ptr<basic_descriptor>> groups;
     std::vector<std::unique_ptr<sparse_set<Entity>>> handlers;
-    std::vector<std::unique_ptr<basic_descriptor>> descriptors;
     mutable std::vector<std::unique_ptr<sparse_set<Entity>>> pools;
     mutable std::vector<signals> sighs;
     std::vector<entity_type> entities;