Skip to content
Flecs v4.1
flecs::observer Struct Referencefinal

Observer. More...

#include <impl.hpp>

Public Member Functions

 observer ()
 Default constructor.
 observer (flecs::world_t *world, const ecs_observer_desc_t *desc)
 Construct from a world and an observer descriptor.
observerctx (void *ctx)
 Set the observer context.
void * ctx () const
 Get the observer context.
template<typename Func>
observerrun (Func &&func)
 Replace the observer's run callback.
template<typename Func>
observereach (Func &&func)
 Replace the observer's each callback.
template<typename Func>
observerrun_each (Func &&func)
 Replace the observer's run callback and use an each callback for iteration.
flecs::query query () const
 Get the query for this observer.
 entity ()
 Default constructor.
 entity (const flecs::world_t *world, flecs::entity_t id)
 Wrap an existing entity ID.
 entity (world_t *world)
 Create a new entity.
 entity (world_t *world, const char *name, const char *sep="::", const char *root_sep="::")
 Create a named entity.
 entity (world_t *world, flecs::entity_t parent, const char *name, const char *sep="::", const char *root_sep="::")
 Create a named entity for a parent using ChildOf hierarchy storage.
 entity (world_t *world, const flecs::Parent &parent, const char *name=nullptr)
 Create a named entity for a parent using Parent hierarchy storage.
 entity (entity_t id)
 Conversion from flecs::entity_t to flecs::entity.
Public Member Functions inherited from flecs::entity
 entity ()
 Default constructor.
 entity (const flecs::world_t *world, flecs::entity_t id)
 Wrap an existing entity ID.
 entity (world_t *world)
 Create a new entity.
 entity (world_t *world, const char *name, const char *sep="::", const char *root_sep="::")
 Create a named entity.
 entity (world_t *world, flecs::entity_t parent, const char *name, const char *sep="::", const char *root_sep="::")
 Create a named entity for a parent using ChildOf hierarchy storage.
 entity (world_t *world, const flecs::Parent &parent, const char *name=nullptr)
 Create a named entity for a parent using Parent hierarchy storage.
 entity (entity_t id)
 Conversion from flecs::entity_t to flecs::entity.
template<typename... T, typename... Args>
decltype(auto) ensure (Args... args) const
template<typename Second>
Second & ensure_second (entity_t first) const
template<typename... T, typename... Args>
void modified (Args... args) const
template<typename T, if_t< is_actual< T >::value > = 0>
ref< T > get_ref_w_id (flecs::id_t component) const
 Get reference to component specified by component ID.
template<typename... T, typename... Args>
auto get_ref (Args... args) const
template<typename Second>
ref< Second > get_ref_second (flecs::entity_t first) const
void clear () const
 Clear an entity.
void destruct () const
 Delete an entity.
void set_child_order (flecs::entity_t *children, int32_t child_count) const
 Set child order.
flecs::entity_view view () const
 Return the entity as an entity_view.
const char * from_json (const char *json)
 Deserialize an entity from JSON.
const char * from_json (const char *json)
 Deserialize an entity from JSON.
Public Member Functions inherited from flecs::entity_builder< entity >
const entityset_doc_name (const char *name) const
 Set human-readable name.
const entityset_doc_brief (const char *brief) const
 Set brief description.
const entityset_doc_detail (const char *detail) const
 Set detailed description.
const entityset_doc_link (const char *link) const
 Set link to external documentation.
const entityset_doc_color (const char *color) const
 Set doc color.
const entityset_doc_uuid (const char *uuid) const
 Set doc UUID.
const entityobserve (flecs::entity_t evt, Func &&callback) const
 Observe an event on an entity.
const entityobserve (Func &&callback) const
 Observe an event on an entity.
const entityobserve (Func &&callback) const
 Observe an event on an entity.
