Flecs v4.0
A fast entity component system (ECS) for C & C++
|
Functions for working with events and observers. More...
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_t * | ecs_observer_get (const ecs_world_t *world, ecs_entity_t observer) |
Get observer object. | |
Functions for working with events and observers.
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.
world | The world. |
desc | Event parameters. |
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().
world | The world. |
desc | Event parameters. |
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.
world | The world. |
observer | The observer. |
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.
world | The world. |
desc | The observer creation parameters. |