examples/systems/
system_basics.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 let s = world
24 .system::<(&mut Position, &Velocity)>()
25 .each_entity(|e, (p, v)| {
26 p.x += v.x;
27 p.y += v.y;
28 println!("{}: {{ {}, {} }}", e.name(), p.x, p.y);
29 });
30
31 world
33 .entity_named("e1")
34 .set(Position { x: 10.0, y: 20.0 })
35 .set(Velocity { x: 1.0, y: 2.0 });
36
37 world
38 .entity_named("e2")
39 .set(Position { x: 10.0, y: 20.0 })
40 .set(Velocity { x: 3.0, y: 4.0 });
41
42 world.entity_named("e3").set(Position { x: 10.0, y: 20.0 });
44
45 s.run();
47
48 }
52
53#[cfg(feature = "flecs_nightly_tests")]
54#[test]
55fn test() {
56 let output_capture = OutputCapture::capture().unwrap();
57 main();
58 output_capture.test("system_basics".to_string());
59}