summaryrefslogtreecommitdiff
path: root/src/proc_gen/herringbone.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/proc_gen/herringbone.rs')
-rw-r--r--src/proc_gen/herringbone.rs46
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),
+// }
+// }