Fix more visibility bugs, and make opaque
public.
This commit is contained in:
parent
3c54768e69
commit
8224d85b4b
|
@ -61,7 +61,7 @@ impl Visible {
|
||||||
Self(0)
|
Self(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn opaque() -> Self {
|
pub fn opaque() -> Self {
|
||||||
Self(u8::MAX)
|
Self(u8::MAX)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,6 +274,7 @@ fn update_viewshed(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_viewshed_for_coordinates(
|
fn update_viewshed_for_coordinates(
|
||||||
|
config: Res<RapierConfiguration>,
|
||||||
visible: Query<(Entity, &Coordinates), (Changed<Coordinates>, With<Visible>)>,
|
visible: Query<(Entity, &Coordinates), (Changed<Coordinates>, With<Visible>)>,
|
||||||
mut viewers: Query<(Entity, &mut Viewshed, &Coordinates)>,
|
mut viewers: Query<(Entity, &mut Viewshed, &Coordinates)>,
|
||||||
map: Query<&Map>,
|
map: Query<&Map>,
|
||||||
|
@ -281,6 +282,9 @@ fn update_viewshed_for_coordinates(
|
||||||
collider_query: QueryPipelineColliderComponentsQuery,
|
collider_query: QueryPipelineColliderComponentsQuery,
|
||||||
visible_query: Query<&Visible>,
|
visible_query: Query<&Visible>,
|
||||||
) {
|
) {
|
||||||
|
if !config.query_pipeline_active {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (visible_entity, coordinates) in visible.iter() {
|
for (visible_entity, coordinates) in visible.iter() {
|
||||||
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
|
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
|
||||||
if viewer_entity == visible_entity
|
if viewer_entity == visible_entity
|
||||||
|
@ -304,12 +308,16 @@ fn update_viewshed_for_coordinates(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_viewshed_for_start(
|
fn update_viewshed_for_start(
|
||||||
|
config: Res<RapierConfiguration>,
|
||||||
mut viewers: Query<(Entity, &mut Viewshed, &Coordinates), Changed<Coordinates>>,
|
mut viewers: Query<(Entity, &mut Viewshed, &Coordinates), Changed<Coordinates>>,
|
||||||
map: Query<&Map>,
|
map: Query<&Map>,
|
||||||
query_pipeline: Res<QueryPipeline>,
|
query_pipeline: Res<QueryPipeline>,
|
||||||
collider_query: QueryPipelineColliderComponentsQuery,
|
collider_query: QueryPipelineColliderComponentsQuery,
|
||||||
visible: Query<&Visible>,
|
visible: Query<&Visible>,
|
||||||
) {
|
) {
|
||||||
|
if !config.query_pipeline_active {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
|
for (viewer_entity, mut viewshed, start) in viewers.iter_mut() {
|
||||||
if let Ok(map) = map.single() {
|
if let Ok(map) = map.single() {
|
||||||
update_viewshed(
|
update_viewshed(
|
||||||
|
@ -413,28 +421,31 @@ fn intersection(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log_visible(
|
fn log_visible(
|
||||||
// time: Res<Time>,
|
time: Res<Time>,
|
||||||
// mut recently_lost: Local<HashMap<Entity, Timer>>,
|
mut recently_lost: Local<HashMap<Entity, Timer>>,
|
||||||
mut events: EventReader<VisibilityChanged>,
|
mut events: EventReader<VisibilityChanged>,
|
||||||
mut log: Query<&mut Log>,
|
mut log: Query<&mut Log>,
|
||||||
viewers: Query<(Entity, &Coordinates, &Transform), (With<Player>, With<Viewshed>)>,
|
viewers: Query<(Entity, &Coordinates, &Transform), (With<Player>, With<Viewshed>)>,
|
||||||
vieweds: Query<
|
visible: Query<
|
||||||
(&Name, Option<&RigidBodyPosition>, Option<&ColliderPosition>),
|
(&Name, Option<&RigidBodyPosition>, Option<&ColliderPosition>),
|
||||||
Without<DontLogWhenVisible>,
|
Without<DontLogWhenVisible>,
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
/*for timer in recently_lost.values_mut() {
|
for timer in recently_lost.values_mut() {
|
||||||
timer.tick(time.delta());
|
timer.tick(time.delta());
|
||||||
}*/
|
}
|
||||||
//recently_lost.retain(|_entity, timer| !timer.finished());
|
recently_lost.retain(|_entity, timer| !timer.finished());
|
||||||
for event in events.iter() {
|
for event in events.iter() {
|
||||||
if let VisibilityChanged::Gained { viewer, viewed } = event {
|
let viewer = match event {
|
||||||
if let Ok((viewer_entity, viewer_coordinates, viewer_transform)) = viewers.get(*viewer)
|
VisibilityChanged::Gained { viewer, .. } => viewer,
|
||||||
{
|
VisibilityChanged::Lost { viewer, .. } => viewer,
|
||||||
if *viewed == viewer_entity {
|
};
|
||||||
|
if let Ok((viewer_entity, viewer_coordinates, viewer_transform)) = viewers.get(*viewer) {
|
||||||
|
if let VisibilityChanged::Gained { viewed, .. } = event {
|
||||||
|
if *viewed == viewer_entity || recently_lost.contains_key(viewed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Ok((name, body_position, collider_position)) = vieweds.get(*viewed) {
|
if let Ok((name, body_position, collider_position)) = visible.get(*viewed) {
|
||||||
if let Ok(mut log) = log.single_mut() {
|
if let Ok(mut log) = log.single_mut() {
|
||||||
let viewed_coordinates = if let Some(p) = body_position {
|
let viewed_coordinates = if let Some(p) = body_position {
|
||||||
(p.position.translation.x, p.position.translation.y)
|
(p.position.translation.x, p.position.translation.y)
|
||||||
|
@ -450,6 +461,8 @@ fn log_visible(
|
||||||
log.push(format!("{}: {}", **name, location));
|
log.push(format!("{}: {}", **name, location));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if let VisibilityChanged::Lost { viewed, .. } = event {
|
||||||
|
recently_lost.insert(*viewed, Timer::from_seconds(2., false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user