1#ifndef ENTT_ENTITY_OBSERVER_HPP
2#define ENTT_ENTITY_OBSERVER_HPP
9#include "../core/type_traits.hpp"
54 template<
typename AnyOf>
89 template<
typename AnyOf>
159template<
typename Registry,
typename Allocator>
161 using mask_type = std::uint64_t;
164 template<std::
size_t Index>
172 struct matcher_handler;
176 template<std::
size_t Index>
187 template<std::
size_t Index>
209 if constexpr(
sizeof...(Ignore) == 0) {
224 template<std::
size_t Index>
246 (matcher_handler<Matcher>::disconnect(
storage, parent), ...);
251 static_assert(
sizeof...(Matcher) < std::numeric_limits<mask_type>::digits,
"Too many matchers");
265 using iterator =
typename registry_type::common_type::iterator;
378 return storage.storage_type::base_type::begin();
387 return storage.storage_type::base_type::end();
408 template<
typename Func>
410 for(
const auto entity: *
this) {
424 template<
typename Func>
426 std::as_const(*this).each(std::move(func));
bool empty() const noexcept
Checks whether an observer is empty.
typename registry_type::common_type::iterator iterator
Random access iterator type.
basic_observer()
Default constructor.
void clear() noexcept
Clears the underlying container.
iterator begin() const noexcept
Returns an iterator to the first entity of the observer.
typename registry_type::entity_type entity_type
Underlying entity identifier.
void connect(registry_type ®, basic_collector< Matcher... >)
Connects an observer to a given registry.
basic_observer(const allocator_type &allocator)
Constructs an empty storage with a given allocator.
void disconnect()
Disconnects an observer from the registry it keeps track of.
basic_observer & operator=(basic_observer &&)=delete
Default move assignment operator, deleted on purpose.
basic_observer(basic_observer &&)=delete
Default move constructor, deleted on purpose.
void each(Func func)
Iterates entities and applies the given function object to them, then clears the observer.
~basic_observer()=default
Default destructor.
void each(Func func) const
Iterates entities and applies the given function object to them.
iterator end() const noexcept
Returns an iterator that is past the last entity of the observer.
basic_observer & operator=(const basic_observer &)=delete
Default copy assignment operator, deleted on purpose.
const entity_type * data() const noexcept
Direct access to the list of entities of the observer.
basic_observer(const basic_observer &)=delete
Default copy constructor, deleted on purpose.
std::size_t size_type
Unsigned integer type.
size_type size() const noexcept
Returns the number of elements in an observer.
basic_observer(registry_type ®, basic_collector< Matcher... >, const allocator_type &allocator=allocator_type{})
Creates an observer and connects it to a given registry.
Allocator allocator_type
Allocator type.
void erase(const entity_type entt)
Erases an entity from a sparse set.
pointer data() const noexcept
Direct access to the internal packed array.
void clear()
Clears a sparse set.
size_type size() const noexcept
Returns the number of elements in a sparse set.
bool contains(const entity_type entt) const noexcept
Checks if a sparse set contains an entity.
bool empty() const noexcept
Checks whether a sparse set is empty.
const value_type & get(const entity_type entt) const noexcept
Returns the object assigned to an entity.
value_type & emplace(const entity_type entt, Args &&...args)
Assigns an entity to a storage and constructs its object.
entity
Default entity identifier.
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
constexpr basic_collector collector
Variable template used to ease the definition of collectors.
static constexpr auto update() noexcept
Adds an observing matcher to the collector.
static constexpr auto group(exclude_t< NoneOf... >=exclude_t{}) noexcept
Adds a grouping matcher to the collector.
static constexpr auto where(exclude_t< NoneOf... >=exclude_t{}) noexcept
Updates the filter of the last added matcher.
static constexpr auto update() noexcept
Adds an observing matcher to the collector.
static constexpr auto group(exclude_t< NoneOf... >=exclude_t{}) noexcept
Adds a grouping matcher to the collector.
Alias for exclusion lists.
Provides a common way to define storage types.
A class to use to push around lists of types, nothing more.