Quellcode durchsuchen

registry: removed the dependency on the snapshot stuff

Michele Caini vor 5 Jahren
Ursprung
Commit
92c59f3ea1
4 geänderte Dateien mit 45 neuen und 79 gelöschten Zeilen
  1. 4 4
      docs/md/entity.md
  2. 0 36
      src/entt/entity/registry.hpp
  3. 35 34
      test/entt/entity/snapshot.cpp
  4. 6 5
      test/snapshot/snapshot.cpp

+ 4 - 4
docs/md/entity.md

@@ -850,7 +850,7 @@ To take a snapshot of a registry, use the `snapshot` class:
 ```cpp
 output_archive output;
 
-snapshot{registry}
+entt::snapshot{registry}
     .entities(output)
     .component<a_component, another_component>(output);
 ```
@@ -887,7 +887,7 @@ As an example:
 const auto view = registry.view<serialize>();
 output_archive output;
 
-snapshot{registry}.component<a_component, another_component>(output, view.cbegin(), view.cend());
+entt::snapshot{registry}.component<a_component, another_component>(output, view.cbegin(), view.cend());
 ```
 
 Note that `component` stores items along with entities. It means that it works
@@ -907,7 +907,7 @@ To use it, just pass to the constructor a valid registry:
 ```cpp
 input_archive input;
 
-snapshot_loader{registry}
+entt::snapshot_loader{registry}
     .entities(input)
     .component<a_component, another_component>(input)
     .orphans();
