-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsystem_pipeline.rs
64 lines (53 loc) · 1.52 KB
/
system_pipeline.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::z_ignore_test_common::*;
use flecs_ecs::prelude::*;
#[derive(Debug, Component)]
pub struct Position {
pub x: f32,
pub y: f32,
}
#[derive(Debug, Component)]
pub struct Velocity {
pub x: f32,
pub y: f32,
}
fn main() {
let world = World::new();
// Create a system for moving an entity
world
.system::<(&mut Position, &Velocity)>()
.kind::<flecs::pipeline::OnUpdate>()
.each(|(p, v)| {
p.x += v.x;
p.y += v.y;
});
// Create a system for printing the entity position
world
.system::<&Position>()
.kind::<flecs::pipeline::PostUpdate>()
.each_entity(|e, p| {
println!("{}: {{ {}, {} }}", e.name(), p.x, p.y);
});
// Create a few test entities for a Position, Velocity query
world
.entity_named("e1")
.set(Position { x: 10.0, y: 20.0 })
.set(Velocity { x: 1.0, y: 2.0 });
world
.entity_named("e2")
.set(Position { x: 10.0, y: 20.0 })
.set(Velocity { x: 3.0, y: 4.0 });
// Run the default pipeline. This will run all systems ordered by their
// phase. Systems within the same phase are ran in declaration order. This
// function is usually called in a loop.
world.progress();
// Output:
// e1: { 11, 22 }
// e2: { 13, 24 }
}
#[cfg(feature = "flecs_nightly_tests")]
#[test]
fn test() {
let output_capture = OutputCapture::capture().unwrap();
main();
output_capture.test("system_pipeline".to_string());
}