registry: make ::valid backward compatible

This commit is contained in:
Michele Caini
2023-06-22 10:29:42 +02:00
parent f6f01ef1bc
commit da56665b03
3 changed files with 4 additions and 4 deletions

View File

@@ -527,7 +527,7 @@ public:
* @return True if the identifier is valid, false otherwise.
*/
[[nodiscard]] bool valid(const entity_type entt) const {
return entities.contains(entt);
return entities.contains(entt) && (entities.index(entt) < entities.in_use());
}
/**

View File

@@ -576,8 +576,8 @@ TEST(Registry, CreateWithHint) {
auto e2 = registry.create(entt::entity{3});
ASSERT_EQ(e2, entt::entity{1});
ASSERT_TRUE(registry.valid(entt::entity{0}));
ASSERT_TRUE(registry.valid(entt::entity{2}));
ASSERT_FALSE(registry.valid(entt::entity{0}));
ASSERT_FALSE(registry.valid(entt::entity{2}));
ASSERT_EQ(e3, entt::entity{3});
registry.release(e2);

View File

@@ -270,7 +270,7 @@ TEST(BasicSnapshotLoader, GetEntityType) {
ASSERT_TRUE(registry.valid(entities[0u]));
ASSERT_TRUE(registry.valid(entities[1u]));
ASSERT_TRUE(registry.valid(entities[2u]));
ASSERT_FALSE(registry.valid(entities[2u]));
ASSERT_EQ(storage.size(), 3u);
ASSERT_EQ(storage.in_use(), 2u);