sigh_mixin: slightly improved pop + review insert
This commit is contained in:
@@ -29,21 +29,25 @@ class sigh_mixin final: public Type {
|
||||
using underlying_iterator = typename Type::base_type::basic_iterator;
|
||||
|
||||
void pop(underlying_iterator first, underlying_iterator last) final {
|
||||
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||
if(destruction.empty()) {
|
||||
Type::pop(first, last);
|
||||
} else {
|
||||
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||
|
||||
for(; first != last; ++first) {
|
||||
const auto entt = *first;
|
||||
destruction.publish(*owner, entt);
|
||||
const auto it = Type::find(entt);
|
||||
Type::pop(it, it + 1u);
|
||||
for(; first != last; ++first) {
|
||||
const auto entt = *first;
|
||||
destruction.publish(*owner, entt);
|
||||
const auto it = Type::find(entt);
|
||||
Type::pop(it, it + 1u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
underlying_iterator try_emplace(const typename Type::entity_type entt, const bool force_back, const void *value) final {
|
||||
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||
const auto it = Type::try_emplace(entt, force_back, value);
|
||||
|
||||
if(it != Type::base_type::end()) {
|
||||
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||
construction.publish(*owner, *it);
|
||||
}
|
||||
|
||||
@@ -210,11 +214,14 @@ public:
|
||||
*/
|
||||
template<typename It, typename... Args>
|
||||
void insert(It first, It last, Args &&...args) {
|
||||
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||
Type::insert(first, last, std::forward<Args>(args)...);
|
||||
|
||||
for(auto it = construction.empty() ? last : first; it != last; ++it) {
|
||||
construction.publish(*owner, *it);
|
||||
if(!construction.empty()) {
|
||||
ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
|
||||
|
||||
for(; first != last; ++first) {
|
||||
construction.publish(*owner, *first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,17 @@ TEST(SighMixin, GenericType) {
|
||||
counter on_destroy{};
|
||||
|
||||
pool.bind(entt::forward_as_any(registry));
|
||||
|
||||
ASSERT_TRUE(pool.empty());
|
||||
|
||||
pool.insert(entities, entities + 1u);
|
||||
pool.erase(entities[0u]);
|
||||
|
||||
ASSERT_TRUE(pool.empty());
|
||||
|
||||
ASSERT_EQ(on_construct.value, 0);
|
||||
ASSERT_EQ(on_destroy.value, 0);
|
||||
|
||||
pool.on_construct().connect<&listener<entt::registry>>(on_construct);
|
||||
pool.on_destroy().connect<&listener<entt::registry>>(on_destroy);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user