handle: discard entity on destruction
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user