diff --git a/src/model/mod.rs b/src/model/mod.rs index 9beeb8e..4b2b954 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -926,13 +926,15 @@ fn calculate_biome(snapshot: &world::Snapshot, x: i32, z: i32, img: &image::Dyna for xx in -1 .. 2 { for zz in -1 .. 2 { let bi = snapshot.get_biome(x+xx, z+zz); - let ix = bi.color_index & 0xFF; - let iy = bi.color_index >> 8; + let color_index = bi.get_color_index(); + let ix = color_index & 0xFF; + let iy = color_index >> 8; let ix = min(max(ix, 0), 255); let iy = min(max(iy, 0), 255); let col = img.get_pixel(ix as u32, iy as u32); + let col = bi.process_color(col); r += col.data[0] as u32; g += col.data[1] as u32; b += col.data[2] as u32; diff --git a/src/world/biome.rs b/src/world/biome.rs index 8477389..9472bc4 100644 --- a/src/world/biome.rs +++ b/src/world/biome.rs @@ -1,25 +1,46 @@ +use image::Rgba; + #[derive(Clone, Copy)] pub struct Biome { pub id: usize, pub temperature: f64, pub moisture: f64, - pub color_index: usize, } impl Biome { - const fn new(id: usize, t: f64, m: f64) -> Biome{ + const fn new(id: usize, t: f64, m: f64) -> Biome { Biome { id: id, temperature: t, moisture: m*t, - color_index: (((1.0 - t) * 255.0) as usize) | ((((1.0 - (m*t)) * 255.0) as usize) << 8), } } pub fn by_id(id: usize) -> Biome { *BY_ID.get(id).unwrap_or(&INVALID) } + + pub fn get_color_index(self) -> usize { + let t = self.temperature.min(1.0).max(0.0); + let m = self.moisture.min(1.0).max(0.0); + (((1.0 - t) * 255.0) as usize) | ((((1.0 - (m*t)) * 255.0) as usize) << 8) + } + + pub fn process_color(self, col: Rgba) -> Rgba { + if self.id == ROOFED_FOREST.id || self.id == ROOFED_FOREST_MOUNTAINS.id { + Rgba { + data: [ + ((col.data[0] as u32 + 0x28) / 2) as u8, + ((col.data[1] as u32 + 0x34) / 2) as u8, + ((col.data[2] as u32 + 0x0A) / 2) as u8, + 255 + ] + } + } else { + col + } + } } macro_rules! define_biomes {