fixed range destroy - it's probably slightly slower now but it works also with views and groups (close #261)
This commit is contained in:
@@ -643,30 +643,14 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Destroys all the entities in a range.
|
||||
* @tparam It Type of forward iterator.
|
||||
* @tparam It Type of input iterator.
|
||||
* @param first An iterator to the first element of the range to generate.
|
||||
* @param last An iterator past the last element of the range to generate.
|
||||
*/
|
||||
template<typename It>
|
||||
void destroy(It first, It last) {
|
||||
ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
|
||||
|
||||
for(auto pos = pools.size(); pos; --pos) {
|
||||
if(auto &pdata = pools[pos-1]; pdata.pool) {
|
||||
std::for_each(first, last, [&pdata, this](const auto entity) {
|
||||
if(pdata.pool->has(entity)) {
|
||||
pdata.remove(*this, entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// just a way to protect users from listeners that attach components
|
||||
ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return orphan(entity); }));
|
||||
|
||||
std::for_each(first, last, [this](const auto entity) {
|
||||
release(entity);
|
||||
});
|
||||
// useless this-> used to suppress a warning with clang
|
||||
std::for_each(first, last, [this](const auto entity) { this->destroy(entity); });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1412,7 +1396,7 @@ public:
|
||||
* components.<br/>
|
||||
* This is particularly well suited to plugin systems and mods in general.
|
||||
*
|
||||
* @tparam It Type of forward iterator.
|
||||
* @tparam It Type of input iterator.
|
||||
* @param first An iterator to the first element of the range of components.
|
||||
* @param last An iterator past the last element of the range of components.
|
||||
* @return A newly created runtime view.
|
||||
|
||||
@@ -987,15 +987,6 @@ TEST(Registry, DestroyByComponents) {
|
||||
ASSERT_TRUE(registry.valid(e1));
|
||||
ASSERT_TRUE(registry.valid(e2));
|
||||
|
||||
{
|
||||
const auto view = registry.view<int, char, double>();
|
||||
registry.destroy(view.begin(), view.end());
|
||||
}
|
||||
|
||||
ASSERT_FALSE(registry.valid(e0));
|
||||
ASSERT_TRUE(registry.valid(e1));
|
||||
ASSERT_TRUE(registry.valid(e2));
|
||||
|
||||
{
|
||||
const auto view = registry.view<int, char>();
|
||||
registry.destroy(view.begin(), view.end());
|
||||
|
||||
Reference in New Issue
Block a user