minedmap: move some internal functions out of impl blocks

This commit is contained in:
Matthias Schiffer 2023-05-01 17:51:38 +02:00
parent 1a5e8894fe
commit 2dd9283d95
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
2 changed files with 30 additions and 28 deletions

View file

@ -6,6 +6,19 @@ use minedmap::{io::storage, resource::Biome, types::*, world};
use super::common::*;
fn block_color(block: &world::layer::BlockInfo, _biome: &Biome) -> [u8; 4] {
let h = block
.depth
.map(|depth| 0.5 + 0.005 * depth.0 as f32)
.unwrap_or_default();
let c = block
.block_type
.color
.0
.map(|v| (f32::from(v) * h).clamp(0.0, 255.0) as u8);
[c[0], c[1], c[2], 255]
}
pub struct TileRenderer<'a> {
config: &'a Config,
}
@ -20,19 +33,6 @@ impl<'a> TileRenderer<'a> {
storage::read(&processed_path).context("Failed to load processed region data")
}
fn block_color(block: &world::layer::BlockInfo, _biome: &Biome) -> [u8; 4] {
let h = block
.depth
.map(|depth| 0.5 + 0.005 * depth.0 as f32)
.unwrap_or_default();
let c = block
.block_type
.color
.0
.map(|v| (f32::from(v) * h).clamp(0.0, 255.0) as u8);
[c[0], c[1], c[2], 255]
}
fn render_chunk(
image: &mut image::RgbaImage,
coords: ChunkCoords,
@ -47,7 +47,7 @@ impl<'a> TileRenderer<'a> {
z: BlockZ(z as u8),
};
image::Rgba(match (&blocks[coords], &biomes[coords]) {
(Some(block), Some(biome)) => Self::block_color(block, biome),
(Some(block), Some(biome)) => block_color(block, biome),
_ => [0, 0, 0, 0],
})
});