From 924ee01f9188878d6ee7ad940ba81f16a132785a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 5 May 2023 23:04:06 +0200 Subject: [PATCH] world/layer: introduce LayerData struct to fix clippy type complexity warning --- src/bin/minedmap/region_processor.rs | 26 ++++++++++---------------- src/world/layer.rs | 23 +++++++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/bin/minedmap/region_processor.rs b/src/bin/minedmap/region_processor.rs index e410013..415cca0 100644 --- a/src/bin/minedmap/region_processor.rs +++ b/src/bin/minedmap/region_processor.rs @@ -2,7 +2,12 @@ use std::{fs, path::Path}; use anyhow::{Context, Result}; -use minedmap::{io::storage, resource, types::*, world}; +use minedmap::{ + io::storage, + resource, + types::*, + world::{self, layer::LayerData}, +}; use super::common::*; @@ -34,18 +39,7 @@ impl<'a> RegionProcessor<'a> { } /// Processes a single chunk - fn process_chunk( - &self, - data: world::de::Chunk, - ) -> Result< - Option<( - ( - Box, - Box, - ), - Box, - )>, - > { + fn process_chunk(&self, data: world::de::Chunk) -> Result> { let chunk = world::chunk::Chunk::new(&data, &self.block_types, &self.biome_types)?; world::layer::top_layer(&chunk) } @@ -110,15 +104,15 @@ impl<'a> RegionProcessor<'a> { minedmap::io::region::from_file(path)?.foreach_chunk( |chunk_coords, data: world::de::Chunk| { - let Some((processed_chunk, block_light)) = self + let Some(layer_data) = self .process_chunk(data) .with_context(|| format!("Failed to process chunk {:?}", chunk_coords))? else { 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); Ok(()) diff --git a/src/world/layer.rs b/src/world/layer.rs index a457191..89cff41 100644 --- a/src/world/layer.rs +++ b/src/world/layer.rs @@ -86,6 +86,13 @@ pub type BlockInfoArray = LayerBlockArray>; pub type BiomeArray = LayerBlockArray>; pub type BlockLightArray = LayerBlockArray; +#[derive(Debug, Default)] +pub struct LayerData { + pub blocks: Box, + pub biomes: Box, + pub block_light: Box, +} + /// Fills in a [BlockInfoArray] with the information of the chunk's top /// block layer /// @@ -93,9 +100,7 @@ pub type BlockLightArray = LayerBlockArray; /// determined as the block that should be visible on the rendered /// map. For water blocks, the height of the first non-water block /// is additionally filled in as the water depth. -pub fn top_layer( - chunk: &Chunk, -) -> Result, Box), Box)>> { +pub fn top_layer(chunk: &Chunk) -> Result> { use BLOCKS_PER_CHUNK as N; if chunk.is_empty() { @@ -103,9 +108,7 @@ pub fn top_layer( } let mut done = 0; - let mut blocks = Box::::default(); - let mut block_biomes = Box::::default(); - let mut light = Box::::default(); + let mut ret = LayerData::default(); for SectionIterItem { y: section_y, @@ -116,7 +119,7 @@ pub fn top_layer( { for y in BlockY::iter().rev() { for xz in BlockInfoArray::keys() { - let entry = &mut blocks[xz]; + let entry = &mut ret.blocks[xz]; if entry.done() { continue; } @@ -137,13 +140,13 @@ pub fn top_layer( done += 1; }; - let biome_entry = &mut block_biomes[xz]; + let biome_entry = &mut ret.biomes[xz]; if !entry.is_none() && biome_entry.is_none() { *biome_entry = biomes.biome_at(section_y, coords)?.copied(); } 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 { @@ -153,5 +156,5 @@ pub fn top_layer( } } - Ok(Some(((blocks, block_biomes), light))) + Ok(Some(ret)) }