Просмотр исходного кода

registry: use traits_type::next if possible

Michele Caini 3 лет назад
Родитель
Сommit
4d2b2c6de5
2 измененных файлов с 8 добавлено и 5 удалено
  1. 7 4
      src/entt/entity/registry.hpp
  2. 1 1
      test/entt/entity/registry.cpp

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

@@ -673,10 +673,13 @@ public:
      */
     version_type release(const entity_type entt, const version_type version) {
         ENTT_ASSERT(orphan(entt), "Non-orphan entity");
-        const auto vers = static_cast<version_type>(version + (version == traits_type::to_version(tombstone)));
+        auto elem = traits_type::construct(traits_type::to_entity(entt), version);
+        elem = (elem == tombstone) ? traits_type::next(elem) : elem;
+
         shortcut->erase(entt);
-        shortcut->bump(traits_type::construct(traits_type::to_entity(entt), vers));
-        return vers;
+        shortcut->bump(elem);
+
+        return traits_type::to_version(elem);
     }
 
     /**
@@ -708,7 +711,7 @@ public:
      * @return The version of the recycled entity.
      */
     version_type destroy(const entity_type entt) {
-        return destroy(entt, static_cast<version_type>(traits_type::to_version(entt) + 1u));
+        return destroy(entt, traits_type::to_version(traits_type::next(entt)));
     }
 
     /**

+ 1 - 1
test/entt/entity/registry.cpp

@@ -499,7 +499,7 @@ TEST(Registry, Data) {
     registry.release(entity);
 
     ASSERT_EQ(*std::as_const(registry).data(), other);
-    ASSERT_EQ(*(std::as_const(registry).data() + 1u), traits_type::construct(traits_type::to_entity(entity), 1));
+    ASSERT_EQ(*(std::as_const(registry).data() + 1u), traits_type::next(entity));
 }
 
 TEST(Registry, CreateManyEntitiesAtOnce) {