range registry::stomp is no longer available
This commit is contained in:
1
TODO
1
TODO
@@ -38,4 +38,5 @@
|
||||
* multi component registry::remove and some others?
|
||||
- remove create overload for spwaning
|
||||
- clean up stomp functions
|
||||
- review internal clone
|
||||
* get rid of registry::skip_family_pools
|
||||
|
||||
@@ -177,7 +177,8 @@ class basic_registry {
|
||||
std::unique_ptr<sparse_set<Entity>> pool;
|
||||
void(* remove)(sparse_set<Entity> &, basic_registry &, const Entity);
|
||||
std::unique_ptr<sparse_set<Entity>>(* clone)(const sparse_set<Entity> &);
|
||||
void(* stomp)(const sparse_set<Entity> &, const Entity, basic_registry &, const Entity);
|
||||
const void *(* get)(const sparse_set<Entity> &, const Entity);
|
||||
void(* set)(basic_registry &, const Entity, const void *);
|
||||
ENTT_ID_TYPE runtime_type;
|
||||
};
|
||||
|
||||
@@ -261,13 +262,21 @@ class basic_registry {
|
||||
static_cast<pool_type<Component> &>(cpool).remove(owner, entt);
|
||||
};
|
||||
|
||||
pdata->get = [](const sparse_set<Entity> &cpool, const Entity entt) -> const void * {
|
||||
if constexpr(ENTT_ENABLE_ETO(Component)) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return static_cast<const pool_type<Component> &>(cpool).try_get(entt);
|
||||
}
|
||||
};
|
||||
|
||||
if constexpr(std::is_copy_constructible_v<std::decay_t<Component>>) {
|
||||
pdata->clone = [](const sparse_set<Entity> &cpool) -> std::unique_ptr<sparse_set<Entity>> {
|
||||
return std::make_unique<pool_type<Component>>(static_cast<const pool_type<Component> &>(cpool));
|
||||
};
|
||||
|
||||
pdata->stomp = [](const sparse_set<Entity> &cpool, const Entity from, basic_registry &other, const Entity to) {
|
||||
other.assign_or_replace<Component>(to, static_cast<const pool_type<Component> &>(cpool).get(from));
|
||||
pdata->set = [](basic_registry &target, const Entity entt, const void *instance) {
|
||||
target.assign_or_replace<Component>(entt, *static_cast<const std::decay_t<Component> *>(instance));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1506,7 +1515,8 @@ public:
|
||||
auto &curr = other.pools[pos-1];
|
||||
curr.remove = pdata.remove;
|
||||
curr.clone = pdata.clone;
|
||||
curr.stomp = pdata.stomp;
|
||||
curr.set = pdata.set;
|
||||
curr.get = pdata.get;
|
||||
curr.pool = pdata.clone(*pdata.pool);
|
||||
curr.runtime_type = pdata.runtime_type;
|
||||
}
|
||||
@@ -1555,37 +1565,14 @@ public:
|
||||
*/
|
||||
template<typename... Component, typename... Exclude>
|
||||
void stomp(const entity_type dst, const entity_type src, const basic_registry &other, exclude_t<Exclude...> = {}) {
|
||||
const entity_type entt[1]{dst};
|
||||
stomp<Component...>(std::begin(entt), std::end(entt), src, other, exclude<Exclude...>);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stomps the entities in a range and their components.
|
||||
*
|
||||
* @sa stomp
|
||||
*
|
||||
* @tparam Component Types of components to copy.
|
||||
* @tparam It Type of input iterator.
|
||||
* @tparam Exclude Types of components not to be copied.
|
||||
* @param first An iterator to the first element of the range to stomp.
|
||||
* @param last An iterator past the last element of the range to stomp.
|
||||
* @param src A valid entity identifier to be copied.
|
||||
* @param other The registry that owns the source entity.
|
||||
*/
|
||||
template<typename... Component, typename It, typename... Exclude>
|
||||
void stomp(It first, It last, const entity_type src, const basic_registry &other, exclude_t<Exclude...> = {}) {
|
||||
static_assert((sizeof...(Component) == 0 || sizeof...(Exclude) == 0) && std::conjunction_v<std::is_copy_constructible<Component>...>);
|
||||
|
||||
for(auto pos = other.pools.size(); pos; --pos) {
|
||||
if(const auto &pdata = other.pools[pos-1]; pdata.pool && pdata.stomp
|
||||
&& (!sizeof...(Component) || ... || (pdata.runtime_type == to_integer(type<Component>())))
|
||||
&& ((pdata.runtime_type != to_integer(type<Exclude>())) && ...)
|
||||
&& pdata.pool->has(src))
|
||||
{
|
||||
std::for_each(first, last, [this, &pdata, src](const auto entity) {
|
||||
pdata.stomp(*pdata.pool, src, *this, entity);
|
||||
});
|
||||
if constexpr(sizeof...(Component) == 0) {
|
||||
for(auto pos = other.pools.size(); pos; --pos) {
|
||||
if(const auto &pdata = other.pools[pos-1]; pdata.set && ((pdata.runtime_type != to_integer(type<Exclude>())) && ...) && pdata.pool->has(src)) {
|
||||
pdata.set(*this, dst, pdata.get(*pdata.pool, src));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(assign_or_replace<Component>(dst, other.get<Component>(src)), ...);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1444,7 +1444,7 @@ TEST(Registry, Stomp) {
|
||||
registry.assign<char>(prototype, 'c');
|
||||
|
||||
auto entity = registry.create();
|
||||
registry.stomp<int, char, double>(entity, prototype, registry);
|
||||
registry.stomp<int, char>(entity, prototype, registry);
|
||||
|
||||
ASSERT_TRUE((registry.has<int, char>(entity)));
|
||||
ASSERT_EQ(registry.get<int>(entity), 3);
|
||||
@@ -1486,42 +1486,6 @@ TEST(Registry, StompExclude) {
|
||||
ASSERT_TRUE(registry.orphan(entity));
|
||||
}
|
||||
|
||||
TEST(Registry, StompMulti) {
|
||||
entt::registry registry;
|
||||
|
||||
const auto prototype = registry.create();
|
||||
registry.assign<int>(prototype, 3);
|
||||
registry.assign<char>(prototype, 'c');
|
||||
|
||||
entt::entity entities[2];
|
||||
registry.create(std::begin(entities), std::end(entities));
|
||||
registry.stomp<int, char, double>(std::begin(entities), std::end(entities), prototype, registry);
|
||||
|
||||
ASSERT_TRUE((registry.has<int, char>(entities[0])));
|
||||
ASSERT_TRUE((registry.has<int, char>(entities[1])));
|
||||
ASSERT_EQ(registry.get<int>(entities[0]), 3);
|
||||
ASSERT_EQ(registry.get<char>(entities[1]), 'c');
|
||||
}
|
||||
|
||||
TEST(Registry, StompExcludeMulti) {
|
||||
entt::registry registry;
|
||||
|
||||
const auto prototype = registry.create();
|
||||
registry.assign<int>(prototype, 3);
|
||||
registry.assign<char>(prototype, 'c');
|
||||
|
||||
entt::entity entities[2];
|
||||
registry.create(std::begin(entities), std::end(entities));
|
||||
registry.stomp(std::begin(entities), std::end(entities), prototype, registry, entt::exclude<char>);
|
||||
|
||||
ASSERT_TRUE((registry.has<int>(entities[0])));
|
||||
ASSERT_TRUE((registry.has<int>(entities[1])));
|
||||
ASSERT_FALSE((registry.has<char>(entities[0])));
|
||||
ASSERT_FALSE((registry.has<char>(entities[1])));
|
||||
ASSERT_EQ(registry.get<int>(entities[0]), 3);
|
||||
ASSERT_EQ(registry.get<int>(entities[1]), 3);
|
||||
}
|
||||
|
||||
TEST(Registry, StompMoveOnlyComponent) {
|
||||
entt::registry registry;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user