Explorar el Código

snapshot: cleanup (waiting for further improvements)

Michele Caini hace 2 años
padre
commit
ea5c558bd4
Se han modificado 1 ficheros con 15 adiciones y 26 borrados
  1. 15 26
      src/entt/entity/snapshot.hpp

+ 15 - 26
src/entt/entity/snapshot.hpp

@@ -1,7 +1,6 @@
 #ifndef ENTT_ENTITY_SNAPSHOT_HPP
 #ifndef ENTT_ENTITY_SNAPSHOT_HPP
 #define ENTT_ENTITY_SNAPSHOT_HPP
 #define ENTT_ENTITY_SNAPSHOT_HPP
 
 
-#include <array>
 #include <cstddef>
 #include <cstddef>
 #include <iterator>
 #include <iterator>
 #include <tuple>
 #include <tuple>
@@ -31,30 +30,6 @@ template<typename Registry>
 class basic_snapshot {
 class basic_snapshot {
     using traits_type = typename Registry::traits_type;
     using traits_type = typename Registry::traits_type;
 
 
-    template<typename Component, typename Archive, typename It>
-    void get(Archive &archive, std::size_t sz, It first, It last) const {
-        const auto view = reg->template view<Component>();
-        archive(static_cast<typename traits_type::entity_type>(sz));
-
-        for(auto it = first; it != last; ++it) {
-            if(view.contains(*it)) {
-                std::apply(archive, std::tuple_cat(std::make_tuple(*it), view.get(*it)));
-            }
-        }
-    }
-
-    template<typename... Component, typename Archive, typename It, std::size_t... Index>
-    void component(Archive &archive, It first, It last, std::index_sequence<Index...>) const {
-        const auto view{std::make_tuple(reg->template view<Component>()...)};
-        std::array<std::size_t, sizeof...(Index)> size{};
-
-        for(auto it = first; it != last; ++it) {
-            ((std::get<Index>(view).contains(*it) ? ++size[Index] : 0u), ...);
-        }
-
-        (get<Component>(archive, size[Index], first, last), ...);
-    }
-
 public:
 public:
     /*! Basic registry type. */
     /*! Basic registry type. */
     using registry_type = Registry;
     using registry_type = Registry;
@@ -147,7 +122,21 @@ public:
      */
      */
     template<typename Component, typename Archive, typename It>
     template<typename Component, typename Archive, typename It>
     const basic_snapshot &component(Archive &archive, It first, It last) const {
     const basic_snapshot &component(Archive &archive, It first, It last) const {
-        component<Component>(archive, first, last, std::index_sequence_for<Component>{});
+        const auto view = reg->template view<Component>();
+        std::size_t size{};
+
+        for(auto it = first; it != last; ++it) {
+            size += view.contains(*it);
+        }
+
+        archive(static_cast<typename traits_type::entity_type>(size));
+
+        for(auto it = first; it != last; ++it) {
+            if(view.contains(*it)) {
+                std::apply(archive, std::tuple_cat(std::make_tuple(*it), view.get(*it)));
+            }
+        }
+
         return *this;
         return *this;
     }
     }