veloren_world/sim/
way.rs

1use vek::*;
2
3#[derive(Copy, Clone, Debug, Default)]
4pub struct Way {
5    /// Offset from chunk center in blocks (no more than half chunk width)
6    pub offset: Vec2<i8>,
7    /// Neighbor connections, one bit each
8    pub neighbors: u8,
9}
10
11impl Way {
12    pub fn is_way(&self) -> bool { self.neighbors != 0 }
13
14    pub fn clear(&mut self) { self.neighbors = 0; }
15}
16
17#[derive(Copy, Clone, Debug)]
18pub struct Path {
19    pub width: f32, // Actually radius
20}
21
22impl Default for Path {
23    fn default() -> Self { Self { width: 5.0 } }
24}
25
26impl Lerp for Path {
27    type Output = Self;
28
29    fn lerp_unclamped(from: Self, to: Self, factor: f32) -> Self::Output {
30        Self {
31            width: Lerp::lerp(from.width, to.width, factor),
32        }
33    }
34}
35
36impl Path {
37    /// Return the number of blocks of headspace required at the given path
38    /// distance
39    /// TODO: make this generic over width
40    pub fn head_space(&self, dist: f32) -> i32 { (8 - (dist * 0.25).powi(6).round() as i32).max(1) }
41
42    /// Get the surface colour of a path given the surrounding surface color
43    pub fn surface_color(&self, col: Rgb<u8>) -> Rgb<u8> { col.map(|e| (e as f32 * 0.7) as u8) }
44}