Flecs v4.0
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 event.
 
void ecs_enqueue (ecs_world_t *world, ecs_event_desc_t *desc)
 Enqueue event.
 
ecs_entity_t ecs_observer_init (ecs_world_t *world, const ecs_observer_desc_t *desc)
 Create observer.
 
const ecs_observer_tecs_observer_get (const ecs_world_t *world, ecs_entity_t observer)
 Get 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 event.

This sends an event to matching triggers & 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 builtin flecs events, as this may violate assumptions the code makes about the conditions under which those events are sent.

Triggers 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.
descEvent parameters.
See also
ecs_enqueue()

◆ ecs_enqueue()

void ecs_enqueue ( ecs_world_t * world,
ecs_event_desc_t * desc )

Enqueue 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.
descEvent parameters.

◆ ecs_observer_get()

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

Get observer object.

Returns 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 observer.

Observers are like triggers, but can subscribe for multiple 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.