diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-30 20:10:07 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-30 20:10:07 -0700 |
| commit | 8e128d3ca24fa10dc7d871f7daf6c43eaddc385c (patch) | |
| tree | c4b32bfb559941041965418daefda1deffafd8e9 /src/proc_gen/herringbone.rs | |
| parent | 56bba5560be95c1e05bfec11e4fc085654f3589d (diff) | |
wip biome abstraction
Diffstat (limited to 'src/proc_gen/herringbone.rs')
| -rw-r--r-- | src/proc_gen/herringbone.rs | 46 |
1 files changed, 37 insertions, 9 deletions
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<Item = (IVec2, &Tile, TileOrientation)> { + 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), +// } +// } |
