Browse Source

snapshot: review basic_continuous_loader::entities

Michele Caini 3 years ago
parent
commit
bde0219fe6
1 changed files with 10 additions and 9 deletions
  1. 10 9
      src/entt/entity/snapshot.hpp

+ 10 - 9
src/entt/entity/snapshot.hpp

@@ -85,7 +85,7 @@ public:
      */
     template<typename Archive>
     const basic_snapshot &entities(Archive &archive) const {
-        const auto sz = static_cast<typename traits_type::entity_type> (reg->size());
+        const auto sz = static_cast<typename traits_type::entity_type>(reg->size());
         const auto released = static_cast<typename traits_type::entity_type>(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};
+        entity_type entt{entt::null};
+        std::size_t pos{};
+
+        for(const auto last = length - released; pos < last; ++pos) {
             archive(entt);
+            restore(entt);
+        }
 
-            if(const auto entity = traits_type::to_entity(entt); entity == pos) {
-                restore(entt);
-            } else {
-                destroy(entt);
-            }
+        for(; pos < length; ++pos) {
+            archive(entt);
+            destroy(entt);
         }
 
         return *this;