handle: discard entity on destruction

This commit is contained in:
Michele Caini
2022-12-23 16:53:51 +01:00
parent 2f873f2dd2
commit 2dccd90166
2 changed files with 7 additions and 5 deletions

View File

@@ -43,7 +43,9 @@ public:
: entt{value},
it{from},
last{to} {
while(it != last && !it->second.contains(entt)) { ++it; }
while(it != last && !it->second.contains(entt)) {
++it;
}
}
constexpr handle_storage_iterator &operator++() noexcept {
@@ -196,7 +198,7 @@ struct basic_handle {
/*! @brief Destroys the entity associated with a handle. */
void destroy() {
reg->destroy(entt);
reg->destroy(std::exchange(entt, null));
}
/**
@@ -204,7 +206,7 @@ struct basic_handle {
* @param version A desired version upon destruction.
*/
void destroy(const version_type version) {
reg->destroy(entt, version);
reg->destroy(std::exchange(entt, null), version);
}
/**

View File

@@ -83,8 +83,8 @@ TEST(BasicHandle, Destruction) {
ASSERT_FALSE(handle);
ASSERT_FALSE(handle.valid());
ASSERT_NE(handle.registry(), nullptr);
ASSERT_EQ(handle.entity(), entity);
ASSERT_EQ(registry.current(entity), typename entt::registry::version_type{});
ASSERT_EQ(handle.entity(), entt::entity{entt::null});
handle = entt::handle{registry, registry.create()};
@@ -98,8 +98,8 @@ TEST(BasicHandle, Destruction) {
ASSERT_FALSE(handle);
ASSERT_FALSE(handle.valid());
ASSERT_NE(handle.registry(), nullptr);
ASSERT_EQ(handle.entity(), entity);
ASSERT_NE(registry.current(entity), typename entt::registry::version_type{});
ASSERT_EQ(handle.entity(), entt::entity{entt::null});
}
TEST(BasicHandle, Comparison) {