|
|
@@ -191,8 +191,8 @@ class basic_registry {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- template<typename Component, typename... Args>
|
|
|
- const pool_handler<Component> & assure(Args &&... args) const {
|
|
|
+ template<typename Component>
|
|
|
+ const pool_handler<Component> & assure() const {
|
|
|
static std::size_t index{pools.size()};
|
|
|
|
|
|
if(const auto length = pools.size(); !(index < length) || pools[index].type_id != type_info<Component>::id()) {
|
|
|
@@ -203,7 +203,7 @@ class basic_registry {
|
|
|
|
|
|
pdata.type_id = type_info<Component>::id();
|
|
|
// use reset and new to avoid instantiating std::unique_ptr with pool_handler<Component>
|
|
|
- pdata.pool.reset(new pool_handler<Component>(std::forward<Args>(args)...));
|
|
|
+ pdata.pool.reset(new pool_handler<Component>());
|
|
|
|
|
|
pdata.remove = [](sparse_set<entity_type> &cpool, basic_registry &owner, const entity_type entt) {
|
|
|
static_cast<pool_handler<Component> &>(cpool).remove(owner, entt);
|
|
|
@@ -211,7 +211,14 @@ class basic_registry {
|
|
|
|
|
|
if constexpr(std::is_copy_constructible_v<std::decay_t<Component>>) {
|
|
|
pdata.assure = [](basic_registry &other, const sparse_set<entity_type> &cpool) {
|
|
|
- other.assure<Component>(static_cast<const pool_handler<Component> &>(cpool));
|
|
|
+ if constexpr(ENTT_ENABLE_ETO(Component)) {
|
|
|
+ other.assure<Component>().assign(other, cpool.begin(), cpool.end());
|
|
|
+ } else {
|
|
|
+ other.assure<Component>().assign(other, cpool.begin(), cpool.end(), [&cpool](auto *instance) {
|
|
|
+ const auto &source = static_cast<const pool_handler<Component> &>(cpool);
|
|
|
+ std::copy(source.cbegin(), source.cend(), instance);
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
pdata.stamp = [](basic_registry &other, const entity_type dst, const sparse_set<entity_type> &cpool, const entity_type src) {
|
|
|
@@ -249,13 +256,11 @@ public:
|
|
|
/**
|
|
|
* @brief Prepares a pool for the given type if required.
|
|
|
* @tparam Component Type of component for which to prepare a pool.
|
|
|
- * @tparam Args Types of arguments to use to prepare the pool.
|
|
|
- * @param args Parameters to use to initialize the pool.
|
|
|
*/
|
|
|
- template<typename Component, typename... Args>
|
|
|
- void prepare(Args &&... args) {
|
|
|
+ template<typename Component>
|
|
|
+ void prepare() {
|
|
|
ENTT_ASSERT(std::none_of(pools.cbegin(), pools.cend(), [](auto &&pdata) { return pdata.type_id == type_info<Component>::id(); }));
|
|
|
- assure<Component>(std::forward<Args>(args)...);
|
|
|
+ assure<Component>();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1508,16 +1513,18 @@ public:
|
|
|
other.destroyed = destroyed;
|
|
|
other.entities = entities;
|
|
|
|
|
|
- if constexpr(sizeof...(Component) == 0) {
|
|
|
- std::for_each(pools.cbegin(), pools.cend(), [&other](auto &&pdata) {
|
|
|
+ std::for_each(pools.cbegin(), pools.cend(), [&other](auto &&pdata) {
|
|
|
+ if constexpr(sizeof...(Component) == 0) {
|
|
|
if(pdata.assure && ((pdata.type_id != type_info<Exclude>::id()) && ...)) {
|
|
|
pdata.assure(other, *pdata.pool);
|
|
|
}
|
|
|
- });
|
|
|
- } else {
|
|
|
- static_assert(sizeof...(Exclude) == 0 && std::conjunction_v<std::is_copy_constructible<Component>...>);
|
|
|
- (other.assure<Component>(assure<Component>()), ...);
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ static_assert(sizeof...(Exclude) == 0 && std::conjunction_v<std::is_copy_constructible<Component>...>);
|
|
|
+ if(pdata.assure && ((pdata.type_id == type_info<Component>::id()) || ...)) {
|
|
|
+ pdata.assure(other, *pdata.pool);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
return other;
|
|
|
}
|