const entityset_json (flecs::id_t e, const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a component from JSON.
const entityset_json (flecs::entity_t r, flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a pair from JSON.
const entityset_json (const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a component from JSON.
const entityset_json (const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a pair from JSON.
const entityset_json (flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a pair from JSON.
const entityset_json_second (flecs::entity_t r, const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a pair from JSON.
 entity_view ()
 Default constructor.
 entity_view (flecs::world_t *world, flecs::id_t id)
 Wrap an existing entity ID.
 entity_view (entity_t id)
 Implicit conversion from flecs::entity_t to flecs::entity_view.
const entityadd (Args... args) const
const entityadd_second (flecs::entity_t first) const
const entityadd_if (bool cond, flecs::id_t component) const
 Conditional add.
const entityis_a (entity_t second) const
 Shortcut for add(IsA, entity).
const entitychild_of (entity_t second) const
 Shortcut for add(ChildOf, entity).
const entitydepends_on (entity_t second) const
 Shortcut for add(DependsOn, entity).
const entityremove (Args... args) const
const entityremove_second (flecs::entity_t first) const
const entityauto_override (Args... args) const
const entityauto_override_second (flecs::entity_t first) const
const entityset_auto_override (A &&value) const
const entityemplace_auto_override (Args &&... args) const
const entityenable () const
 Enable an entity.
const entitydisable () const
 Disable an entity.
const entityset_ptr (entity_t comp, size_t size, const void *ptr) const
const entityset (A &&value) const
const entityset_second (entity_t first, Second &&value) const
const entityassign (A &&value) const
const entityassign_second (entity_t first, Second &&value) const
const entityinsert (const Func &func) const
 Set 1..N components.
const entityemplace (Args &&... args) const
const entityemplace_first (flecs::entity_t second, Args &&... args) const
const entityemplace_second (flecs::entity_t first, Args &&... args) const
const entityscope (const Func &func) const
 The function will be run with the scope set to the current entity.
const entityset_name (const char *name) const
 Set the entity name.
const entityset_alias (const char *name) const
 Set the entity alias.
const entityunit (const char *symbol, flecs::entity_t prefix=0, flecs::entity_t base=0, flecs::entity_t over=0, int32_t factor=0, int32_t power=0) const
 Make an entity a unit.
Public Member Functions inherited from flecs::entity_view
 entity_view ()
 Default constructor.
 entity_view (flecs::world_t *world, flecs::id_t id)
 Wrap an existing entity ID.
 entity_view (entity_t id)
 Implicit conversion from flecs::entity_t to flecs::entity_view.
entity_t id () const
 Get entity ID.
bool is_valid () const
 Check if entity is valid.
 operator bool () const
 Conversion to bool.
bool is_alive () const
 Check if entity is alive.
flecs::string_view name () const
 Return the entity name.
flecs::string_view symbol () const
 Return the entity symbol.
flecs::string path (const char *sep="::", const char *init_sep="::") const
 Return the entity path.
flecs::string path_from (flecs::entity_t parent, const char *sep="::", const char *init_sep="::") const
 Return the entity path relative to a parent.
template<typename Parent>
flecs::string path_from (const char *sep="::", const char *init_sep="::") const
 Return the entity path relative to a typed parent.
bool enabled () const
 Check if entity is enabled (does not have the Disabled tag).
flecs::type type () const
 Get the entity's type.
flecs::table table () const
 Get the entity's table.
flecs::table_range range () const
 Get table range for the entity.
template<typename Func>
void each (const Func &func) const
 Iterate (component) IDs of an entity.
template<typename Func>
void each (flecs::id_t first, flecs::id_t second, const Func &func) const
 Iterate matching pair IDs of an entity.
template<typename Func>
void each (const flecs::entity_view &rel, const Func &func) const
 Iterate targets for a given relationship.
template<typename First, typename Func>
void each (const Func &func) const
 Iterate targets for a given relationship.
template<typename Func>
void children (flecs::entity_t rel, Func &&func) const
 Iterate children for an entity.
template<typename Rel, typename Func>
void children (Func &&func) const
 Iterate children for an entity.
template<typename Func>
void children (Func &&func) const
 Iterate children for an entity.
template<typename... T, typename... Args>
decltype(auto) try_get (Args... args) const
template<typename... T, typename... Args>
decltype(auto) try_get_second (Args... args) const
template<typename... T>
auto try_get_n () const
template<typename Func, if_t< is_callable< Func >::value > = 0>
bool get (const Func &func) const
template<typename... T, typename... Args>
decltype(auto) get (Args... args) const
template<typename... T, typename... Args>
decltype(auto) get_second (Args... args) const
template<typename... T>
auto get_n () const
template<typename... T, typename... Args>
decltype(auto) try_get_mut (Args... args) const
template<typename... T, typename... Args>
decltype(auto) try_get_mut_second (Args... args) const
template<typename... T>
auto try_get_mut_n () const
template<typename... T, typename... Args>
decltype(auto) get_mut (Args... args) const
template<typename... T, typename... Args>
decltype(auto) get_mut_second (Args... args) const
template<typename... T>
auto get_mut_n () const
template<typename Enum>
Enum get_constant () const
 Get enum constant for enum relationship.
template<typename First>
flecs::entity target (int32_t index=0) const
 Get target for a given pair.
flecs::entity target (flecs::entity_t first, int32_t index=0) const
 Get target for a given pair.
flecs::entity target_for (flecs::entity_t relationship, flecs::id_t id) const
 Get the target of a pair for a given relationship ID.
template<typename T>
flecs::entity target_for (flecs::entity_t relationship) const
 Get the target of a pair for a given relationship ID.
template<typename First, typename Second>
flecs::entity target_for (flecs::entity_t relationship) const
 Get the target of a pair for a given relationship ID.
int32_t depth (flecs::entity_t rel) const
 Get the depth for a given relationship.
template<typename Rel>
int32_t depth () const
 Get the depth for a given relationship.
flecs::entity parent () const
 Get parent of entity.
flecs::entity lookup (const char *path, bool search_path=false) const
 Lookup an entity by name.
template<typename... T, typename... Args>
bool has (Args... args) const
template<typename Second>
bool has_second (flecs::entity_t first) const
template<typename... T, typename... Args>
bool owns (Args... args) const
template<typename Second>
bool owns_second (flecs::entity_t first) const
template<typename... T, typename... Args>
bool enabled (Args... args) const
flecs::entity clone (bool clone_value=true, flecs::entity_t dst_id=0) const
 Clone an entity.
flecs::entity mut (const flecs::world &stage) const
 Return a mutable entity handle for the current stage.
flecs::entity mut (const flecs::iter &it) const
 Same as mut(world), but for an iterator.
flecs::entity mut (const flecs::entity_view &e) const
 Same as mut(world), but for an entity.
flecs::string to_json (const flecs::entity_to_json_desc_t *desc=nullptr) const
 Serialize an entity to JSON.
const char * doc_name () const
 Get human-readable name.
const char * doc_brief () const
 Get brief description.
const char * doc_detail () const
 Get detailed description.
const char * doc_link () const
 Get link to external documentation.
const char * doc_color () const
 Get color.
const char * doc_uuid () const
 Get UUID.
int32_t alert_count (flecs::entity_t alert=0) const
 Return the number of alerts for an entity.
template<typename E>
to_constant () const
 Convert an entity to an enum constant.
void emit (flecs::entity_t evt) const
 Emit an event for an entity.
void emit (flecs::entity evt) const
 Emit an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void emit () const
 Emit an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void emit (const Evt &payload) const
 Emit an event with payload for an entity.
void enqueue (flecs::entity_t evt) const
 Enqueue an event for an entity.
void enqueue (flecs::entity evt) const
 Enqueue an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void enqueue () const
 Enqueue an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void enqueue (const Evt &payload) const
 Enqueue an event with payload for an entity.
int32_t alert_count (flecs::entity_t alert=0) const
 Return the number of alerts for an entity.
const char * doc_name () const
 Get human-readable name.
const char * doc_brief () const
 Get brief description.
const char * doc_detail () const
 Get detailed description.
const char * doc_link () const
 Get link to external documentation.
const char * doc_color () const
 Get color.
const char * doc_uuid () const
 Get UUID.
template<typename E>
to_constant () const
 Convert an entity to an enum constant.
void emit (flecs::entity_t evt) const
 Emit an event for an entity.
void emit (flecs::entity evt) const
 Emit an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void emit () const
 Emit an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void emit (const Evt &payload) const
 Emit an event with payload for an entity.
void enqueue (flecs::entity_t evt) const
 Enqueue an event for an entity.
void enqueue (flecs::entity evt) const
 Enqueue an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void enqueue () const
 Enqueue an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void enqueue (const Evt &payload) const
 Enqueue an event with payload for an entity.
flecs::string to_json (const flecs::entity_to_json_desc_t *desc=nullptr) const
 Serialize an entity to JSON.
Public Member Functions inherited from flecs::id
 id (flecs::id_t value)
 id (flecs::world_t *world, flecs::id_t value=0)
 id (flecs::world_t *world, flecs::id_t first, flecs::id_t second)
 id (flecs::world_t *world, const char *expr)
 id (flecs::id_t first, flecs::id_t second)
 id (const flecs::id &first, const flecs::id &second)
bool is_pair () const
 Test if ID is a pair (has first, second).
bool is_value_pair () const
 Test if ID is a value pair (has first, value).
bool is_wildcard () const
 Test if ID is a wildcard.
bool is_entity () const
 Test if ID is an entity.
flecs::entity entity () const
 Return ID as entity (only allowed when ID is a valid entity).
flecs::entity add_flags (flecs::id_t flags) const
 Return ID with flags added.
flecs::entity remove_flags (flecs::id_t flags) const
 Return ID with flags removed.
flecs::entity remove_flags () const
 Return ID without flags.
flecs::entity remove_generation () const
 Return ID without generation.
flecs::entity type_id () const
 Return component type of ID.
bool has_flags (flecs::id_t flags) const
 Test if ID has specified flags.
bool has_flags () const
 Test if ID has any flags.
flecs::entity flags () const
 Return ID flags set on ID.
bool has_relation (flecs::id_t first) const
 Test if ID has the specified first element.
flecs::entity first () const
 Get first element from a pair.
flecs::entity second () const
 Get second element from a pair.
flecs::string str () const
 Convert ID to string.
flecs::string flags_str () const
 Convert flags of ID to string.
flecs::id_t raw_id () const
 Return flecs::id_t value.
 operator flecs::id_t () const
flecs::world world () const
 Get the world.

Additional Inherited Members

Static Public Member Functions inherited from flecs::entity
static flecs::entity null (const flecs::world_t *world)
 Entity ID 0.
static flecs::entity null ()
 Entity ID 0 without a world.
Protected Member Functions inherited from flecs::entity_builder< entity >
const entityto_base () const
Protected Attributes inherited from flecs::id
flecs::world_tworld_
 World is optional, but guarantees that entity identifiers extracted from the ID are valid.
flecs::id_t id_
 The raw ID value.
const entityunit (flecs::entity_t prefix=0, flecs::entity_t base=0, flecs::entity_t over=0, int32_t factor=0, int32_t power=0) const
 Make an entity a derived unit.
const entityunit_prefix (const char *symbol, int32_t factor=0, int32_t power=0) const
 Make an entity a unit prefix.
const entityquantity (flecs::entity_t quantity) const
 Add a quantity to a unit.
const entityquantity () const
 Add a quantity to a unit.
const entityquantity () const
 Make an entity a quantity.

Detailed Description

Observer.

Definition at line 17 of file impl.hpp.

Constructor & Destructor Documentation

◆ observer() [1/2]

flecs::observer::observer ( )
inlineexplicit

Default constructor.

Definition at line 22 of file impl.hpp.

◆ observer() [2/2]

flecs::observer::observer ( flecs::world_t * world,
const ecs_observer_desc_t * desc )
inline

Construct from a world and an observer descriptor.

Definition at line 25 of file impl.hpp.

Member Function Documentation

◆ ctx() [1/2]

void * flecs::observer::ctx ( ) const
inline

Get the observer context.

Definition at line 39 of file impl.hpp.

◆ ctx() [2/2]

observer & flecs::observer::ctx ( void * ctx)
inline

Set the observer context.

Definition at line 31 of file impl.hpp.

◆ each()

template<typename Func>
observer & flecs::observer::each ( Func && func)
inline

Replace the observer's each callback.

Definition at line 56 of file impl.hpp.

◆ entity() [1/7]

Default constructor.

Creates an empty entity.

Definition at line 32 of file entity.hpp.

◆ entity() [2/7]

flecs::entity::entity ( const flecs::world_t * world,
flecs::entity_t id )
inlineexplicit

Wrap an existing entity ID.

Parameters
worldThe world in which the entity is created.
idThe entity ID.

Definition at line 39 of file entity.hpp.

◆ entity() [3/7]

flecs::entity::entity ( entity_t id)
inlineexplicit

Conversion from flecs::entity_t to flecs::entity.

Parameters
idThe entity_t value to convert.

Definition at line 124 of file entity.hpp.

◆ entity() [4/7]

flecs::entity::entity ( world_t * world)
inlineexplicit

Create a new entity.

Parameters
worldThe world in which to create the entity.

Definition at line 48 of file entity.hpp.

◆ entity() [5/7]

flecs::entity::entity ( world_t * world,
const char * name,
const char * sep = "::",
const char * root_sep = "::" )
inlineexplicit

Create a named entity.

Parameters
worldThe world in which to create the entity.
nameThe entity name.
sepString used to indicate scoping (Foo::Bar).
root_sepString used to indicate name is fully scoped (::Foo::Bar).

Definition at line 62 of file entity.hpp.

◆ entity() [6/7]

flecs::entity::entity ( world_t * world,
const flecs::Parent & parent,
const char * name = nullptr )
inlineexplicit

Create a named entity for a parent using Parent hierarchy storage.

The specified name cannot be a scoped identifier. For example:

  • OK: "Foo"
  • Not OK: "Foo::Bar"
Parameters
worldThe world in which to create the entity.
parentThe parent entity.
nameThe entity name (optional).

Definition at line 111 of file entity.hpp.

◆ entity() [7/7]

flecs::entity::entity ( world_t * world,
flecs::entity_t parent,
const char * name,
const char * sep = "::",
const char * root_sep = "::" )
inlineexplicit

Create a named entity for a parent using ChildOf hierarchy storage.

Parameters
worldThe world in which to create the entity.
parentThe parent entity ID.
nameThe entity name.
sepString used to indicate scoping (Foo::Bar).
root_sepString used to indicate name is fully scoped (::Foo::Bar).

Definition at line 85 of file entity.hpp.

◆ query()

flecs::query flecs::observer::query ( ) const
inline

Get the query for this observer.

Definition at line 78 of file impl.hpp.

◆ run()

template<typename Func>
observer & flecs::observer::run ( Func && func)
inline

Replace the observer's run callback.

Definition at line 45 of file impl.hpp.

◆ run_each()

template<typename Func>
observer & flecs::observer::run_each ( Func && func)
inline

Replace the observer's run callback and use an each callback for iteration.

Definition at line 68 of file impl.hpp.


The documentation for this struct was generated from the following file:
  • include/flecs/addons/cpp/mixins/observer/impl.hpp