Simplify visibility calculation.
This commit is contained in:
parent
dc1c14fd23
commit
10fc85d384
|
@ -107,7 +107,6 @@ fn update_viewshed(
|
|||
collider_query: &QueryPipelineColliderComponentsQuery,
|
||||
map: &Map,
|
||||
blocks_visibility: &Query<&BlocksVisibility>,
|
||||
coordinates: &Query<&Coordinates>,
|
||||
) {
|
||||
let mut context: Context<u8> = Context::default();
|
||||
let vision_distance = vision_distance::Circle::new(viewshed.range);
|
||||
|
@ -129,17 +128,9 @@ fn update_viewshed(
|
|||
Some(&|v| v.entity() != *viewer_entity && blocks_visibility.get(v.entity()).is_ok()),
|
||||
|handle| {
|
||||
if let Ok(blocks_visibility) = blocks_visibility.get(handle.entity()) {
|
||||
if let Ok(coordinates) = coordinates.get(handle.entity()) {
|
||||
if coordinates.i32() == (coord.x, coord.y) {
|
||||
opacity = **blocks_visibility;
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
} else {
|
||||
opacity = **blocks_visibility;
|
||||
false
|
||||
}
|
||||
// println!("Visibility blocked at {:?}", coord);
|
||||
opacity = **blocks_visibility;
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
@ -170,7 +161,6 @@ fn update_viewshed_for_coordinates(
|
|||
query_pipeline: Res<QueryPipeline>,
|
||||
collider_query: QueryPipelineColliderComponentsQuery,
|
||||
blocks_visibility: Query<&BlocksVisibility>,
|
||||
coordinates_query: Query<&Coordinates>,
|
||||
) {
|
||||
for (visible_entity, coordinates) in visible.iter() {
|
||||
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
|
||||
|
@ -188,7 +178,6 @@ fn update_viewshed_for_coordinates(
|
|||
&collider_query,
|
||||
map,
|
||||
&blocks_visibility,
|
||||
&coordinates_query,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +190,6 @@ fn update_viewshed_for_start(
|
|||
query_pipeline: Res<QueryPipeline>,
|
||||
collider_query: QueryPipelineColliderComponentsQuery,
|
||||
blocks_visibility: Query<&BlocksVisibility>,
|
||||
coordinates_query: Query<&Coordinates>,
|
||||
) {
|
||||
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
|
||||
if let Ok(map) = map.single() {
|
||||
|
@ -213,7 +201,6 @@ fn update_viewshed_for_start(
|
|||
&collider_query,
|
||||
map,
|
||||
&blocks_visibility,
|
||||
&coordinates_query,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +213,6 @@ fn remove_blocks_visibility(
|
|||
query_pipeline: Res<QueryPipeline>,
|
||||
collider_query: QueryPipelineColliderComponentsQuery,
|
||||
blocks_visibility: Query<&BlocksVisibility>,
|
||||
coordinates_query: Query<&Coordinates>,
|
||||
) {
|
||||
for _ in removed.iter() {
|
||||
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
|
||||
|
@ -239,7 +225,6 @@ fn remove_blocks_visibility(
|
|||
&collider_query,
|
||||
map,
|
||||
&blocks_visibility,
|
||||
&coordinates_query,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -288,7 +273,7 @@ fn log_visible(
|
|||
let collider_set = QueryPipelineColliderComponentsSet(&collider_query);
|
||||
let shape = Cuboid::new(Vec2::new(0.49, 0.49).into());
|
||||
for viewed_coordinates in &viewshed.visible {
|
||||
if coordinates.distance(viewed_coordinates) >= viewshed.range as f32 - 1.5 {
|
||||
if coordinates.distance(viewed_coordinates) >= viewshed.range as f32 - 0.1 {
|
||||
continue;
|
||||
}
|
||||
let shape_pos = (
|
||||
|
|
Loading…
Reference in New Issue
Block a user