registry: use traits_type::next if possible

This commit is contained in:
Michele Caini
2023-02-16 09:24:03 +01:00
parent 80d55a226c
commit 4d2b2c6de5
2 changed files with 8 additions and 5 deletions

View File

@@ -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)));
}
/**

View File

@@ -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) {