fixes for hex select

This commit is contained in:
2024-05-31 19:36:30 -04:00
parent f491739ee8
commit ee0b17f4b6
2 changed files with 14 additions and 20 deletions

View File

@@ -249,13 +249,13 @@ pub mod prelude {
assert!(radius != 0, "Radius cannot be zero"); assert!(radius != 0, "Radius cannot be zero");
let width = self.width; let width = self.width;
let mut chunks = self.hex_select_mut(pos, radius, true, |h, r| { let mut chunks = self.hex_select_mut(pos, radius, true, |p, h, r| {
let d = (r as f32) / (radius as f32); let d = (r as f32) / (radius as f32);
let cur = h.clone(); let cur = *h;
let h2 = cur - depth; let h2 = cur - depth;
*h = h2.lerp(cur, d * d); *h = h2.lerp(cur, d * d);
return pos.to_chunk_index(width); return p.to_chunk_index(width);
}); });
chunks.dedup(); chunks.dedup();
@@ -263,21 +263,15 @@ pub mod prelude {
return chunks; return chunks;
} }
pub fn hex_select<OP, Ret>( pub fn hex_select<OP, Ret>(&self, center: &HexCoord, radius: usize, include_center: bool, op: OP) -> Vec<Ret>
&mut self,
center: &HexCoord,
radius: usize,
include_center: bool,
op: OP,
) -> Vec<Ret>
where where
OP: Fn(f32, usize) -> Ret + Sync + Send, OP: Fn(&HexCoord, f32, usize) -> Ret + Sync + Send,
{ {
assert!(radius != 0, "Radius cannot be zero"); assert!(radius != 0, "Radius cannot be zero");
if include_center { if include_center {
let h = self.sample_height(center); let h = self.sample_height(&center);
(op)(h, 0); (op)(&center, h, 0);
} }
let mut result = Vec::with_capacity(get_tile_count(radius)); let mut result = Vec::with_capacity(get_tile_count(radius));
@@ -288,7 +282,7 @@ pub mod prelude {
for _j in 0..k { for _j in 0..k {
p = p.get_neighbor(i); p = p.get_neighbor(i);
let h = self.sample_height(&p); let h = self.sample_height(&p);
result.push((op)(h, k)); result.push((op)(&p, h, k));
} }
} }
} }
@@ -304,13 +298,13 @@ pub mod prelude {
op: OP, op: OP,
) -> Vec<Ret> ) -> Vec<Ret>
where where
OP: Fn(&mut f32, usize) -> Ret + Sync + Send, OP: Fn(&HexCoord, &mut f32, usize) -> Ret + Sync + Send,
{ {
assert!(radius != 0, "Radius cannot be zero"); assert!(radius != 0, "Radius cannot be zero");
if include_center { if include_center {
let h = self.sample_height_mut(center); let h = self.sample_height_mut(&center);
(op)(h, 0); (op)(&center, h, 0);
} }
let mut result = Vec::with_capacity(get_tile_count(radius)); let mut result = Vec::with_capacity(get_tile_count(radius));
@@ -321,7 +315,7 @@ pub mod prelude {
for _j in 0..k { for _j in 0..k {
p = p.get_neighbor(i); p = p.get_neighbor(i);
let h = self.sample_height_mut(&p); let h = self.sample_height_mut(&p);
result.push((op)(h, k)); result.push((op)(&p, h, k));
} }
} }
} }

View File

@@ -20,9 +20,9 @@ fn main() {
primary_window: Some(Window { primary_window: Some(Window {
title: "Phos".into(), title: "Phos".into(),
name: Some("phos".into()), name: Some("phos".into()),
// resolution: (1920., 1080.).into(), resolution: (1920., 1080.).into(),
present_mode: PresentMode::AutoNoVsync, present_mode: PresentMode::AutoNoVsync,
mode: bevy::window::WindowMode::BorderlessFullscreen, // mode: bevy::window::WindowMode::BorderlessFullscreen,
..default() ..default()
}), }),
..default() ..default()