diff --git a/src/entt/entity/snapshot.hpp b/src/entt/entity/snapshot.hpp index 096dda3b2..45c741d10 100644 --- a/src/entt/entity/snapshot.hpp +++ b/src/entt/entity/snapshot.hpp @@ -47,7 +47,11 @@ class basic_snapshot { const auto entt = *(first++); if(reg.template has(entt)) { - archive(entt, reg.template get(entt)); + if constexpr(std::is_empty_v) { + archive(entt); + } else { + archive(entt, reg.template get(entt)); + } } } } @@ -138,7 +142,12 @@ public: for(std::remove_const_t i{}; i < sz; ++i) { const auto entt = entities[i]; - archive(entt, reg.template get(entt)); + + if constexpr(std::is_empty_v) { + archive(entt); + } else { + archive(entt, reg.template get(entt)); + } }; } else { (component(archive), ...); @@ -219,7 +228,13 @@ class basic_snapshot_loader { while(length--) { Entity entt{}; Type instance{}; - archive(entt, instance); + + if constexpr(std::is_empty_v) { + archive(entt); + } else { + archive(entt, instance); + } + static constexpr auto destroyed = false; force(reg, entt, destroyed); reg.template assign(args..., entt, std::as_const(instance)); @@ -402,7 +417,13 @@ class basic_continuous_loader { while(length--) { Entity entt{}; Other instance{}; - archive(entt, instance); + + if constexpr(std::is_empty_v) { + archive(entt); + } else { + archive(entt, instance); + } + restore(entt); (update(instance, member), ...); func(map(entt), instance); diff --git a/test/snapshot/snapshot.cpp b/test/snapshot/snapshot.cpp index a89325bdf..48e549b3c 100644 --- a/test/snapshot/snapshot.cpp +++ b/test/snapshot/snapshot.cpp @@ -3,6 +3,7 @@ #include #include #include +#include struct position { float x; @@ -52,6 +53,7 @@ TEST(Snapshot, Full) { auto e3 = source.create(); source.assign(e3, 1000, 100); + source.assign>(e3); source.destroy(e2); auto v2 = source.current(e2); @@ -60,12 +62,12 @@ TEST(Snapshot, Full) { // output finishes flushing its contents when it goes out of scope cereal::JSONOutputArchive output{storage}; source.snapshot().entities(output).destroyed(output) - .component(output); + .component>(output); } cereal::JSONInputArchive input{storage}; destination.loader().entities(input).destroyed(input) - .component(input); + .component>(input); ASSERT_TRUE(destination.valid(e0)); ASSERT_TRUE(destination.has(e0)); @@ -84,6 +86,7 @@ TEST(Snapshot, Full) { ASSERT_TRUE(destination.valid(e3)); ASSERT_TRUE(destination.has(e3)); + ASSERT_TRUE(destination.has>(e3)); ASSERT_EQ(destination.get(e3).duration, 1000); ASSERT_EQ(destination.get(e3).elapsed, 0); } @@ -118,18 +121,19 @@ TEST(Snapshot, Continuous) { auto e3 = source.create(); source.assign(e3, 1000, 1000); source.assign(e3, e2); + source.assign>(e3); { // output finishes flushing its contents when it goes out of scope cereal::JSONOutputArchive output{storage}; - source.snapshot().entities(output).component(output); + source.snapshot().entities(output).component>(output); } cereal::JSONInputArchive input{storage}; entt::continuous_loader loader{destination}; loader.entities(input) .component(input, &relationship::parent) - .component(input); + .component>(input); ASSERT_FALSE(destination.valid(e0)); ASSERT_TRUE(loader.has(e0)); @@ -178,4 +182,5 @@ TEST(Snapshot, Continuous) { ASSERT_EQ(destination.get(l3).elapsed, 0); ASSERT_TRUE(destination.has(l3)); ASSERT_EQ(destination.get(l3).parent, l2); + ASSERT_TRUE(destination.has>(l3)); }