entity/*: rollback erase -> remove (no longer a breaking change :)
This commit is contained in:
@@ -292,16 +292,11 @@ bool all = registry.has<position, velocity>(entity);
|
||||
bool any = registry.any<position, velocity>(entity);
|
||||
```
|
||||
|
||||
If the goal is to delete a single component from an entity that owns it or even
|
||||
multiple instances of a given type at once, the `remove` and `erase` member
|
||||
function templates are the way to go:
|
||||
If the goal is to delete a component from an entity that owns it, the `remove`
|
||||
member function template is the way to go:
|
||||
|
||||
```cpp
|
||||
// removes the component from its entity
|
||||
registry.remove<position>(entity);
|
||||
|
||||
// removes multiple instances of the given type at once
|
||||
registry.remove<position>(std::cbegin(entities), std::cend(entities));
|
||||
```
|
||||
|
||||
When in doubt whether the entity owns the component, use the `remove_if_exists`
|
||||
|
||||
@@ -57,13 +57,10 @@ struct storage_adapter_mixin: Storage {
|
||||
|
||||
/**
|
||||
* @brief Removes entities from a pool.
|
||||
* @tparam Args Types of arguments to forward to the underlying storage.
|
||||
* @param entity A valid entity identifier.
|
||||
* @param args Optional parameters to forward to the underlying storage.
|
||||
*/
|
||||
template<typename... Args>
|
||||
void remove(basic_registry<entity_type> &, const entity_type entity, Args &&... args) {
|
||||
Storage::remove(entity, std::forward<Args>(args)...);
|
||||
void remove(basic_registry<entity_type> &, const entity_type entity) {
|
||||
Storage::remove(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,8 +70,8 @@ struct storage_adapter_mixin: Storage {
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
*/
|
||||
template<typename It>
|
||||
void erase(basic_registry<entity_type> &, It first, It last) {
|
||||
Storage::erase(first, last);
|
||||
void remove(basic_registry<entity_type> &, It first, It last) {
|
||||
Storage::remove(first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,14 +224,14 @@ struct sigh_pool_mixin: Pool {
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
*/
|
||||
template<typename It>
|
||||
void erase(basic_registry<entity_type> &owner, It first, It last) {
|
||||
void remove(basic_registry<entity_type> &owner, It first, It last) {
|
||||
if(!destruction.empty()) {
|
||||
for(auto it = first; it != last; ++it) {
|
||||
destruction.publish(owner, *it);
|
||||
}
|
||||
}
|
||||
|
||||
Pool::erase(owner, first, last);
|
||||
Pool::remove(owner, first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ class basic_registry {
|
||||
struct pool_data {
|
||||
type_info info{};
|
||||
std::unique_ptr<basic_sparse_set<Entity>> pool{};
|
||||
void(* erase)(basic_sparse_set<Entity> &, basic_registry &, const Entity *, const Entity *){};
|
||||
void(* remove)(basic_sparse_set<Entity> &, basic_registry &, const Entity *, const Entity *){};
|
||||
};
|
||||
|
||||
template<typename...>
|
||||
@@ -114,8 +114,8 @@ class basic_registry {
|
||||
if(auto &&pdata = pools[index]; !pdata.pool) {
|
||||
pdata.info = type_id<Component>();
|
||||
pdata.pool.reset(new pool_t<Entity, Component>());
|
||||
pdata.erase = +[](basic_sparse_set<Entity> &cpool, basic_registry &owner, const Entity *first, const Entity *last) {
|
||||
static_cast<pool_t<Entity, Component> &>(cpool).erase(owner, first, last);
|
||||
pdata.remove = +[](basic_sparse_set<Entity> &cpool, basic_registry &owner, const Entity *first, const Entity *last) {
|
||||
static_cast<pool_t<Entity, Component> &>(cpool).remove(owner, first, last);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -703,14 +703,12 @@ public:
|
||||
* component.
|
||||
*
|
||||
* @tparam Component Types of components to remove.
|
||||
* @tparam Args Types of arguments to forward to the storage classes.
|
||||
* @param entity A valid entity identifier.
|
||||
* @param args Optional parameters to forward to the storage classes.
|
||||
*/
|
||||
template<typename... Component, typename... Args>
|
||||
void remove(const entity_type entity, Args &&... args) {
|
||||
template<typename... Component>
|
||||
void remove(const entity_type entity) {
|
||||
ENTT_ASSERT(valid(entity));
|
||||
(assure<Component>().remove(*this, entity, std::forward<Args>(args)...), ...);
|
||||
(assure<Component>().remove(*this, entity), ...);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,9 +722,9 @@ public:
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
*/
|
||||
template<typename... Component, typename It>
|
||||
void erase(It first, It last) {
|
||||
void remove(It first, It last) {
|
||||
ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
|
||||
(assure<Component>().erase(*this, first, last), ...);
|
||||
(assure<Component>().remove(*this, first, last), ...);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -780,7 +778,7 @@ public:
|
||||
|
||||
for(auto pos = pools.size(); pos; --pos) {
|
||||
if(auto &pdata = pools[pos-1]; pdata.pool && pdata.pool->contains(entity)) {
|
||||
pdata.erase(*pdata.pool, *this, std::begin(wrap), std::end(wrap));
|
||||
pdata.remove(*pdata.pool, *this, std::begin(wrap), std::end(wrap));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -937,7 +935,7 @@ public:
|
||||
if constexpr(sizeof...(Component) == 0) {
|
||||
for(auto pos = pools.size(); pos; --pos) {
|
||||
if(const auto &pdata = pools[pos-1]; pdata.pool) {
|
||||
pdata.erase(*pdata.pool, *this, pdata.pool->rbegin(), pdata.pool->rend());
|
||||
pdata.remove(*pdata.pool, *this, pdata.pool->rbegin(), pdata.pool->rend());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -948,7 +946,7 @@ public:
|
||||
}
|
||||
} else {
|
||||
([this](auto &&cpool) {
|
||||
cpool.erase(*this, cpool.basic_sparse_set<entity_type>::begin(), cpool.basic_sparse_set<entity_type>::end());
|
||||
cpool.remove(*this, cpool.basic_sparse_set<entity_type>::begin(), cpool.basic_sparse_set<entity_type>::end());
|
||||
}(assure<Component>()), ...);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@ public:
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
*/
|
||||
template<typename It>
|
||||
void erase(It first, It last) {
|
||||
void remove(It first, It last) {
|
||||
if(std::distance(first, last) == std::distance(packed.begin(), packed.end())) {
|
||||
// no validity check, let it be misused
|
||||
clear();
|
||||
|
||||
@@ -440,8 +440,8 @@ public:
|
||||
* @param last An iterator past the last element of the range of entities.
|
||||
*/
|
||||
template<typename It>
|
||||
void erase(It first, It last) {
|
||||
underlying_type::erase(first, last);
|
||||
void remove(It first, It last) {
|
||||
underlying_type::remove(first, last);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -138,7 +138,7 @@ TEST(Benchmark, Remove) {
|
||||
timer.elapsed();
|
||||
}
|
||||
|
||||
TEST(Benchmark, EraseMany) {
|
||||
TEST(Benchmark, RemoveMany) {
|
||||
entt::registry registry;
|
||||
std::vector<entt::entity> entities(1000000);
|
||||
|
||||
@@ -149,11 +149,11 @@ TEST(Benchmark, EraseMany) {
|
||||
|
||||
timer timer;
|
||||
auto view = registry.view<int>();
|
||||
registry.erase<int>(++view.begin(), view.end());
|
||||
registry.remove<int>(++view.begin(), view.end());
|
||||
timer.elapsed();
|
||||
}
|
||||
|
||||
TEST(Benchmark, EraseAll) {
|
||||
TEST(Benchmark, RemoveAll) {
|
||||
entt::registry registry;
|
||||
std::vector<entt::entity> entities(1000000);
|
||||
|
||||
@@ -164,7 +164,7 @@ TEST(Benchmark, EraseAll) {
|
||||
|
||||
timer timer;
|
||||
auto view = registry.view<int>();
|
||||
registry.erase<int>(view.begin(), view.end());
|
||||
registry.remove<int>(view.begin(), view.end());
|
||||
timer.elapsed();
|
||||
}
|
||||
|
||||
|
||||
@@ -1195,7 +1195,7 @@ TEST(Registry, Insert) {
|
||||
ASSERT_EQ(registry.get<float>(e2), 2.f);
|
||||
}
|
||||
|
||||
TEST(Registry, Erase) {
|
||||
TEST(Registry, Remove) {
|
||||
entt::registry registry;
|
||||
|
||||
const auto e0 = registry.create();
|
||||
@@ -1216,7 +1216,7 @@ TEST(Registry, Erase) {
|
||||
ASSERT_TRUE(registry.has<int>(e2));
|
||||
|
||||
const auto view = registry.view<int, char>();
|
||||
registry.erase<int>(view.begin(), view.end());
|
||||
registry.remove<int>(view.begin(), view.end());
|
||||
|
||||
ASSERT_FALSE(registry.has<int>(e0));
|
||||
ASSERT_FALSE(registry.has<int>(e1));
|
||||
|
||||
@@ -138,7 +138,7 @@ TEST(SparseSet, Insert) {
|
||||
ASSERT_EQ(set.data()[set.index(entt::entity{24})], entt::entity{24});
|
||||
}
|
||||
|
||||
TEST(SparseSet, Erase) {
|
||||
TEST(SparseSet, Remove) {
|
||||
entt::sparse_set set;
|
||||
entt::entity entities[3];
|
||||
|
||||
@@ -147,17 +147,17 @@ TEST(SparseSet, Erase) {
|
||||
entities[2] = entt::entity{9};
|
||||
|
||||
set.insert(std::begin(entities), std::end(entities));
|
||||
set.erase(set.begin(), set.end());
|
||||
set.remove(set.begin(), set.end());
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
|
||||
set.insert(std::begin(entities), std::end(entities));
|
||||
set.erase(set.rbegin(), set.rend());
|
||||
set.remove(set.rbegin(), set.rend());
|
||||
|
||||
ASSERT_TRUE(set.empty());
|
||||
|
||||
set.insert(std::begin(entities), std::end(entities));
|
||||
set.erase(entities, entities + 2u);
|
||||
set.remove(entities, entities + 2u);
|
||||
|
||||
ASSERT_FALSE(set.empty());
|
||||
ASSERT_EQ(*set.begin(), entt::entity{9});
|
||||
@@ -165,7 +165,7 @@ TEST(SparseSet, Erase) {
|
||||
set.clear();
|
||||
set.insert(std::begin(entities), std::end(entities));
|
||||
std::swap(entities[1], entities[2]);
|
||||
set.erase(entities, entities + 2u);
|
||||
set.remove(entities, entities + 2u);
|
||||
|
||||
ASSERT_FALSE(set.empty());
|
||||
ASSERT_EQ(*set.begin(), entt::entity{42});
|
||||
|
||||
@@ -120,20 +120,20 @@ TEST(Storage, InsertEmptyType) {
|
||||
ASSERT_EQ(pool.size(), 2u);
|
||||
}
|
||||
|
||||
TEST(Storage, Erase) {
|
||||
TEST(Storage, Remove) {
|
||||
entt::storage<int> pool;
|
||||
entt::sparse_set &base = pool;
|
||||
|
||||
pool.emplace(entt::entity{3});
|
||||
pool.emplace(entt::entity{42});
|
||||
base.erase(base.begin(), base.end());
|
||||
base.remove(base.begin(), base.end());
|
||||
|
||||
ASSERT_TRUE(pool.empty());
|
||||
|
||||
pool.emplace(entt::entity{3}, 3);
|
||||
pool.emplace(entt::entity{42}, 42);
|
||||
pool.emplace(entt::entity{9}, 9);
|
||||
base.erase(base.rbegin(), base.rbegin() + 2u);
|
||||
base.remove(base.rbegin(), base.rbegin() + 2u);
|
||||
|
||||
ASSERT_FALSE(pool.empty());
|
||||
ASSERT_EQ(*pool.begin(), 9);
|
||||
@@ -144,7 +144,7 @@ TEST(Storage, Erase) {
|
||||
pool.emplace(entt::entity{9}, 9);
|
||||
|
||||
entt::entity entities[2]{entt::entity{3}, entt::entity{9}};
|
||||
base.erase(std::begin(entities), std::end(entities));
|
||||
base.remove(std::begin(entities), std::end(entities));
|
||||
|
||||
ASSERT_FALSE(pool.empty());
|
||||
ASSERT_EQ(*pool.begin(), 42);
|
||||
|
||||
Reference in New Issue
Block a user