mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
types: introduce LayerBlockArray
A LayerBlockArray is a generic array of data stored for each block of a chunk layer. It provides the same methods as a ChunkArray.
This commit is contained in:
parent
789a4002c7
commit
3ef48783b7
1 changed files with 34 additions and 0 deletions
34
src/types.rs
34
src/types.rs
|
@ -52,6 +52,40 @@ impl Debug for LayerBlockCoords {
|
|||
}
|
||||
}
|
||||
|
||||
/// Generic array for data stored per block of a chunk layer
|
||||
///
|
||||
/// Includes various convenient iteration functions.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct LayerBlockArray<T>(pub [[T; BLOCKS_PER_CHUNK]; BLOCKS_PER_CHUNK]);
|
||||
|
||||
impl<T> LayerBlockArray<T> {
|
||||
pub fn keys() -> impl Iterator<Item = LayerBlockCoords> + Clone + Debug {
|
||||
iproduct!(BlockZ::iter(), BlockX::iter()).map(|(z, x)| LayerBlockCoords { x, z })
|
||||
}
|
||||
|
||||
pub fn values(&self) -> impl Iterator<Item = &T> + Clone + Debug {
|
||||
Self::keys().map(|k| &self[k])
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (LayerBlockCoords, &T)> + Clone + Debug {
|
||||
Self::keys().map(|k| (k, &self[k]))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Index<LayerBlockCoords> for LayerBlockArray<T> {
|
||||
type Output = T;
|
||||
|
||||
fn index(&self, index: LayerBlockCoords) -> &Self::Output {
|
||||
&self.0[index.z.0 as usize][index.x.0 as usize]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IndexMut<LayerBlockCoords> for LayerBlockArray<T> {
|
||||
fn index_mut(&mut self, index: LayerBlockCoords) -> &mut Self::Output {
|
||||
&mut self.0[index.z.0 as usize][index.x.0 as usize]
|
||||
}
|
||||
}
|
||||
|
||||
/// X, Y and Z coordinates of a block in a chunk section
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct SectionBlockCoords {
|
||||
|
|
Loading…
Add table
Reference in a new issue