mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
world/layer: move more top_layer() logic into LayerEntry::fill()
This commit is contained in:
parent
0437ec70b6
commit
0b392d7a3a
1 changed files with 21 additions and 36 deletions
|
@ -51,22 +51,30 @@ impl<'a> LayerEntry<'a> {
|
||||||
self.depth.is_some()
|
self.depth.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill(&mut self, y: BlockHeight, block_type: BlockType) -> bool {
|
fn fill(&mut self, section: SectionIterItem, coords: SectionBlockCoords) -> Result<bool> {
|
||||||
if !block_type.is(BlockFlag::Opaque) {
|
let Some(block_type) = section.section.block_at(coords)?
|
||||||
return false;
|
.filter(|block_type| block_type.is(BlockFlag::Opaque))
|
||||||
}
|
else {
|
||||||
|
if self.is_empty() {
|
||||||
|
*self.block_light = section.block_light.block_light_at(coords);
|
||||||
|
}
|
||||||
|
|
||||||
if self.block.is_none() {
|
return Ok(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
if self.is_empty() {
|
||||||
*self.block = Some(block_type);
|
*self.block = Some(block_type);
|
||||||
|
*self.biome = section.biomes.biome_at(section.y, coords)?.copied();
|
||||||
}
|
}
|
||||||
|
|
||||||
if block_type.is(BlockFlag::Water) {
|
if block_type.is(BlockFlag::Water) {
|
||||||
return false;
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
*self.depth = Some(y);
|
let height = BlockHeight::new(section.y, coords.y)?;
|
||||||
|
*self.depth = Some(height);
|
||||||
|
|
||||||
true
|
Ok(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,13 +114,7 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<LayerData>> {
|
||||||
let mut done = 0;
|
let mut done = 0;
|
||||||
let mut ret = LayerData::default();
|
let mut ret = LayerData::default();
|
||||||
|
|
||||||
for SectionIterItem {
|
for section in chunk.sections().rev() {
|
||||||
y: section_y,
|
|
||||||
section,
|
|
||||||
biomes,
|
|
||||||
block_light,
|
|
||||||
} in chunk.sections().rev()
|
|
||||||
{
|
|
||||||
for y in BlockY::iter().rev() {
|
for y in BlockY::iter().rev() {
|
||||||
for xz in BlockInfoArray::keys() {
|
for xz in BlockInfoArray::keys() {
|
||||||
let mut entry = ret.entry(xz);
|
let mut entry = ret.entry(xz);
|
||||||
|
@ -121,29 +123,12 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<LayerData>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let coords = SectionBlockCoords { xz, y };
|
let coords = SectionBlockCoords { xz, y };
|
||||||
|
if !entry.fill(section, coords)? {
|
||||||
'check_block: {
|
continue;
|
||||||
let Some(block_type) = section.block_at(coords)? else {
|
|
||||||
break 'check_block;
|
|
||||||
};
|
|
||||||
|
|
||||||
let height = BlockHeight::new(section_y, y)?;
|
|
||||||
if !entry.fill(height, block_type) {
|
|
||||||
break 'check_block;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert!(entry.done());
|
|
||||||
done += 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
if !entry.is_empty() && entry.biome.is_none() {
|
|
||||||
*entry.biome = biomes.biome_at(section_y, coords)?.copied();
|
|
||||||
}
|
|
||||||
|
|
||||||
if entry.is_empty() {
|
|
||||||
*entry.block_light = block_light.block_light_at(coords);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert!(entry.done());
|
||||||
|
done += 1;
|
||||||
if done == N * N {
|
if done == N * N {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue