Skip to main content

steel_core/chunk/
status.rs

1//! Chunk generation status.
2
3use wincode::{SchemaRead, SchemaWrite};
4
5use super::heightmap::HeightmapType;
6
7/// The status of a chunk.
8#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, SchemaWrite, SchemaRead)]
9pub enum ChunkStatus {
10    /// The chunk is empty.
11    Empty,
12    /// The chunk is being processed for structure starts.
13    StructureStarts,
14    /// The chunk is being processed for structure references.
15    StructureReferences,
16    /// The chunk is being processed for biomes.
17    Biomes,
18    /// The chunk is being processed for noise.
19    Noise,
20    /// The chunk is being processed for surfaces.
21    Surface,
22    /// The chunk is being processed for carvers.
23    Carvers,
24    /// The chunk is being processed for features.
25    Features,
26    /// The chunk is being initialized for light.
27    InitializeLight,
28    /// The chunk is being lit.
29    Light,
30    /// The chunk is being spawned.
31    Spawn,
32    /// The chunk is fully generated.
33    Full,
34}
35
36impl ChunkStatus {
37    /// Gets the index of the status.
38    #[must_use]
39    pub const fn get_index(self) -> usize {
40        self as usize
41    }
42
43    /// Gets the status from an index.
44    #[must_use]
45    pub const fn from_index(index: usize) -> Option<Self> {
46        match index {
47            0 => Some(Self::Empty),
48            1 => Some(Self::StructureStarts),
49            2 => Some(Self::StructureReferences),
50            3 => Some(Self::Biomes),
51            4 => Some(Self::Noise),
52            5 => Some(Self::Surface),
53            6 => Some(Self::Carvers),
54            7 => Some(Self::Features),
55            8 => Some(Self::InitializeLight),
56            9 => Some(Self::Light),
57            10 => Some(Self::Spawn),
58            11 => Some(Self::Full),
59            _ => None,
60        }
61    }
62
63    /// Gets the next status in the generation order.
64    #[must_use]
65    pub const fn next(self) -> Option<Self> {
66        match self {
67            Self::Empty => Some(Self::StructureStarts),
68            Self::StructureStarts => Some(Self::StructureReferences),
69            Self::StructureReferences => Some(Self::Biomes),
70            Self::Biomes => Some(Self::Noise),
71            Self::Noise => Some(Self::Surface),
72            Self::Surface => Some(Self::Carvers),
73            Self::Carvers => Some(Self::Features),
74            Self::Features => Some(Self::InitializeLight),
75            Self::InitializeLight => Some(Self::Light),
76            Self::Light => Some(Self::Spawn),
77            Self::Spawn => Some(Self::Full),
78            Self::Full => None,
79        }
80    }
81
82    /// Gets the parent status in the generation order.
83    #[must_use]
84    pub const fn parent(self) -> Option<Self> {
85        match self {
86            Self::Empty => None,
87            Self::StructureStarts => Some(Self::Empty),
88            Self::StructureReferences => Some(Self::StructureStarts),
89            Self::Biomes => Some(Self::StructureReferences),
90            Self::Noise => Some(Self::Biomes),
91            Self::Surface => Some(Self::Noise),
92            Self::Carvers => Some(Self::Surface),
93            Self::Features => Some(Self::Carvers),
94            Self::InitializeLight => Some(Self::Features),
95            Self::Light => Some(Self::InitializeLight),
96            Self::Spawn => Some(Self::Light),
97            Self::Full => Some(Self::Spawn),
98        }
99    }
100
101    /// Returns the heightmap types that should be updated at this status.
102    ///
103    /// Before CARVERS status, worldgen heightmaps are used.
104    /// At CARVERS and after, final heightmaps are used.
105    #[must_use]
106    pub const fn heightmaps_after(self) -> &'static [HeightmapType] {
107        match self {
108            Self::Empty
109            | Self::StructureStarts
110            | Self::StructureReferences
111            | Self::Biomes
112            | Self::Noise
113            | Self::Surface => HeightmapType::worldgen_types(),
114            Self::Carvers
115            | Self::Features
116            | Self::InitializeLight
117            | Self::Light
118            | Self::Spawn
119            | Self::Full => HeightmapType::final_types(),
120        }
121    }
122}