Skip to content
Flecs v4.1
systems/custom_pipeline

  • C

    View on GitHub

    1#include <custom_pipeline.h>
    2#include <stdio.h>
    3
    4// Custom pipelines make it possible for applications to override which systems
    5// are ran by a pipeline and how they are ordered. Pipelines are queries under
    6// the hood, and custom pipelines override the query used for system matching.
    7
    8// If you only want to use custom phases in addition or in place of the builtin
    9// phases see the custom_phases and custom_phases_no_builtin examples, as this
    10// does not require using a custom pipeline.
    11
    12// Dummy system
    13void Sys(ecs_iter_t *it) {
    14 (void)it;
    15
    16 printf("System ran!\n");
    17}
    18
    19int main(int argc, char *argv[]) {
    20 ecs_world_t *ecs = ecs_init_w_args(argc, argv);
    21
    22 ECS_TAG(ecs, Physics);
    23
    24 // Create a pipeline that matches systems with Physics. Note that this
    25 // pipeline does not require the use of phases (see custom_phases) or of the
    26 // DependsOn relationship.
    27 ecs_entity_t pipeline = ecs_pipeline(ecs, {
    28 .query.terms = {
    29 { .id = EcsSystem }, // Mandatory, must always match systems
    30 { .id = Physics }
    31 }
    32 });
    33
    34 // Configure the world to use the custom pipeline
    35 ecs_set_pipeline(ecs, pipeline);
    36
    37 // Create system with Physics tag
    38 ECS_SYSTEM(ecs, Sys, Physics, 0);
    39
    40 // Runs the pipeline & system
    41 ecs_progress(ecs, 0);
    42
    43 return ecs_fini(ecs);
    44
    45 // Output
    46 // System ran!
    47}
    const ecs_entity_t EcsSystem
    Tag added to systems.
    FLECS_API void ecs_set_pipeline(ecs_world_t *world, ecs_entity_t pipeline)
    Set a custom pipeline.
    FLECS_API bool ecs_progress(ecs_world_t *world, ecs_ftime_t delta_time)
    Progress a world.
    #define ecs_pipeline(world,...)
    Convenience macro to create a pipeline.
    Definition pipeline.h:82
    #define ECS_SYSTEM(world, id, phase,...)
    Declare and define a system.
    Definition system.h:263
    ecs_id_t ecs_entity_t
    An entity identifier.
    Definition flecs.h:395
    struct ecs_world_t ecs_world_t
    A world is the container for all ECS data and supporting features.
    Definition flecs.h:439
    #define ECS_TAG(world, id)
    Declare and define a tag.
    Definition flecs_c.h:59
    int ecs_fini(ecs_world_t *world)
    Delete a world.
    ecs_world_t * ecs_init_w_args(int argc, char *argv[])
    Create a new world with arguments.
    Iterator.
    Definition flecs.h:1183

  • C++

    View on GitHub

    1#include <custom_pipeline.h>
    2#include <iostream>
    3
    4// Custom pipelines make it possible for applications to override which systems
    5// are ran by a pipeline and how they are ordered. Pipelines are queries under
    6// the hood, and custom pipelines override the query used for system matching.
    7
    8// If you only want to use custom phases in addition or in place of the builtin
    9// phases see the custom_phases and custom_phases_no_builtin examples, as this
    10// does not require using a custom pipeline.
    11
    12struct Physics {};
    13
    14int main(int argc, char *argv[]) {
    15 flecs::world ecs(argc, argv);
    16
    17 // Create a pipeline that matches systems with Physics. Note that this
    18 // pipeline does not require the use of phases (see custom_phases) or of the
    19 // DependsOn relationship.
    20 flecs::entity pipeline = ecs.pipeline()
    21 .with(flecs::System) // Mandatory, must always match systems
    22 .with<Physics>()
    23 .build();
    24
    25 // Configure the world to use the custom pipeline
    26 ecs.set_pipeline(pipeline);
    27
    28 // Create system with Physics tag
    29 ecs.system()
    30 .kind<Physics>()
    31 .run([](flecs::iter&) {
    32 std::cout << "System ran!\n";
    33 });
    34
    35 // Runs the pipeline & system
    36 ecs.progress();
    37
    38 // Output:
    39 // System ran!
    40}
    Entity.
    Definition entity.hpp:30
    Class for iterating over query results.
    Definition iter.hpp:68
    The world.
    Definition world.hpp:129