world/chunk: include biomes in section iterator item

This commit is contained in:
Matthias Schiffer 2023-04-08 21:03:50 +02:00
parent ddc515a9d7
commit 0d2c99dacf
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
2 changed files with 36 additions and 25 deletions

View file

@ -50,10 +50,12 @@ enum SectionIterInner<'a> {
/// Iterator over sections of [Chunk::V1_13] /// Iterator over sections of [Chunk::V1_13]
V1_13 { V1_13 {
iter: btree_map::Iter<'a, SectionY, (SectionV1_13<'a>, BlockLight<'a>)>, iter: btree_map::Iter<'a, SectionY, (SectionV1_13<'a>, BlockLight<'a>)>,
biomes: &'a BiomesV0<'a>,
}, },
/// Iterator over sections of [Chunk::V0] /// Iterator over sections of [Chunk::V0]
V0 { V0 {
iter: btree_map::Iter<'a, SectionY, (SectionV0<'a>, BlockLight<'a>)>, iter: btree_map::Iter<'a, SectionY, (SectionV0<'a>, BlockLight<'a>)>,
biomes: &'a BiomesV0<'a>,
}, },
/// Empty iterator over an unpopulated chunk ([Chunk::Empty]) /// Empty iterator over an unpopulated chunk ([Chunk::Empty])
Empty, Empty,
@ -208,11 +210,19 @@ impl<'a> Chunk<'a> {
Chunk::V1_18 { section_map } => V1_18 { Chunk::V1_18 { section_map } => V1_18 {
iter: section_map.iter(), iter: section_map.iter(),
}, },
Chunk::V1_13 { section_map, .. } => V1_13 { Chunk::V1_13 {
section_map,
biomes,
} => V1_13 {
iter: section_map.iter(), iter: section_map.iter(),
biomes,
}, },
Chunk::V0 { section_map, .. } => V0 { Chunk::V0 {
section_map,
biomes,
} => V0 {
iter: section_map.iter(), iter: section_map.iter(),
biomes,
}, },
Chunk::Empty => Empty, Chunk::Empty => Empty,
}, },
@ -224,6 +234,7 @@ impl<'a> Chunk<'a> {
pub struct SectionIterItem<'a> { pub struct SectionIterItem<'a> {
pub y: SectionY, pub y: SectionY,
pub section: &'a dyn Section, pub section: &'a dyn Section,
pub biomes: &'a dyn Biomes,
pub block_light: BlockLight<'a>, pub block_light: BlockLight<'a>,
} }
@ -247,30 +258,29 @@ impl<'a> SectionIter<'a> {
{ {
match &mut self.inner { match &mut self.inner {
SectionIterInner::V1_18 { iter } => f(&mut iter.map( SectionIterInner::V1_18 { iter } => f(&mut iter.map(
|(&y, (section, _, block_light))| SectionIterItem { |(&y, (section, biomes, block_light))| SectionIterItem {
y, y,
section, section,
biomes,
block_light: *block_light, block_light: *block_light,
}, },
)), )),
SectionIterInner::V1_13 { iter } => { SectionIterInner::V1_13 { iter, biomes } => f(&mut iter.map(
f( |(&y, (section, block_light))| SectionIterItem {
&mut iter.map(|(&y, (section, block_light))| SectionIterItem {
y, y,
section, section,
biomes: *biomes,
block_light: *block_light, block_light: *block_light,
}), },
) )),
} SectionIterInner::V0 { iter, biomes } => f(&mut iter.map(
SectionIterInner::V0 { iter } => { |(&y, (section, block_light))| SectionIterItem {
f(
&mut iter.map(|(&y, (section, block_light))| SectionIterItem {
y, y,
section, section,
biomes: *biomes,
block_light: *block_light, block_light: *block_light,
}), },
) )),
}
SectionIterInner::Empty => f(&mut iter::empty()), SectionIterInner::Empty => f(&mut iter::empty()),
} }
} }
@ -286,8 +296,8 @@ impl<'a> Iterator for SectionIter<'a> {
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) {
match &self.inner { match &self.inner {
SectionIterInner::V1_18 { iter } => iter.size_hint(), SectionIterInner::V1_18 { iter } => iter.size_hint(),
SectionIterInner::V1_13 { iter } => iter.size_hint(), SectionIterInner::V1_13 { iter, .. } => iter.size_hint(),
SectionIterInner::V0 { iter } => iter.size_hint(), SectionIterInner::V0 { iter, .. } => iter.size_hint(),
SectionIterInner::Empty => (0, Some(0)), SectionIterInner::Empty => (0, Some(0)),
} }
} }
@ -307,8 +317,8 @@ impl<'a> ExactSizeIterator for SectionIter<'a> {
fn len(&self) -> usize { fn len(&self) -> usize {
match &self.inner { match &self.inner {
SectionIterInner::V1_18 { iter } => iter.len(), SectionIterInner::V1_18 { iter } => iter.len(),
SectionIterInner::V1_13 { iter } => iter.len(), SectionIterInner::V1_13 { iter, .. } => iter.len(),
SectionIterInner::V0 { iter } => iter.len(), SectionIterInner::V0 { iter, .. } => iter.len(),
SectionIterInner::Empty => 0, SectionIterInner::Empty => 0,
} }
} }

View file

@ -106,6 +106,7 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<(Box<BlockInfoArray>, Box<Block
for SectionIterItem { for SectionIterItem {
y: section_y, y: section_y,
section, section,
biomes: _,
block_light, block_light,
} in chunk.sections().rev() } in chunk.sections().rev()
{ {