Michele Caini 1 год назад
Родитель
Сommit
4686094c09
2 измененных файлов с 10 добавлено и 5 удалено
  1. 1 0
      TODO
  2. 9 5
      src/entt/entity/storage.hpp

+ 1 - 0
TODO

@@ -38,3 +38,4 @@ TODO:
 * any cdynamic to support const ownership construction
 * return meta context from meta objects
 * allow passing arguments to meta setter/getter (we can fallback on meta invoke for everything probably)
+* update storage from_placeholder to avoid increasing placeholder if null

+ 9 - 5
src/entt/entity/storage.hpp

@@ -988,13 +988,17 @@ class basic_storage<Entity, Entity, Allocator>
     using underlying_iterator = typename basic_sparse_set<Entity, Allocator>::basic_iterator;
     using traits_type = entt_traits<Entity>;
 
+    auto from_placeholder() noexcept {
+        ENTT_ASSERT(placeholder < traits_type::to_entity(null), "No more entities available");
+        return traits_type::combine(static_cast<typename traits_type::entity_type>(placeholder++), {});
+    }
+
     auto next() noexcept {
-        entity_type entt = null;
+        entity_type entt = from_placeholder();
 
-        do {
-            ENTT_ASSERT(placeholder < traits_type::to_entity(null), "No more entities available");
-            entt = traits_type::combine(static_cast<typename traits_type::entity_type>(placeholder++), {});
-        } while(base_type::current(entt) != traits_type::to_version(tombstone) && entt != null);
+        while(base_type::current(entt) != traits_type::to_version(tombstone) && entt != null) {
+            entt = from_placeholder();
+        }
 
         return entt;
     }