Revert "entity: minor changes"

This reverts commit af69a0a1fd.
This commit is contained in:
Michele Caini
2020-11-02 14:05:07 +01:00
parent 22596e0f5b
commit 05b514b743
3 changed files with 32 additions and 22 deletions

3
TODO
View File

@@ -17,10 +17,7 @@
- ...
WIP:
* currently, the erased remove of pdata forces pools to implement a range remove because it uses this one
* document the handle way for extended operations
* runtime, named pools
* faster destroy
* make view pack work also with groups, add multi-type iterator (not only input iterators)
* add exclude-only views to combine with packs
* deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views

View File

@@ -74,13 +74,17 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
class iterable_group {
friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>>;
template<typename It>
class iterable_group_iterator {
template<typename, typename>
class iterable_group_iterator;
template<typename It, typename... Type>
class iterable_group_iterator<It, type_list<Type...>> {
friend class iterable_group;
iterable_group_iterator(It from, const basic_group &parent) ENTT_NOEXCEPT
template<typename... Args>
iterable_group_iterator(It from, const std::tuple<pool_type<Get> *...> &args) ENTT_NOEXCEPT
: it{from},
group{&parent}
pools{std::get<pool_type<Type> *>(args)...}
{}
public:
@@ -100,7 +104,8 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
}
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
return std::tuple_cat(std::make_tuple(*it), group->get(*it));
const auto entt = *it;
return std::tuple_cat(std::make_tuple(entt), std::forward_as_tuple(std::get<pool_type<Type> *>(pools)->get(entt)...));
}
[[nodiscard]] bool operator==(const iterable_group_iterator &other) const ENTT_NOEXCEPT {
@@ -113,35 +118,43 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
private:
It it;
const basic_group *group;
const std::tuple<pool_type<Type> *...> pools;
};
iterable_group(const basic_group &parent)
: group{parent}
iterable_group(basic_sparse_set<Entity> &ref, const std::tuple<pool_type<Get> *...> &cpools)
: handler{&ref},
pools{cpools}
{}
public:
using iterator = iterable_group_iterator<typename basic_sparse_set<Entity>::iterator>;
using reverse_iterator = iterable_group_iterator<typename basic_sparse_set<Entity>::reverse_iterator>;
using iterator = iterable_group_iterator<
typename basic_sparse_set<Entity>::iterator,
type_list_cat_t<std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>...>
>;
using reverse_iterator = iterable_group_iterator<
typename basic_sparse_set<Entity>::reverse_iterator,
type_list_cat_t<std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>...>
>;
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
return { group.begin(), group };
return { handler->begin(), pools };
}
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return { group.end(), group };
return { handler->end(), pools };
}
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
return { group.rbegin(), group };
return { handler->rbegin(), pools };
}
[[nodiscard]] reverse_iterator rend() const ENTT_NOEXCEPT {
return { group.rend(), group };
return { handler->rend(), pools };
}
private:
const basic_group group;
basic_sparse_set<Entity> *handler;
const std::tuple<pool_type<Get> *...> pools;
};
basic_group(basic_sparse_set<Entity> &ref, pool_type<Get> &... gpool) ENTT_NOEXCEPT
@@ -449,7 +462,7 @@ public:
* @return An iterable object to use to _visit_ the group.
*/
[[nodiscard]] iterable_group each() const ENTT_NOEXCEPT {
return *this;
return iterable_group{*handler, pools};
}
/**

View File

@@ -159,7 +159,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
iterable_view_iterator(It from, const basic_view &parent) ENTT_NOEXCEPT
: it{from},
view{&parent}
view{parent}
{}
public:
@@ -179,7 +179,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
}
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
return std::tuple_cat(std::make_tuple(*it), view->get(*it));
return std::tuple_cat(std::make_tuple(*it), view.get(*it));
}
[[nodiscard]] bool operator==(const iterable_view_iterator &other) const ENTT_NOEXCEPT {
@@ -192,7 +192,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
private:
It it;
const basic_view *view;
const basic_view view;
};
iterable_view(const basic_view &parent)