multi-component registry::reserve

This commit is contained in:
Michele Caini
2019-09-11 23:10:24 +02:00
parent 94e2fe2cbb
commit d4b18b1e27
2 changed files with 16 additions and 20 deletions

View File

@@ -382,29 +382,26 @@ public:
}
/**
* @brief Increases the capacity of the pool for the given component.
* @brief Increases the capacity of the registry or of the pools for the
* given components.
*
* If the new capacity is greater than the current capacity, new storage is
* allocated, otherwise the method does nothing.
* If no components are specified, the capacity of the registry is
* increased, that is the number of entities it contains. Otherwise the
* capacity of the pools for the given components is increased.
*
* @tparam Component Type of component for which to reserve storage.
* In both cases, if the new capacity is greater than the current capacity,
* new storage is allocated, otherwise the method does nothing.
*
* @tparam Component Types of components for which to reserve storage.
* @param cap Desired capacity.
*/
template<typename Component>
template<typename... Component>
void reserve(const size_type cap) {
assure<Component>()->reserve(cap);
}
/**
* @brief Increases the capacity of a registry in terms of entities.
*
* If the new capacity is greater than the current capacity, new storage is
* allocated, otherwise the method does nothing.
*
* @param cap Desired capacity.
*/
void reserve(const size_type cap) {
entities.reserve(cap);
if constexpr(sizeof...(Component) == 0) {
entities.reserve(cap);
} else {
(assure<Component>()->reserve(cap), ...);
}
}
/**

View File

@@ -90,9 +90,8 @@ TEST(Registry, Functionalities) {
ASSERT_EQ(registry.size(), entt::registry::size_type{0});
ASSERT_EQ(registry.alive(), entt::registry::size_type{0});
ASSERT_NO_THROW((registry.reserve<int, char>(8)));
ASSERT_NO_THROW(registry.reserve(42));
ASSERT_NO_THROW(registry.reserve<int>(8));
ASSERT_NO_THROW(registry.reserve<char>(8));
ASSERT_TRUE(registry.empty());
ASSERT_EQ(registry.capacity(), entt::registry::size_type{42});