pool/storage/sparse_set: pushed range-erase at the bottom of the hierarchy

This commit is contained in:
Michele Caini
2020-10-14 19:08:23 +02:00
parent a62b93acec
commit 9a0650c703
3 changed files with 28 additions and 16 deletions

View File

@@ -168,7 +168,7 @@ struct default_pool final: basic_storage<Entity, Type> {
/**
* @brief Removes multiple entities from a pool.
*
* @see remove
* @see erase
*
* @tparam It Type of input iterator.
* @param owner The registry that issued the request.
@@ -177,19 +177,13 @@ struct default_pool final: basic_storage<Entity, Type> {
*/
template<typename It>
void erase(basic_registry<entity_type> &owner, It first, It last) {
if(std::distance(first, last) == std::distance(this->begin(), this->end())) {
if(!destruction.empty()) {
for(; first != last; ++first) {
destruction.publish(owner, *first);
}
}
this->clear();
} else {
for(; first != last; ++first) {
this->erase(owner, *first);
if(!destruction.empty()) {
for(auto it = first; it != last; ++it) {
destruction.publish(owner, *it);
}
}
basic_sparse_set<entity_type>::erase(first, last);
}
/**

View File

@@ -425,7 +425,7 @@ public:
*
* @param entt A valid entity identifier.
*/
void erase(const entity_type entt) {
virtual void erase(const entity_type entt) {
ENTT_ASSERT(contains(entt));
const auto curr = page(entt);
const auto pos = offset(entt);
@@ -435,6 +435,24 @@ public:
packed.pop_back();
}
/**
* @brief Removes multiple entities from a pool.
* @tparam It Type of input iterator.
* @param first An iterator to the first element of the range of entities.
* @param last An iterator past the last element of the range of entities.
*/
template<typename It>
void erase(It first, It last) {
if(std::distance(first, last) == packed.size()) {
// no validity check, let it be misused
clear();
} else {
for(; first != last; ++first) {
erase(*first);
}
}
}
/**
* @brief Swaps two entities in the internal packed array.
*
@@ -598,7 +616,7 @@ public:
/**
* @brief Clears a sparse set.
*/
void clear() ENTT_NOEXCEPT {
virtual void clear() ENTT_NOEXCEPT {
sparse.clear();
packed.clear();
}

View File

@@ -424,7 +424,7 @@ public:
*
* @param entt A valid entity identifier.
*/
void erase(const entity_type entt) {
void erase(const entity_type entt) override {
auto other = std::move(instances.back());
instances[underlying_type::index(entt)] = std::move(other);
instances.pop_back();
@@ -510,7 +510,7 @@ public:
}
/*! @brief Clears a storage. */
void clear() ENTT_NOEXCEPT {
void clear() ENTT_NOEXCEPT override {
underlying_type::clear();
instances.clear();
}