examples/systems/
system_custom_pipeline.rs

1use crate::z_ignore_test_common::*;
2
3use flecs_ecs::prelude::*;
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#[derive(Debug, Component, Default)]
13struct Physics;
14
15fn main() {
16    let world = World::new();
17
18    // Create a pipeline that matches systems with Physics. Note that this
19    // pipeline does not require the use of phases (see custom_phases) or of the
20    // DependsOn relationship.
21    let pipeline = world
22        .pipeline()
23        .with_id(flecs::system::System::ID)
24        .with::<&Physics>()
25        .build();
26
27    // Configure the world to use the custom pipeline
28    world.set_pipeline_id(pipeline.entity());
29
30    // Create system with Physics tag
31    world.system::<()>().kind::<Physics>().run(|mut it| {
32        while it.next() {
33            println!("System with Physics ran!");
34        }
35    });
36
37    // Create system without Physics tag
38    world.system::<()>().run(|mut it| {
39        while it.next() {
40            println!("System without Physics ran!");
41        }
42    });
43
44    // Runs the pipeline & system
45    world.progress();
46
47    // Output:
48    //   System with Physics ran!
49}
50
51#[cfg(feature = "flecs_nightly_tests")]
52#[test]
53fn test() {
54    let output_capture = OutputCapture::capture().unwrap();
55    main();
56    output_capture.test("system_custom_pipeline".to_string());
57}