Pārlūkot izejas kodu

registry: slightly better destroy (yet not quite there though)

Michele Caini 3 gadi atpakaļ
vecāks
revīzija
7a05a16c54
1 mainītis faili ar 25 papildinājumiem un 2 dzēšanām
  1. 25 2
      src/entt/entity/registry.hpp

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

@@ -801,8 +801,31 @@ public:
      */
     template<typename It>
     void destroy(It first, It last) {
-        for(; first != last; ++first) {
-            destroy(*first);
+        if constexpr(std::is_same_v<It, typename basic_common_type::iterator>) {
+            basic_common_type *owner = nullptr;
+
+            for(size_type pos = pools.size(); pos; --pos) {
+                if(pools.begin()[pos - 1u].second->data() == first.data()) {
+                    owner = pools.begin()[pos - 1u].second.get();
+                } else {
+                    pools.begin()[pos - 1u].second->remove(first, last);
+                }
+            }
+
+            if(owner) {
+                // waiting to further/completely optimize this with the entity storage
+                for(; first != last; ++first) {
+                    const auto entt = *first;
+                    owner->remove(entt);
+                    release(entt);
+                }
+            } else {
+                release(std::move(first), std::move(last));
+            }
+        } else {
+            for(; first != last; ++first) {
+                destroy(*first);
+            }
         }
     }