1 #ifndef ENTT_ENTITY_RUNTIME_VIEW_HPP
2 #define ENTT_ENTITY_RUNTIME_VIEW_HPP
10 #include <type_traits>
11 #include "../config/config.h"
12 #include "sparse_set.hpp"
58 template<
typename Entity>
59 class basic_runtime_view {
79 bool valid() const ENTT_NOEXCEPT {
80 return std::all_of(from, to, [
entt = *
begin](
const auto *
view) {
86 using difference_type =
typename underlying_iterator_type::difference_type;
87 using value_type =
typename underlying_iterator_type::value_type;
88 using pointer =
typename underlying_iterator_type::pointer;
89 using reference =
typename underlying_iterator_type::reference;
90 using iterator_category = std::forward_iterator_tag;
92 iterator() ENTT_NOEXCEPT = default;
94 iterator & operator++() ENTT_NOEXCEPT {
95 return (++
begin !=
end && !valid()) ? ++(*this) : *
this;
98 iterator operator++(
int) ENTT_NOEXCEPT {
99 iterator orig = *
this;
100 return ++(*this), orig;
103 bool operator==(
const iterator &other)
const ENTT_NOEXCEPT {
104 return other.begin ==
begin;
107 bool operator!=(
const iterator &other)
const ENTT_NOEXCEPT {
108 return !(*
this == other);
111 pointer operator->() const ENTT_NOEXCEPT {
112 return begin.operator->();
115 reference operator*() const ENTT_NOEXCEPT {
116 return *operator->();
120 underlying_iterator_type
begin;
121 underlying_iterator_type
end;
122 const sparse_set<Entity> *
const *from;
123 const sparse_set<Entity> *
const *to;
126 basic_runtime_view(std::vector<
const sparse_set<Entity> *> others) ENTT_NOEXCEPT
127 : pools{std::move(others)}
129 const auto it = std::min_element(pools.begin(), pools.end(), [](
const auto *lhs,
const auto *rhs) {
130 return (!lhs && rhs) || (lhs && rhs && lhs->size() < rhs->size());
134 std::rotate(pools.begin(), it, pools.end());
137 bool valid() const ENTT_NOEXCEPT {
138 return !pools.empty() && pools.front();
154 return valid() ? pools.front()->size() :
size_type{};
162 return !valid() || pools.front()->empty();
183 const auto &pool = *pools.front();
184 const auto *
const *data = pools.data();
185 it = { pool.begin(), pool.end(), data + 1, data + pools.size() };
210 const auto &pool = *pools.front();
211 it = { pool.end(), pool.end(),
nullptr,
nullptr };
223 return valid() && std::all_of(pools.cbegin(), pools.cend(), [
entt](
const auto *
view) {
243 template<
typename Func>
245 std::for_each(
begin(),
end(), func);
249 std::vector<const sparse_set<Entity> *> pools;
256 #endif // ENTT_ENTITY_RUNTIME_VIEW_HPP