Return 0 opacity if out of range.
This commit is contained in:
parent
90351718cc
commit
ecec85d37c
|
@ -58,7 +58,12 @@ impl Viewshed {
|
||||||
(start.x.abs() + self.range as f32 * 2.) as u32,
|
(start.x.abs() + self.range as f32 * 2.) as u32,
|
||||||
(start.y.abs() + self.range as f32 * 2.) as u32,
|
(start.y.abs() + self.range as f32 * 2.) as u32,
|
||||||
);
|
);
|
||||||
let visibility_grid = VisibilityGrid(*viewer_entity, opacity_map.clone());
|
let visibility_grid = VisibilityGrid(
|
||||||
|
*viewer_entity,
|
||||||
|
start.as_ivec2(),
|
||||||
|
self.range,
|
||||||
|
opacity_map.clone(),
|
||||||
|
);
|
||||||
let mut new_visible = HashSet::new();
|
let mut new_visible = HashSet::new();
|
||||||
let mut new_visible_entities = HashSet::new();
|
let mut new_visible_entities = HashSet::new();
|
||||||
// println!("Start: {viewer_entity}");
|
// println!("Start: {viewer_entity}");
|
||||||
|
@ -281,7 +286,7 @@ fn viewshed_removed(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VisibilityGrid(Entity, OpacityMap);
|
struct VisibilityGrid(Entity, IVec2, u32, OpacityMap);
|
||||||
|
|
||||||
impl InputGrid for VisibilityGrid {
|
impl InputGrid for VisibilityGrid {
|
||||||
type Grid = (u32, u32);
|
type Grid = (u32, u32);
|
||||||
|
@ -294,7 +299,11 @@ impl InputGrid for VisibilityGrid {
|
||||||
|
|
||||||
fn get_opacity(&self, _grid: &Self::Grid, coord: Coord) -> Self::Opacity {
|
fn get_opacity(&self, _grid: &Self::Grid, coord: Coord) -> Self::Opacity {
|
||||||
// println!("Checking {coord:?}");
|
// println!("Checking {coord:?}");
|
||||||
if let Some((opacity, entities)) = self.1.get(&IVec2::new(coord.x, coord.y)) {
|
let coord = IVec2::new(coord.x, coord.y);
|
||||||
|
if coord.distance(&self.1) > self.2 as f32 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if let Some((opacity, entities)) = self.3.get(&coord) {
|
||||||
if entities.contains(&self.0) {
|
if entities.contains(&self.0) {
|
||||||
// println!("Hit viewer, 0");
|
// println!("Hit viewer, 0");
|
||||||
0
|
0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user