Get rid of a bunch of iter
calls.
This commit is contained in:
parent
01b796062e
commit
966cdd903b
|
@ -62,7 +62,7 @@ where
|
||||||
ExplorationType: Component + Default + Copy + Ord,
|
ExplorationType: Component + Default + Copy + Ord,
|
||||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||||
{
|
{
|
||||||
for (actions, visible, mut focused) in explorers.iter_mut() {
|
for (actions, visible, mut focused) in &mut explorers {
|
||||||
let mut types: Vec<ExplorationType> = vec![];
|
let mut types: Vec<ExplorationType> = vec![];
|
||||||
for e in visible.iter() {
|
for e in visible.iter() {
|
||||||
if let Ok(t) = features.get(*e) {
|
if let Ok(t) = features.get(*e) {
|
||||||
|
@ -128,7 +128,7 @@ where
|
||||||
ExplorationType: Component + Default + PartialEq,
|
ExplorationType: Component + Default + PartialEq,
|
||||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||||
{
|
{
|
||||||
for (entity, actions, visible_entities, focused_type, exploring) in explorers.iter() {
|
for (entity, actions, visible_entities, focused_type, exploring) in &explorers {
|
||||||
let mut features = features
|
let mut features = features
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|v| visible_entities.contains(&v.0))
|
.filter(|v| visible_entities.contains(&v.0))
|
||||||
|
@ -218,7 +218,7 @@ fn exploration_focus<State, MapData>(
|
||||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||||
MapData: 'static + Clone + Default + Send + Sync,
|
MapData: 'static + Clone + Default + Send + Sync,
|
||||||
{
|
{
|
||||||
for (entity, actions, transform, exploring) in explorers.iter() {
|
for (entity, actions, transform, exploring) in &explorers {
|
||||||
let coordinates = transform.translation;
|
let coordinates = transform.translation;
|
||||||
let mut exploring = if let Some(exploring) = exploring {
|
let mut exploring = if let Some(exploring) = exploring {
|
||||||
**exploring
|
**exploring
|
||||||
|
@ -260,8 +260,8 @@ fn navigate_to_explored<State, MapData>(
|
||||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||||
MapData: 'static + Clone + Default + Send + Sync,
|
MapData: 'static + Clone + Default + Send + Sync,
|
||||||
{
|
{
|
||||||
for (entity, actions, exploring) in explorers.iter() {
|
for (entity, actions, exploring) in &explorers {
|
||||||
for (map, revealed_tiles) in map.iter() {
|
for (map, revealed_tiles) in &map {
|
||||||
let point = **exploring;
|
let point = **exploring;
|
||||||
let idx = point.to_index(map.width);
|
let idx = point.to_index(map.width);
|
||||||
let known = revealed_tiles[idx];
|
let known = revealed_tiles[idx];
|
||||||
|
@ -363,10 +363,10 @@ fn cleanup(
|
||||||
explorers: Query<Entity, With<Exploring>>,
|
explorers: Query<Entity, With<Exploring>>,
|
||||||
focus: Query<Entity, With<ExplorationFocused>>,
|
focus: Query<Entity, With<ExplorationFocused>>,
|
||||||
) {
|
) {
|
||||||
for entity in explorers.iter() {
|
for entity in &explorers {
|
||||||
commands.entity(entity).remove::<Exploring>();
|
commands.entity(entity).remove::<Exploring>();
|
||||||
}
|
}
|
||||||
for entity in focus.iter() {
|
for entity in &focus {
|
||||||
commands.entity(entity).remove::<ExplorationFocused>();
|
commands.entity(entity).remove::<ExplorationFocused>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ fn read_log(
|
||||||
mut position: Local<usize>,
|
mut position: Local<usize>,
|
||||||
log: Query<&Log, Changed<Log>>,
|
log: Query<&Log, Changed<Log>>,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
for log in log.iter() {
|
for log in &log {
|
||||||
if *position >= log.len() {
|
if *position >= log.len() {
|
||||||
*position = 0;
|
*position = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
maps: Query<(Entity, &Map<D>, &SpawnColliders), Changed<SpawnColliders>>,
|
maps: Query<(Entity, &Map<D>, &SpawnColliders), Changed<SpawnColliders>>,
|
||||||
) {
|
) {
|
||||||
for (map_entity, map, spawn_colliders) in maps.iter() {
|
for (map_entity, map, spawn_colliders) in &maps {
|
||||||
if **spawn_colliders {
|
if **spawn_colliders {
|
||||||
commands
|
commands
|
||||||
.entity(map_entity)
|
.entity(map_entity)
|
||||||
|
@ -244,7 +244,7 @@ fn spawn_portals<D: 'static + Clone + Default + Send + Sync>(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
map: Query<(Entity, &Map<D>, &SpawnPortals), Changed<SpawnPortals>>,
|
map: Query<(Entity, &Map<D>, &SpawnPortals), Changed<SpawnPortals>>,
|
||||||
) {
|
) {
|
||||||
for (map_entity, map, spawn_portals) in map.iter() {
|
for (map_entity, map, spawn_portals) in &map {
|
||||||
if **spawn_portals {
|
if **spawn_portals {
|
||||||
commands.entity(map_entity).remove::<SpawnPortals>();
|
commands.entity(map_entity).remove::<SpawnPortals>();
|
||||||
let mut portals: Vec<(f32, f32)> = vec![];
|
let mut portals: Vec<(f32, f32)> = vec![];
|
||||||
|
@ -297,9 +297,9 @@ fn spawn_portal_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||||
map: Query<(Entity, &SpawnColliders), With<Map<D>>>,
|
map: Query<(Entity, &SpawnColliders), With<Map<D>>>,
|
||||||
portals: Query<Entity, (With<Portal>, Without<Collider>)>,
|
portals: Query<Entity, (With<Portal>, Without<Collider>)>,
|
||||||
) {
|
) {
|
||||||
for (entity, spawn_colliders) in map.iter() {
|
for (entity, spawn_colliders) in &map {
|
||||||
if **spawn_colliders {
|
if **spawn_colliders {
|
||||||
for portal_entity in portals.iter() {
|
for portal_entity in &portals {
|
||||||
commands
|
commands
|
||||||
.entity(portal_entity)
|
.entity(portal_entity)
|
||||||
.insert((Collider::cuboid(0.5, 0.5), Sensor));
|
.insert((Collider::cuboid(0.5, 0.5), Sensor));
|
||||||
|
|
|
@ -224,7 +224,7 @@ fn controls(
|
||||||
}
|
}
|
||||||
if cleanup {
|
if cleanup {
|
||||||
commands.entity(entity).remove::<Exploring>();
|
commands.entity(entity).remove::<Exploring>();
|
||||||
for entity in exploration_focused.iter() {
|
for entity in &exploration_focused {
|
||||||
commands.entity(entity).remove::<ExplorationFocused>();
|
commands.entity(entity).remove::<ExplorationFocused>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ fn update_direction(
|
||||||
(With<Player>, Changed<Transform>),
|
(With<Player>, Changed<Transform>),
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
for (entity, transform, direction) in query.iter_mut() {
|
for (entity, transform, direction) in &mut query {
|
||||||
let yaw = transform.yaw();
|
let yaw = transform.yaw();
|
||||||
let new_direction: CardinalDirection = yaw.into();
|
let new_direction: CardinalDirection = yaw.into();
|
||||||
if let Some(mut direction) = direction {
|
if let Some(mut direction) = direction {
|
||||||
|
@ -333,7 +333,7 @@ fn speak_direction(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_speed(mut commands: Commands, query: Query<Entity, (Added<Speed>, Without<Velocity>)>) {
|
fn add_speed(mut commands: Commands, query: Query<Entity, (Added<Speed>, Without<Velocity>)>) {
|
||||||
for entity in query.iter() {
|
for entity in &query {
|
||||||
commands.entity(entity).insert(Velocity {
|
commands.entity(entity).insert(Velocity {
|
||||||
linvel: Vec2::ZERO,
|
linvel: Vec2::ZERO,
|
||||||
..default()
|
..default()
|
||||||
|
|
|
@ -244,7 +244,7 @@ fn calculate_path(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_tasks(mut commands: Commands, mut query: Query<(Entity, &mut Calculating)>) {
|
fn poll_tasks(mut commands: Commands, mut query: Query<(Entity, &mut Calculating)>) {
|
||||||
for (entity, mut calculating) in query.iter_mut() {
|
for (entity, mut calculating) in &mut query {
|
||||||
if let Some(result) = future::block_on(future::poll_once(&mut **calculating)) {
|
if let Some(result) = future::block_on(future::poll_once(&mut **calculating)) {
|
||||||
if let Some(path) = result {
|
if let Some(path) = result {
|
||||||
trace!("{entity:?}: Path: {path:?}");
|
trace!("{entity:?}: Path: {path:?}");
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn tag_behind(
|
||||||
if config.downshift_behind {
|
if config.downshift_behind {
|
||||||
if let Ok(listener_transform) = listener.get_single() {
|
if let Ok(listener_transform) = listener.get_single() {
|
||||||
let listener_forward = listener_transform.forward();
|
let listener_forward = listener_transform.forward();
|
||||||
for (entity, transform, sound, icon) in sounds.iter() {
|
for (entity, transform, sound, icon) in &sounds {
|
||||||
if icon.is_none() && sound.is_none() {
|
if icon.is_none() && sound.is_none() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ fn tag_behind(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for entity in behind.iter() {
|
for entity in &behind {
|
||||||
commands.run_if_exists(entity, |mut entity| {
|
commands.run_if_exists(entity, |mut entity| {
|
||||||
entity.remove::<Behind>();
|
entity.remove::<Behind>();
|
||||||
});
|
});
|
||||||
|
@ -61,7 +61,7 @@ fn behind_added(
|
||||||
mut last_sound_pitch: ResMut<LastSoundPitch>,
|
mut last_sound_pitch: ResMut<LastSoundPitch>,
|
||||||
mut query: Query<(Entity, Option<&mut SoundIcon>, Option<&mut Sound>), Added<Behind>>,
|
mut query: Query<(Entity, Option<&mut SoundIcon>, Option<&mut Sound>), Added<Behind>>,
|
||||||
) {
|
) {
|
||||||
for (entity, icon, sound) in query.iter_mut() {
|
for (entity, icon, sound) in &mut query {
|
||||||
if let Some(mut icon) = icon {
|
if let Some(mut icon) = icon {
|
||||||
icon.pitch *= config.downshift;
|
icon.pitch *= config.downshift;
|
||||||
last_icon_pitch.insert(entity, icon.pitch);
|
last_icon_pitch.insert(entity, icon.pitch);
|
||||||
|
@ -97,7 +97,7 @@ fn sound_icon_changed(
|
||||||
mut last_icon_pitch: ResMut<LastIconPitch>,
|
mut last_icon_pitch: ResMut<LastIconPitch>,
|
||||||
mut icons: Query<(Entity, &mut SoundIcon), (With<Behind>, Changed<SoundIcon>)>,
|
mut icons: Query<(Entity, &mut SoundIcon), (With<Behind>, Changed<SoundIcon>)>,
|
||||||
) {
|
) {
|
||||||
for (entity, mut icon) in icons.iter_mut() {
|
for (entity, mut icon) in &mut icons {
|
||||||
let should_change = if let Some(pitch) = last_icon_pitch.get(&entity) {
|
let should_change = if let Some(pitch) = last_icon_pitch.get(&entity) {
|
||||||
*pitch != icon.pitch
|
*pitch != icon.pitch
|
||||||
} else {
|
} else {
|
||||||
|
@ -115,7 +115,7 @@ fn sound_changed(
|
||||||
mut last_sound_pitch: ResMut<LastSoundPitch>,
|
mut last_sound_pitch: ResMut<LastSoundPitch>,
|
||||||
mut sounds: Query<(Entity, &mut Sound), (With<Behind>, Without<SoundIcon>, Changed<Sound>)>,
|
mut sounds: Query<(Entity, &mut Sound), (With<Behind>, Without<SoundIcon>, Changed<Sound>)>,
|
||||||
) {
|
) {
|
||||||
for (entity, mut sound) in sounds.iter_mut() {
|
for (entity, mut sound) in &mut sounds {
|
||||||
let should_change = if let Some(pitch) = last_sound_pitch.get(&entity) {
|
let should_change = if let Some(pitch) = last_sound_pitch.get(&entity) {
|
||||||
*pitch != sound.pitch
|
*pitch != sound.pitch
|
||||||
} else {
|
} else {
|
||||||
|
@ -134,7 +134,7 @@ fn sync_config(
|
||||||
behind: Query<Entity, With<Behind>>,
|
behind: Query<Entity, With<Behind>>,
|
||||||
) {
|
) {
|
||||||
if config.is_changed() {
|
if config.is_changed() {
|
||||||
for entity in behind.iter() {
|
for entity in &behind {
|
||||||
commands.entity(entity).remove::<Behind>();
|
commands.entity(entity).remove::<Behind>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl Default for Footstep {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn added(mut commands: Commands, footsteps: Query<(Entity, &Footstep), Added<Footstep>>) {
|
fn added(mut commands: Commands, footsteps: Query<(Entity, &Footstep), Added<Footstep>>) {
|
||||||
for (entity, footstep) in footsteps.iter() {
|
for (entity, footstep) in &footsteps {
|
||||||
let buffer = footstep.buffer.clone();
|
let buffer = footstep.buffer.clone();
|
||||||
commands.run_if_exists(entity, move |mut entity| {
|
commands.run_if_exists(entity, move |mut entity| {
|
||||||
entity.insert(Sound {
|
entity.insert(Sound {
|
||||||
|
@ -46,7 +46,7 @@ fn update(
|
||||||
mut footsteps: Query<(Entity, &Footstep, &Parent, &mut Sound)>,
|
mut footsteps: Query<(Entity, &Footstep, &Parent, &mut Sound)>,
|
||||||
transforms_storage: Query<&GlobalTransform>,
|
transforms_storage: Query<&GlobalTransform>,
|
||||||
) {
|
) {
|
||||||
for (entity, footstep, parent, mut sound) in footsteps.iter_mut() {
|
for (entity, footstep, parent, mut sound) in &mut footsteps {
|
||||||
if let Ok(transform) = transforms_storage.get(**parent) {
|
if let Ok(transform) = transforms_storage.get(**parent) {
|
||||||
if let Some(last) = last_step_distance.get(&entity) {
|
if let Some(last) = last_step_distance.get(&entity) {
|
||||||
let distance = last.0 + (last.1.distance(transform));
|
let distance = last.0 + (last.1.distance(transform));
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl Default for SoundIcon {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added<SoundIcon>>) {
|
fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added<SoundIcon>>) {
|
||||||
for (entity, icon) in icons.iter() {
|
for (entity, icon) in &icons {
|
||||||
let buffer = icon.buffer.clone();
|
let buffer = icon.buffer.clone();
|
||||||
let gain = icon.gain;
|
let gain = icon.gain;
|
||||||
let pitch = icon.pitch;
|
let pitch = icon.pitch;
|
||||||
|
@ -75,8 +75,8 @@ fn update<S>(
|
||||||
if !config.states.is_empty() && !config.states.contains(&state.0) {
|
if !config.states.is_empty() && !config.states.contains(&state.0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for visible in viewers.iter() {
|
for visible in &viewers {
|
||||||
for (icon_entity, mut icon, visibility, parent, mut sound) in icons.iter_mut() {
|
for (icon_entity, mut icon, visibility, parent, mut sound) in &mut icons {
|
||||||
let entity = if visibility.is_some() {
|
let entity = if visibility.is_some() {
|
||||||
Some(icon_entity)
|
Some(icon_entity)
|
||||||
} else if parent.is_some() {
|
} else if parent.is_some() {
|
||||||
|
@ -118,7 +118,7 @@ fn exploration_focus_changed(
|
||||||
mut icons: Query<&mut SoundIcon>,
|
mut icons: Query<&mut SoundIcon>,
|
||||||
) {
|
) {
|
||||||
const ICON_GAIN: f64 = 3.;
|
const ICON_GAIN: f64 = 3.;
|
||||||
for (entity, children) in focused.iter_mut() {
|
for (entity, children) in &mut focused {
|
||||||
if let Ok(mut icon) = icons.get_mut(entity) {
|
if let Ok(mut icon) = icons.get_mut(entity) {
|
||||||
icon.gain *= ICON_GAIN;
|
icon.gain *= ICON_GAIN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub use volumetric::Volumetric;
|
||||||
|
|
||||||
/*fn scale_sounds(config: Res<CoreConfig>, mut sounds: Query<&mut Sound>) {
|
/*fn scale_sounds(config: Res<CoreConfig>, mut sounds: Query<&mut Sound>) {
|
||||||
let pixels_per_unit = config.pixels_per_unit as f32;
|
let pixels_per_unit = config.pixels_per_unit as f32;
|
||||||
for mut sound in sounds.iter_mut() {
|
for mut sound in &mut sounds {
|
||||||
sound.reference_distance *= pixels_per_unit;
|
sound.reference_distance *= pixels_per_unit;
|
||||||
if sound.max_distance != f32::MAX {
|
if sound.max_distance != f32::MAX {
|
||||||
sound.max_distance *= pixels_per_unit;
|
sound.max_distance *= pixels_per_unit;
|
||||||
|
|
|
@ -253,7 +253,7 @@ fn add_visibility_indices<MapData: 'static + Clone + Default + Send + Sync>(
|
||||||
map_config: Res<MapPlugin<MapData>>,
|
map_config: Res<MapPlugin<MapData>>,
|
||||||
query: Query<(Entity, &Map<MapData>), (Added<Map<MapData>>, Without<RevealedTiles>)>,
|
query: Query<(Entity, &Map<MapData>), (Added<Map<MapData>>, Without<RevealedTiles>)>,
|
||||||
) {
|
) {
|
||||||
for (entity, map) in query.iter() {
|
for (entity, map) in &query {
|
||||||
let count = map.width * map.height;
|
let count = map.width * map.height;
|
||||||
commands
|
commands
|
||||||
.entity(entity)
|
.entity(entity)
|
||||||
|
@ -314,8 +314,7 @@ fn update_viewshed(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut cache = HashMap::new();
|
let mut cache = HashMap::new();
|
||||||
for (viewer_entity, mut viewshed, mut visible_entities, viewer_transform) in viewers.iter_mut()
|
for (viewer_entity, mut viewshed, mut visible_entities, viewer_transform) in &mut viewers {
|
||||||
{
|
|
||||||
viewshed.update(
|
viewshed.update(
|
||||||
&viewer_entity,
|
&viewer_entity,
|
||||||
&mut visible_entities,
|
&mut visible_entities,
|
||||||
|
@ -345,7 +344,7 @@ fn remove_visible(
|
||||||
if !removed.is_empty() {
|
if !removed.is_empty() {
|
||||||
let mut cache = HashMap::new();
|
let mut cache = HashMap::new();
|
||||||
for removed in &mut removed {
|
for removed in &mut removed {
|
||||||
for (viewer_entity, mut viewshed, mut visible_entities, start) in viewers.iter_mut() {
|
for (viewer_entity, mut viewshed, mut visible_entities, start) in &mut viewers {
|
||||||
if !visible_entities.contains(&removed) {
|
if !visible_entities.contains(&removed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -369,8 +368,8 @@ fn update_revealed_tiles<D: 'static + Clone + Default + Send + Sync>(
|
||||||
mut map: Query<(&Map<D>, &mut RevealedTiles)>,
|
mut map: Query<(&Map<D>, &mut RevealedTiles)>,
|
||||||
viewers: Query<&Viewshed, (With<Player>, Changed<Viewshed>)>,
|
viewers: Query<&Viewshed, (With<Player>, Changed<Viewshed>)>,
|
||||||
) {
|
) {
|
||||||
for viewshed in viewers.iter() {
|
for viewshed in &viewers {
|
||||||
for (map, mut revealed_tiles) in map.iter_mut() {
|
for (map, mut revealed_tiles) in &mut map {
|
||||||
for v in viewshed.visible_points.iter() {
|
for v in viewshed.visible_points.iter() {
|
||||||
let idx = v.to_index(map.width);
|
let idx = v.to_index(map.width);
|
||||||
if idx >= revealed_tiles.len() {
|
if idx >= revealed_tiles.len() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user