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
83
84
85
86
87
88
|
use crate::sim::sim::UpdateCtx;
mod fire;
mod gas;
mod sand;
mod smoke;
mod water;
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum MaterialId {
Void = 0,
Sand,
Wood,
Water,
Gas,
Fire,
Smoke,
}
pub struct MaterialDef {
pub name: &'static str,
pub color: (u8, u8, u8, u8),
pub density: u8,
pub sim_update: Option<fn(ctx: &mut UpdateCtx) -> ()>,
}
static MATERIALS: [MaterialDef; 7] = [
MaterialDef {
name: "Void",
color: (0x00, 0x00, 0x00, 0x00),
density: 0,
sim_update: None,
},
MaterialDef {
name: "Sand",
color: (0xDE, 0xCB, 0x85, 0xFF),
density: 50,
sim_update: Some(sand::sim_update),
},
MaterialDef {
name: "Wood",
color: (0x85, 0x56, 0x1D, 0xFF),
density: 50,
sim_update: None,
},
MaterialDef {
name: "Water",
color: (0x38, 0xA9, 0xFF, 0xFF),
density: 40,
sim_update: Some(water::sim_update),
},
MaterialDef {
name: "Gas",
color: (0xBD, 0xFF, 0xE4, 0xAA),
density: 10,
sim_update: Some(gas::sim_update),
},
MaterialDef {
name: "Fire",
color: (0xFC, 0x66, 0x00, 0xAA),
// for now this matches wood
density: 50,
sim_update: Some(fire::sim_update),
},
MaterialDef {
name: "Smoke",
color: (0x32, 0x35, 0x36, 0xAA),
density: 15,
sim_update: Some(smoke::sim_update),
},
];
impl MaterialId {
pub const ALL: [MaterialId; 7] = [
MaterialId::Void,
MaterialId::Sand,
MaterialId::Wood,
MaterialId::Water,
MaterialId::Gas,
MaterialId::Fire,
MaterialId::Smoke,
];
#[inline]
pub fn def(self) -> &'static MaterialDef {
&MATERIALS[self as usize]
}
}
|