Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Observers

Functions for working with events and observers. More...

Collaboration diagram for Observers:

Classes

struct  ecs_observer_desc_t
 Used with ecs_observer_init(). More...
 
struct  ecs_event_desc_t
 Used with ecs_emit(). More...
 

Typedefs

typedef struct ecs_observer_desc_t ecs_observer_desc_t
 Used with ecs_observer_init().
 
typedef struct ecs_event_desc_t ecs_event_desc_t
 Used with ecs_emit().
 

Functions

void ecs_emit (ecs_world_t *world, ecs_event_desc_t *desc)
 Send an event.
 
void ecs_enqueue (ecs_world_t *world, ecs_event_desc_t *desc)
 Enqueue an event.
 
ecs_entity_t ecs_observer_init (ecs_world_t *world, const ecs_observer_desc_t *desc)
 Create an observer.
 
const ecs_observer_tecs_observer_get (const ecs_world_t *world, ecs_entity_t observer)
 Get the observer object.
 

Detailed Description

Functions for working with events and observers.

Function Documentation

◆ ecs_emit()

void ecs_emit ( ecs_world_t * world,
ecs_event_desc_t * desc )

Send an event.

This sends an event to matching observers and is the mechanism used by Flecs itself to send OnAdd, OnRemove, etc. events.

Applications can use this function to send custom events, where a custom event can be any regular entity.

Applications should not send built-in Flecs events, as this may violate assumptions the code makes about the conditions under which those events are sent.

Observers are invoked synchronously. It is therefore safe to use stack-based data as event context, which can be set in the "param" member.

Parameters
worldThe world.
descThe event parameters.
See also
ecs_enqueue()

◆ ecs_enqueue()

void ecs_enqueue ( ecs_world_t * world,
ecs_event_desc_t * desc )

Enqueue an event.

Same as ecs_emit(), but enqueues an event in the command queue instead. The event will be emitted when ecs_defer_end() is called.

If this operation is called when the provided world is not in deferred mode, it behaves just like ecs_emit().

Parameters
worldThe world.
descThe event parameters.

◆ ecs_observer_get()

const ecs_observer_t * ecs_observer_get ( const ecs_world_t * world,
ecs_entity_t observer )

Get the observer object.

Return the observer object. Can be used to access various information about the observer, like the query and context.

Parameters
worldThe world.
observerThe observer.
Returns
The observer object.

◆ ecs_observer_init()

ecs_entity_t ecs_observer_init ( ecs_world_t * world,
const ecs_observer_desc_t * desc )

Create an observer.

Observers can subscribe for one or more terms. An observer only triggers when the source of the event meets all terms.

See the documentation for ecs_observer_desc_t for more details.

Parameters
worldThe world.
descThe observer creation parameters.
Returns
The observer, or 0 if the operation failed.