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 {
80 bool valid() const ENTT_NOEXCEPT {
81 return std::all_of(from, to, [
entt = *
begin](
const auto *
view) {
87 using difference_type =
typename underlying_iterator_type::difference_type;
88 using value_type =
typename underlying_iterator_type::value_type;
89 using pointer =
typename underlying_iterator_type::pointer;
90 using reference =
typename underlying_iterator_type::reference;
91 using iterator_category = std::forward_iterator_tag;
93 iterator() ENTT_NOEXCEPT = default;
95 iterator & operator++() ENTT_NOEXCEPT {
96 return (++
begin !=
end && !valid()) ? ++(*this) : *
this;
99 iterator operator++(
int) ENTT_NOEXCEPT {
100 iterator orig = *
this;
101 return ++(*this), orig;
104 bool operator==(
const iterator &other)
const ENTT_NOEXCEPT {
105 return other.begin ==
begin;
108 bool operator!=(
const iterator &other)
const ENTT_NOEXCEPT {
109 return !(*
this == other);
112 pointer operator->() const ENTT_NOEXCEPT {
113 return begin.operator->();
116 reference operator*() const ENTT_NOEXCEPT {
117 return *operator->();
121 underlying_iterator_type
begin;
122 underlying_iterator_type
end;
128 : pools{std::move(others)}
130 const auto it = std::min_element(pools.begin(), pools.end(), [](
const auto *lhs,
const auto *rhs) {
131 return (!lhs && rhs) || (lhs && rhs && lhs->size() < rhs->size());
135 std::rotate(pools.begin(), it, pools.end());
138 bool valid() const ENTT_NOEXCEPT {
139 return !pools.
empty() && pools.front();
155 return valid() ? pools.front()->size() :
size_type{};
163 return !valid() || pools.front()->empty();
184 const auto &pool = *pools.front();
185 const auto *
const *data = pools.data();
186 it = { pool.begin(), pool.end(), data + 1, data + pools.size() };
211 const auto &pool = *pools.front();
212 it = { pool.end(), pool.end(),
nullptr,
nullptr };
224 return valid() && std::all_of(pools.cbegin(), pools.cend(), [
entt](
const auto *
view) {
244 template<
typename Func>
246 std::for_each(
begin(),
end(), func);
250 std::vector<const sparse_set<Entity> *> pools;
257 #endif // ENTT_ENTITY_RUNTIME_VIEW_HPP bool contains(const entity_type entt) const ENTT_NOEXCEPT
Checks if a view contains an entity.
Basic sparse set implementation.
typename sparse_set< Entity >::size_type size_type
Unsigned integer type.
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.
std::size_t size_type
Unsigned integer type.
typename sparse_set< Entity >::entity_type 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.
Fast and reliable entity-component system.
Entity entity_type
Underlying entity identifier.
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.
iterator_type find(const entity_type entt) const ENTT_NOEXCEPT
Finds an entity.
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.
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.