view: deprecated ::less, ::each returns only non-empty types now
This commit is contained in:
6
TODO
6
TODO
@@ -15,12 +15,16 @@
|
||||
* document undocumented parts (entt::overload and a few others)
|
||||
* any-of rule for views/groups (eg entity has A and any of B/C/D)
|
||||
- get -> all, exclude -> none
|
||||
* review multi component views to reduce instantiations once empty types are gone...
|
||||
|
||||
Next:
|
||||
* replace observer class with observer functions
|
||||
* get(cmp, entity) -> void *, set(cmp, entity, void *)
|
||||
* ENTT_ENABLE_ETO -> ENTT_IS_EMPTY (ignore default constructible)
|
||||
* review multi component views to reduce instantiations once empty types are gone...
|
||||
* update doc for empty types
|
||||
* avoid using deprecated functions all around
|
||||
* remove all is possible from storage<empty>
|
||||
* replace/emplace_or_replace/patch don't return
|
||||
|
||||
* WIP:
|
||||
- deprecate snapshot, loader, ...
|
||||
|
||||
@@ -709,7 +709,6 @@ public:
|
||||
emplace(entt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Assigns one or more entities to a storage.
|
||||
*
|
||||
|
||||
@@ -467,7 +467,8 @@ public:
|
||||
*/
|
||||
template<typename Comp, typename Func>
|
||||
void each(Func func) const {
|
||||
traverse<Comp>(std::move(func), type_list<Component...>{});
|
||||
using non_empty_type = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Component), type_list<>, type_list<Component>>...>;
|
||||
traverse<Comp>(std::move(func), non_empty_type{});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -491,9 +492,9 @@ public:
|
||||
* @param func A valid function object.
|
||||
*/
|
||||
template<typename Func>
|
||||
[[deprecated("use ::each instead")]]
|
||||
void less(Func func) const {
|
||||
const auto *view = candidate();
|
||||
((std::get<pool_type<Component> *>(pools) == view ? less<Component>(std::move(func)) : void()), ...);
|
||||
each(std::move(func));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -524,9 +525,9 @@ public:
|
||||
* @param func A valid function object.
|
||||
*/
|
||||
template<typename Comp, typename Func>
|
||||
[[deprecated("use ::each instead")]]
|
||||
void less(Func func) const {
|
||||
using non_empty_type = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Component), type_list<>, type_list<Component>>...>;
|
||||
traverse<Comp>(std::move(func), non_empty_type{});
|
||||
each<Comp>(std::move(func));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -767,15 +768,27 @@ public:
|
||||
*/
|
||||
template<typename Func>
|
||||
void each(Func func) const {
|
||||
if constexpr(std::is_invocable_v<Func, decltype(get({}))>) {
|
||||
for(auto &&component: *pool) {
|
||||
func(component);
|
||||
if constexpr(ENTT_ENABLE_ETO(Component)) {
|
||||
if constexpr(std::is_invocable_v<Func>) {
|
||||
for(auto pos = pool->size(); pos; --pos) {
|
||||
func();
|
||||
}
|
||||
} else {
|
||||
for(const auto entt: *this) {
|
||||
func(entt);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto raw = pool->begin();
|
||||
if constexpr(std::is_invocable_v<Func, decltype(get({}))>) {
|
||||
for(auto &&component: *pool) {
|
||||
func(component);
|
||||
}
|
||||
} else {
|
||||
auto raw = pool->begin();
|
||||
|
||||
for(const auto entt: *this) {
|
||||
func(entt, *(raw++));
|
||||
for(const auto entt: *this) {
|
||||
func(entt, *(raw++));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -809,20 +822,9 @@ public:
|
||||
* @param func A valid function object.
|
||||
*/
|
||||
template<typename Func>
|
||||
[[deprecated("use ::each instead")]]
|
||||
void less(Func func) const {
|
||||
if constexpr(ENTT_ENABLE_ETO(Component)) {
|
||||
if constexpr(std::is_invocable_v<Func>) {
|
||||
for(auto pos = pool->size(); pos; --pos) {
|
||||
func();
|
||||
}
|
||||
} else {
|
||||
for(const auto entt: *this) {
|
||||
func(entt);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
each(std::move(func));
|
||||
}
|
||||
each(std::move(func));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -432,28 +432,25 @@ TEST(MultiComponentView, EachWithHoles) {
|
||||
|
||||
TEST(MultiComponentView, ConstNonConstAndAllInBetween) {
|
||||
entt::registry registry;
|
||||
auto view = registry.view<int, const char, std::true_type>();
|
||||
auto view = registry.view<int, const char>();
|
||||
|
||||
ASSERT_EQ(view.size(), decltype(view.size()){0});
|
||||
|
||||
const auto entity = registry.create();
|
||||
registry.assign<int>(entity, 0);
|
||||
registry.assign<char>(entity, 'c');
|
||||
registry.assign<std::true_type>(entity);
|
||||
|
||||
ASSERT_EQ(view.size(), decltype(view.size()){1});
|
||||
|
||||
ASSERT_TRUE((std::is_same_v<decltype(view.get<int>({})), int &>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(view.get<const char>({})), const char &>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(view.get<std::true_type>({})), std::true_type>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(view.get<int, const char, std::true_type>({})), std::tuple<int &, const char &, std::true_type>>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(view.get<int, const char>({})), std::tuple<int &, const char &>>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(view.raw<const char>()), const char *>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(view.raw<int>()), int *>));
|
||||
|
||||
view.each([](auto &&i, auto &&c, auto &&e) {
|
||||
view.each([](auto &&i, auto &&c) {
|
||||
ASSERT_TRUE((std::is_same_v<decltype(i), int &>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(c), const char &>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(e), std::true_type &&>));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user