mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Update codebase to use IntoIterator
where possible. (#5269)
Remove unnecessary calls to `iter()`/`iter_mut()`. Mainly updates the use of queries in our code, docs, and examples. ```rust // From for _ in list.iter() { for _ in list.iter_mut() { // To for _ in &list { for _ in &mut list { ``` We already enable the pedantic lint [clippy::explicit_iter_loop](https://rust-lang.github.io/rust-clippy/stable/) inside of Bevy. However, this only warns for a few known types from the standard library. ## Note for reviewers As you can see the additions and deletions are exactly equal. Maybe give it a quick skim to check I didn't sneak in a crypto miner, but you don't have to torture yourself by reading every line. I already experienced enough pain making this PR :) Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
parent
3203a8585c
commit
4847f7e3ad
95 changed files with 191 additions and 191 deletions
|
@ -30,7 +30,7 @@ impl Benchmark {
|
|||
}
|
||||
|
||||
fn query_system(mut query: Query<(&Velocity, &mut Position)>) {
|
||||
for (velocity, mut position) in query.iter_mut() {
|
||||
for (velocity, mut position) in &mut query {
|
||||
position.0 += velocity.0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ pub fn insert_commands(criterion: &mut Criterion) {
|
|||
|
||||
bencher.iter(|| {
|
||||
let mut commands = Commands::new(&mut command_queue, &world);
|
||||
for entity in entities.iter() {
|
||||
for entity in &entities {
|
||||
commands
|
||||
.entity(*entity)
|
||||
.insert_bundle((Matrix::default(), Vec3::default()));
|
||||
|
@ -112,7 +112,7 @@ pub fn insert_commands(criterion: &mut Criterion) {
|
|||
bencher.iter(|| {
|
||||
let mut commands = Commands::new(&mut command_queue, &world);
|
||||
let mut values = Vec::with_capacity(entity_count);
|
||||
for entity in entities.iter() {
|
||||
for entity in &entities {
|
||||
values.push((*entity, (Matrix::default(), Vec3::default())));
|
||||
}
|
||||
commands.insert_or_spawn_batch(values);
|
||||
|
|
|
@ -43,7 +43,7 @@ fn concrete_struct_field(criterion: &mut Criterion) {
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
bencher.iter(|| {
|
||||
for name in field_names.iter() {
|
||||
for name in &field_names {
|
||||
s.field(black_box(name));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -183,7 +183,7 @@ pub fn animation_player(
|
|||
mut transforms: Query<&mut Transform>,
|
||||
children: Query<&Children>,
|
||||
) {
|
||||
for (entity, mut player) in animation_players.iter_mut() {
|
||||
for (entity, mut player) in &mut animation_players {
|
||||
if let Some(animation_clip) = animations.get(&player.animation_clip) {
|
||||
// Continue if paused unless the `AnimationPlayer` was changed
|
||||
// This allow the animation to still be updated if the player.elapsed field was manually updated in pause
|
||||
|
|
|
@ -110,7 +110,7 @@ impl AssetServer {
|
|||
{
|
||||
let mut loaders = self.server.loaders.write();
|
||||
let loader_index = loaders.len();
|
||||
for extension in loader.extensions().iter() {
|
||||
for extension in loader.extensions() {
|
||||
self.server
|
||||
.extension_to_loader_index
|
||||
.write()
|
||||
|
|
|
@ -236,7 +236,7 @@ pub fn prepare_core_3d_depth_textures(
|
|||
>,
|
||||
) {
|
||||
let mut textures = HashMap::default();
|
||||
for (entity, camera) in views_3d.iter() {
|
||||
for (entity, camera) in &views_3d {
|
||||
if let Some(physical_target_size) = camera.physical_target_size {
|
||||
let cached_texture = textures
|
||||
.entry(camera.target.clone())
|
||||
|
|
|
@ -78,7 +78,7 @@ use bevy_ecs::prelude::*;
|
|||
struct Position { x: f32, y: f32 }
|
||||
|
||||
fn print_position(query: Query<(Entity, &Position)>) {
|
||||
for (entity, position) in query.iter() {
|
||||
for (entity, position) in &query {
|
||||
println!("Entity {:?} is at position: x {}, y {}", entity, position.x, position.y);
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ struct Velocity { x: f32, y: f32 }
|
|||
|
||||
// This system moves each entity with a Position and Velocity component
|
||||
fn movement(mut query: Query<(&mut Position, &Velocity)>) {
|
||||
for (mut position, velocity) in query.iter_mut() {
|
||||
for (mut position, velocity) in &mut query {
|
||||
position.x += velocity.x;
|
||||
position.y += velocity.y;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ struct Alive;
|
|||
// Gets the Position component of all Entities with Player component and without the Alive
|
||||
// component.
|
||||
fn system(query: Query<&Position, (With<Player>, Without<Alive>)>) {
|
||||
for position in query.iter() {
|
||||
for position in &query {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -197,13 +197,13 @@ struct Velocity { x: f32, y: f32 }
|
|||
|
||||
// Gets the Position component of all Entities whose Velocity has changed since the last run of the System
|
||||
fn system_changed(query: Query<&Position, Changed<Velocity>>) {
|
||||
for position in query.iter() {
|
||||
for position in &query {
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the Position component of all Entities that had a Velocity component added since the last run of the System
|
||||
fn system_added(query: Query<&Position, Added<Velocity>>) {
|
||||
for position in query.iter() {
|
||||
for position in &query {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -79,24 +79,24 @@ fn print_changed_entities(
|
|||
entity_with_added_component: Query<Entity, Added<Age>>,
|
||||
entity_with_mutated_component: Query<(Entity, &Age), Changed<Age>>,
|
||||
) {
|
||||
for entity in entity_with_added_component.iter() {
|
||||
for entity in &entity_with_added_component {
|
||||
println!(" {:?} has it's first birthday!", entity);
|
||||
}
|
||||
for (entity, value) in entity_with_mutated_component.iter() {
|
||||
for (entity, value) in &entity_with_mutated_component {
|
||||
println!(" {:?} is now {:?} frames old", entity, value);
|
||||
}
|
||||
}
|
||||
|
||||
// This system iterates over all entities and increases their age in every frame
|
||||
fn age_all_entities(mut entities: Query<&mut Age>) {
|
||||
for mut age in entities.iter_mut() {
|
||||
for mut age in &mut entities {
|
||||
age.frames += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// This system iterates over all entities in every frame and despawns entities older than 2 frames
|
||||
fn remove_old_entities(mut commands: Commands, entities: Query<(Entity, &Age)>) {
|
||||
for (entity, age) in entities.iter() {
|
||||
for (entity, age) in &entities {
|
||||
if age.frames > 2 {
|
||||
println!(" despawning {:?} due to age > 2", entity);
|
||||
commands.entity(entity).despawn();
|
||||
|
|
|
@ -134,7 +134,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
|
|||
let mut field_idents = Vec::new();
|
||||
let mut field_types = Vec::new();
|
||||
|
||||
for field in fields.iter() {
|
||||
for field in fields {
|
||||
let WorldQueryFieldInfo { is_ignored, attrs } = read_world_query_field_info(field);
|
||||
|
||||
let field_ident = field.ident.as_ref().unwrap().clone();
|
||||
|
|
|
@ -84,7 +84,7 @@ use std::{
|
|||
/// # struct Expired;
|
||||
/// #
|
||||
/// fn dispose_expired_food(mut commands: Commands, query: Query<Entity, With<Expired>>) {
|
||||
/// for food_entity in query.iter() {
|
||||
/// for food_entity in &query {
|
||||
/// commands.entity(food_entity).despawn();
|
||||
/// }
|
||||
/// }
|
||||
|
|
|
@ -79,7 +79,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// }
|
||||
///
|
||||
/// fn my_system(query: Query<MyQuery>) {
|
||||
/// for q in query.iter() {
|
||||
/// for q in &query {
|
||||
/// // Note the type of the returned item.
|
||||
/// let q: MyQueryItem<'_> = q;
|
||||
/// q.foo;
|
||||
|
@ -130,11 +130,11 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// fn my_system(mut health_query: Query<HealthQuery>) {
|
||||
/// // Iterator's item is `HealthQueryReadOnlyItem`.
|
||||
/// for health in health_query.iter() {
|
||||
/// for health in &health_query {
|
||||
/// println!("Total: {}", health.total());
|
||||
/// }
|
||||
/// // Iterator's item is `HealthQueryItem`.
|
||||
/// for mut health in health_query.iter_mut() {
|
||||
/// for mut health in &mut health_query {
|
||||
/// health.damage(1.0);
|
||||
/// println!("Total (mut): {}", health.total());
|
||||
/// }
|
||||
|
@ -158,7 +158,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// }
|
||||
///
|
||||
/// fn my_system(mut my_query: Query<(FooReadOnly, FooReadOnly)>) {
|
||||
/// for (i1, i2) in my_query.iter_mut() {
|
||||
/// for (i1, i2) in &mut my_query {
|
||||
/// let _: FooReadOnlyItem<'_> = i1;
|
||||
/// let _: FooReadOnlyItem<'_> = i2;
|
||||
/// }
|
||||
|
@ -254,7 +254,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
///
|
||||
/// // You can also compose derived queries with regular ones in tuples.
|
||||
/// fn my_system(query: Query<(&Foo, MyQuery, FooQuery)>) {
|
||||
/// for (foo, my_query, foo_query) in query.iter() {
|
||||
/// for (foo, my_query, foo_query) in &query {
|
||||
/// foo; my_query; foo_query;
|
||||
/// }
|
||||
/// }
|
||||
|
@ -279,7 +279,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// }
|
||||
///
|
||||
/// fn my_system(query: Query<EmptyQuery>) {
|
||||
/// for _ in query.iter() {}
|
||||
/// for _ in &query {}
|
||||
/// }
|
||||
///
|
||||
/// # bevy_ecs::system::assert_is_system(my_system);
|
||||
|
@ -311,7 +311,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
|||
/// }
|
||||
///
|
||||
/// fn my_system(query: Query<Entity, MyFilter<Foo, Qux>>) {
|
||||
/// for _ in query.iter() {}
|
||||
/// for _ in &query {}
|
||||
/// }
|
||||
///
|
||||
/// # bevy_ecs::system::assert_is_system(my_system);
|
||||
|
@ -1087,7 +1087,7 @@ unsafe impl<'w, T: Fetch<'w>> Fetch<'w> for OptionFetch<T> {
|
|||
/// # struct Transform {};
|
||||
/// #
|
||||
/// fn print_moving_objects_system(query: Query<(&Name, ChangeTrackers<Transform>)>) {
|
||||
/// for (name, tracker) in query.iter() {
|
||||
/// for (name, tracker) in &query {
|
||||
/// if tracker.is_changed() {
|
||||
/// println!("Entity moved: {:?}", name);
|
||||
/// } else {
|
||||
|
|
|
@ -36,7 +36,7 @@ use super::ReadOnlyWorldQuery;
|
|||
/// # struct Name { name: &'static str };
|
||||
/// #
|
||||
/// fn compliment_entity_system(query: Query<&Name, With<IsBeautiful>>) {
|
||||
/// for name in query.iter() {
|
||||
/// for name in &query {
|
||||
/// println!("{} is looking lovely today!", name.name);
|
||||
/// }
|
||||
/// }
|
||||
|
@ -177,7 +177,7 @@ impl<T> Copy for WithFetch<T> {}
|
|||
/// # struct Name { name: &'static str };
|
||||
/// #
|
||||
/// fn no_permit_system(query: Query<&Name, Without<Permit>>) {
|
||||
/// for name in query.iter() {
|
||||
/// for name in &query{
|
||||
/// println!("{} has no permit!", name.name);
|
||||
/// }
|
||||
/// }
|
||||
|
@ -324,7 +324,7 @@ impl<T> Copy for WithoutFetch<T> {}
|
|||
/// # struct Style {};
|
||||
/// #
|
||||
/// fn print_cool_entity_system(query: Query<Entity, Or<(Changed<Color>, Changed<Style>)>>) {
|
||||
/// for entity in query.iter() {
|
||||
/// for entity in &query {
|
||||
/// println!("Entity {:?} got a new style or color", entity);
|
||||
/// }
|
||||
/// }
|
||||
|
@ -685,7 +685,7 @@ impl_tick_filter!(
|
|||
/// # struct Name {};
|
||||
///
|
||||
/// fn print_add_name_component(query: Query<&Name, Added<Name>>) {
|
||||
/// for name in query.iter() {
|
||||
/// for name in &query {
|
||||
/// println!("Named entity created: {:?}", name)
|
||||
/// }
|
||||
/// }
|
||||
|
@ -725,7 +725,7 @@ impl_tick_filter!(
|
|||
/// # struct Transform {};
|
||||
///
|
||||
/// fn print_moving_objects_system(query: Query<&Name, Changed<Transform>>) {
|
||||
/// for name in query.iter() {
|
||||
/// for name in &query {
|
||||
/// println!("Entity Moved: {:?}", name);
|
||||
/// }
|
||||
/// }
|
||||
|
|
|
@ -264,7 +264,7 @@ impl<Q: WorldQuery, F: WorldQuery> QueryState<Q, F> {
|
|||
///
|
||||
/// let mut mutable_component_values = query_state.get_many_mut(&mut world, entities).unwrap();
|
||||
///
|
||||
/// for mut a in mutable_component_values.iter_mut(){
|
||||
/// for mut a in &mut mutable_component_values {
|
||||
/// a.0 += 5;
|
||||
/// }
|
||||
///
|
||||
|
@ -1074,7 +1074,7 @@ impl<Q: WorldQuery, F: WorldQuery> QueryState<Q, F> {
|
|||
|
||||
let tables = &world.storages.tables;
|
||||
|
||||
for entity in entity_list.into_iter() {
|
||||
for entity in entity_list {
|
||||
let location = match world.entities.get(*entity.borrow()) {
|
||||
Some(location) => location,
|
||||
None => continue,
|
||||
|
|
|
@ -81,7 +81,7 @@ impl ParallelSystemExecutor for ParallelExecutor {
|
|||
self.should_run.grow(systems.len());
|
||||
|
||||
// Construct scheduling data for systems.
|
||||
for container in systems.iter() {
|
||||
for container in systems {
|
||||
let dependencies_total = container.dependencies().len();
|
||||
let system = container.system();
|
||||
let (start_sender, start_receiver) = async_channel::bounded(1);
|
||||
|
|
|
@ -492,7 +492,7 @@ impl Tables {
|
|||
.from_key(component_ids)
|
||||
.or_insert_with(|| {
|
||||
let mut table = Table::with_capacity(0, component_ids.len());
|
||||
for component_id in component_ids.iter() {
|
||||
for component_id in component_ids {
|
||||
table.add_column(components.get_info_unchecked(*component_id));
|
||||
}
|
||||
tables.push(table);
|
||||
|
|
|
@ -75,7 +75,7 @@ unsafe impl SystemParamState for ParallelCommandsState {
|
|||
}
|
||||
|
||||
fn apply(&mut self, world: &mut World) {
|
||||
for cq in self.thread_local_storage.iter_mut() {
|
||||
for cq in &mut self.thread_local_storage {
|
||||
cq.get_mut().apply(world);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ mod tests {
|
|||
query: Query<Entity, With<Foo>>,
|
||||
mut counter: ResMut<usize>,
|
||||
) {
|
||||
for entity in query.iter() {
|
||||
for entity in &query {
|
||||
*counter += 1;
|
||||
commands.entity(entity).remove::<Foo>();
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ impl SystemMeta {
|
|||
/// world.resource_scope(|world, mut cached_state: Mut<CachedSystemState>| {
|
||||
/// let mut event_reader = cached_state.event_state.get_mut(world);
|
||||
///
|
||||
/// for events in event_reader.iter(){
|
||||
/// for events in event_reader.iter() {
|
||||
/// println!("Hello World!");
|
||||
/// };
|
||||
/// });
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
//! mut query: Query<(&Player, &mut Score)>,
|
||||
//! mut round: ResMut<Round>,
|
||||
//! ) {
|
||||
//! for (player, mut score) in query.iter_mut() {
|
||||
//! for (player, mut score) in &mut query {
|
||||
//! if player.alive {
|
||||
//! score.0 += round.0;
|
||||
//! }
|
||||
|
@ -135,7 +135,7 @@ mod tests {
|
|||
#[test]
|
||||
fn simple_system() {
|
||||
fn sys(query: Query<&A>) {
|
||||
for a in query.iter() {
|
||||
for a in &query {
|
||||
println!("{:?}", a);
|
||||
}
|
||||
}
|
||||
|
@ -598,7 +598,7 @@ mod tests {
|
|||
mut modified: ResMut<bool>,
|
||||
) {
|
||||
assert_eq!(query.iter().count(), 1, "entity exists");
|
||||
for entity in query.iter() {
|
||||
for entity in &query {
|
||||
let location = entities.get(entity).unwrap();
|
||||
let archetype = archetypes.get(location.archetype_id).unwrap();
|
||||
let archetype_components = archetype.components().collect::<Vec<_>>();
|
||||
|
|
|
@ -211,7 +211,7 @@ use std::{any::TypeId, borrow::Borrow, fmt::Debug};
|
|||
/// # #[derive(Component)]
|
||||
/// # struct ComponentB;
|
||||
/// fn immutable_query_system(query: Query<(&ComponentA, &ComponentB)>) {
|
||||
/// for (a, b) in query.iter() {
|
||||
/// for (a, b) in &query {
|
||||
/// // Here, `a` and `b` are normal references to components, relatively of
|
||||
/// // `&ComponentA` and `&ComponentB` types.
|
||||
/// }
|
||||
|
@ -219,7 +219,7 @@ use std::{any::TypeId, borrow::Borrow, fmt::Debug};
|
|||
/// # bevy_ecs::system::assert_is_system(immutable_query_system);
|
||||
///
|
||||
/// fn mutable_query_system(mut query: Query<(&mut ComponentA, &ComponentB)>) {
|
||||
/// for (mut a, b) in query.iter_mut() {
|
||||
/// for (mut a, b) in &mut query {
|
||||
/// // Similar to the above system, but this time `ComponentA` can be accessed mutably.
|
||||
/// // Note the usage of `mut` in the tuple and the call to `iter_mut` instead of `iter`.
|
||||
/// }
|
||||
|
@ -285,7 +285,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
|
|||
/// # struct Player { name: String }
|
||||
/// #
|
||||
/// fn report_names_system(query: Query<&Player>) {
|
||||
/// for player in query.iter() {
|
||||
/// for player in &query {
|
||||
/// println!("Say hello to {}!", player.name);
|
||||
/// }
|
||||
/// }
|
||||
|
@ -315,7 +315,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
|
|||
/// # struct Velocity { x: f32, y: f32, z: f32 }
|
||||
/// fn gravity_system(mut query: Query<&mut Velocity>) {
|
||||
/// const DELTA: f32 = 1.0 / 60.0;
|
||||
/// for mut velocity in query.iter_mut() {
|
||||
/// for mut velocity in &mut query {
|
||||
/// velocity.y -= 9.8 * DELTA;
|
||||
/// }
|
||||
/// }
|
||||
|
@ -782,7 +782,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
|
|||
/// }
|
||||
///
|
||||
/// fn check_all_targets_in_range(targeting_query: Query<(Entity, &Targets, &Position)>, targets_query: Query<&Position>){
|
||||
/// for (targeting_entity, targets, origin) in targeting_query.iter(){
|
||||
/// for (targeting_entity, targets, origin) in &targeting_query {
|
||||
/// // We can use "destructuring" to unpack the results nicely
|
||||
/// let [target_1, target_2, target_3] = targets_query.many(targets.0);
|
||||
///
|
||||
|
@ -885,7 +885,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
|
|||
/// }
|
||||
///
|
||||
/// fn spring_forces(spring_query: Query<&Spring>, mut mass_query: Query<(&Position, &mut Force)>){
|
||||
/// for spring in spring_query.iter(){
|
||||
/// for spring in &spring_query {
|
||||
/// // We can use "destructuring" to unpack our query items nicely
|
||||
/// let [(position_1, mut force_1), (position_2, mut force_2)] = mass_query.many_mut(spring.connected_entities);
|
||||
///
|
||||
|
@ -1375,7 +1375,7 @@ impl<'w, 's, Q: ReadOnlyWorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
|
|||
/// # struct Player { name: String }
|
||||
/// #
|
||||
/// fn report_names_system(query: Query<&Player>) {
|
||||
/// for player in query.iter() {
|
||||
/// for player in &query {
|
||||
/// println!("Say hello to {}!", player.name);
|
||||
/// }
|
||||
/// }
|
||||
|
|
|
@ -17,7 +17,7 @@ pub struct Children(pub(crate) SmallVec<[Entity; 8]>);
|
|||
|
||||
impl MapEntities for Children {
|
||||
fn map_entities(&mut self, entity_map: &EntityMap) -> Result<(), MapEntitiesError> {
|
||||
for entity in self.0.iter_mut() {
|
||||
for entity in &mut self.0 {
|
||||
*entity = entity_map.get(*entity)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -459,7 +459,7 @@ pub fn add_clusters(
|
|||
mut commands: Commands,
|
||||
cameras: Query<(Entity, Option<&ClusterConfig>), (With<Camera>, Without<Clusters>)>,
|
||||
) {
|
||||
for (entity, config) in cameras.iter() {
|
||||
for (entity, config) in &cameras {
|
||||
let config = config.copied().unwrap_or_default();
|
||||
// actual settings here don't matter - they will be overwritten in assign_lights_to_clusters
|
||||
commands
|
||||
|
@ -901,7 +901,7 @@ pub(crate) fn assign_lights_to_clusters(
|
|||
}
|
||||
|
||||
for (view_entity, camera_transform, camera, frustum, config, clusters, mut visible_lights) in
|
||||
views.iter_mut()
|
||||
&mut views
|
||||
{
|
||||
let clusters = clusters.into_inner();
|
||||
|
||||
|
@ -1420,7 +1420,7 @@ pub fn update_directional_light_frusta(
|
|||
Or<(Changed<GlobalTransform>, Changed<DirectionalLight>)>,
|
||||
>,
|
||||
) {
|
||||
for (transform, directional_light, mut frustum, visibility) in views.iter_mut() {
|
||||
for (transform, directional_light, mut frustum, visibility) in &mut views {
|
||||
// The frustum is used for culling meshes to the light for shadow mapping
|
||||
// so if shadow mapping is disabled for this light, then the frustum is
|
||||
// not needed.
|
||||
|
@ -1454,7 +1454,7 @@ pub fn update_point_light_frusta(
|
|||
.map(|CubeMapFace { target, up }| GlobalTransform::identity().looking_at(*target, *up))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for (entity, transform, point_light, mut cubemap_frusta) in views.iter_mut() {
|
||||
for (entity, transform, point_light, mut cubemap_frusta) in &mut views {
|
||||
// The frusta are used for culling meshes to the light for shadow mapping
|
||||
// so if shadow mapping is disabled for this light, then the frusta are
|
||||
// not needed.
|
||||
|
@ -1559,7 +1559,7 @@ pub fn check_light_mesh_visibility(
|
|||
) {
|
||||
// Directonal lights
|
||||
for (directional_light, frustum, mut visible_entities, maybe_view_mask, visibility) in
|
||||
directional_lights.iter_mut()
|
||||
&mut directional_lights
|
||||
{
|
||||
visible_entities.entities.clear();
|
||||
|
||||
|
@ -1577,7 +1577,7 @@ pub fn check_light_mesh_visibility(
|
|||
maybe_entity_mask,
|
||||
maybe_aabb,
|
||||
maybe_transform,
|
||||
) in visible_entity_query.iter_mut()
|
||||
) in &mut visible_entity_query
|
||||
{
|
||||
if !visibility.is_visible {
|
||||
continue;
|
||||
|
@ -1603,7 +1603,7 @@ pub fn check_light_mesh_visibility(
|
|||
// to prevent holding unneeded memory
|
||||
}
|
||||
|
||||
for visible_lights in visible_point_lights.iter() {
|
||||
for visible_lights in &visible_point_lights {
|
||||
for light_entity in visible_lights.entities.iter().copied() {
|
||||
// Point lights
|
||||
if let Ok((
|
||||
|
@ -1636,7 +1636,7 @@ pub fn check_light_mesh_visibility(
|
|||
maybe_entity_mask,
|
||||
maybe_aabb,
|
||||
maybe_transform,
|
||||
) in visible_entity_query.iter_mut()
|
||||
) in &mut visible_entity_query
|
||||
{
|
||||
if !visibility.is_visible {
|
||||
continue;
|
||||
|
|
|
@ -333,7 +333,7 @@ pub fn queue_material_meshes<M: Material>(
|
|||
M::Data: PartialEq + Eq + Hash + Clone,
|
||||
{
|
||||
for (view, visible_entities, mut opaque_phase, mut alpha_mask_phase, mut transparent_phase) in
|
||||
views.iter_mut()
|
||||
&mut views
|
||||
{
|
||||
let draw_opaque_pbr = opaque_draw_functions
|
||||
.read()
|
||||
|
|
|
@ -885,7 +885,7 @@ pub fn prepare_lights(
|
|||
.write_buffer(&render_device, &render_queue);
|
||||
|
||||
// set up light data for each view
|
||||
for (entity, extracted_view, clusters) in views.iter() {
|
||||
for (entity, extracted_view, clusters) in &views {
|
||||
let point_light_depth_texture = texture_cache.get(
|
||||
&render_device,
|
||||
TextureDescriptor {
|
||||
|
@ -1482,7 +1482,7 @@ pub fn prepare_clusters(
|
|||
mesh_pipeline.clustered_forward_buffer_binding_type,
|
||||
BufferBindingType::Storage { .. }
|
||||
);
|
||||
for (entity, cluster_config, extracted_clusters) in views.iter() {
|
||||
for (entity, cluster_config, extracted_clusters) in &views {
|
||||
let mut view_clusters_bindings =
|
||||
ViewClusterBindings::new(mesh_pipeline.clustered_forward_buffer_binding_type);
|
||||
view_clusters_bindings.clear();
|
||||
|
@ -1562,7 +1562,7 @@ pub fn queue_shadows(
|
|||
directional_light_entities: Query<&VisibleEntities, With<ExtractedDirectionalLight>>,
|
||||
spot_light_entities: Query<&VisibleEntities, With<ExtractedPointLight>>,
|
||||
) {
|
||||
for view_lights in view_lights.iter() {
|
||||
for view_lights in &view_lights {
|
||||
let draw_shadow_mesh = shadow_draw_functions
|
||||
.read()
|
||||
.get_id::<DrawShadowMesh>()
|
||||
|
|
|
@ -753,7 +753,7 @@ pub fn queue_mesh_view_bind_groups(
|
|||
light_meta.view_gpu_lights.binding(),
|
||||
global_light_meta.gpu_point_lights.binding(),
|
||||
) {
|
||||
for (entity, view_shadow_bindings, view_cluster_bindings) in views.iter() {
|
||||
for (entity, view_shadow_bindings, view_cluster_bindings) in &views {
|
||||
let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor {
|
||||
entries: &[
|
||||
BindGroupEntry {
|
||||
|
|
|
@ -51,7 +51,7 @@ impl Plugin for WireframePlugin {
|
|||
}
|
||||
|
||||
fn extract_wireframes(mut commands: Commands, query: Query<Entity, With<Wireframe>>) {
|
||||
for entity in query.iter() {
|
||||
for entity in &query {
|
||||
commands.get_or_spawn(entity).insert(Wireframe);
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ fn queue_wireframes(
|
|||
.get_id::<DrawWireframes>()
|
||||
.unwrap();
|
||||
let msaa_key = MeshPipelineKey::from_msaa_samples(msaa.samples);
|
||||
for (view, visible_entities, mut opaque_phase) in views.iter_mut() {
|
||||
for (view, visible_entities, mut opaque_phase) in &mut views {
|
||||
let rangefinder = view.rangefinder3d();
|
||||
|
||||
let add_render_phase =
|
||||
|
|
|
@ -103,7 +103,7 @@ fn parse_meta(args: &mut ReflectFieldAttr, meta: &Meta) -> Result<(), syn::Error
|
|||
Err(syn::Error::new(list.path.span(), "unexpected property"))
|
||||
}
|
||||
Meta::List(list) => {
|
||||
for nested in list.nested.iter() {
|
||||
for nested in &list.nested {
|
||||
if let NestedMeta::Meta(meta) = nested {
|
||||
parse_meta(args, meta)?;
|
||||
}
|
||||
|
|
|
@ -362,10 +362,10 @@ pub fn camera_system<T: CameraProjection + Component>(
|
|||
.collect();
|
||||
|
||||
let mut added_cameras = vec![];
|
||||
for entity in &mut queries.p1().iter() {
|
||||
for entity in &queries.p1() {
|
||||
added_cameras.push(entity);
|
||||
}
|
||||
for (entity, mut camera, mut camera_projection) in queries.p0().iter_mut() {
|
||||
for (entity, mut camera, mut camera_projection) in &mut queries.p0() {
|
||||
if camera
|
||||
.target
|
||||
.is_changed(&changed_window_ids, &changed_image_handles)
|
||||
|
|
|
@ -465,7 +465,7 @@ impl InnerMeshVertexBufferLayout {
|
|||
attribute_descriptors: &[VertexAttributeDescriptor],
|
||||
) -> Result<VertexBufferLayout, MissingVertexAttributeError> {
|
||||
let mut attributes = Vec::with_capacity(attribute_descriptors.len());
|
||||
for attribute_descriptor in attribute_descriptors.iter() {
|
||||
for attribute_descriptor in attribute_descriptors {
|
||||
if let Some(index) = self
|
||||
.attribute_ids
|
||||
.iter()
|
||||
|
|
|
@ -63,14 +63,14 @@ impl<I: BatchedPhaseItem> RenderPhase<I> {
|
|||
|
||||
/// This system sorts all [`RenderPhases`](RenderPhase) for the [`PhaseItem`] type.
|
||||
pub fn sort_phase_system<I: PhaseItem>(mut render_phases: Query<&mut RenderPhase<I>>) {
|
||||
for mut phase in render_phases.iter_mut() {
|
||||
for mut phase in &mut render_phases {
|
||||
phase.sort();
|
||||
}
|
||||
}
|
||||
|
||||
/// This system batches the [`PhaseItem`]s of all [`RenderPhase`]s of this type.
|
||||
pub fn batch_phase_system<I: BatchedPhaseItem>(mut render_phases: Query<&mut RenderPhase<I>>) {
|
||||
for mut phase in render_phases.iter_mut() {
|
||||
for mut phase in &mut render_phases {
|
||||
phase.batch();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ fn prepare_view_uniforms(
|
|||
views: Query<(Entity, &ExtractedView)>,
|
||||
) {
|
||||
view_uniforms.uniforms.clear();
|
||||
for (entity, camera) in views.iter() {
|
||||
for (entity, camera) in &views {
|
||||
let projection = camera.projection;
|
||||
let inverse_projection = projection.inverse();
|
||||
let view = camera.transform.compute_matrix();
|
||||
|
@ -187,7 +187,7 @@ fn prepare_view_targets(
|
|||
cameras: Query<(Entity, &ExtractedCamera)>,
|
||||
) {
|
||||
let mut sampled_textures = HashMap::default();
|
||||
for (entity, camera) in cameras.iter() {
|
||||
for (entity, camera) in &cameras {
|
||||
if let Some(target_size) = camera.physical_target_size {
|
||||
if let Some(texture_view) = camera.target.get_texture_view(&windows, &images) {
|
||||
let sampled_target = if msaa.samples > 1 {
|
||||
|
|
|
@ -139,7 +139,7 @@ pub fn calculate_bounds(
|
|||
meshes: Res<Assets<Mesh>>,
|
||||
without_aabb: Query<(Entity, &Handle<Mesh>), (Without<Aabb>, Without<NoFrustumCulling>)>,
|
||||
) {
|
||||
for (entity, mesh_handle) in without_aabb.iter() {
|
||||
for (entity, mesh_handle) in &without_aabb {
|
||||
if let Some(mesh) = meshes.get(mesh_handle) {
|
||||
if let Some(aabb) = mesh.compute_aabb() {
|
||||
commands.entity(entity).insert(aabb);
|
||||
|
@ -151,7 +151,7 @@ pub fn calculate_bounds(
|
|||
pub fn update_frusta<T: Component + CameraProjection + Send + Sync + 'static>(
|
||||
mut views: Query<(&GlobalTransform, &T, &mut Frustum)>,
|
||||
) {
|
||||
for (transform, projection, mut frustum) in views.iter_mut() {
|
||||
for (transform, projection, mut frustum) in &mut views {
|
||||
let view_projection =
|
||||
projection.get_projection_matrix() * transform.compute_matrix().inverse();
|
||||
*frustum = Frustum::from_view_projection(
|
||||
|
@ -189,7 +189,7 @@ pub fn check_visibility(
|
|||
computed_visibility.is_visible = false;
|
||||
}
|
||||
|
||||
for (mut visible_entities, frustum, maybe_view_mask) in view_query.iter_mut() {
|
||||
for (mut visible_entities, frustum, maybe_view_mask) in &mut view_query {
|
||||
let view_mask = maybe_view_mask.copied().unwrap_or_default();
|
||||
visible_entities.entities.clear();
|
||||
visible_entity_query.p1().par_for_each_mut(
|
||||
|
|
|
@ -53,7 +53,7 @@ pub fn scene_spawner(
|
|||
>,
|
||||
mut scene_spawner: ResMut<SceneSpawner>,
|
||||
) {
|
||||
for (entity, scene, instance) in scene_to_spawn.iter_mut() {
|
||||
for (entity, scene, instance) in &mut scene_to_spawn {
|
||||
let new_instance = scene_spawner.spawn_as_child(scene.clone(), entity);
|
||||
if let Some(mut old_instance) = instance {
|
||||
scene_spawner.despawn_instance(**old_instance);
|
||||
|
@ -62,7 +62,7 @@ pub fn scene_spawner(
|
|||
commands.entity(entity).insert(SceneInstance(new_instance));
|
||||
}
|
||||
}
|
||||
for (entity, dynamic_scene, instance) in dynamic_scene_to_spawn.iter_mut() {
|
||||
for (entity, dynamic_scene, instance) in &mut dynamic_scene_to_spawn {
|
||||
let new_instance = scene_spawner.spawn_dynamic_as_child(dynamic_scene.clone(), entity);
|
||||
if let Some(mut old_instance) = instance {
|
||||
scene_spawner.despawn_instance(**old_instance);
|
||||
|
|
|
@ -227,7 +227,7 @@ impl SceneSpawner {
|
|||
) -> Result<(), SceneSpawnError> {
|
||||
for scene_handle in scene_handles {
|
||||
if let Some(spawned_instances) = self.spawned_dynamic_scenes.get(scene_handle) {
|
||||
for instance_id in spawned_instances.iter() {
|
||||
for instance_id in spawned_instances {
|
||||
if let Some(instance_info) = self.spawned_instances.get_mut(instance_id) {
|
||||
Self::spawn_dynamic_internal(
|
||||
world,
|
||||
|
|
|
@ -71,7 +71,7 @@ impl<'a> Serialize for ComponentsSerializer<'a> {
|
|||
S: serde::Serializer,
|
||||
{
|
||||
let mut state = serializer.serialize_seq(Some(self.components.len()))?;
|
||||
for component in self.components.iter() {
|
||||
for component in self.components {
|
||||
state.serialize_element(&ReflectSerializer::new(
|
||||
&**component,
|
||||
&*self.registry.read(),
|
||||
|
|
|
@ -310,7 +310,7 @@ pub fn queue_material2d_meshes<M: SpecializedMaterial2d>(
|
|||
return;
|
||||
}
|
||||
let render_device = render_device.into_inner();
|
||||
for (visible_entities, mut transparent_phase) in views.iter_mut() {
|
||||
for (visible_entities, mut transparent_phase) in &mut views {
|
||||
let draw_transparent_pbr = transparent_draw_functions
|
||||
.read()
|
||||
.get_id::<DrawMaterial2d<M>>()
|
||||
|
|
|
@ -408,7 +408,7 @@ pub fn queue_mesh2d_view_bind_groups(
|
|||
views: Query<Entity, With<ExtractedView>>,
|
||||
) {
|
||||
if let Some(view_binding) = view_uniforms.uniforms.binding() {
|
||||
for entity in views.iter() {
|
||||
for entity in &views {
|
||||
let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor {
|
||||
entries: &[BindGroupEntry {
|
||||
binding: 0,
|
||||
|
|
|
@ -389,7 +389,7 @@ pub fn queue_sprites(
|
|||
let mut colored_index = 0;
|
||||
|
||||
// FIXME: VisibleEntities is ignored
|
||||
for mut transparent_phase in views.iter_mut() {
|
||||
for mut transparent_phase in &mut views {
|
||||
let extracted_sprites = &mut extracted_sprites.sprites;
|
||||
let image_bind_groups = &mut *image_bind_groups;
|
||||
|
||||
|
@ -420,7 +420,7 @@ pub fn queue_sprites(
|
|||
// Compatible items share the same entity.
|
||||
// Batches are merged later (in `batch_phase_system()`), so that they can be interrupted
|
||||
// by any other phase item (and they can interrupt other items from batching).
|
||||
for extracted_sprite in extracted_sprites.iter() {
|
||||
for extracted_sprite in extracted_sprites {
|
||||
let new_batch = SpriteBatch {
|
||||
image_handle_id: extracted_sprite.image_handle_id,
|
||||
colored: extracted_sprite.color != Color::WHITE,
|
||||
|
|
|
@ -147,7 +147,7 @@ pub fn update_text2d_layout(
|
|||
let factor_changed = scale_factor_changed.iter().last().is_some();
|
||||
let scale_factor = windows.scale_factor(WindowId::primary());
|
||||
|
||||
for (entity, text_changed, text, maybe_bounds, mut calculated_size) in text_query.iter_mut() {
|
||||
for (entity, text_changed, text, maybe_bounds, mut calculated_size) in &mut text_query {
|
||||
if factor_changed || text_changed || queue.remove(&entity) {
|
||||
let text_bounds = match maybe_bounds {
|
||||
Some(bounds) => Vec2::new(
|
||||
|
|
|
@ -34,7 +34,7 @@ pub fn transform_propagate_system(
|
|||
if let Some((children, changed_children)) = children {
|
||||
// If our `Children` has changed, we need to recalculate everything below us
|
||||
changed |= changed_children;
|
||||
for child in children.iter() {
|
||||
for child in children {
|
||||
let _ = propagate_recursive(
|
||||
&global_transform,
|
||||
&mut transform_query,
|
||||
|
@ -80,7 +80,7 @@ fn propagate_recursive(
|
|||
let (children, changed_children) = children_query.get(entity).map_err(drop)?;
|
||||
// If our `Children` has changed, we need to recalculate everything below us
|
||||
changed |= changed_children;
|
||||
for child in children.iter() {
|
||||
for child in children {
|
||||
let _ = propagate_recursive(
|
||||
&global_matrix,
|
||||
transform_query,
|
||||
|
|
|
@ -112,7 +112,7 @@ impl FlexSurface {
|
|||
|
||||
pub fn update_children(&mut self, entity: Entity, children: &Children) {
|
||||
let mut taffy_children = Vec::with_capacity(children.len());
|
||||
for child in children.iter() {
|
||||
for child in children {
|
||||
if let Some(taffy_node) = self.entity_to_taffy.get(child) {
|
||||
taffy_children.push(*taffy_node);
|
||||
} else {
|
||||
|
@ -231,7 +231,7 @@ pub fn flex_node_system(
|
|||
query: Query<(Entity, &Style, Option<&CalculatedSize>), F>,
|
||||
) {
|
||||
// update changed nodes
|
||||
for (entity, style, calculated_size) in query.iter() {
|
||||
for (entity, style, calculated_size) in &query {
|
||||
// TODO: remove node from old hierarchy if its root has changed
|
||||
if let Some(calculated_size) = calculated_size {
|
||||
flex_surface.upsert_leaf(entity, style, *calculated_size, scaling_factor);
|
||||
|
@ -241,7 +241,7 @@ pub fn flex_node_system(
|
|||
}
|
||||
}
|
||||
|
||||
for (entity, style, calculated_size) in changed_size_query.iter() {
|
||||
for (entity, style, calculated_size) in &changed_size_query {
|
||||
flex_surface.upsert_leaf(entity, style, *calculated_size, logical_to_physical_factor);
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ pub fn flex_node_system(
|
|||
}
|
||||
|
||||
// update children
|
||||
for (entity, children) in children_query.iter() {
|
||||
for (entity, children) in &children_query {
|
||||
flex_surface.update_children(entity, children);
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ pub fn flex_node_system(
|
|||
let to_logical = |v| (physical_to_logical_factor * v as f64) as f32;
|
||||
|
||||
// PERF: try doing this incrementally
|
||||
for (entity, mut node, mut transform, parent) in node_transform_query.iter_mut() {
|
||||
for (entity, mut node, mut transform, parent) in &mut node_transform_query {
|
||||
let layout = flex_surface.get_layout(entity).unwrap();
|
||||
let new_size = Vec2::new(
|
||||
to_logical(layout.size.width),
|
||||
|
|
|
@ -529,8 +529,8 @@ pub fn queue_uinodes(
|
|||
}));
|
||||
let draw_ui_function = draw_functions.read().get_id::<DrawUi>().unwrap();
|
||||
let pipeline = pipelines.specialize(&mut pipeline_cache, &ui_pipeline, UiPipelineKey {});
|
||||
for mut transparent_phase in views.iter_mut() {
|
||||
for (entity, batch) in ui_batches.iter() {
|
||||
for mut transparent_phase in &mut views {
|
||||
for (entity, batch) in &ui_batches {
|
||||
image_bind_groups
|
||||
.values
|
||||
.entry(batch.image.clone_weak())
|
||||
|
|
|
@ -23,7 +23,7 @@ pub fn ui_z_system(
|
|||
children_query: Query<&Children>,
|
||||
) {
|
||||
let mut current_global_z = 0.0;
|
||||
for entity in root_node_query.iter() {
|
||||
for entity in &root_node_query {
|
||||
current_global_z = update_hierarchy(
|
||||
&children_query,
|
||||
&mut node_query,
|
||||
|
@ -71,7 +71,7 @@ pub fn update_clipping_system(
|
|||
mut node_query: Query<(&Node, &GlobalTransform, &Style, Option<&mut CalculatedClip>)>,
|
||||
children_query: Query<&Children>,
|
||||
) {
|
||||
for root_node in root_node_query.iter() {
|
||||
for root_node in &root_node_query {
|
||||
update_clipping(
|
||||
&mut commands,
|
||||
&children_query,
|
||||
|
|
|
@ -25,7 +25,7 @@ pub fn image_node_system(
|
|||
textures: Res<Assets<Image>>,
|
||||
mut query: Query<(&mut CalculatedSize, &UiImage), With<ImageMode>>,
|
||||
) {
|
||||
for (mut calculated_size, image) in query.iter_mut() {
|
||||
for (mut calculated_size, image) in &mut query {
|
||||
if let Some(texture) = textures.get(image) {
|
||||
let size = Size {
|
||||
width: texture.texture_descriptor.size.width as f32,
|
||||
|
|
|
@ -162,7 +162,7 @@ impl WindowResizeConstraints {
|
|||
/// # App::new().add_system(access_window_system).run();
|
||||
/// # }
|
||||
/// fn access_window_system(mut windows: ResMut<Windows>){
|
||||
/// for mut window in windows.iter_mut(){
|
||||
/// for mut window in windows.iter_mut() {
|
||||
/// window.set_title(String::from("Yay, I'm a window!"));
|
||||
/// }
|
||||
/// }
|
||||
|
|
|
@ -317,7 +317,7 @@ pub fn queue_colored_mesh2d(
|
|||
return;
|
||||
}
|
||||
// Iterate each view (a camera is a view)
|
||||
for (visible_entities, mut transparent_phase) in views.iter_mut() {
|
||||
for (visible_entities, mut transparent_phase) in &mut views {
|
||||
let draw_colored_mesh2d = transparent_draw_functions
|
||||
.read()
|
||||
.get_id::<DrawColoredMesh2d>()
|
||||
|
|
|
@ -30,7 +30,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
/// The sprite is animated by changing its translation depending on the time that has passed since
|
||||
/// the last frame.
|
||||
fn sprite_movement(time: Res<Time>, mut sprite_position: Query<(&mut Direction, &mut Transform)>) {
|
||||
for (mut logo, mut transform) in sprite_position.iter_mut() {
|
||||
for (mut logo, mut transform) in &mut sprite_position {
|
||||
match *logo {
|
||||
Direction::Up => transform.translation.y += 150. * time.delta_seconds(),
|
||||
Direction::Down => transform.translation.y -= 150. * time.delta_seconds(),
|
||||
|
|
|
@ -156,7 +156,7 @@ fn snap_to_player_system(
|
|||
// get the player translation in 2D
|
||||
let player_translation = player_transform.translation.xy();
|
||||
|
||||
for mut enemy_transform in query.iter_mut() {
|
||||
for mut enemy_transform in &mut query {
|
||||
// get the vector from the enemy ship to the player ship in 2D and normalize it.
|
||||
let to_player = (player_translation - enemy_transform.translation.xy()).normalize();
|
||||
|
||||
|
@ -198,7 +198,7 @@ fn rotate_to_player_system(
|
|||
// get the player translation in 2D
|
||||
let player_translation = player_transform.translation.xy();
|
||||
|
||||
for (config, mut enemy_transform) in query.iter_mut() {
|
||||
for (config, mut enemy_transform) in &mut query {
|
||||
// get the enemy ship forward vector in 2D (already unit length)
|
||||
let enemy_forward = (enemy_transform.rotation * Vec3::Y).xy();
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ fn animate_sprite(
|
|||
&Handle<TextureAtlas>,
|
||||
)>,
|
||||
) {
|
||||
for (mut timer, mut sprite, texture_atlas_handle) in query.iter_mut() {
|
||||
for (mut timer, mut sprite, texture_atlas_handle) in &mut query {
|
||||
timer.tick(time.delta());
|
||||
if timer.just_finished() {
|
||||
let texture_atlas = texture_atlases.get(texture_atlas_handle).unwrap();
|
||||
|
|
|
@ -100,7 +100,7 @@ fn animate_translation(
|
|||
time: Res<Time>,
|
||||
mut query: Query<&mut Transform, (With<Text>, With<AnimateTranslation>)>,
|
||||
) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.translation.x = 100.0 * time.seconds_since_startup().sin() as f32 - 400.0;
|
||||
transform.translation.y = 100.0 * time.seconds_since_startup().cos() as f32;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ fn animate_rotation(
|
|||
time: Res<Time>,
|
||||
mut query: Query<&mut Transform, (With<Text>, With<AnimateRotation>)>,
|
||||
) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotation = Quat::from_rotation_z(time.seconds_since_startup().cos() as f32);
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ fn animate_scale(
|
|||
) {
|
||||
// Consider changing font-size instead of scaling the transform. Scaling a Text2D will scale the
|
||||
// rendered quad, resulting in a pixellated look.
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.translation = Vec3::new(400.0, 0.0, 0.0);
|
||||
transform.scale = Vec3::splat((time.seconds_since_startup().sin() as f32 + 1.1) * 2.0);
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ fn animate_light_direction(
|
|||
time: Res<Time>,
|
||||
mut query: Query<&mut Transform, With<DirectionalLight>>,
|
||||
) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_y(time.delta_seconds() * 0.5);
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ fn movement(
|
|||
time: Res<Time>,
|
||||
mut query: Query<&mut Transform, With<Movable>>,
|
||||
) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
let mut direction = Vec3::ZERO;
|
||||
if input.pressed(KeyCode::Up) {
|
||||
direction.y += 1.0;
|
||||
|
|
|
@ -46,7 +46,7 @@ fn animate_light_direction(
|
|||
time: Res<Time>,
|
||||
mut query: Query<&mut Transform, With<DirectionalLight>>,
|
||||
) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotation = Quat::from_euler(
|
||||
EulerRot::ZYX,
|
||||
0.0,
|
||||
|
|
|
@ -17,7 +17,7 @@ struct Rotator;
|
|||
|
||||
/// rotates the parent, which will result in the child also rotating
|
||||
fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<Rotator>>) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_x(3.0 * time.delta_seconds());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ fn setup(
|
|||
|
||||
/// Rotates the inner cube (first pass)
|
||||
fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<FirstPassCube>>) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_x(1.5 * time.delta_seconds());
|
||||
transform.rotate_z(1.3 * time.delta_seconds());
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<FirstPa
|
|||
|
||||
/// Rotates the outer cube (main pass)
|
||||
fn cube_rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<MainPassCube>>) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_x(1.0 * time.delta_seconds());
|
||||
transform.rotate_y(0.7 * time.delta_seconds());
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ fn toggle_light(
|
|||
mut directional_lights: Query<&mut DirectionalLight>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::L) {
|
||||
for mut light in point_lights.iter_mut() {
|
||||
for mut light in &mut point_lights {
|
||||
light.intensity = if light.intensity == 0.0 {
|
||||
println!("Using PointLight");
|
||||
100000000.0
|
||||
|
@ -126,7 +126,7 @@ fn toggle_light(
|
|||
0.0
|
||||
};
|
||||
}
|
||||
for mut light in directional_lights.iter_mut() {
|
||||
for mut light in &mut directional_lights {
|
||||
light.illuminance = if light.illuminance == 0.0 {
|
||||
println!("Using DirectionalLight");
|
||||
100000.0
|
||||
|
@ -140,7 +140,7 @@ fn toggle_light(
|
|||
fn adjust_point_light_biases(input: Res<Input<KeyCode>>, mut query: Query<&mut PointLight>) {
|
||||
let depth_bias_step_size = 0.01;
|
||||
let normal_bias_step_size = 0.1;
|
||||
for mut light in query.iter_mut() {
|
||||
for mut light in &mut query {
|
||||
if input.just_pressed(KeyCode::Key1) {
|
||||
light.shadow_depth_bias -= depth_bias_step_size;
|
||||
println!("PointLight shadow_depth_bias: {}", light.shadow_depth_bias);
|
||||
|
@ -172,7 +172,7 @@ fn adjust_directional_light_biases(
|
|||
) {
|
||||
let depth_bias_step_size = 0.01;
|
||||
let normal_bias_step_size = 0.1;
|
||||
for mut light in query.iter_mut() {
|
||||
for mut light in &mut query {
|
||||
if input.just_pressed(KeyCode::Key5) {
|
||||
light.shadow_depth_bias -= depth_bias_step_size;
|
||||
println!(
|
||||
|
@ -259,7 +259,7 @@ fn camera_controller(
|
|||
mouse_delta += mouse_event.delta;
|
||||
}
|
||||
|
||||
for (mut transform, mut options) in query.iter_mut() {
|
||||
for (mut transform, mut options) in &mut query {
|
||||
if !options.enabled {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ fn toggle_light(
|
|||
mut directional_lights: Query<&mut DirectionalLight>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::L) {
|
||||
for mut light in point_lights.iter_mut() {
|
||||
for mut light in &mut point_lights {
|
||||
light.intensity = if light.intensity == 0.0 {
|
||||
println!("Using PointLight");
|
||||
100000000.0
|
||||
|
@ -132,7 +132,7 @@ fn toggle_light(
|
|||
0.0
|
||||
};
|
||||
}
|
||||
for mut light in directional_lights.iter_mut() {
|
||||
for mut light in &mut directional_lights {
|
||||
light.illuminance = if light.illuminance == 0.0 {
|
||||
println!("Using DirectionalLight");
|
||||
100000.0
|
||||
|
|
|
@ -86,7 +86,7 @@ fn setup(
|
|||
}
|
||||
|
||||
fn rotate(mut query: Query<&mut Transform, With<Shape>>, time: Res<Time>) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_y(time.delta_seconds() / 2.);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ fn move_scene_entities(
|
|||
children: Query<&Children>,
|
||||
mut transforms: Query<&mut Transform>,
|
||||
) {
|
||||
for moved_scene_entity in moved_scene.iter() {
|
||||
for moved_scene_entity in &moved_scene {
|
||||
let mut offset = 0.;
|
||||
iter_hierarchy(moved_scene_entity, &children, &mut |entity| {
|
||||
if let Ok(mut transform) = transforms.get_mut(entity) {
|
||||
|
|
|
@ -163,7 +163,7 @@ fn setup(
|
|||
|
||||
/// Animate the joint marked with [`AnimatedJoint`] component.
|
||||
fn joint_animation(time: Res<Time>, mut query: Query<&mut Transform, With<AnimatedJoint>>) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotation = Quat::from_axis_angle(
|
||||
Vec3::Z,
|
||||
0.5 * PI * time.time_since_startup().as_secs_f32().sin(),
|
||||
|
|
|
@ -50,7 +50,7 @@ fn joint_animation(
|
|||
mut transform_query: Query<&mut Transform>,
|
||||
) {
|
||||
// Iter skinned mesh entity
|
||||
for skinned_mesh_parent in parent_query.iter() {
|
||||
for skinned_mesh_parent in &parent_query {
|
||||
// Mesh node is the parent of the skinned mesh entity.
|
||||
let mesh_node_entity = skinned_mesh_parent.get();
|
||||
// Get `Children` in the mesh node.
|
||||
|
|
|
@ -86,7 +86,7 @@ fn handle_tasks(
|
|||
box_mesh_handle: Res<BoxMeshHandle>,
|
||||
box_material_handle: Res<BoxMaterialHandle>,
|
||||
) {
|
||||
for (entity, mut task) in transform_tasks.iter_mut() {
|
||||
for (entity, mut task) in &mut transform_tasks {
|
||||
if let Some(transform) = future::block_on(future::poll_once(&mut task.0)) {
|
||||
// Add our new PbrBundle of components to our tagged entity
|
||||
commands.entity(entity).insert_bundle(PbrBundle {
|
||||
|
|
|
@ -84,7 +84,7 @@ fn move_text(
|
|||
mut texts: Query<(Entity, &mut Transform), With<Text>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
for (entity, mut position) in texts.iter_mut() {
|
||||
for (entity, mut position) in &mut texts {
|
||||
position.translation -= Vec3::new(0.0, 100.0 * time.delta_seconds(), 0.0);
|
||||
if position.translation.y < -300.0 {
|
||||
commands.entity(entity).despawn();
|
||||
|
|
|
@ -22,7 +22,7 @@ fn setup(mut commands: Commands) {
|
|||
}
|
||||
|
||||
fn change_component(time: Res<Time>, mut query: Query<(Entity, &mut MyComponent)>) {
|
||||
for (entity, mut component) in query.iter_mut() {
|
||||
for (entity, mut component) in &mut query {
|
||||
if rand::thread_rng().gen_bool(0.1) {
|
||||
info!("changing component {:?}", entity);
|
||||
component.0 = time.seconds_since_startup();
|
||||
|
@ -33,7 +33,7 @@ fn change_component(time: Res<Time>, mut query: Query<(Entity, &mut MyComponent)
|
|||
// There are query filters for `Changed<T>` and `Added<T>`
|
||||
// Only entities matching the filters will be in the query
|
||||
fn change_detection(query: Query<(Entity, &MyComponent), Changed<MyComponent>>) {
|
||||
for (entity, component) in query.iter() {
|
||||
for (entity, component) in &query {
|
||||
info!("{:?} changed: {:?}", entity, component,);
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ fn tracker_monitoring(
|
|||
Option<ChangeTrackers<MyComponent>>,
|
||||
)>,
|
||||
) {
|
||||
for (entity, component, trackers) in query.iter() {
|
||||
for (entity, component, trackers) in &query {
|
||||
info!("{:?}: {:?} -> {:?}", entity, component, trackers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ fn print_components_read_only(
|
|||
query: Query<ReadOnlyCustomQuery<ComponentC, ComponentD>, QueryFilter<ComponentC, ComponentD>>,
|
||||
) {
|
||||
println!("Print components (read_only):");
|
||||
for e in query.iter() {
|
||||
for e in &query {
|
||||
println!("Entity: {:?}", e.entity);
|
||||
println!("A: {:?}", e.a);
|
||||
println!("B: {:?}", e.b);
|
||||
|
@ -127,7 +127,7 @@ fn print_components_iter_mut(
|
|||
mut query: Query<CustomQuery<ComponentC, ComponentD>, QueryFilter<ComponentC, ComponentD>>,
|
||||
) {
|
||||
println!("Print components (iter_mut):");
|
||||
for e in query.iter_mut() {
|
||||
for e in &mut query {
|
||||
// Re-declaring the variable to illustrate the type of the actual iterator item.
|
||||
let e: CustomQueryItem<'_, _, _> = e;
|
||||
println!("Entity: {:?}", e.entity);
|
||||
|
@ -145,7 +145,7 @@ fn print_components_iter(
|
|||
query: Query<CustomQuery<ComponentC, ComponentD>, QueryFilter<ComponentC, ComponentD>>,
|
||||
) {
|
||||
println!("Print components (iter):");
|
||||
for e in query.iter() {
|
||||
for e in &query {
|
||||
// Re-declaring the variable to illustrate the type of the actual iterator item.
|
||||
let e: CustomQueryReadOnlyItem<'_, _, _> = e;
|
||||
println!("Entity: {:?}", e.entity);
|
||||
|
@ -177,7 +177,7 @@ fn print_components_tuple(
|
|||
>,
|
||||
) {
|
||||
println!("Print components (tuple):");
|
||||
for (entity, a, b, nested, (generic_c, generic_d)) in query.iter() {
|
||||
for (entity, a, b, nested, (generic_c, generic_d)) in &query {
|
||||
println!("Entity: {:?}", entity);
|
||||
println!("A: {:?}", a);
|
||||
println!("B: {:?}", b);
|
||||
|
|
|
@ -88,7 +88,7 @@ fn new_round_system(game_rules: Res<GameRules>, mut game_state: ResMut<GameState
|
|||
|
||||
// This system updates the score for each entity with the "Player" and "Score" component.
|
||||
fn score_system(mut query: Query<(&Player, &mut Score)>) {
|
||||
for (player, mut score) in query.iter_mut() {
|
||||
for (player, mut score) in &mut query {
|
||||
let scored_a_point = random::<bool>();
|
||||
if scored_a_point {
|
||||
score.value += 1;
|
||||
|
@ -114,7 +114,7 @@ fn score_check_system(
|
|||
mut game_state: ResMut<GameState>,
|
||||
query: Query<(&Player, &Score)>,
|
||||
) {
|
||||
for (player, score) in query.iter() {
|
||||
for (player, score) in &query {
|
||||
if score.value == game_rules.winning_score {
|
||||
game_state.winning_player = Some(player.name.clone());
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ fn setup_system(mut commands: Commands) {
|
|||
}
|
||||
|
||||
fn print_text_system(time: Res<Time>, mut query: Query<(&mut PrinterTick, &TextToPrint)>) {
|
||||
for (mut timer, text) in query.iter_mut() {
|
||||
for (mut timer, text) in &mut query {
|
||||
if timer.tick(time.delta()).just_finished() {
|
||||
info!("{}", text.0);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ fn transition_to_in_game_system(
|
|||
// Type arguments on functions come after the function name, but before ordinary arguments.
|
||||
// Here, the `Component` trait is a trait bound on T, our generic type
|
||||
fn cleanup_system<T: Component>(mut commands: Commands, query: Query<Entity, With<T>>) {
|
||||
for e in query.iter() {
|
||||
for e in &query {
|
||||
commands.entity(e).despawn_recursive();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,14 +71,14 @@ fn rotate(
|
|||
mut transform_query: Query<&mut Transform, With<Sprite>>,
|
||||
) {
|
||||
let angle = std::f32::consts::PI / 2.0;
|
||||
for (parent, children) in parents_query.iter_mut() {
|
||||
for (parent, children) in &mut parents_query {
|
||||
if let Ok(mut transform) = transform_query.get_mut(parent) {
|
||||
transform.rotate_z(-angle * time.delta_seconds());
|
||||
}
|
||||
|
||||
// To iterate through the entities children, just treat the Children component as a Vec
|
||||
// Alternatively, you could query entities that have a Parent component
|
||||
for child in children.iter() {
|
||||
for child in children {
|
||||
if let Ok(mut transform) = transform_query.get_mut(*child) {
|
||||
transform.rotate_z(angle * 2.0 * time.delta_seconds());
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ fn interact_bodies(mut query: Query<(&Mass, &GlobalTransform, &mut Acceleration)
|
|||
|
||||
fn integrate(mut query: Query<(&mut Acceleration, &mut Transform, &mut LastPos)>) {
|
||||
let dt_sq = (DELTA_TIME * DELTA_TIME) as f32;
|
||||
for (mut acceleration, mut transform, mut last_pos) in query.iter_mut() {
|
||||
for (mut acceleration, mut transform, mut last_pos) in &mut query {
|
||||
// verlet integration
|
||||
// x(t+dt) = 2x(t) - x(t-dt) + a(t)dt^2 + O(dt^4)
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ fn menu(
|
|||
(Changed<Interaction>, With<Button>),
|
||||
>,
|
||||
) {
|
||||
for (interaction, mut color) in interaction_query.iter_mut() {
|
||||
for (interaction, mut color) in &mut interaction_query {
|
||||
match *interaction {
|
||||
Interaction::Clicked => {
|
||||
*color = PRESSED_BUTTON.into();
|
||||
|
@ -112,7 +112,7 @@ fn movement(
|
|||
input: Res<Input<KeyCode>>,
|
||||
mut query: Query<&mut Transform, With<Sprite>>,
|
||||
) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
let mut direction = Vec3::ZERO;
|
||||
if input.pressed(KeyCode::Left) {
|
||||
direction.x -= 1.0;
|
||||
|
@ -134,7 +134,7 @@ fn movement(
|
|||
}
|
||||
|
||||
fn change_color(time: Res<Time>, mut query: Query<&mut Sprite>) {
|
||||
for mut sprite in query.iter_mut() {
|
||||
for mut sprite in &mut query {
|
||||
sprite
|
||||
.color
|
||||
.set_b((time.seconds_since_startup() * 0.5).sin() as f32 + 2.0);
|
||||
|
|
|
@ -45,7 +45,7 @@ fn setup(mut commands: Commands) {
|
|||
/// This system ticks all the `Timer` components on entities within the scene
|
||||
/// using bevy's `Time` resource to get the delta between each update.
|
||||
fn print_when_completed(time: Res<Time>, mut query: Query<&mut PrintOnCompletionTimer>) {
|
||||
for mut timer in query.iter_mut() {
|
||||
for mut timer in &mut query {
|
||||
if timer.tick(time.delta()).just_finished() {
|
||||
info!("Entity timer just finished");
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
|
|||
|
||||
// remove all entities that are not a camera
|
||||
fn teardown(mut commands: Commands, entities: Query<Entity, Without<Camera>>) {
|
||||
for entity in entities.iter() {
|
||||
for entity in &entities {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -343,7 +343,7 @@ fn move_paddle(
|
|||
}
|
||||
|
||||
fn apply_velocity(mut query: Query<(&mut Transform, &Velocity)>) {
|
||||
for (mut transform, velocity) in query.iter_mut() {
|
||||
for (mut transform, velocity) in &mut query {
|
||||
transform.translation.x += velocity.x * TIME_STEP;
|
||||
transform.translation.y += velocity.y * TIME_STEP;
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ fn check_for_collisions(
|
|||
let ball_size = ball_transform.scale.truncate();
|
||||
|
||||
// check collision with walls
|
||||
for (collider_entity, transform, maybe_brick) in collider_query.iter() {
|
||||
for (collider_entity, transform, maybe_brick) in &collider_query {
|
||||
let collision = collide(
|
||||
ball_transform.translation,
|
||||
ball_size,
|
||||
|
|
|
@ -242,7 +242,7 @@ fn deselect(sprite: &mut Sprite, contributor: &Contributor, transform: &mut Tran
|
|||
fn velocity_system(time: Res<Time>, mut velocity_query: Query<&mut Velocity>) {
|
||||
let delta = time.delta_seconds();
|
||||
|
||||
for mut velocity in velocity_query.iter_mut() {
|
||||
for mut velocity in &mut velocity_query {
|
||||
velocity.translation += Vec3::new(0.0, GRAVITY * delta, 0.0);
|
||||
}
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ fn collision_system(
|
|||
let wall_left = -(window.width() / 2.);
|
||||
let wall_right = window.width() / 2.;
|
||||
|
||||
for (mut velocity, mut transform) in query.iter_mut() {
|
||||
for (mut velocity, mut transform) in &mut query {
|
||||
let left = transform.translation.x - SPRITE_SIZE / 2.0;
|
||||
let right = transform.translation.x + SPRITE_SIZE / 2.0;
|
||||
let top = transform.translation.y + SPRITE_SIZE / 2.0;
|
||||
|
@ -299,7 +299,7 @@ fn collision_system(
|
|||
fn move_system(time: Res<Time>, mut query: Query<(&Velocity, &mut Transform)>) {
|
||||
let delta = time.delta_seconds();
|
||||
|
||||
for (velocity, mut transform) in query.iter_mut() {
|
||||
for (velocity, mut transform) in &mut query {
|
||||
transform.translation += delta * velocity.translation;
|
||||
transform.rotate_z(velocity.rotation * delta);
|
||||
}
|
||||
|
|
|
@ -356,7 +356,7 @@ mod menu {
|
|||
(Changed<Interaction>, With<Button>),
|
||||
>,
|
||||
) {
|
||||
for (interaction, mut color, selected) in interaction_query.iter_mut() {
|
||||
for (interaction, mut color, selected) in &mut interaction_query {
|
||||
*color = match (*interaction, selected) {
|
||||
(Interaction::Clicked, _) | (Interaction::None, Some(_)) => PRESSED_BUTTON.into(),
|
||||
(Interaction::Hovered, Some(_)) => HOVERED_PRESSED_BUTTON.into(),
|
||||
|
@ -374,7 +374,7 @@ mod menu {
|
|||
mut commands: Commands,
|
||||
mut setting: ResMut<T>,
|
||||
) {
|
||||
for (interaction, button_setting, entity) in interaction_query.iter() {
|
||||
for (interaction, button_setting, entity) in &interaction_query {
|
||||
if *interaction == Interaction::Clicked && *setting != *button_setting {
|
||||
let (previous_button, mut previous_color) = selected_query.single_mut();
|
||||
*previous_color = NORMAL_BUTTON.into();
|
||||
|
@ -787,7 +787,7 @@ mod menu {
|
|||
mut menu_state: ResMut<State<MenuState>>,
|
||||
mut game_state: ResMut<State<GameState>>,
|
||||
) {
|
||||
for (interaction, menu_button_action) in interaction_query.iter() {
|
||||
for (interaction, menu_button_action) in &interaction_query {
|
||||
if *interaction == Interaction::Clicked {
|
||||
match menu_button_action {
|
||||
MenuButtonAction::Quit => app_exit_events.send(AppExit),
|
||||
|
@ -814,7 +814,7 @@ mod menu {
|
|||
|
||||
// Generic system that takes a component as a parameter, and will despawn all entities with that component
|
||||
fn despawn_screen<T: Component>(to_despawn: Query<Entity, With<T>>, mut commands: Commands) {
|
||||
for entity in to_despawn.iter() {
|
||||
for entity in &to_despawn {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ fn button_handler(
|
|||
(Changed<Interaction>, With<Button>),
|
||||
>,
|
||||
) {
|
||||
for (interaction, mut color) in interaction_query.iter_mut() {
|
||||
for (interaction, mut color) in &mut interaction_query {
|
||||
match *interaction {
|
||||
Interaction::Clicked => {
|
||||
*color = Color::BLUE.into();
|
||||
|
|
|
@ -66,7 +66,7 @@ fn load_scene_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
// This system logs all ComponentA components in our world. Try making a change to a ComponentA in
|
||||
// load_scene_example.scn. You should immediately see the changes appear in the console.
|
||||
fn log_system(query: Query<(Entity, &ComponentA), Changed<ComponentA>>) {
|
||||
for (entity, component_a) in query.iter() {
|
||||
for (entity, component_a) in &query {
|
||||
info!(" Entity({})", entity.id());
|
||||
info!(
|
||||
" ComponentA: {{ x: {} y: {} }}\n",
|
||||
|
|
|
@ -116,9 +116,9 @@ fn queue_custom(
|
|||
let key = MeshPipelineKey::from_msaa_samples(msaa.samples)
|
||||
| MeshPipelineKey::from_primitive_topology(PrimitiveTopology::TriangleList);
|
||||
|
||||
for (view, mut transparent_phase) in views.iter_mut() {
|
||||
for (view, mut transparent_phase) in &mut views {
|
||||
let rangefinder = view.rangefinder3d();
|
||||
for (entity, mesh_uniform, mesh_handle) in material_meshes.iter() {
|
||||
for (entity, mesh_uniform, mesh_handle) in &material_meshes {
|
||||
if let Some(mesh) = render_meshes.get(mesh_handle) {
|
||||
let pipeline = pipelines
|
||||
.specialize(&mut pipeline_cache, &custom_pipeline, key, &mesh.layout)
|
||||
|
|
|
@ -157,7 +157,7 @@ fn main_camera_cube_rotator_system(
|
|||
time: Res<Time>,
|
||||
mut query: Query<&mut Transform, With<MainCube>>,
|
||||
) {
|
||||
for mut transform in query.iter_mut() {
|
||||
for mut transform in &mut query {
|
||||
transform.rotate_x(0.55 * time.delta_seconds());
|
||||
transform.rotate_z(0.15 * time.delta_seconds());
|
||||
}
|
||||
|
|
|
@ -116,9 +116,9 @@ fn queue_custom(
|
|||
|
||||
let msaa_key = MeshPipelineKey::from_msaa_samples(msaa.samples);
|
||||
|
||||
for (view, mut transparent_phase) in views.iter_mut() {
|
||||
for (view, mut transparent_phase) in &mut views {
|
||||
let rangefinder = view.rangefinder3d();
|
||||
for (entity, mesh_uniform, mesh_handle) in material_meshes.iter() {
|
||||
for (entity, mesh_uniform, mesh_handle) in &material_meshes {
|
||||
if let Some(mesh) = meshes.get(mesh_handle) {
|
||||
let key =
|
||||
msaa_key | MeshPipelineKey::from_primitive_topology(mesh.primitive_topology);
|
||||
|
@ -147,7 +147,7 @@ fn prepare_instance_buffers(
|
|||
query: Query<(Entity, &InstanceMaterialData)>,
|
||||
render_device: Res<RenderDevice>,
|
||||
) {
|
||||
for (entity, instance_data) in query.iter() {
|
||||
for (entity, instance_data) in &query {
|
||||
let buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
|
||||
label: Some("instance data buffer"),
|
||||
contents: bytemuck::cast_slice(instance_data.as_slice()),
|
||||
|
|
|
@ -223,7 +223,7 @@ fn spawn_birds(
|
|||
}
|
||||
|
||||
fn movement_system(time: Res<Time>, mut bird_query: Query<(&mut Bird, &mut Transform)>) {
|
||||
for (mut bird, mut transform) in bird_query.iter_mut() {
|
||||
for (mut bird, mut transform) in &mut bird_query {
|
||||
transform.translation.x += bird.velocity.x * time.delta_seconds();
|
||||
transform.translation.y += bird.velocity.y * time.delta_seconds();
|
||||
bird.velocity.y += GRAVITY * time.delta_seconds();
|
||||
|
@ -235,7 +235,7 @@ fn collision_system(windows: Res<Windows>, mut bird_query: Query<(&mut Bird, &Tr
|
|||
let half_width = window.width() as f32 * 0.5;
|
||||
let half_height = window.height() as f32 * 0.5;
|
||||
|
||||
for (mut bird, transform) in bird_query.iter_mut() {
|
||||
for (mut bird, transform) in &mut bird_query {
|
||||
let x_vel = bird.velocity.x;
|
||||
let y_vel = bird.velocity.y;
|
||||
let x_pos = transform.translation.x;
|
||||
|
|
|
@ -187,7 +187,7 @@ fn setup_scene_once_loaded(
|
|||
mut done: Local<bool>,
|
||||
) {
|
||||
if !*done && player.iter().len() == foxes.count {
|
||||
for mut player in player.iter_mut() {
|
||||
for mut player in &mut player {
|
||||
player.play(animations.0[0].clone_weak()).repeat();
|
||||
}
|
||||
*done = true;
|
||||
|
@ -204,7 +204,7 @@ fn update_fox_rings(
|
|||
}
|
||||
|
||||
let dt = time.delta_seconds();
|
||||
for (ring, rotation_direction, mut transform) in rings.iter_mut() {
|
||||
for (ring, rotation_direction, mut transform) in &mut rings {
|
||||
let angular_velocity = foxes.speed / ring.radius;
|
||||
transform.rotate_y(rotation_direction.sign() * angular_velocity * dt);
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ fn keyboard_animation_control(
|
|||
*current_animation = (*current_animation + 1) % animations.0.len();
|
||||
}
|
||||
|
||||
for mut player in animation_player.iter_mut() {
|
||||
for mut player in &mut animation_player {
|
||||
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||
if player.is_paused() {
|
||||
player.resume();
|
||||
|
|
|
@ -244,7 +244,7 @@ struct Update(f32);
|
|||
|
||||
/// update positions system
|
||||
fn update(time: Res<Time>, mut query: Query<(&mut Transform, &mut Update)>) {
|
||||
for (mut t, mut u) in query.iter_mut() {
|
||||
for (mut t, mut u) in &mut query {
|
||||
u.0 += time.delta_seconds() * 0.1;
|
||||
set_translation(&mut t.translation, u.0);
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ fn setup_scene_after_load(
|
|||
|
||||
let mut min = Vec3A::splat(f32::MAX);
|
||||
let mut max = Vec3A::splat(f32::MIN);
|
||||
for (transform, maybe_aabb) in meshes.iter() {
|
||||
for (transform, maybe_aabb) in &meshes {
|
||||
let aabb = maybe_aabb.unwrap();
|
||||
// If the Aabb had not been rotated, applying the non-uniform scale would produce the
|
||||
// correct bounds. However, it could very well be rotated and so we first convert to
|
||||
|
@ -309,7 +309,7 @@ fn update_lights(
|
|||
} else if key_input.just_pressed(KeyCode::Key0) {
|
||||
projection_adjustment.z += SCALE_STEP;
|
||||
}
|
||||
for (_, mut light) in query.iter_mut() {
|
||||
for (_, mut light) in &mut query {
|
||||
light.shadow_projection.left *= projection_adjustment.x;
|
||||
light.shadow_projection.right *= projection_adjustment.x;
|
||||
light.shadow_projection.bottom *= projection_adjustment.y;
|
||||
|
@ -325,7 +325,7 @@ fn update_lights(
|
|||
*animate_directional_light = !*animate_directional_light;
|
||||
}
|
||||
if *animate_directional_light {
|
||||
for (mut transform, _) in query.iter_mut() {
|
||||
for (mut transform, _) in &mut query {
|
||||
transform.rotation = Quat::from_euler(
|
||||
EulerRot::ZYX,
|
||||
0.0,
|
||||
|
|
|
@ -48,7 +48,7 @@ fn setup(
|
|||
|
||||
// This system will rotate any entity in the scene with a Rotatable component around its y-axis.
|
||||
fn rotate_cube(mut cubes: Query<(&mut Transform, &Rotatable)>, timer: Res<Time>) {
|
||||
for (mut transform, cube) in cubes.iter_mut() {
|
||||
for (mut transform, cube) in &mut cubes {
|
||||
// The speed is first multiplied by TAU which is a full rotation (360deg) in radians,
|
||||
// and then multiplied by delta_seconds which is the time that passed last frame.
|
||||
// In other words. Speed is equal to the amount of rotations per second.
|
||||
|
|
|
@ -128,7 +128,7 @@ fn move_cubes_according_to_global_transform(
|
|||
direction: Res<Direction>,
|
||||
timer: Res<Time>,
|
||||
) {
|
||||
for mut global_transform in cubes.iter_mut() {
|
||||
for mut global_transform in &mut cubes {
|
||||
global_transform.translation += direction.0 * timer.delta_seconds();
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ fn move_cubes_according_to_local_transform(
|
|||
direction: Res<Direction>,
|
||||
timer: Res<Time>,
|
||||
) {
|
||||
for mut transform in cubes.iter_mut() {
|
||||
for mut transform in &mut cubes {
|
||||
transform.translation += direction.0 * timer.delta_seconds();
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ fn toggle_movement(
|
|||
) {
|
||||
// Update the currently movable entities and remove their Move component if the assigned key was pressed to disable their movement.
|
||||
// This will also make them transparent so they can be identified as 'disabled' in the scene.
|
||||
for (entity, material_handle, toggled_by) in movable_entities.iter() {
|
||||
for (entity, material_handle, toggled_by) in &movable_entities {
|
||||
if keyboard_input.just_pressed(toggled_by.0) {
|
||||
materials
|
||||
.get_mut(material_handle)
|
||||
|
@ -178,7 +178,7 @@ fn toggle_movement(
|
|||
}
|
||||
// Update the currently non-movable entities and add a Move component if the assigned key was pressed to enable their movement.
|
||||
// This will also make them opaque so they can be identified as 'enabled' in the scene.
|
||||
for (entity, material_handle, toggled_by) in static_entities.iter() {
|
||||
for (entity, material_handle, toggled_by) in &static_entities {
|
||||
if keyboard_input.just_pressed(toggled_by.0) {
|
||||
materials
|
||||
.get_mut(material_handle)
|
||||
|
|
|
@ -66,7 +66,7 @@ fn setup(
|
|||
// This system will check if a scaled entity went above or below the entities scaling bounds
|
||||
// and change the direction of the scaling vector.
|
||||
fn change_scale_direction(mut cubes: Query<(&mut Transform, &mut Scaling)>) {
|
||||
for (mut transform, mut cube) in cubes.iter_mut() {
|
||||
for (mut transform, mut cube) in &mut cubes {
|
||||
// If an entity scaled beyond the maximum of its size in any dimension
|
||||
// the scaling vector is flipped so the scaling is gradually reverted.
|
||||
// Additionally, to ensure the condition does not trigger again we floor the elements to
|
||||
|
@ -92,7 +92,7 @@ fn change_scale_direction(mut cubes: Query<(&mut Transform, &mut Scaling)>) {
|
|||
// This system will scale any entity with assigned Scaling in each direction
|
||||
// by cycling through the directions to scale.
|
||||
fn scale_cube(mut cubes: Query<(&mut Transform, &Scaling)>, timer: Res<Time>) {
|
||||
for (mut transform, cube) in cubes.iter_mut() {
|
||||
for (mut transform, cube) in &mut cubes {
|
||||
transform.scale += cube.scale_direction * cube.scale_speed * timer.delta_seconds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ fn setup(
|
|||
|
||||
// This system will move the cube forward.
|
||||
fn move_cube(mut cubes: Query<(&mut Transform, &mut CubeState)>, timer: Res<Time>) {
|
||||
for (mut transform, cube) in cubes.iter_mut() {
|
||||
for (mut transform, cube) in &mut cubes {
|
||||
// Move the cube forward smoothly at a given move_speed.
|
||||
let forward = transform.forward();
|
||||
transform.translation += forward * cube.move_speed * timer.delta_seconds();
|
||||
|
@ -107,11 +107,11 @@ fn rotate_cube(
|
|||
) {
|
||||
// Calculate the point to circle around. (The position of the center_sphere)
|
||||
let mut center: Vec3 = Vec3::ZERO;
|
||||
for sphere in center_spheres.iter() {
|
||||
for sphere in ¢er_spheres {
|
||||
center += sphere.translation;
|
||||
}
|
||||
// Update the rotation of the cube(s).
|
||||
for (mut transform, cube) in cubes.iter_mut() {
|
||||
for (mut transform, cube) in &mut cubes {
|
||||
// Calculate the rotation of the cube if it would be looking at the sphere in the center.
|
||||
let look_at_sphere = transform.looking_at(center, transform.local_y());
|
||||
// Interpolate between the current rotation and the fully turned rotation
|
||||
|
@ -132,11 +132,11 @@ fn scale_down_sphere_proportional_to_cube_travel_distance(
|
|||
// First we need to calculate the length of between
|
||||
// the current position of the orbiting cube and the spawn position.
|
||||
let mut distances = 0.0;
|
||||
for (cube_transform, cube_state) in cubes.iter() {
|
||||
for (cube_transform, cube_state) in &cubes {
|
||||
distances += (cube_state.start_pos - cube_transform.translation).length();
|
||||
}
|
||||
// Now we use the calculated value to scale the sphere in the center accordingly.
|
||||
for (mut transform, center) in centers.iter_mut() {
|
||||
for (mut transform, center) in &mut centers {
|
||||
// Calculate the new size from the calculated distances and the centers scale_factor.
|
||||
// Since we want to have the sphere at its max_size at the cubes spawn location we start by
|
||||
// using the max_size as start value and subtract the distances scaled by a scaling factor.
|
||||
|
|
|
@ -62,7 +62,7 @@ fn setup(
|
|||
|
||||
// This system will move all Movable entities with a Transform
|
||||
fn move_cube(mut cubes: Query<(&mut Transform, &mut Movable)>, timer: Res<Time>) {
|
||||
for (mut transform, mut cube) in cubes.iter_mut() {
|
||||
for (mut transform, mut cube) in &mut cubes {
|
||||
// Check if the entity moved too far from its spawn, if so invert the moving direction.
|
||||
if (cube.spawn - transform.translation).length() > cube.max_distance {
|
||||
cube.speed *= -1.0;
|
||||
|
|
|
@ -24,7 +24,7 @@ fn button_system(
|
|||
>,
|
||||
mut text_query: Query<&mut Text>,
|
||||
) {
|
||||
for (interaction, mut color, children) in interaction_query.iter_mut() {
|
||||
for (interaction, mut color, children) in &mut interaction_query {
|
||||
let mut text = text_query.get_mut(children[0]).unwrap();
|
||||
match *interaction {
|
||||
Interaction::Clicked => {
|
||||
|
|
|
@ -65,7 +65,7 @@ fn atlas_render_system(
|
|||
|
||||
fn text_update_system(mut state: ResMut<State>, time: Res<Time>, mut query: Query<&mut Text>) {
|
||||
if state.timer.tick(time.delta()).finished() {
|
||||
for mut text in query.iter_mut() {
|
||||
for mut text in &mut query {
|
||||
let c = rand::random::<u8>() as char;
|
||||
if !text.sections[0].value.contains(c) {
|
||||
text.sections[0].value.push(c);
|
||||
|
|
|
@ -96,7 +96,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
}
|
||||
|
||||
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text, With<FpsText>>) {
|
||||
for mut text in query.iter_mut() {
|
||||
for mut text in &mut query {
|
||||
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
|
||||
if let Some(average) = fps.average() {
|
||||
// Update the value of the second section
|
||||
|
@ -107,7 +107,7 @@ fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text,
|
|||
}
|
||||
|
||||
fn text_color_system(time: Res<Time>, mut query: Query<&mut Text, With<ColorText>>) {
|
||||
for mut text in query.iter_mut() {
|
||||
for mut text in &mut query {
|
||||
let seconds = time.seconds_since_startup() as f32;
|
||||
// We used the `Text::with_section` helper method, but it is still just a `Text`,
|
||||
// so to update it, we are still updating the one and only section
|
||||
|
|
|
@ -177,7 +177,7 @@ fn change_text_system(
|
|||
diagnostics: Res<Diagnostics>,
|
||||
mut query: Query<&mut Text, With<TextChanges>>,
|
||||
) {
|
||||
for mut text in query.iter_mut() {
|
||||
for mut text in &mut query {
|
||||
let mut fps = 0.0;
|
||||
if let Some(fps_diagnostic) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
|
||||
if let Some(fps_avg) = fps_diagnostic.average() {
|
||||
|
|
|
@ -315,7 +315,7 @@ fn mouse_scroll(
|
|||
query_item: Query<&Node>,
|
||||
) {
|
||||
for mouse_wheel_event in mouse_wheel_events.iter() {
|
||||
for (mut scrolling_list, mut style, children, uinode) in query_list.iter_mut() {
|
||||
for (mut scrolling_list, mut style, children, uinode) in &mut query_list {
|
||||
let items_height: f32 = children
|
||||
.iter()
|
||||
.map(|entity| query_item.get(*entity).unwrap().size.y)
|
||||
|
|
|
@ -111,7 +111,7 @@ pub(crate) mod test_setup {
|
|||
time: Res<Time>,
|
||||
mut cube_transform: Query<&mut Transform, With<Rotator>>,
|
||||
) {
|
||||
for mut transform in cube_transform.iter_mut() {
|
||||
for mut transform in &mut cube_transform {
|
||||
transform.rotate_x(time.delta_seconds());
|
||||
transform.rotate_local_y(time.delta_seconds());
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ fn despawn_dead_enemies(
|
|||
mut dead_enemies: EventWriter<EnemyDied>,
|
||||
enemies: Query<(Entity, &Enemy)>,
|
||||
) {
|
||||
for (entity, enemy) in enemies.iter() {
|
||||
for (entity, enemy) in &enemies {
|
||||
if enemy.hit_points == 0 {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
dead_enemies.send(EnemyDied(enemy.score_value));
|
||||
|
@ -30,7 +30,7 @@ fn despawn_dead_enemies(
|
|||
}
|
||||
|
||||
fn hurt_enemies(mut enemies: Query<&mut Enemy>) {
|
||||
for mut enemy in enemies.iter_mut() {
|
||||
for mut enemy in &mut enemies {
|
||||
enemy.hit_points -= 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue