EnTT
3.6.0
|
Observer. More...
#include <observer.hpp>
Public Types | |
using | entity_type = Entity |
Underlying entity identifier. | |
using | size_type = std::size_t |
Unsigned integer type. | |
using | iterator = typename basic_sparse_set< Entity >::iterator |
Random access iterator type. | |
Public Member Functions | |
basic_observer () | |
Default constructor. | |
basic_observer (const basic_observer &)=delete | |
Default copy constructor, deleted on purpose. | |
basic_observer (basic_observer &&)=delete | |
Default move constructor, deleted on purpose. | |
template<typename... Matcher> | |
basic_observer (basic_registry< entity_type > ®, basic_collector< Matcher... >) | |
Creates an observer and connects it to a given registry. More... | |
~basic_observer ()=default | |
Default destructor. | |
basic_observer & | operator= (const basic_observer &)=delete |
Default copy assignment operator, deleted on purpose. More... | |
basic_observer & | operator= (basic_observer &&)=delete |
Default move assignment operator, deleted on purpose. More... | |
template<typename... Matcher> | |
void | connect (basic_registry< entity_type > ®, basic_collector< Matcher... >) |
Connects an observer to a given registry. More... | |
void | disconnect () |
Disconnects an observer from the registry it keeps track of. | |
size_type | size () const noexcept |
Returns the number of elements in an observer. More... | |
bool | empty () const noexcept |
Checks whether an observer is empty. More... | |
const entity_type * | data () const noexcept |
Direct access to the list of entities of the observer. More... | |
iterator | begin () const noexcept |
Returns an iterator to the first entity of the observer. More... | |
iterator | end () const noexcept |
Returns an iterator that is past the last entity of the observer. More... | |
void | clear () noexcept |
Clears the underlying container. | |
template<typename Func > | |
void | each (Func func) const |
Iterates entities and applies the given function object to them. More... | |
template<typename Func > | |
void | each (Func func) |
Iterates entities and applies the given function object to them, then clears the observer. More... | |
Observer.
An observer returns all the entities and only the entities that fit the requirements of at least one matcher. Moreover, it's guaranteed that the entity list is tightly packed in memory for fast iterations.
In general, observers don't stay true to the order of any set of components.
Observers work mainly with two types of matchers, provided through a collector:
If an entity respects the requirements of multiple matchers, it will be returned once and only once by the observer in any case.
Matchers support also filtering by means of a where clause that accepts both a list of types and an exclusion list.
Whenever a matcher finds that an entity matches its requirements, the condition of the filter is verified before to register the entity itself. Moreover, a registered entity isn't returned by the observer if the condition set by the filter is broken in the meantime.
Important
Iterators aren't invalidated if:
In all the other cases, modifying the pools of the given components in any way invalidates all the iterators and using them results in undefined behavior.
Entity | A valid entity type (see entt_traits for more details). |
Definition at line 172 of file observer.hpp.
|
inline |
Creates an observer and connects it to a given registry.
Matcher | Types of matchers to use to initialize the observer. |
reg | A valid reference to a registry. |
Definition at line 298 of file observer.hpp.
|
inlinenoexcept |
Returns an iterator to the first entity of the observer.
The returned iterator points to the first entity of the observer. If the container is empty, the returned iterator will be equal to end()
.
Definition at line 379 of file observer.hpp.
|
inline |
Connects an observer to a given registry.
Matcher | Types of matchers to use to initialize the observer. |
reg | A valid reference to a registry. |
Definition at line 325 of file observer.hpp.
|
inlinenoexcept |
Direct access to the list of entities of the observer.
The returned pointer is such that range [data(), data() + size())
is always a valid range, even if the container is empty.
begin
/end
iterators.Definition at line 367 of file observer.hpp.
|
inline |
Iterates entities and applies the given function object to them, then clears the observer.
Func | Type of the function object to invoke. |
func | A valid function object. |
Definition at line 432 of file observer.hpp.
|
inline |
Iterates entities and applies the given function object to them.
The function object is invoked for each entity.
The signature of the function must be equivalent to the following form:
Func | Type of the function object to invoke. |
func | A valid function object. |
Definition at line 416 of file observer.hpp.
|
inlinenoexcept |
Checks whether an observer is empty.
Definition at line 351 of file observer.hpp.
|
inlinenoexcept |
Returns an iterator that is past the last entity of the observer.
The returned iterator points to the entity following the last entity of the observer. Attempting to dereference the returned iterator results in undefined behavior.
Definition at line 393 of file observer.hpp.
|
delete |
Default move assignment operator, deleted on purpose.
|
delete |
Default copy assignment operator, deleted on purpose.
|
inlinenoexcept |
Returns the number of elements in an observer.
Definition at line 343 of file observer.hpp.