group: group_handler::size function for owning groups

This commit is contained in:
Michele Caini
2023-03-29 18:26:41 +02:00
parent ebb1e8a728
commit 77c59aabfa
2 changed files with 12 additions and 13 deletions

View File

@@ -95,13 +95,9 @@ template<typename... Lhs, typename... Rhs>
struct owning_group_descriptor {
using size_type = std::size_t;
owning_group_descriptor(const size_type sz)
: size{sz} {}
virtual ~owning_group_descriptor() = default;
virtual size_type check(const id_type *, const size_type, const size_type, const size_type) const noexcept = 0;
const size_type size;
virtual size_type size() const noexcept = 0;
};
template<typename, typename, typename>
@@ -144,8 +140,7 @@ public:
using size_type = typename owning_group_descriptor::size_type;
group_handler(Owned &...opool, Get &...gpool, Exclude &...epool)
: owning_group_descriptor{sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude)},
pools{&opool..., &gpool...},
: pools{&opool..., &gpool...},
filter{&epool...},
len{} {
std::apply([this](auto *...cpool) { ((cpool->on_construct().template connect<&group_handler::push_on_construct>(*this), cpool->on_destroy().template connect<&group_handler::remove_if>(*this)), ...); }, pools);
@@ -175,6 +170,10 @@ public:
return cnt;
}
size_type size() const noexcept final {
return sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude);
}
void previous(const owning_group_descriptor &elem) {
std::apply([this, &elem](auto *...cpool) { ((cpool->on_destroy().disconnect(this), cpool->on_destroy().before(&elem).template connect<&group_handler::remove_if>(*this)), ...); }, pools);
std::apply([this, &elem](auto *...cpool) { ((cpool->on_construct().disconnect(this), cpool->on_construct().before(&elem).template connect<&group_handler::remove_if>(*this)), ...); }, filter);

View File

@@ -1226,10 +1226,10 @@ public:
auto handler = std::allocate_shared<handler_type>(get_allocator(), assure<std::remove_const_t<Owned>>()..., assure<std::remove_const_t<Get>>()..., assure<std::remove_const_t<Exclude>>()...);
owning_groups.emplace(type_hash<handler_type>::value(), handler);
ENTT_ASSERT(std::all_of(owning_groups.cbegin(), owning_groups.cend(), [&elem, hsize = handler->size](const auto &data) {
ENTT_ASSERT(std::all_of(owning_groups.cbegin(), owning_groups.cend(), [&elem, hsize = handler->size()](const auto &data) {
const auto overlapping = data.second->check(elem, sizeof...(Owned), 0u, 0u);
const auto sz = data.second->check(elem, sizeof...(Owned), sizeof...(Get), sizeof...(Exclude));
return !overlapping || ((sz == hsize) || (sz == data.second->size));
return !overlapping || ((sz == hsize) || (sz == data.second->size()));
}),
"Conflicting groups");
@@ -1237,12 +1237,12 @@ public:
const internal::owning_group_descriptor *next = nullptr;
for(auto &&data: owning_groups) {
if(data.second->check(elem, sizeof...(Owned), 0u, 0u)) {
if(const auto sz = data.second->size; sz < handler->size && (prev == nullptr || prev->size < sz)) {
if(const auto sz = data.second->size(); data.second->check(elem, sizeof...(Owned), 0u, 0u)) {
if(sz < handler->size() && (prev == nullptr || prev->size() < sz)) {
prev = data.second.get();
}
if(const auto sz = data.second->size; sz > handler->size && (next == nullptr || next->size > sz)) {
if(sz > handler->size() && (next == nullptr || next->size() > sz)) {
next = data.second.get();
}
}
@@ -1303,7 +1303,7 @@ public:
[[nodiscard]] bool sortable(const basic_group<owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> &) noexcept {
constexpr auto size = sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude);
const id_type elem[]{type_hash<typename Owned::value_type>::value()...};
auto pred = [&elem, size](const auto &data) { return data.second->check(elem, sizeof...(Owned), 0u, 0u) && (size < data.second->size); };
auto pred = [&elem, size](const auto &data) { return data.second->check(elem, sizeof...(Owned), 0u, 0u) && (size < data.second->size()); };
return std::find_if(owning_groups.cbegin(), owning_groups.cend(), std::move(pred)) == owning_groups.cend();
}