-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutations.rs
68 lines (56 loc) · 1.28 KB
/
mutations.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
65
66
67
68
use stecs::prelude::*;
struct World {
blocks: StructOf<Vec<Block>>,
}
#[derive(SplitFields)]
#[split(debug)]
struct Position {
x: i64,
}
#[derive(SplitFields)]
#[split(debug)]
struct Block {
#[split(nested)]
position: Position,
height: i64,
}
fn main() {
let mut world = World {
blocks: Default::default(),
};
world.blocks.insert(Block {
position: Position { x: 0 },
height: 2,
});
// Print
for (_, block) in world.blocks.iter() {
println!("{:?}", block);
}
// Iterate over the whole archetype
println!("position.x += height");
for (_, block) in world.blocks.iter_mut() {
*block.position.x += *block.height;
}
// Print
for (_, block) in world.blocks.iter() {
println!("{:?}", block);
}
// Iterate over a storage
println!("height += 1");
for x in world.blocks.height.iter_mut() {
*x += 1;
}
// Print
for (_, block) in world.blocks.iter() {
println!("{:?}", block);
}
// Iterate over a whole nested archetype
println!("position.x += 1");
for (_, position) in world.blocks.position.iter_mut() {
*position.x += 1;
}
// Print
for (_, block) in world.blocks.iter() {
println!("{:?}", block);
}
}