summaryrefslogtreecommitdiff
path: root/src/sim/materials/mod.rs
blob: 86ae7d51aa228fdb67bb140779da89b69bf8be72 (plain)
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
use crate::sim::sim::UpdateCtx;

mod sand;
mod water;

#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum MaterialId {
    Void = 0,
    Sand,
    Wood,
    Water,
}

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; 4] = [
    MaterialDef {
        name: "Void",
        color: (0x00, 0x00, 0x00, 0xFF),
        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),
    },
];

impl MaterialId {
    pub const ALL: [MaterialId; 4] = [
        MaterialId::Void,
        MaterialId::Sand,
        MaterialId::Wood,
        MaterialId::Water,
    ];
    #[inline]
    pub fn def(self) -> &'static MaterialDef {
        &MATERIALS[self as usize]
    }
}