Class observer_builder_i

Synopsis

#include <include/flecs/addons/cpp/builder.hpp>

template<typename Base, typename ... Components>
class observer_builder_i : public filter_builder_i<Base, Components ...>

Description

No description yet.

Inheritance

Ancestors: filter_builder_i

Methods

observer_builder_i overload
ctxSet system context
eventSpecify when the event(s) for which the trigger run.
selfAssociate observer with entity
world

Source

Lines 791-835 in include/flecs/addons/cpp/builder.hpp.

template<typename Base, typename ... Components>
class observer_builder_i : public filter_builder_i<Base, Components ...> {
    using BaseClass = filter_builder_i<Base, Components ...>;
public:
    observer_builder_i()
        : BaseClass(nullptr)
        , m_desc(nullptr)
        , m_event_count(0) { }

    observer_builder_i(ecs_observer_desc_t *desc) 
        : BaseClass(&desc->filter)
        , m_desc(desc)
        , m_event_count(0) { }

    /** Specify when the event(s) for which the trigger run.
     * @param kind The kind that specifies when the system should be ran.
     */
    Base& event(entity_t kind) {
        m_desc->events[m_event_count ++] = kind;
        return *this;
    }

    /** Associate observer with entity */
    Base& self(flecs::entity self) {
        m_desc->self = self;
        return *this;
    }

    /** Set system context */
    Base& ctx(void *ptr) {
        m_desc->ctx = ptr;
        return *this;
    }    

protected:
    virtual flecs::world_t* world() = 0;

private:
    operator Base&() {
        return *static_cast<Base*>(this);
    }

    ecs_observer_desc_t *m_desc;
    int32_t m_event_count;
};