Struct ecs_observer_desc_t


#include <include/flecs.h>

typedef struct ecs_observer_desc_t


Used with ecs_observer_init.

Mentioned in


Lines 761-810 in include/flecs.h.

typedef struct ecs_observer_desc_t {
    int32_t _canary;

    /* Existing entity to associate with observer (optional) */
    ecs_entity_t entity;

    /* Filter for observer */
    ecs_filter_desc_t filter;

    /* Events to observe (OnAdd, OnRemove, OnSet, UnSet) */
    ecs_entity_t events[ECS_OBSERVER_DESC_EVENT_COUNT_MAX];

    /* When observer is created, generate events from existing data. For example,
     * EcsOnAdd Position would match all existing instances of Position.
     * This is only supported for events that are iterable (see EcsIterable) */
    bool yield_existing;

    /* Callback to invoke on an event, invoked when the observer matches. */
    ecs_iter_action_t callback;

    /* Callback invoked on an event. When left to NULL the default runner
     * is used which matches the event with the observer's filter, and calls
     * 'callback' when it matches. 
     * A reason to override the run function is to improve performance, if there
     * are more efficient way to test whether an event matches the observer than
     * the general purpose query matcher. */
    ecs_run_action_t run;

    /* User context to pass to callback */
    void *ctx;

    /* Context to be used for language bindings */
    void *binding_ctx;

    /* Callback to free ctx */
    ecs_ctx_free_t ctx_free;

    /* Callback to free binding_ctx */     
    ecs_ctx_free_t binding_ctx_free;

    /* Observable with which to register the observer */
    ecs_poly_t *observable;

    /* Optional shared last event id for multiple observers. Ensures only one
     * of the observers with the shared id gets triggered for an event */
    int32_t *last_event_id;

    /* Used for internal purposes */
    int32_t term_index;
} ecs_observer_desc_t;