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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*!
Easy to use entity component system.
# Overview
- Entity is set of components identified by unique ID.
- Component is struct with data.
- System is behaviour working with components.
All components must implement Component trait:
```ignore
struct Position {
x : i32
}
impl Component for Position {}
```
Entity can be created almost everywhere:
```ignore
let entity = entity_manager.create_entity();
entity.add_component(Position {x : 0, y : 0, z : 0});
entity.add_component(Velocity {x : 1});
entity.refresh();
```
Simplest system can be created with macro.
typically, you will need only process some components, like this:
```ignore
process_entities!((MoveSystem): |pos: Position, vel: Velocity| => {
pos.x += vel.x;
println!("Moving! position: {}, velocity: {}", pos.x, vel.x);
});
```
This system now must be added to world like this:
```ignore
world.set_system(MoveSystem::new());
```
this macro will be expanded to this:
```ignore
pub struct MoveSystem;
impl System for MoveSystem {
fn aspect() -> Aspect {
aspect_all![Position, Velocity]
}
fn process_one(&mut self, entity: &mut Entity) {
let mut pos = entity.get_component::<Position>();
let mut vel = entity.get_component::<Velocity>();
pos.x += vel.x;
println!("Moving! position: {}, velocity: {}", pos.x, vel.x);
}
}
```
*/
extern crate tinyprof;
extern crate time;
pub use *;