group: simplify non-critical virtual function

This commit is contained in:
skypjack
2024-07-19 10:31:30 +02:00
parent d16fa5c605
commit 7431d93691
3 changed files with 10 additions and 15 deletions

3
TODO
View File

@@ -36,9 +36,8 @@ TODO:
* improve front (no multiple checks) and back (ie no contains) for multi-type view
* cleanup common view from tricks to handle single swap-only and in-place, if constexpr branches
* exploit ref/cref in any to avoid invoking the vtable if possible
* review meta properties and details, maybe a dense map is too much
* review meta properties and details: maybe a dense map is too much, investigate using any rather than shared<void> for meta properties
* entity based component_traits
* investigate using any rather than shared<void> for meta properties
* copy-and-swap for any and meta_any
* improve seek function for overloaded meta functions
* fix cmake warning about FetchContent_Populate

View File

@@ -94,8 +94,8 @@ template<typename... Lhs, typename... Rhs>
struct group_descriptor {
using size_type = std::size_t;
virtual ~group_descriptor() noexcept = default;
virtual size_type owned(const id_type *, const size_type) const noexcept {
return 0u;
virtual bool owned(const id_type) const noexcept {
return false;
}
};
@@ -149,16 +149,14 @@ public:
common_setup();
}
size_type owned(const id_type *elem, const size_type length) const noexcept final {
size_type cnt = 0u;
for(auto pos = 0u; pos < length; ++pos) {
for(auto next = 0u; next < Owned; ++next) {
cnt += (elem[pos] == pools[next]->type().hash());
virtual bool owned(const id_type hash) const noexcept {
for(size_type pos{}; pos < Owned; ++pos) {
if(pools[pos]->type().hash() == hash) {
return true;
}
}
return cnt;
return false;
}
[[nodiscard]] size_type length() const noexcept {

View File

@@ -1099,8 +1099,7 @@ public:
handler = std::allocate_shared<handler_type>(get_allocator(), get_allocator(), std::forward_as_tuple(assure<std::remove_const_t<Get>>()...), std::forward_as_tuple(assure<std::remove_const_t<Exclude>>()...));
} else {
handler = std::allocate_shared<handler_type>(get_allocator(), std::forward_as_tuple(assure<std::remove_const_t<Owned>>()..., assure<std::remove_const_t<Get>>()...), std::forward_as_tuple(assure<std::remove_const_t<Exclude>>()...));
[[maybe_unused]] const std::array elem{type_hash<std::remove_const_t<Owned>>::value()..., type_hash<std::remove_const_t<Get>>::value()..., type_hash<std::remove_const_t<Exclude>>::value()...};
ENTT_ASSERT(std::all_of(groups.cbegin(), groups.cend(), [&elem](const auto &data) { return data.second->owned(elem.data(), sizeof...(Owned)) == 0u; }), "Conflicting groups");
ENTT_ASSERT(std::all_of(groups.cbegin(), groups.cend(), [](const auto &data) { return !(data.second->owned(type_id<Owned>().hash()) || ...); }), "Conflicting groups");
}
groups.emplace(group_type::group_id(), handler);
@@ -1130,8 +1129,7 @@ public:
*/
template<typename Type, typename... Other>
[[nodiscard]] bool owned() const {
const std::array elem{type_hash<std::remove_const_t<Type>>::value(), type_hash<std::remove_const_t<Other>>::value()...};
return std::any_of(groups.cbegin(), groups.cend(), [&elem](auto &&data) { return data.second->owned(elem.data(), 1u + sizeof...(Other)); });
return std::any_of(groups.cbegin(), groups.cend(), [](auto &&data) { return (data.second->owned(type_id<Type>().hash()) || ... || data.second->owned(type_id<Other>().hash())); });
}
/**