@@ -950,7 +950,7 @@ limit its lifetime to that of a temporary object.
 Example of use:
 
 ```cpp
-entt::continuous_loader<entt::entity> loader{registry};
+entt::continuous_loader loader{registry};
 input_archive input;
 
 loader.entities(input)

+ 0 - 36
src/entt/entity/registry.hpp

@@ -20,7 +20,6 @@
 #include "fwd.hpp"
 #include "group.hpp"
 #include "runtime_view.hpp"
-#include "snapshot.hpp"
 #include "sparse_set.hpp"
 #include "storage.hpp"
 #include "utility.hpp"
@@ -1567,41 +1566,6 @@ public:
         return { std::move(selected) };
     }
 
-    /**
-     * @brief Returns a temporary object to use to create snapshots.
-     *
-     * A snapshot is either a full or a partial dump of a registry.<br/>
-     * It can be used to save and restore its internal state or to keep two or
-     * more instances of this class in sync, as an example in a client-server
-     * architecture.
-     *
-     * @return A temporary object to use to take snasphosts.
-     */
-    [[deprecated("basic_snapshot has now a constructor that accepts a reference to a registry")]]
-    entt::basic_snapshot<Entity> snapshot() const {
-        return { *this };
-    }
-
-    /**
-     * @brief Returns a temporary object to use to load snapshots.
-     *
-     * A snapshot is either a full or a partial dump of a registry.<br/>
-     * It can be used to save and restore its internal state or to keep two or
-     * more instances of this class in sync, as an example in a client-server
-     * architecture.
-     *
-     * @note
-     * The loader returned by this function requires that the registry be empty.
-     * In case it isn't, all the data will be automatically deleted before to
-     * return.
-     *
-     * @return A temporary object to use to load snasphosts.
-     */
-    [[deprecated("basic_snapshot_loader has now a constructor that accepts a reference to a registry")]]
-    basic_snapshot_loader<Entity> loader() {
-        return { *this };
-    }
-
     /**
      * @brief Visits an entity and returns the types for its components.
      *

+ 35 - 34
test/entt/entity/snapshot.cpp

@@ -5,6 +5,7 @@
 #include <type_traits>
 #include <gtest/gtest.h>
 #include <entt/entity/registry.hpp>
+#include <entt/entity/snapshot.hpp>
 #include <entt/entity/entity.hpp>
 
 template<typename Storage>
@@ -97,10 +98,10 @@ TEST(Snapshot, Dump) {
     output_archive<storage_type> output{storage};
     input_archive<storage_type> input{storage};
 
-    registry.snapshot()
-            .entities(output)
-            .destroyed(output)
-            .component<int, char, double, a_component, another_component>(output);
+    entt::snapshot{registry}
+        .entities(output)
+        .destroyed(output)
+        .component<int, char, double, a_component, another_component>(output);
 
     registry.clear();
 
@@ -109,11 +110,11 @@ TEST(Snapshot, Dump) {
     ASSERT_FALSE(registry.valid(e2));
     ASSERT_FALSE(registry.valid(e3));
 
-    registry.loader()
-            .entities(input)
-            .destroyed(input)
-            .component<int, char, double, a_component, another_component>(input)
-            .orphans();
+    entt::snapshot_loader{registry}
+        .entities(input)
+        .destroyed(input)
+        .component<int, char, double, a_component, another_component>(input)
+        .orphans();
 
     ASSERT_TRUE(registry.valid(e0));
     ASSERT_FALSE(registry.valid(e1));
@@ -168,10 +169,10 @@ TEST(Snapshot, Partial) {
     output_archive<storage_type> output{storage};
     input_archive<storage_type> input{storage};
 
-    registry.snapshot()
-            .entities(output)
-            .destroyed(output)
-            .component<char, int>(output);
+    entt::snapshot{registry}
+        .entities(output)
+        .destroyed(output)
+        .component<char, int>(output);
 
     registry.clear();
 
@@ -180,10 +181,10 @@ TEST(Snapshot, Partial) {
     ASSERT_FALSE(registry.valid(e2));
     ASSERT_FALSE(registry.valid(e3));
 
-    registry.loader()
-            .entities(input)
-            .destroyed(input)
-            .component<char, int>(input);
+    entt::snapshot_loader{registry}
+        .entities(input)
+        .destroyed(input)
+        .component<char, int>(input);
 
     ASSERT_TRUE(registry.valid(e0));
     ASSERT_FALSE(registry.valid(e1));
@@ -197,9 +198,9 @@ TEST(Snapshot, Partial) {
     ASSERT_EQ(registry.get<int>(e2), 3);
     ASSERT_EQ(registry.get<char>(e3), '0');
 
-    registry.snapshot()
-            .entities(output)
-            .destroyed(output);
+    entt::snapshot{registry}
+        .entities(output)
+        .destroyed(output);
 
     registry.clear();
 
@@ -208,10 +209,10 @@ TEST(Snapshot, Partial) {
     ASSERT_FALSE(registry.valid(e2));
     ASSERT_FALSE(registry.valid(e3));
 
-    registry.loader()
-            .entities(input)
-            .destroyed(input)
-            .orphans();
+    entt::snapshot_loader{registry}
+        .entities(input)
+        .destroyed(input)
+        .orphans();
 
     ASSERT_FALSE(registry.valid(e0));
     ASSERT_FALSE(registry.valid(e1));
@@ -246,9 +247,9 @@ TEST(Snapshot, Iterator) {
     const auto view = registry.view<a_component>();
     const auto size = view.size();
 
-    registry.snapshot().component<another_component>(output, view.begin(), view.end());
+    entt::snapshot{registry}.component<another_component>(output, view.begin(), view.end());
     registry.clear();
-    registry.loader().component<another_component>(input);
+    entt::snapshot_loader{registry}.component<another_component>(input);
 
     ASSERT_EQ(registry.view<another_component>().size(), size);
 
@@ -317,7 +318,7 @@ TEST(Snapshot, Continuous) {
     dst.assign<a_component>(entity);
     dst.assign<another_component>(entity, -1, -1);
 
-    src.snapshot()
+    entt::snapshot{src}
        .entities(output)
        .destroyed(output)
        .component<a_component, another_component, what_a_component, map_component>(output);
@@ -381,7 +382,7 @@ TEST(Snapshot, Continuous) {
 
     auto size = dst.size();
 
-    src.snapshot()
+    entt::snapshot{src}
         .entities(output)
         .destroyed(output)
         .component<a_component, what_a_component, map_component, another_component>(output);
@@ -414,7 +415,7 @@ TEST(Snapshot, Continuous) {
         component.bar = entity;
     });
 
-    src.snapshot()
+    entt::snapshot{src}
         .entities(output)
         .destroyed(output)
         .component<what_a_component, map_component, a_component, another_component>(output);
@@ -442,7 +443,7 @@ TEST(Snapshot, Continuous) {
     src.destroy(entity);
     loader.shrink();
 
-    src.snapshot()
+    entt::snapshot{src}
         .entities(output)
         .destroyed(output)
         .component<a_component, another_component, what_a_component, map_component>(output);
@@ -473,7 +474,7 @@ TEST(Snapshot, Continuous) {
     dst.clear<a_component>();
     a_component_cnt = src.size<a_component>();
 
-    src.snapshot()
+    entt::snapshot{src}
         .entities(output)
         .destroyed(output)
         .component<a_component, what_a_component, map_component, another_component>(output);
@@ -494,7 +495,7 @@ TEST(Snapshot, Continuous) {
     src.clear<a_component>();
     a_component_cnt = {};
 
-    src.snapshot()
+    entt::snapshot{src}
         .entities(output)
         .destroyed(output)
         .component<what_a_component, map_component, a_component, another_component>(output);
@@ -531,7 +532,7 @@ TEST(Snapshot, MoreOnShrink) {
     input_archive<storage_type> input{storage};
 
     auto entity = src.create();
-    src.snapshot().entities(output);
+    entt::snapshot{src}.entities(output);
     loader.entities(input).shrink();
 
     ASSERT_TRUE(dst.valid(entity));
@@ -579,7 +580,7 @@ TEST(Snapshot, SyncDataMembers) {
         decltype(map_component::both){{{ child, child }}}
     );
 
-    src.snapshot().entities(output).component<what_a_component, map_component>(output);
+    entt::snapshot{src}.entities(output).component<what_a_component, map_component>(output);
 
     loader.entities(input).component<what_a_component, map_component>(
         input,

+ 6 - 5
test/snapshot/snapshot.cpp

@@ -3,6 +3,7 @@
 #include <vector>
 #include <cereal/archives/json.hpp>
 #include <entt/entity/registry.hpp>
+#include <entt/entity/snapshot.hpp>
 #include <entt/entity/helper.hpp>
 
 struct position {
@@ -61,13 +62,13 @@ 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<position, timer, relationship, entt::tag<"empty"_hs>>(output);
+        entt::snapshot{source}.entities(output).destroyed(output)
+            .component<position, timer, relationship, entt::tag<"empty"_hs>>(output);
     }
 
     cereal::JSONInputArchive input{storage};
-    destination.loader().entities(input).destroyed(input)
-            .component<position, timer, relationship, entt::tag<"empty"_hs>>(input);
+    entt::snapshot_loader{destination}.entities(input).destroyed(input)
+        .component<position, timer, relationship, entt::tag<"empty"_hs>>(input);
 
     ASSERT_TRUE(destination.valid(e0));
     ASSERT_TRUE(destination.has<position>(e0));
@@ -126,7 +127,7 @@ TEST(Snapshot, Continuous) {
     {
         // output finishes flushing its contents when it goes out of scope
         cereal::JSONOutputArchive output{storage};
-        source.snapshot().entities(output).component<position, relationship, timer, entt::tag<"empty"_hs>>(output);
+        entt::snapshot{source}.entities(output).component<position, relationship, timer, entt::tag<"empty"_hs>>(output);
     }
 
     cereal::JSONInputArchive input{storage};