From 09da190e937e3bb47cd6b40bb26d8449ff507882 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 28 Oct 2020 16:24:44 +0100 Subject: [PATCH] entity/*: rollback erase -> remove (no longer a breaking change :) --- docs/md/entity.md | 9 ++------- src/entt/entity/pool.hpp | 15 ++++++--------- src/entt/entity/registry.hpp | 24 +++++++++++------------- src/entt/entity/sparse_set.hpp | 2 +- src/entt/entity/storage.hpp | 4 ++-- test/benchmark/benchmark.cpp | 8 ++++---- test/entt/entity/registry.cpp | 4 ++-- test/entt/entity/sparse_set.cpp | 10 +++++----- test/entt/entity/storage.cpp | 8 ++++---- 9 files changed, 37 insertions(+), 47 deletions(-) diff --git a/docs/md/entity.md b/docs/md/entity.md index 3117c7229..b7682f73f 100644 --- a/docs/md/entity.md +++ b/docs/md/entity.md @@ -292,16 +292,11 @@ bool all = registry.has(entity); bool any = registry.any(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(entity); - -// removes multiple instances of the given type at once -registry.remove(std::cbegin(entities), std::cend(entities)); ``` When in doubt whether the entity owns the component, use the `remove_if_exists` diff --git a/src/entt/entity/pool.hpp b/src/entt/entity/pool.hpp index 42bd76f4a..03af45732 100644 --- a/src/entt/entity/pool.hpp +++ b/src/entt/entity/pool.hpp @@ -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 - void remove(basic_registry &, const entity_type entity, Args &&... args) { - Storage::remove(entity, std::forward(args)...); + void remove(basic_registry &, 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 - void erase(basic_registry &, It first, It last) { - Storage::erase(first, last); + void remove(basic_registry &, 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 - void erase(basic_registry &owner, It first, It last) { + void remove(basic_registry &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); } /** diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index c2686c8ac..a0477eea6 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -45,7 +45,7 @@ class basic_registry { struct pool_data { type_info info{}; std::unique_ptr> pool{}; - void(* erase)(basic_sparse_set &, basic_registry &, const Entity *, const Entity *){}; + void(* remove)(basic_sparse_set &, basic_registry &, const Entity *, const Entity *){}; }; template @@ -114,8 +114,8 @@ class basic_registry { if(auto &&pdata = pools[index]; !pdata.pool) { pdata.info = type_id(); pdata.pool.reset(new pool_t()); - pdata.erase = +[](basic_sparse_set &cpool, basic_registry &owner, const Entity *first, const Entity *last) { - static_cast &>(cpool).erase(owner, first, last); + pdata.remove = +[](basic_sparse_set &cpool, basic_registry &owner, const Entity *first, const Entity *last) { + static_cast &>(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 - void remove(const entity_type entity, Args &&... args) { + template + void remove(const entity_type entity) { ENTT_ASSERT(valid(entity)); - (assure().remove(*this, entity, std::forward(args)...), ...); + (assure().remove(*this, entity), ...); } /** @@ -724,9 +722,9 @@ public: * @param last An iterator past the last element of the range of entities. */ template - 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().erase(*this, first, last), ...); + (assure().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::begin(), cpool.basic_sparse_set::end()); + cpool.remove(*this, cpool.basic_sparse_set::begin(), cpool.basic_sparse_set::end()); }(assure()), ...); } } diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index 03f8d70e9..742e31f9a 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -442,7 +442,7 @@ public: * @param last An iterator past the last element of the range of entities. */ template - 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(); diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 8d4aab7a5..4ab903fcb 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -440,8 +440,8 @@ public: * @param last An iterator past the last element of the range of entities. */ template - void erase(It first, It last) { - underlying_type::erase(first, last); + void remove(It first, It last) { + underlying_type::remove(first, last); } /** diff --git a/test/benchmark/benchmark.cpp b/test/benchmark/benchmark.cpp index 9e2bbe8f0..91e683f3c 100644 --- a/test/benchmark/benchmark.cpp +++ b/test/benchmark/benchmark.cpp @@ -138,7 +138,7 @@ TEST(Benchmark, Remove) { timer.elapsed(); } -TEST(Benchmark, EraseMany) { +TEST(Benchmark, RemoveMany) { entt::registry registry; std::vector entities(1000000); @@ -149,11 +149,11 @@ TEST(Benchmark, EraseMany) { timer timer; auto view = registry.view(); - registry.erase(++view.begin(), view.end()); + registry.remove(++view.begin(), view.end()); timer.elapsed(); } -TEST(Benchmark, EraseAll) { +TEST(Benchmark, RemoveAll) { entt::registry registry; std::vector entities(1000000); @@ -164,7 +164,7 @@ TEST(Benchmark, EraseAll) { timer timer; auto view = registry.view(); - registry.erase(view.begin(), view.end()); + registry.remove(view.begin(), view.end()); timer.elapsed(); } diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index f908e79d9..6e6fe6cda 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -1195,7 +1195,7 @@ TEST(Registry, Insert) { ASSERT_EQ(registry.get(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(e2)); const auto view = registry.view(); - registry.erase(view.begin(), view.end()); + registry.remove(view.begin(), view.end()); ASSERT_FALSE(registry.has(e0)); ASSERT_FALSE(registry.has(e1)); diff --git a/test/entt/entity/sparse_set.cpp b/test/entt/entity/sparse_set.cpp index c8d080cc6..a427b4c18 100644 --- a/test/entt/entity/sparse_set.cpp +++ b/test/entt/entity/sparse_set.cpp @@ -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}); diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index 911768940..8751a68f6 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -120,20 +120,20 @@ TEST(Storage, InsertEmptyType) { ASSERT_EQ(pool.size(), 2u); } -TEST(Storage, Erase) { +TEST(Storage, Remove) { entt::storage 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);