From bde0219fe63b2f4a294d820e4a84352f914c22c7 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 26 Jan 2023 11:54:03 +0100 Subject: [PATCH] snapshot: review basic_continuous_loader::entities --- src/entt/entity/snapshot.hpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/entt/entity/snapshot.hpp b/src/entt/entity/snapshot.hpp index dd3441e27..9b963e4f6 100644 --- a/src/entt/entity/snapshot.hpp +++ b/src/entt/entity/snapshot.hpp @@ -85,7 +85,7 @@ public: */ template const basic_snapshot &entities(Archive &archive) const { - const auto sz = static_cast (reg->size()); + const auto sz = static_cast(reg->size()); const auto released = static_cast(reg->released()); archive(sz); @@ -438,18 +438,19 @@ public: typename traits_type::entity_type released{}; archive(length); - // discards the number of destroyed entities archive(released); - for(std::size_t pos{}; pos < length; ++pos) { - entity_type entt{entt::null}; - archive(entt); + entity_type entt{entt::null}; + std::size_t pos{}; - if(const auto entity = traits_type::to_entity(entt); entity == pos) { - restore(entt); - } else { - destroy(entt); - } + for(const auto last = length - released; pos < last; ++pos) { + archive(entt); + restore(entt); + } + + for(; pos < length; ++pos) { + archive(entt); + destroy(entt); } return *this;