mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
world/layer: introduce LayerData struct to fix clippy type complexity warning
This commit is contained in:
parent
b66bdf5ce1
commit
924ee01f91
2 changed files with 23 additions and 26 deletions
|
@ -2,7 +2,12 @@ use std::{fs, path::Path};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
use minedmap::{io::storage, resource, types::*, world};
|
use minedmap::{
|
||||||
|
io::storage,
|
||||||
|
resource,
|
||||||
|
types::*,
|
||||||
|
world::{self, layer::LayerData},
|
||||||
|
};
|
||||||
|
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
|
|
||||||
|
@ -34,18 +39,7 @@ impl<'a> RegionProcessor<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes a single chunk
|
/// Processes a single chunk
|
||||||
fn process_chunk(
|
fn process_chunk(&self, data: world::de::Chunk) -> Result<Option<LayerData>> {
|
||||||
&self,
|
|
||||||
data: world::de::Chunk,
|
|
||||||
) -> Result<
|
|
||||||
Option<(
|
|
||||||
(
|
|
||||||
Box<world::layer::BlockInfoArray>,
|
|
||||||
Box<world::layer::BiomeArray>,
|
|
||||||
),
|
|
||||||
Box<world::layer::BlockLightArray>,
|
|
||||||
)>,
|
|
||||||
> {
|
|
||||||
let chunk = world::chunk::Chunk::new(&data, &self.block_types, &self.biome_types)?;
|
let chunk = world::chunk::Chunk::new(&data, &self.block_types, &self.biome_types)?;
|
||||||
world::layer::top_layer(&chunk)
|
world::layer::top_layer(&chunk)
|
||||||
}
|
}
|
||||||
|
@ -110,15 +104,15 @@ impl<'a> RegionProcessor<'a> {
|
||||||
|
|
||||||
minedmap::io::region::from_file(path)?.foreach_chunk(
|
minedmap::io::region::from_file(path)?.foreach_chunk(
|
||||||
|chunk_coords, data: world::de::Chunk| {
|
|chunk_coords, data: world::de::Chunk| {
|
||||||
let Some((processed_chunk, block_light)) = self
|
let Some(layer_data) = self
|
||||||
.process_chunk(data)
|
.process_chunk(data)
|
||||||
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?
|
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?
|
||||||
else {
|
else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
processed_region[chunk_coords] = Some(processed_chunk);
|
processed_region[chunk_coords] = Some((layer_data.blocks, layer_data.biomes));
|
||||||
|
|
||||||
let chunk_lightmap = Self::render_chunk_lightmap(block_light);
|
let chunk_lightmap = Self::render_chunk_lightmap(layer_data.block_light);
|
||||||
overlay_chunk(&mut lightmap, &chunk_lightmap, chunk_coords);
|
overlay_chunk(&mut lightmap, &chunk_lightmap, chunk_coords);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -86,6 +86,13 @@ pub type BlockInfoArray = LayerBlockArray<Option<BlockInfo>>;
|
||||||
pub type BiomeArray = LayerBlockArray<Option<Biome>>;
|
pub type BiomeArray = LayerBlockArray<Option<Biome>>;
|
||||||
pub type BlockLightArray = LayerBlockArray<u8>;
|
pub type BlockLightArray = LayerBlockArray<u8>;
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct LayerData {
|
||||||
|
pub blocks: Box<BlockInfoArray>,
|
||||||
|
pub biomes: Box<BiomeArray>,
|
||||||
|
pub block_light: Box<BlockLightArray>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Fills in a [BlockInfoArray] with the information of the chunk's top
|
/// Fills in a [BlockInfoArray] with the information of the chunk's top
|
||||||
/// block layer
|
/// block layer
|
||||||
///
|
///
|
||||||
|
@ -93,9 +100,7 @@ pub type BlockLightArray = LayerBlockArray<u8>;
|
||||||
/// determined as the block that should be visible on the rendered
|
/// determined as the block that should be visible on the rendered
|
||||||
/// map. For water blocks, the height of the first non-water block
|
/// map. For water blocks, the height of the first non-water block
|
||||||
/// is additionally filled in as the water depth.
|
/// is additionally filled in as the water depth.
|
||||||
pub fn top_layer(
|
pub fn top_layer(chunk: &Chunk) -> Result<Option<LayerData>> {
|
||||||
chunk: &Chunk,
|
|
||||||
) -> Result<Option<((Box<BlockInfoArray>, Box<BiomeArray>), Box<BlockLightArray>)>> {
|
|
||||||
use BLOCKS_PER_CHUNK as N;
|
use BLOCKS_PER_CHUNK as N;
|
||||||
|
|
||||||
if chunk.is_empty() {
|
if chunk.is_empty() {
|
||||||
|
@ -103,9 +108,7 @@ pub fn top_layer(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut done = 0;
|
let mut done = 0;
|
||||||
let mut blocks = Box::<BlockInfoArray>::default();
|
let mut ret = LayerData::default();
|
||||||
let mut block_biomes = Box::<BiomeArray>::default();
|
|
||||||
let mut light = Box::<BlockLightArray>::default();
|
|
||||||
|
|
||||||
for SectionIterItem {
|
for SectionIterItem {
|
||||||
y: section_y,
|
y: section_y,
|
||||||
|
@ -116,7 +119,7 @@ pub fn top_layer(
|
||||||
{
|
{
|
||||||
for y in BlockY::iter().rev() {
|
for y in BlockY::iter().rev() {
|
||||||
for xz in BlockInfoArray::keys() {
|
for xz in BlockInfoArray::keys() {
|
||||||
let entry = &mut blocks[xz];
|
let entry = &mut ret.blocks[xz];
|
||||||
if entry.done() {
|
if entry.done() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -137,13 +140,13 @@ pub fn top_layer(
|
||||||
done += 1;
|
done += 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
let biome_entry = &mut block_biomes[xz];
|
let biome_entry = &mut ret.biomes[xz];
|
||||||
if !entry.is_none() && biome_entry.is_none() {
|
if !entry.is_none() && biome_entry.is_none() {
|
||||||
*biome_entry = biomes.biome_at(section_y, coords)?.copied();
|
*biome_entry = biomes.biome_at(section_y, coords)?.copied();
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.is_none() {
|
if entry.is_none() {
|
||||||
light[xz] = block_light.block_light_at(coords);
|
ret.block_light[xz] = block_light.block_light_at(coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
if done == N * N {
|
if done == N * N {
|
||||||
|
@ -153,5 +156,5 @@ pub fn top_layer(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(((blocks, block_biomes), light)))
|
Ok(Some(ret))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue