Class system

Synopsis

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

template<typename ... Components>
class system : public entity

Description

No description yet.

Mentioned in

Methods

system overload
ctx overload
disable
enable
interval overloadSet system interval
interval overloadGet interval
query
rate overloadSet system rate
run
run_worker

Source

Lines 69-169 in include/flecs/addons/cpp/system.hpp.

template<typename ... Components>
class system : public entity
{
public:
    explicit system() 
        : entity() { }

    explicit system(flecs::world_t *world, flecs::entity_t id)
        : entity(world, id) { }

    /** Set system interval.
     * This operation will cause the system to be ran at the specified interval.
     *
     * The timer is synchronous, and is incremented each frame by delta_time.
     *
     * @param interval The interval value.
     */
    void interval(FLECS_FLOAT interval) {
        ecs_set_interval(m_world, m_id, interval);
    }

    /** Set system rate.
     * This operation will cause the system to be ran at a multiple of the 
     * provided tick source. The tick source may be any entity, including
     * another system.
     *
     * @param tick_source The tick source.
     * @param rate The multiple at which to run the system.
     */
    void rate(const flecs::entity& tick_source, int32_t rate) {
        ecs_set_rate(m_world, m_id, rate, tick_source.id());
    }

    /** Set system rate.
     * This operation will cause the system to be ran at a multiple of the 
     * frame tick frequency. If a tick source was provided, this just updates
     * the rate of the system.
     *
     * @param rate The multiple at which to run the system.
     */
    void rate(int32_t rate) {
        ecs_set_rate(m_world, m_id, rate, 0);
    }    

    /** Get interval.
     * Get interval at which the system is running.
     *
     * @return The timer entity.
     */
    FLECS_FLOAT interval() {
        return ecs_get_interval(m_world, m_id);
    }

    void enable() {
        ecs_enable(m_world, m_id, true);
    }

    void disable() {
        ecs_enable(m_world, m_id, false);
    }

    void ctx(void *ctx) {
        if (ecs_has(m_world, m_id, EcsSystem)) {
            ecs_system_desc_t desc = {};
            desc.entity.entity = m_id;
            desc.ctx = ctx;
            ecs_system_init(m_world, &desc);
        } else {
            ecs_trigger_desc_t desc = {};
            desc.entity.entity = m_id;
            desc.ctx = ctx;
            ecs_trigger_init(m_world, &desc);
        }
    }

    void* ctx() const {
        if (ecs_has(m_world, m_id, EcsSystem)) {
            return ecs_get_system_ctx(m_world, m_id);
        } else {
            return ecs_get_trigger_ctx(m_world, m_id);
        }
    }

    query_base query() const {
        return query_base(m_world, ecs_system_get_query(m_world, m_id));
    }

    system_runner_fluent run(FLECS_FLOAT delta_time = 0.0f, void *param = nullptr) const {
        return system_runner_fluent(m_world, m_id, 0, 0, delta_time, param);
    }

    system_runner_fluent run_worker(
        int32_t stage_current, 
        int32_t stage_count, 
        FLECS_FLOAT delta_time = 0.0f, 
        void *param = nullptr) const 
    {
        return system_runner_fluent(
            m_world, m_id, stage_current, stage_count, delta_time, param);
    }
};