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 terrain is being generated.
19    Terrain,
20    /// The chunk is being processed for features.
21    Features,
22    /// The chunk is being initialized for light.
23    InitializeLight,
24    /// The chunk is being lit.
25    Light,
26    /// The chunk is being spawned.
27    Spawn,
28    /// The chunk is fully generated.
29    Full,
30}
31
32impl ChunkStatus {
33    /// Gets the index of the status.
34    #[must_use]
35    pub const fn get_index(self) -> usize {
36        self as usize
37    }
38
39    /// Gets the status from an index.
40    #[must_use]
41    pub const fn from_index(index: usize) -> Option<Self> {
42        match index {
43            0 => Some(Self::Empty),
44            1 => Some(Self::StructureStarts),
45            2 => Some(Self::StructureReferences),
46            3 => Some(Self::Biomes),
47            4 => Some(Self::Terrain),
48            5 => Some(Self::Features),
49            6 => Some(Self::InitializeLight),
50            7 => Some(Self::Light),
51            8 => Some(Self::Spawn),
52            9 => Some(Self::Full),
53            _ => None,
54        }
55    }
56
57    /// Gets the next status in the generation order.
58    #[must_use]
59    pub const fn next(self) -> Option<Self> {
60        match self {
61            Self::Empty => Some(Self::StructureStarts),
62            Self::StructureStarts => Some(Self::StructureReferences),
63            Self::StructureReferences => Some(Self::Biomes),
64            Self::Biomes => Some(Self::Terrain),
65            Self::Terrain => Some(Self::Features),
66            Self::Features => Some(Self::InitializeLight),
67            Self::InitializeLight => Some(Self::Light),
68            Self::Light => Some(Self::Spawn),
69            Self::Spawn => Some(Self::Full),
70            Self::Full => None,
71        }
72    }
73
74    /// Gets the parent status in the generation order.
75    #[must_use]
76    pub const fn parent(self) -> Option<Self> {
77        match self {
78            Self::Empty => None,
79            Self::StructureStarts => Some(Self::Empty),
80            Self::StructureReferences => Some(Self::StructureStarts),
81            Self::Biomes => Some(Self::StructureReferences),
82            Self::Terrain => Some(Self::Biomes),
83            Self::Features => Some(Self::Terrain),
84            Self::InitializeLight => Some(Self::Features),
85            Self::Light => Some(Self::InitializeLight),
86            Self::Spawn => Some(Self::Light),
87            Self::Full => Some(Self::Spawn),
88        }
89    }
90
91    /// Returns the heightmap types that should be updated at this status.
92    ///
93    /// Before Terrain, worldgen heightmaps are used.
94    /// At Terrain and after, final heightmaps are used.
95    #[must_use]
96    pub const fn heightmaps_after(self) -> &'static [HeightmapType] {
97        match self {
98            Self::Empty | Self::StructureStarts | Self::StructureReferences | Self::Biomes => {
99                HeightmapType::worldgen_types()
100            }
101            Self::Terrain
102            | Self::Features
103            | Self::InitializeLight
104            | Self::Light
105            | Self::Spawn
106            | Self::Full => HeightmapType::final_types(),
107        }
108    }
109}