registry: uses views to initialize groups
This commit is contained in:
3
TODO
3
TODO
@@ -22,5 +22,4 @@
|
||||
* remove duktape example (and eventually provide a new one)?
|
||||
* review and suppress warnings, if any
|
||||
* extract only the type within type_info, hash its name (more portable)
|
||||
* registry
|
||||
- ::group improve, reduce code
|
||||
* registry: groups can break after a discard -> cleanup them
|
||||
|
||||
@@ -1333,26 +1333,16 @@ public:
|
||||
(std::get<pool_type<Get> &>(cpools).on_destroy().before(discard_if).template connect<&handler_type::discard_if>(*handler), ...);
|
||||
(std::get<pool_type<Exclude> &>(cpools).on_construct().before(discard_if).template connect<&handler_type::discard_if>(*handler), ...);
|
||||
|
||||
const auto &cpool = std::min({
|
||||
static_cast<sparse_set<Entity> &>(std::get<pool_type<Owned> &>(cpools))...,
|
||||
static_cast<sparse_set<Entity> &>(std::get<pool_type<Get> &>(cpools))...
|
||||
}, [](const auto &lhs, const auto &rhs) {
|
||||
return lhs.size() < rhs.size();
|
||||
});
|
||||
auto init = view<Owned..., Get...>(entt::exclude<Exclude...>);
|
||||
|
||||
// we cannot iterate backwards because we want to leave behind valid entities in case of owned types
|
||||
std::for_each(cpool.data(), cpool.data() + cpool.size(), [cpools, handler](const auto entity) {
|
||||
if((std::get<pool_type<Owned> &>(cpools).has(entity) && ...)
|
||||
&& (std::get<pool_type<Get> &>(cpools).has(entity) && ...)
|
||||
&& !(std::get<pool_type<Exclude> &>(cpools).has(entity) || ...))
|
||||
{
|
||||
if constexpr(sizeof...(Owned) == 0) {
|
||||
handler->owned.construct(entity);
|
||||
} else {
|
||||
if(!(std::get<0>(cpools).index(entity) < handler->owned)) {
|
||||
const auto pos = handler->owned++;
|
||||
(std::get<pool_type<Owned> &>(cpools).swap(std::get<pool_type<Owned> &>(cpools).data()[pos], entity), ...);
|
||||
}
|
||||
std::for_each(std::make_reverse_iterator(init.end()), std::make_reverse_iterator(init.begin()), [handler](const auto entity) {
|
||||
if constexpr(sizeof...(Owned) == 0) {
|
||||
handler->owned.construct(entity);
|
||||
} else {
|
||||
if(!(std::get<0>(handler->cpools).index(entity) < handler->owned)) {
|
||||
const auto pos = handler->owned++;
|
||||
(std::get<pool_type<Owned> &>(handler->cpools).swap(std::get<pool_type<Owned> &>(handler->cpools).data()[pos], entity), ...);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user