Преглед изворни кода

registry::prepare to force create pools explicitly

Michele Caini пре 6 година
родитељ
комит
c93d0f0d59
2 измењених фајлова са 11 додато и 0 уклоњено
  1. 9 0
      src/entt/entity/registry.hpp
  2. 2 0
      test/entt/entity/registry.cpp

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

@@ -333,6 +333,15 @@ public:
         return component{runtime_type<Component, component_family>()};
     }
 
+    /**
+     * @brief Prepares pools for the given types if required.
+     * @tparam Component Types of components for which to prepare pools.
+     */
+    template<typename... Component>
+    void prepare() {
+        (assure<Component>(), ...);
+    }
+
     /**
      * @brief Returns the number of existing components of the given type.
      * @tparam Component Type of component of which to return the size.

+ 2 - 0
test/entt/entity/registry.cpp

@@ -101,6 +101,8 @@ TEST(Registry, Functionalities) {
     ASSERT_EQ(registry.size<char>(), entt::registry::size_type{0});
     ASSERT_TRUE((registry.empty<int, char>()));
 
+    registry.prepare<double>();
+
     const auto e0 = registry.create();
     const auto e1 = registry.create();