From 0d81dfa35b5d6776a055701e05b63bdce52418e8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 9 Apr 2023 23:20:20 +0200 Subject: [PATCH] main: store biome data in processed data files --- src/main.rs | 18 ++++++++++++------ src/resource/biomes.rs | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 50884e3..e2121e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,12 @@ struct Args { } type RegionCoords = (i32, i32); -type ProcessedRegion = ChunkArray>>; +type ProcessedRegion = ChunkArray< + Option<( + Box, + Box, + )>, +>; struct Config { region_dir: PathBuf, @@ -195,7 +200,7 @@ 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((processed_chunk, block_light)) = self .process_chunk(data) .with_context(|| format!("Failed to process chunk {:?}", chunk_coords))? else { @@ -299,13 +304,14 @@ impl<'a> TileRenderer<'a> { fn render_chunk( image: &mut image::RgbaImage, coords: ChunkCoords, - chunk: &world::layer::BlockInfoArray, + blocks: &world::layer::BlockInfoArray, + _biomes: &world::layer::BiomeArray, ) { const N: u32 = BLOCKS_PER_CHUNK as u32; let chunk_image = image::RgbaImage::from_fn(N, N, |x, z| { image::Rgba( - match &chunk[LayerBlockCoords { + match &blocks[LayerBlockCoords { x: BlockX(x as u8), z: BlockZ(z as u8), }] { @@ -319,11 +325,11 @@ impl<'a> TileRenderer<'a> { fn render_region(image: &mut image::RgbaImage, region: &ProcessedRegion) { for (coords, chunk) in region.iter() { - let Some(chunk) = chunk else { + let Some((blocks, biomes)) = chunk else { continue; }; - Self::render_chunk(image, coords, chunk); + Self::render_chunk(image, coords, blocks, biomes); } } diff --git a/src/resource/biomes.rs b/src/resource/biomes.rs index 1421883..036cafc 100644 --- a/src/resource/biomes.rs +++ b/src/resource/biomes.rs @@ -1,12 +1,14 @@ +use serde::{Deserialize, Serialize}; + use super::Color; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum BiomeGrassColorModifier { DarkForest, Swamp, } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub struct Biome { pub temp: i8, pub downfall: i8,