Get rid of a bunch of iter calls.

This commit is contained in:
Nolan Darilek 2023-03-28 12:13:23 -05:00
parent 01b796062e
commit 966cdd903b
10 changed files with 34 additions and 35 deletions

View File

@ -62,7 +62,7 @@ where
ExplorationType: Component + Default + Copy + Ord,
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![];
for e in visible.iter() {
if let Ok(t) = features.get(*e) {
@ -128,7 +128,7 @@ where
ExplorationType: Component + Default + PartialEq,
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
.iter()
.filter(|v| visible_entities.contains(&v.0))
@ -218,7 +218,7 @@ fn exploration_focus<State, MapData>(
State: 'static + Clone + Debug + Eq + Hash + 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 mut exploring = if let Some(exploring) = exploring {
**exploring
@ -260,8 +260,8 @@ fn navigate_to_explored<State, MapData>(
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
MapData: 'static + Clone + Default + Send + Sync,
{
for (entity, actions, exploring) in explorers.iter() {
for (map, revealed_tiles) in map.iter() {
for (entity, actions, exploring) in &explorers {
for (map, revealed_tiles) in &map {
let point = **exploring;
let idx = point.to_index(map.width);
let known = revealed_tiles[idx];
@ -363,10 +363,10 @@ fn cleanup(
explorers: Query<Entity, With<Exploring>>,
focus: Query<Entity, With<ExplorationFocused>>,
) {
for entity in explorers.iter() {
for entity in &explorers {
commands.entity(entity).remove::<Exploring>();
}
for entity in focus.iter() {
for entity in &focus {
commands.entity(entity).remove::<ExplorationFocused>();
}
}

View File

@ -41,7 +41,7 @@ fn read_log(
mut position: Local<usize>,
log: Query<&Log, Changed<Log>>,
) -> Result<(), Box<dyn Error>> {
for log in log.iter() {
for log in &log {
if *position >= log.len() {
*position = 0;
}

View File

@ -183,7 +183,7 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
mut commands: Commands,
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 {
commands
.entity(map_entity)
@ -244,7 +244,7 @@ fn spawn_portals<D: 'static + Clone + Default + Send + Sync>(
mut commands: Commands,
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 {
commands.entity(map_entity).remove::<SpawnPortals>();
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>>>,
portals: Query<Entity, (With<Portal>, Without<Collider>)>,
) {
for (entity, spawn_colliders) in map.iter() {
for (entity, spawn_colliders) in &map {
if **spawn_colliders {
for portal_entity in portals.iter() {
for portal_entity in &portals {
commands
.entity(portal_entity)
.insert((Collider::cuboid(0.5, 0.5), Sensor));

View File

@ -224,7 +224,7 @@ fn controls(
}
if cleanup {
commands.entity(entity).remove::<Exploring>();
for entity in exploration_focused.iter() {
for entity in &exploration_focused {
commands.entity(entity).remove::<ExplorationFocused>();
}
}
@ -289,7 +289,7 @@ fn update_direction(
(With<Player>, Changed<Transform>),
>,
) {
for (entity, transform, direction) in query.iter_mut() {
for (entity, transform, direction) in &mut query {
let yaw = transform.yaw();
let new_direction: CardinalDirection = yaw.into();
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>)>) {
for entity in query.iter() {
for entity in &query {
commands.entity(entity).insert(Velocity {
linvel: Vec2::ZERO,
..default()

View File

@ -244,7 +244,7 @@ fn calculate_path(
}
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(path) = result {
trace!("{entity:?}: Path: {path:?}");

View File

@ -22,7 +22,7 @@ fn tag_behind(
if config.downshift_behind {
if let Ok(listener_transform) = listener.get_single() {
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() {
continue;
}
@ -41,7 +41,7 @@ fn tag_behind(
}
}
} else {
for entity in behind.iter() {
for entity in &behind {
commands.run_if_exists(entity, |mut entity| {
entity.remove::<Behind>();
});
@ -61,7 +61,7 @@ fn behind_added(
mut last_sound_pitch: ResMut<LastSoundPitch>,
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 {
icon.pitch *= config.downshift;
last_icon_pitch.insert(entity, icon.pitch);
@ -97,7 +97,7 @@ fn sound_icon_changed(
mut last_icon_pitch: ResMut<LastIconPitch>,
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) {
*pitch != icon.pitch
} else {
@ -115,7 +115,7 @@ fn sound_changed(
mut last_sound_pitch: ResMut<LastSoundPitch>,
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) {
*pitch != sound.pitch
} else {
@ -134,7 +134,7 @@ fn sync_config(
behind: Query<Entity, With<Behind>>,
) {
if config.is_changed() {
for entity in behind.iter() {
for entity in &behind {
commands.entity(entity).remove::<Behind>();
}
}

View File

@ -29,7 +29,7 @@ impl Default for 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();
commands.run_if_exists(entity, move |mut entity| {
entity.insert(Sound {
@ -46,7 +46,7 @@ fn update(
mut footsteps: Query<(Entity, &Footstep, &Parent, &mut Sound)>,
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 Some(last) = last_step_distance.get(&entity) {
let distance = last.0 + (last.1.distance(transform));

View File

@ -39,7 +39,7 @@ impl Default for 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 gain = icon.gain;
let pitch = icon.pitch;
@ -75,8 +75,8 @@ fn update<S>(
if !config.states.is_empty() && !config.states.contains(&state.0) {
return;
}
for visible in viewers.iter() {
for (icon_entity, mut icon, visibility, parent, mut sound) in icons.iter_mut() {
for visible in &viewers {
for (icon_entity, mut icon, visibility, parent, mut sound) in &mut icons {
let entity = if visibility.is_some() {
Some(icon_entity)
} else if parent.is_some() {
@ -118,7 +118,7 @@ fn exploration_focus_changed(
mut icons: Query<&mut SoundIcon>,
) {
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) {
icon.gain *= ICON_GAIN;
}

View File

@ -10,7 +10,7 @@ pub use volumetric::Volumetric;
/*fn scale_sounds(config: Res<CoreConfig>, mut sounds: Query<&mut Sound>) {
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;
if sound.max_distance != f32::MAX {
sound.max_distance *= pixels_per_unit;

View File

@ -253,7 +253,7 @@ fn add_visibility_indices<MapData: 'static + Clone + Default + Send + Sync>(
map_config: Res<MapPlugin<MapData>>,
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;
commands
.entity(entity)
@ -314,8 +314,7 @@ fn update_viewshed(
return;
}
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(
&viewer_entity,
&mut visible_entities,
@ -345,7 +344,7 @@ fn remove_visible(
if !removed.is_empty() {
let mut cache = HashMap::new();
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) {
continue;
}
@ -369,8 +368,8 @@ fn update_revealed_tiles<D: 'static + Clone + Default + Send + Sync>(
mut map: Query<(&Map<D>, &mut RevealedTiles)>,
viewers: Query<&Viewshed, (With<Player>, Changed<Viewshed>)>,
) {
for viewshed in viewers.iter() {
for (map, mut revealed_tiles) in map.iter_mut() {
for viewshed in &viewers {
for (map, mut revealed_tiles) in &mut map {
for v in viewshed.visible_points.iter() {
let idx = v.to_index(map.width);
if idx >= revealed_tiles.len() {