From 2335bd23e3b4e09177ff02e236612b78c1730b9c Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Mon, 31 Aug 2026 23:36:08 -0700 Subject: argmax materials --- src/content/world/mines.rs | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'src/content/world/mines.rs') diff --git a/src/content/world/mines.rs b/src/content/world/mines.rs index d7e23bc..9e24a37 100644 --- a/src/content/world/mines.rs +++ b/src/content/world/mines.rs @@ -1,7 +1,11 @@ use fastnoise_lite::{FastNoiseLite, FractalType}; use glam::IVec2; -use crate::{content::materials::MaterialId, proc_gen::Biome, sim::cell::Cell}; +use crate::{ + content::materials::MaterialId, + proc_gen::{Biome, InterpolatedPixel, tileset_loader::TilePixelType}, + sim::cell::Cell, +}; const ROUGHNESS: f32 = 0.375; @@ -12,22 +16,40 @@ pub struct MinesBiome { impl MinesBiome { pub fn new() -> Self { let mut edge_roughness = FastNoiseLite::new(); - edge_roughness.octaves = 2; - edge_roughness.fractal_type = FractalType::Ridged; + edge_roughness.set_fractal_type(Some(FractalType::Ridged)); + edge_roughness.set_fractal_octaves(Some(2)); MinesBiome { edge_roughness } } } impl Biome for MinesBiome { - fn cell(&self, solidity: f32, world: IVec2) -> Cell { + fn fragment(&self, pixel: InterpolatedPixel, world: IVec2) -> Cell { let world = world.as_vec2(); - let displacement = ROUGHNESS * self.edge_roughness.get_noise_2d(world.x, world.y); - if solidity + displacement <= 0.0 { - return Cell::void(); + match pixel.interpolated_pixel_index { + 0 => { + if pixel.interpolated_solidity + displacement <= 0.0 { + return Cell::void(); + } + + Cell::from_material(MaterialId::Dirt) + } + 12 => { + if pixel.interpolated_solidity + displacement <= 0.0 { + return Cell::void(); + } + + Cell::from_material(MaterialId::Water) + } + 13 => { + if pixel.interpolated_solidity + displacement <= 0.0 { + return Cell::void(); + } + + Cell::from_material(MaterialId::Wood) + } + _ => Cell::void(), } - - Cell::from_material(MaterialId::Dirt) } } -- cgit v1.3.1