From 8e128d3ca24fa10dc7d871f7daf6c43eaddc385c Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 30 Aug 2026 20:10:07 -0700 Subject: wip biome abstraction --- src/proc_gen/herringbone.rs | 46 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'src/proc_gen/herringbone.rs') diff --git a/src/proc_gen/herringbone.rs b/src/proc_gen/herringbone.rs index 5e930ec..271b7a1 100644 --- a/src/proc_gen/herringbone.rs +++ b/src/proc_gen/herringbone.rs @@ -3,12 +3,10 @@ use glam::IVec2; use crate::{ config::TILESET_SCALING, - content::materials::MaterialId, proc_gen::tileset_loader::{Tile, TileOrientation, Tileset, TilesetPixelType}, - sim::cell::Cell, }; -fn split_position(world: IVec2, tileset: &Tileset) -> (IVec2, IVec2, TileOrientation) { +pub fn split_position(world: IVec2, tileset: &Tileset) -> (IVec2, IVec2, TileOrientation) { let s = tileset.dimensions.short as i32; let tx = world.x.div_euclid(s); let ty = world.y.div_euclid(s); @@ -74,10 +72,40 @@ fn get_pixel_at_position(world: IVec2, tileset: &Tileset) -> TilesetPixelType { tile.pixels[(local.x + local.y * width) as usize] } -pub fn get_cell_at_position(world: IVec2, tileset: &Tileset) -> Cell { - let pixel = get_pixel_at_position(world, tileset); - match pixel { - TilesetPixelType::Void => Cell::void(), - TilesetPixelType::Terrain => Cell::from_material(MaterialId::Dirt), - } +pub fn tiles_overlapping( + a: IVec2, + b: IVec2, + tileset: &Tileset, +) -> impl Iterator { + let s = IVec2::new( + tileset.dimensions.short as i32, + tileset.dimensions.short as i32, + ); + + let ta = a.div_euclid(s) - 1; + let tb = (b - 1).div_euclid(s); + + (ta.y..=tb.y) + .flat_map(move |ty| (ta.x..=tb.x).map(move |tx| (tx, ty))) + .filter_map(move |(tx, ty)| match (tx - ty).rem_euclid(4) { + 0 => Some(( + IVec2::new(tx, ty), + pick_variant(IVec2::new(tx, ty), TileOrientation::Horizontal, tileset), + TileOrientation::Horizontal, + )), + 3 => Some(( + IVec2::new(tx, ty), + pick_variant(IVec2::new(tx, ty), TileOrientation::Vertical, tileset), + TileOrientation::Vertical, + )), + _ => None, + }) } + +// pub fn get_cell_at_position(world: IVec2, tileset: &Tileset) -> Cell { +// let pixel = get_pixel_at_position(world, tileset); +// match pixel { +// TilesetPixelType::Void => Cell::void(), +// TilesetPixelType::Terrain => Cell::from_material(MaterialId::Dirt), +// } +// } -- cgit v1.3.1