Compare commits
No commits in common. "0751cf344d239eddb7e26ff4ff2de7e6dd894a56" and "197080e5fdfcfc7d1143716fe7082a665d44a34c" have entirely different histories.
0751cf344d
...
197080e5fd
|
@ -4,10 +4,7 @@ use std::{
|
|||
marker::PhantomData,
|
||||
};
|
||||
|
||||
use bevy::{
|
||||
core::{FixedTimestep, FloatOrd},
|
||||
prelude::*,
|
||||
};
|
||||
use bevy::{core::FixedTimestep, prelude::*};
|
||||
use bevy_rapier2d::{na, na::UnitComplex};
|
||||
use coord_2d::{Coord, Size};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
|
@ -62,7 +59,6 @@ impl Viewshed {
|
|||
map: &Map<D>,
|
||||
visible_query: &Query<&Visible>,
|
||||
events: &mut EventWriter<VisibilityChanged>,
|
||||
cache: &mut HashMap<(FloatOrd, FloatOrd), (u8, HashSet<Entity>)>,
|
||||
) {
|
||||
let mut context: Context<u8> = Context::default();
|
||||
let vision_distance = vision_distance::Circle::new(self.range);
|
||||
|
@ -74,22 +70,11 @@ impl Viewshed {
|
|||
let visibility_grid = VisibilityGrid(
|
||||
map,
|
||||
RefCell::new(Box::new(|coord: Coord| {
|
||||
let dest = point!(coord.x as f32 + 0.5, coord.y as f32 + 0.5);
|
||||
if let Some((opacity, entities)) = cache.get(&(FloatOrd(dest.x), FloatOrd(dest.y)))
|
||||
{
|
||||
for e in entities {
|
||||
new_visible_entities.insert(*e);
|
||||
return *opacity;
|
||||
}
|
||||
}
|
||||
let tile = map.at(coord.x as usize, coord.y as usize);
|
||||
if tile.blocks_visibility() {
|
||||
cache.insert(
|
||||
(FloatOrd(dest.x), FloatOrd(dest.y)),
|
||||
(u8::MAX, HashSet::new()),
|
||||
);
|
||||
return u8::MAX;
|
||||
}
|
||||
let dest = point!(coord.x as f32 + 0.5, coord.y as f32 + 0.5);
|
||||
if na::distance(&origin, &dest) > self.range as f32 {
|
||||
return u8::MAX;
|
||||
}
|
||||
|
@ -110,10 +95,6 @@ impl Viewshed {
|
|||
if let Ok(visible) = visible_query.get(entity) {
|
||||
opacity = **visible;
|
||||
}
|
||||
cache.insert(
|
||||
(FloatOrd(dest.x), FloatOrd(dest.y)),
|
||||
(opacity, entities.clone()),
|
||||
);
|
||||
true
|
||||
},
|
||||
);
|
||||
|
@ -316,7 +297,6 @@ fn update_viewshed<D: 'static + Clone + Default + Send + Sync>(
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut cache = HashMap::new();
|
||||
for entity in to_update.iter() {
|
||||
if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) =
|
||||
viewers.get_mut(*entity)
|
||||
|
@ -331,7 +311,6 @@ fn update_viewshed<D: 'static + Clone + Default + Send + Sync>(
|
|||
map,
|
||||
&visible,
|
||||
&mut changed,
|
||||
&mut cache,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -348,7 +327,6 @@ fn remove_visible<D: 'static + Clone + Default + Send + Sync>(
|
|||
mut changed: EventWriter<VisibilityChanged>,
|
||||
) {
|
||||
for removed in removed.iter() {
|
||||
let mut cache = HashMap::new();
|
||||
for (viewer_entity, mut viewshed, mut visible_entities, start) in viewers.iter_mut() {
|
||||
if !visible_entities.contains(&removed) {
|
||||
continue;
|
||||
|
@ -364,7 +342,6 @@ fn remove_visible<D: 'static + Clone + Default + Send + Sync>(
|
|||
map,
|
||||
&visible,
|
||||
&mut changed,
|
||||
&mut cache,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -454,12 +431,7 @@ impl<D: 'static + Clone + Default + Send + Sync> Plugin for VisibilityPlugin<D>
|
|||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<VisibilityChanged>()
|
||||
.add_system(add_visibility_indices::<D>)
|
||||
.add_system_set_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
SystemSet::new()
|
||||
.with_run_criteria(FixedTimestep::step(0.05))
|
||||
.with_system(update_viewshed::<D>),
|
||||
)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, update_viewshed::<D>)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, viewshed_removed)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, remove_visible::<D>)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, update_revealed_tiles::<D>)
|
||||
|
|
Loading…
Reference in New Issue
Block a user