1
0
Эх сурвалжийг харах

snapshot: share ::orphans implementation (to deprecate in future though)

Michele Caini 2 жил өмнө
parent
commit
f91226ef47

+ 27 - 16
src/entt/entity/snapshot.hpp

@@ -16,6 +16,31 @@
 
 namespace entt {
 
+/**
+ * @cond TURN_OFF_DOXYGEN
+ * Internal details not to be documented.
+ */
+
+namespace internal {
+
+template<typename Registry>
+void orphans(Registry &registry) {
+    auto view = registry.template view<typename Registry::entity_type>();
+
+    for(auto entt: view) {
+        if(registry.orphan(entt)) {
+            view.storage()->erase(entt);
+        }
+    }
+}
+
+} // namespace internal
+
+/**
+ * Internal details not to be documented.
+ * @endcond
+ */
+
 /**
  * @brief Utility class to create snapshots from a registry.
  *
@@ -282,14 +307,7 @@ public:
      * @return A valid loader to continue restoring data.
      */
     basic_snapshot_loader &orphans() {
-        auto &storage = reg->template storage<entity_type>();
-
-        for(auto entt: storage) {
-            if(reg->orphan(entt)) {
-                storage.erase(entt);
-            }
-        }
-
+        internal::orphans(*reg);
         return *this;
     }
 
@@ -566,14 +584,7 @@ public:
      * @return A non-const reference to this loader.
      */
     basic_continuous_loader &orphans() {
-        auto &storage = reg->template storage<entity_type>();
-
-        for(auto entt: storage) {
-            if(reg->orphan(entt)) {
-                storage.erase(entt);
-            }
-        }
-
+        internal::orphans(*reg);
         return *this;
     }