examples/systems/
system_pipeline.rs1use crate::z_ignore_test_common::*;
2
3use flecs_ecs::prelude::*;
4
5#[derive(Debug, Component)]
6pub struct Position {
7 pub x: f32,
8 pub y: f32,
9}
10
11#[derive(Debug, Component)]
12pub struct Velocity {
13 pub x: f32,
14 pub y: f32,
15}
16
17fn main() {
18 let world = World::new();
19
20 world
22 .system::<(&mut Position, &Velocity)>()
23 .kind::<flecs::pipeline::OnUpdate>()
24 .each(|(p, v)| {
25 p.x += v.x;
26 p.y += v.y;
27 });
28
29 world
31 .system::<&Position>()
32 .kind::<flecs::pipeline::PostUpdate>()
33 .each_entity(|e, p| {
34 println!("{}: {{ {}, {} }}", e.name(), p.x, p.y);
35 });
36
37 world
39 .entity_named("e1")
40 .set(Position { x: 10.0, y: 20.0 })
41 .set(Velocity { x: 1.0, y: 2.0 });
42
43 world
44 .entity_named("e2")
45 .set(Position { x: 10.0, y: 20.0 })
46 .set(Velocity { x: 3.0, y: 4.0 });
47
48 world.progress();
52
53 }
57
58#[cfg(feature = "flecs_nightly_tests")]
59#[test]
60fn test() {
61 let output_capture = OutputCapture::capture().unwrap();
62 main();
63 output_capture.test("system_pipeline".to_string());
64}