Browse Source

snapshot: deprecate multi-type component loading function

Michele Caini 2 years ago
parent
commit
244c359491
1 changed files with 25 additions and 12 deletions
  1. 25 12
      src/entt/entity/snapshot.hpp

+ 25 - 12
src/entt/entity/snapshot.hpp

@@ -96,31 +96,44 @@ public:
     }
     }
 
 
     /**
     /**
-     * @brief Serializes all required components with associated identifiers.
-     * @tparam Component Types of components to serialize.
+     * @brief Serializes all elements of a type with associated identifiers.
+     * @tparam Component Type of component to serialize.
      * @tparam Archive Type of output archive.
      * @tparam Archive Type of output archive.
      * @param archive A valid reference to an output archive.
      * @param archive A valid reference to an output archive.
      * @return An object of this type to continue creating the snapshot.
      * @return An object of this type to continue creating the snapshot.
      */
      */
-    template<typename... Component, typename Archive>
+    template<typename Component, typename Archive>
     const basic_snapshot &component(Archive &archive) const {
     const basic_snapshot &component(Archive &archive) const {
-        if constexpr(sizeof...(Component) == 1u) {
-            if(const auto *storage = reg->template storage<Component...>(); storage) {
-                archive(static_cast<typename traits_type::entity_type>(storage->size()));
+        if(const auto *storage = reg->template storage<Component>(); storage) {
+            archive(static_cast<typename traits_type::entity_type>(storage->size()));
 
 
-                for(auto elem: storage->reach()) {
-                    std::apply(archive, elem);
-                }
-            } else {
-                archive(typename traits_type::entity_type{});
+            for(auto elem: storage->reach()) {
+                std::apply(archive, elem);
             }
             }
         } else {
         } else {
-            (component<Component>(archive), ...);
+            archive(typename traits_type::entity_type{});
         }
         }
 
 
         return *this;
         return *this;
     }
     }
 
 
+    /**
+     * @brief Serializes all required components with associated identifiers.
+     * @tparam First First type of component to serialize.
+     * @tparam Second Second type of component to serialize.
+     * @tparam Other Other types of components to serialize.
+     * @tparam Archive Type of output archive.
+     * @param archive A valid reference to an output archive.
+     * @return An object of this type to continue creating the snapshot.
+     */
+    template<typename First, typename Second, typename... Other, typename Archive>
+    [[deprecated("use .component<Type>() instead")]] const basic_snapshot &component(Archive &archive) const {
+        component<First>(archive);
+        component<Second>(archive);
+        (component<Other>(archive), ...);
+        return *this;
+    }
+
     /**
     /**
      * @brief Serializes all required components with associated identifiers for
      * @brief Serializes all required components with associated identifiers for
      * the entities in a range.
      * the entities in a range.