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;
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 bool contains(const entity_type entt) const ENTT_NOEXCEPT
Checks if a view contains an entity.
std::size_t size_type
Unsigned integer type.
Basic sparse set implementation.
iterator iterator_type
Input iterator type.
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) ENTT_NOEXCEPT
Compares two hashed strings.
Fast and reliable entity-component system.
bool empty() const ENTT_NOEXCEPT
Checks if the view is definitely empty.
iterator_type begin() const ENTT_NOEXCEPT
Returns an iterator to the first entity that has the given components.
void each(Func func) const
Iterates entities and applies the given function object to them.
basic_view< entity, Types... > view
Alias declaration for the most common use case.
size_type size() const ENTT_NOEXCEPT
Estimates the number of entities that have the given components.
Entity entity_type
Underlying entity identifier.
iterator_type end() const ENTT_NOEXCEPT
Returns an iterator that is past the last entity that has the given components.
iterator iterator_type
Random access iterator type.