ecs: remove &mut requirement on query iterators

This commit is contained in:
Carter Anderson 2020-07-20 13:59:51 -07:00
parent 6194944153
commit 6dc1d07cbc
33 changed files with 88 additions and 93 deletions

View file

@ -68,7 +68,7 @@ pub fn entity_labels_system(
mut query: Query<(Entity, &Labels)>,
) {
let entity_labels = entity_labels.deref_mut();
for (entity, labels) in &mut query.iter() {
for (entity, labels) in query.iter() {
let current_labels = entity_labels
.entity_labels
.entry(entity)

View file

@ -38,7 +38,7 @@ impl Timer {
}
pub fn timer_system(time: Res<Time>, mut query: Query<&mut Timer>) {
for mut timer in &mut query.iter() {
for mut timer in query.iter() {
timer.tick(time.delta_seconds);
}
}

View file

@ -68,7 +68,7 @@ fn iterate_100k(b: &mut Bencher) {
world.spawn((Position(-(i as f32)), Velocity(i as f32)));
}
b.iter(|| {
for (mut pos, vel) in &mut world.query::<(&mut Position, &Velocity)>() {
for (mut pos, vel) in world.query::<(&mut Position, &Velocity)>() {
pos.0 += vel.0;
}
})

View file

@ -321,7 +321,7 @@ impl<'w, Q: Query> QueryBorrow<'w, Q> {
/// Execute the query
///
/// Must be called only once per query.
pub fn iter<'q>(&'q mut self) -> QueryIter<'q, 'w, Q> {
pub fn iter(mut self) -> QueryIter<'w, Q> {
self.borrow();
QueryIter {
borrow: self,
@ -434,9 +434,9 @@ impl<'w, Q: Query> Drop for QueryBorrow<'w, Q> {
}
}
impl<'q, 'w, Q: Query> IntoIterator for &'q mut QueryBorrow<'w, Q> {
type Item = <Q::Fetch as Fetch<'q>>::Item;
type IntoIter = QueryIter<'q, 'w, Q>;
impl<'w, Q: Query> IntoIterator for QueryBorrow<'w, Q> {
type Item = <Q::Fetch as Fetch<'w>>::Item;
type IntoIter = QueryIter<'w, Q>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
@ -444,17 +444,17 @@ impl<'q, 'w, Q: Query> IntoIterator for &'q mut QueryBorrow<'w, Q> {
}
/// Iterator over the set of entities with the components in `Q`
pub struct QueryIter<'q, 'w, Q: Query> {
borrow: &'q mut QueryBorrow<'w, Q>,
pub struct QueryIter<'w, Q: Query> {
borrow: QueryBorrow<'w, Q>,
archetype_index: u32,
iter: Option<ChunkIter<Q>>,
}
unsafe impl<'q, 'w, Q: Query> Send for QueryIter<'q, 'w, Q> {}
unsafe impl<'q, 'w, Q: Query> Sync for QueryIter<'q, 'w, Q> {}
unsafe impl<'w, Q: Query> Send for QueryIter<'w, Q> {}
unsafe impl<'w, Q: Query> Sync for QueryIter<'w, Q> {}
impl<'q, 'w, Q: Query> Iterator for QueryIter<'q, 'w, Q> {
type Item = <Q::Fetch as Fetch<'q>>::Item;
impl<'w, Q: Query> Iterator for QueryIter<'w, Q> {
type Item = <Q::Fetch as Fetch<'w>>::Item;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
@ -489,7 +489,7 @@ impl<'q, 'w, Q: Query> Iterator for QueryIter<'q, 'w, Q> {
}
}
impl<'q, 'w, Q: Query> ExactSizeIterator for QueryIter<'q, 'w, Q> {
impl<'w, Q: Query> ExactSizeIterator for QueryIter<'w, Q> {
fn len(&self) -> usize {
self.borrow
.archetypes

View file

@ -481,6 +481,7 @@ impl World {
///
/// See `remove`.
pub fn remove_one<T: Component>(&mut self, entity: Entity) -> Result<T, ComponentError> {
std::println!("reomve {} ", std::any::type_name::<T>());
self.remove::<(T,)>(entity).map(|(x,)| x)
}

View file

@ -261,17 +261,6 @@ fn clear() {
assert_eq!(world.iter().count(), 0);
}
#[test]
#[should_panic(expected = "twice on the same borrow")]
fn alias() {
let mut world = World::new();
world.spawn(("abc", 123));
world.spawn(("def", 456, true));
let mut q = world.query::<&mut i32>();
let _a = q.iter().collect::<Vec<_>>();
let _b = q.iter().collect::<Vec<_>>();
}
#[test]
fn remove_missing() {
let mut world = World::new();

View file

@ -158,6 +158,10 @@ impl<'a, Q: HecsQuery> Query<'a, Q> {
.archetype_access
.immutable
.contains(location.archetype as usize)
|| self
.archetype_access
.mutable
.contains(location.archetype as usize)
{
self.world
.get(entity)

View file

@ -27,7 +27,7 @@ pub fn active_cameras_system(
) {
for (name, active_camera) in active_cameras.cameras.iter_mut() {
if let None = active_camera {
for (camera_entity, camera) in &mut query.iter() {
for (camera_entity, camera) in query.iter() {
if let Some(ref current_name) = camera.name {
if current_name == name {
*active_camera = Some(camera_entity);

View file

@ -62,7 +62,7 @@ pub fn camera_system<T: CameraProjection + Component>(
}
}
for (mut camera, mut camera_projection) in &mut query.iter() {
for (mut camera, mut camera_projection) in query.iter() {
if let Some(window) = match camera.window {
WindowReference::Id(id) => {
if changed_window_ids.contains(&id) {

View file

@ -26,13 +26,13 @@ pub fn visible_entities_system(
mut draw_query: Query<(Entity, &Draw)>,
draw_transform_query: Query<(&Draw, &Transform)>,
) {
for (_camera, camera_transform, mut visible_entities) in &mut camera_query.iter() {
for (_camera, camera_transform, mut visible_entities) in camera_query.iter() {
visible_entities.value.clear();
let camera_position = camera_transform.value.w_axis().truncate();
let mut no_transform_order = 0.0;
let mut transparent_entities = Vec::new();
for (entity, draw) in &mut draw_query.iter() {
for (entity, draw) in draw_query.iter() {
if !draw.is_visible {
continue;
}

View file

@ -366,7 +366,7 @@ pub trait Drawable {
}
pub fn clear_draw_system(mut query: Query<&mut Draw>) {
for mut draw in &mut query.iter() {
for mut draw in query.iter() {
draw.clear_render_commands();
}
}

View file

@ -479,7 +479,7 @@ pub fn mesh_resource_provider_system(
}
// TODO: remove this once batches are pipeline specific and deprecate assigned_meshes draw target
for (handle, mut render_pipelines) in &mut query.iter() {
for (handle, mut render_pipelines) in query.iter() {
if let Some(mesh) = meshes.get(&handle) {
for render_pipeline in render_pipelines.pipelines.iter_mut() {
render_pipeline.specialization.primitive_topology = mesh.primitive_topology;

View file

@ -106,7 +106,7 @@ pub fn draw_render_pipelines_system(
mut render_resource_bindings: ResMut<RenderResourceBindings>,
mut query: Query<(&mut Draw, &mut RenderPipelines)>,
) {
for (mut draw, mut render_pipelines) in &mut query.iter() {
for (mut draw, mut render_pipelines) in query.iter() {
let mut drawable = DrawableRenderPipelines {
render_pipelines: &mut render_pipelines,
render_resource_bindings: &mut render_resource_bindings,

View file

@ -422,7 +422,7 @@ fn render_resources_node_system<T: RenderResources>(
let render_resource_context = &**render_resource_context;
state.uniform_buffer_arrays.reset_changed_item_counts();
// update uniforms info
for (uniforms, draw, _render_pipelines) in &mut query.iter() {
for (uniforms, draw, _render_pipelines) in query.iter() {
if !draw.is_visible {
return;
}
@ -438,7 +438,7 @@ fn render_resources_node_system<T: RenderResources>(
.uniform_buffer_arrays
.update_staging_buffer(render_resource_context);
for (uniforms, draw, mut render_pipelines) in &mut query.iter() {
for (uniforms, draw, mut render_pipelines) in query.iter() {
if !draw.is_visible {
return;
}
@ -456,7 +456,7 @@ fn render_resources_node_system<T: RenderResources>(
staging_buffer,
0..state.uniform_buffer_arrays.staging_buffer_size as u64,
&mut |mut staging_buffer, _render_resource_context| {
for (uniforms, draw, mut render_pipelines) in &mut query.iter() {
for (uniforms, draw, mut render_pipelines) in query.iter() {
if !draw.is_visible {
return;
}
@ -479,7 +479,7 @@ fn render_resources_node_system<T: RenderResources>(
} else {
// TODO: can we just remove this?
let mut staging_buffer: [u8; 0] = [];
for (uniforms, draw, mut render_pipelines) in &mut query.iter() {
for (uniforms, draw, mut render_pipelines) in query.iter() {
if !draw.is_visible {
return;
}
@ -657,7 +657,7 @@ fn asset_render_resources_node_system<T: RenderResources>(
}
}
for (asset_handle, _draw, mut render_pipelines) in &mut query.iter() {
for (asset_handle, _draw, mut render_pipelines) in query.iter() {
if let Some(asset_bindings) = asset_render_resource_bindings.get(*asset_handle) {
render_pipelines.bindings.extend(asset_bindings);
}

View file

@ -59,7 +59,7 @@ pub fn shader_defs_system<T>(mut query: Query<(&T, &mut RenderPipelines)>)
where
T: ShaderDefs + Send + Sync + 'static,
{
for (shader_defs, mut render_pipelines) in &mut query.iter() {
for (shader_defs, mut render_pipelines) in query.iter() {
for shader_def in shader_defs.iter_shader_defs() {
for render_pipeline in render_pipelines.pipelines.iter_mut() {
render_pipeline
@ -73,7 +73,7 @@ where
}
pub fn clear_shader_defs_system(mut query: Query<&mut RenderPipelines>) {
for mut render_pipelines in &mut query.iter() {
for mut render_pipelines in query.iter() {
for render_pipeline in render_pipelines.pipelines.iter_mut() {
render_pipeline
.specialization
@ -90,7 +90,7 @@ pub fn asset_shader_defs_system<T>(
) where
T: ShaderDefs + Send + Sync + 'static,
{
for (asset_handle, mut render_pipelines) in &mut query.iter() {
for (asset_handle, mut render_pipelines) in query.iter() {
let shader_defs = assets.get(&asset_handle).unwrap();
for shader_def in shader_defs.iter_shader_defs() {
for render_pipeline in render_pipelines.pipelines.iter_mut() {

View file

@ -23,7 +23,7 @@ pub fn sprite_system(
textures: Res<Assets<Texture>>,
mut query: Query<(&mut Sprite, &Handle<ColorMaterial>)>,
) {
for (mut sprite, handle) in &mut query.iter() {
for (mut sprite, handle) in query.iter() {
let material = materials.get(&handle).unwrap();
if let Some(texture_handle) = material.texture {
if let Some(texture) = textures.get(&texture_handle) {

View file

@ -9,7 +9,7 @@ pub fn missing_previous_parent_system(
mut query: Query<Without<PreviousParent, (Entity, &Parent)>>,
) {
// Add missing `PreviousParent` components
for (entity, _parent) in &mut query.iter() {
for (entity, _parent) in query.iter() {
log::trace!("Adding missing PreviousParent to {:?}", entity);
commands.insert_one(entity, PreviousParent(None));
}
@ -24,7 +24,7 @@ pub fn parent_update_system(
) {
// Entities with a missing `Parent` (ie. ones that have a `PreviousParent`), remove
// them from the `Children` of the `PreviousParent`.
for (entity, previous_parent) in &mut removed_parent_query.iter() {
for (entity, previous_parent) in removed_parent_query.iter() {
log::trace!("Parent was removed from {:?}", entity);
if let Some(previous_parent_entity) = previous_parent.0 {
if let Ok(mut previous_parent_children) =
@ -40,7 +40,7 @@ pub fn parent_update_system(
let mut children_additions = HashMap::<Entity, SmallVec<[Entity; 8]>>::with_capacity(16);
// Entities with a changed Parent (that also have a PreviousParent, even if None)
for (entity, parent, mut previous_parent) in &mut changed_parent_query.iter() {
for (entity, parent, mut previous_parent) in changed_parent_query.iter() {
log::trace!("Parent changed for {:?}", entity);
// If the `PreviousParent` is not None.

View file

@ -13,7 +13,7 @@ pub fn local_transform_translation_system(
>,
>,
) {
for (mut local, translation) in &mut query.iter() {
for (mut local, translation) in query.iter() {
*local = LocalTransform(Mat4::from_translation(translation.0));
}
}
@ -26,7 +26,7 @@ pub fn local_transform_rotation_system(
>,
>,
) {
for (mut local, rotation) in &mut query.iter() {
for (mut local, rotation) in query.iter() {
*local = LocalTransform(Mat4::from_quat(rotation.0));
}
}
@ -39,7 +39,7 @@ pub fn local_transform_scale_system(
>,
>,
) {
for (mut local, scale) in &mut query.iter() {
for (mut local, scale) in query.iter() {
*local = LocalTransform(Mat4::from_scale(Vec3::new(scale.0, scale.0, scale.0)));
}
}
@ -52,7 +52,7 @@ pub fn local_transform_non_uniform_scale_system(
>,
>,
) {
for (mut local, non_uniform_scale) in &mut query.iter() {
for (mut local, non_uniform_scale) in query.iter() {
*local = LocalTransform(Mat4::from_scale(non_uniform_scale.0));
}
}
@ -62,7 +62,7 @@ pub fn local_transform_translation_rotation_system(
Without<Scale, Without<NonUniformScale, (&mut LocalTransform, &Translation, &Rotation)>>,
>,
) {
for (mut local, translation, rotation) in &mut query.iter() {
for (mut local, translation, rotation) in query.iter() {
*local = LocalTransform(Mat4::from_rotation_translation(rotation.0, translation.0));
}
}
@ -72,7 +72,7 @@ pub fn local_transform_translation_scale_system(
Without<Rotation, Without<NonUniformScale, (&mut LocalTransform, &Translation, &Scale)>>,
>,
) {
for (mut local, translation, scale) in &mut query.iter() {
for (mut local, translation, scale) in query.iter() {
*local = LocalTransform(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0),
Quat::default(),
@ -86,7 +86,7 @@ pub fn local_transform_translation_non_uniform_scale_system(
Without<Rotation, Without<Scale, (&mut LocalTransform, &Translation, &NonUniformScale)>>,
>,
) {
for (mut local, translation, non_uniform_scale) in &mut query.iter() {
for (mut local, translation, non_uniform_scale) in query.iter() {
*local = LocalTransform(Mat4::from_scale_rotation_translation(
non_uniform_scale.0,
Quat::default(),
@ -100,7 +100,7 @@ pub fn local_transform_rotation_scale_system(
Without<Translation, Without<NonUniformScale, (&mut LocalTransform, &Rotation, &Scale)>>,
>,
) {
for (mut local, rotation, scale) in &mut query.iter() {
for (mut local, rotation, scale) in query.iter() {
*local = LocalTransform(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0),
rotation.0,
@ -114,7 +114,7 @@ pub fn local_transform_rotation_non_uniform_scale_system(
Without<Translation, Without<Scale, (&mut LocalTransform, &Rotation, &NonUniformScale)>>,
>,
) {
for (mut local, rotation, non_uniform_scale) in &mut query.iter() {
for (mut local, rotation, non_uniform_scale) in query.iter() {
*local = LocalTransform(Mat4::from_scale_rotation_translation(
non_uniform_scale.0,
rotation.0,
@ -128,7 +128,7 @@ pub fn local_transform_translation_rotation_scale_system(
Without<NonUniformScale, (&mut LocalTransform, &Translation, &Rotation, &Scale)>,
>,
) {
for (mut local, translation, rotation, scale) in &mut query.iter() {
for (mut local, translation, rotation, scale) in query.iter() {
*local = LocalTransform(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0),
rotation.0,
@ -150,7 +150,7 @@ pub fn local_transform_translation_rotation_non_uniform_scale_system(
>,
>,
) {
for (mut local, translation, rotation, non_uniform_scale) in &mut query.iter() {
for (mut local, translation, rotation, non_uniform_scale) in query.iter() {
*local = LocalTransform(Mat4::from_scale_rotation_translation(
non_uniform_scale.0,
rotation.0,

View file

@ -10,7 +10,7 @@ pub fn transform_propagate_system(
mut children_query: Query<&Children>,
mut local_transform_query: Query<&LocalTransform>,
) {
for (children, mut transform, local_transform) in &mut root_query.iter() {
for (children, mut transform, local_transform) in root_query.iter() {
if let Some(local_transform) = local_transform {
transform.value = local_transform.0;
}

View file

@ -10,7 +10,7 @@ pub fn transform_translation_system(
Without<Rotation, Without<Scale, Without<NonUniformScale, (&mut Transform, &Translation)>>>,
>,
) {
for (mut transform, translation) in &mut query.iter() {
for (mut transform, translation) in query.iter() {
if !transform.sync {
continue;
}
@ -24,7 +24,7 @@ pub fn transform_rotation_system(
Without<Translation, Without<Scale, Without<NonUniformScale, (&mut Transform, &Rotation)>>>,
>,
) {
for (mut transform, rotation) in &mut query.iter() {
for (mut transform, rotation) in query.iter() {
if !transform.sync {
continue;
}
@ -38,7 +38,7 @@ pub fn transform_scale_system(
Without<Translation, Without<Rotation, Without<NonUniformScale, (&mut Transform, &Scale)>>>,
>,
) {
for (mut transform, scale) in &mut query.iter() {
for (mut transform, scale) in query.iter() {
if !transform.sync {
continue;
}
@ -52,7 +52,7 @@ pub fn transform_non_uniform_scale_system(
Without<Translation, Without<Rotation, Without<Scale, (&mut Transform, &NonUniformScale)>>>,
>,
) {
for (mut transform, non_uniform_scale) in &mut query.iter() {
for (mut transform, non_uniform_scale) in query.iter() {
if !transform.sync {
continue;
}
@ -66,7 +66,7 @@ pub fn transform_translation_rotation_system(
Without<Scale, Without<NonUniformScale, (&mut Transform, &Translation, &Rotation)>>,
>,
) {
for (mut transform, translation, rotation) in &mut query.iter() {
for (mut transform, translation, rotation) in query.iter() {
if !transform.sync {
continue;
}
@ -80,7 +80,7 @@ pub fn transform_translation_scale_system(
Without<Rotation, Without<NonUniformScale, (&mut Transform, &Translation, &Scale)>>,
>,
) {
for (mut transform, translation, scale) in &mut query.iter() {
for (mut transform, translation, scale) in query.iter() {
if !transform.sync {
continue;
}
@ -98,7 +98,7 @@ pub fn transform_translation_non_uniform_scale_system(
Without<Rotation, Without<Scale, (&mut Transform, &Translation, &NonUniformScale)>>,
>,
) {
for (mut transform, translation, non_uniform_scale) in &mut query.iter() {
for (mut transform, translation, non_uniform_scale) in query.iter() {
if !transform.sync {
continue;
}
@ -116,7 +116,7 @@ pub fn transform_rotation_scale_system(
Without<Translation, Without<NonUniformScale, (&mut Transform, &Rotation, &Scale)>>,
>,
) {
for (mut transform, rotation, scale) in &mut query.iter() {
for (mut transform, rotation, scale) in query.iter() {
if !transform.sync {
continue;
}
@ -134,7 +134,7 @@ pub fn transform_rotation_non_uniform_scale_system(
Without<Translation, Without<Scale, (&mut Transform, &Rotation, &NonUniformScale)>>,
>,
) {
for (mut transform, rotation, non_uniform_scale) in &mut query.iter() {
for (mut transform, rotation, non_uniform_scale) in query.iter() {
if !transform.sync {
continue;
}
@ -150,7 +150,7 @@ pub fn transform_rotation_non_uniform_scale_system(
pub fn transform_translation_rotation_scale_system(
mut query: Query<Without<NonUniformScale, (&mut Transform, &Translation, &Rotation, &Scale)>>,
) {
for (mut transform, translation, rotation, scale) in &mut query.iter() {
for (mut transform, translation, rotation, scale) in query.iter() {
if !transform.sync {
continue;
}
@ -166,7 +166,7 @@ pub fn transform_translation_rotation_scale_system(
pub fn transform_translation_rotation_non_uniform_scale_system(
mut query: Query<Without<Scale, (&mut Transform, &Translation, &Rotation, &NonUniformScale)>>,
) {
for (mut transform, translation, rotation, non_uniform_scale) in &mut query.iter() {
for (mut transform, translation, rotation, non_uniform_scale) in query.iter() {
if !transform.sync {
continue;
}

View file

@ -69,7 +69,7 @@ pub fn ui_focus_system(
}
if mouse_button_input.just_released(MouseButton::Left) {
for (_entity, _node, _transform, click, _hover, _focus_policy) in &mut node_query.iter() {
for (_entity, _node, _transform, click, _hover, _focus_policy) in node_query.iter() {
if let Some(mut click) = click {
if *click == Click::Pressed {
*click = Click::Released;
@ -83,8 +83,9 @@ pub fn ui_focus_system(
let mut hovered_entity = None;
{
let mut query_iter = node_query.iter();
let mut moused_over_z_sorted_nodes = query_iter
// let mut query_iter = node_query.iter();
let mut moused_over_z_sorted_nodes = node_query
.iter()
.iter()
.filter_map(|(entity, node, transform, click, hover, focus_policy)| {
let position = transform.value.w_axis();

View file

@ -24,7 +24,7 @@ pub fn text_system(
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
mut query: Query<&Text>,
) {
for text in &mut query.iter() {
for text in query.iter() {
let font_atlases = font_atlas_sets
.get_or_insert_with(Handle::from_id(text.font.id), || {
FontAtlasSet::new(text.font)
@ -54,7 +54,7 @@ pub fn draw_text_system(
mut asset_render_resource_bindings: ResMut<AssetRenderResourceBindings>,
mut query: Query<(&mut Draw, &Text, &Node, &Transform)>,
) {
for (mut draw, text, node, transform) in &mut query.iter() {
for (mut draw, text, node, transform) in query.iter() {
let position = transform.value.w_axis().truncate() - (node.size / 2.0).extend(0.0);
let mut drawable_text = DrawableText {

View file

@ -12,7 +12,7 @@ fn animate_sprite_system(
texture_atlases: Res<Assets<TextureAtlas>>,
mut query: Query<(&mut Timer, &mut TextureAtlasSprite, &Handle<TextureAtlas>)>,
) {
for (mut timer, mut sprite, texture_atlas_handle) in &mut query.iter() {
for (mut timer, mut sprite, texture_atlas_handle) in query.iter() {
if timer.finished {
let texture_atlas = texture_atlases.get(&texture_atlas_handle).unwrap();
sprite.index = ((sprite.index as usize + 1) % texture_atlas.textures.len()) as u32;

View file

@ -12,7 +12,7 @@ fn main() {
/// rotates the parent, which will result in the child also rotating
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
for (_rotator, mut rotation) in &mut query.iter() {
for (_rotator, mut rotation) in query.iter() {
rotation.0 = rotation.0 * Quat::from_rotation_x(3.0 * time.delta_seconds);
}
}

View file

@ -19,7 +19,7 @@ fn move_cubes(
mut materials: ResMut<Assets<StandardMaterial>>,
mut query: Query<(&mut Translation, &Handle<StandardMaterial>)>,
) {
for (mut translation, material_handle) in &mut query.iter() {
for (mut translation, material_handle) in query.iter() {
let material = materials.get_mut(&material_handle).unwrap();
translation.0 += Vec3::new(1.0, 0.0, 0.0) * time.delta_seconds;
material.albedo += Color::rgb(-time.delta_seconds, -time.delta_seconds, time.delta_seconds);

View file

@ -19,7 +19,7 @@ fn main() {
/// rotates the parent, which will result in the child also rotating
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
for (_rotator, mut rotation) in &mut query.iter() {
for (_rotator, mut rotation) in query.iter() {
rotation.0 = rotation.0 * Quat::from_rotation_x(3.0 * time.delta_seconds);
}
}
@ -29,7 +29,7 @@ fn camera_order_color_system(
mut camera_query: Query<(&Camera, &VisibleEntities)>,
material_query: Query<&Handle<StandardMaterial>>,
) {
for (_camera, visible_entities) in &mut camera_query.iter() {
for (_camera, visible_entities) in camera_query.iter() {
for visible_entity in visible_entities.iter() {
if let Ok(material_handle) =
material_query.get::<Handle<StandardMaterial>>(visible_entity.entity)

View file

@ -85,7 +85,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 &mut query.iter() {
for (player, mut score) in query.iter() {
let scored_a_point = random::<bool>();
if scored_a_point {
score.value += 1;
@ -112,7 +112,7 @@ fn score_check_system(
mut game_state: ResMut<GameState>,
mut query: Query<(&Player, &Score)>,
) {
for (player, score) in &mut query.iter() {
for (player, score) in query.iter() {
if score.value == game_rules.winning_score {
game_state.winning_player = Some(player.name.clone());
}
@ -238,7 +238,7 @@ struct State {
// NOTE: this doesn't do anything relevant to our game, it is just here for illustrative purposes
#[allow(dead_code)]
fn local_state_system(mut state: Local<State>, mut query: Query<(&Player, &Score)>) {
for (player, score) in &mut query.iter() {
for (player, score) in query.iter() {
println!("processed: {} {}", player.name, score.value);
}
println!("this system ran {} times", state.counter);

View file

@ -160,7 +160,7 @@ fn paddle_movement_system(
keyboard_input: Res<Input<KeyCode>>,
mut query: Query<(&Paddle, &mut Translation)>,
) {
for (paddle, mut translation) in &mut query.iter() {
for (paddle, mut translation) in query.iter() {
let mut direction = 0.0;
if keyboard_input.pressed(KeyCode::Left) {
direction -= 1.0;
@ -175,13 +175,13 @@ fn paddle_movement_system(
}
fn ball_movement_system(time: Res<Time>, mut ball_query: Query<(&Ball, &mut Translation)>) {
for (ball, mut translation) in &mut ball_query.iter() {
for (ball, mut translation) in ball_query.iter() {
translation.0 += ball.velocity * time.delta_seconds;
}
}
fn scoreboard_system(scoreboard: Res<Scoreboard>, mut query: Query<&mut Text>) {
for mut text in &mut query.iter() {
for mut text in query.iter() {
text.value = format!("Score: {}", scoreboard.score);
}
}
@ -194,13 +194,13 @@ fn ball_collision_system(
mut brick_query: Query<(Entity, &Brick, &Translation, &Sprite)>,
mut wall_query: Query<(&Wall, &Translation, &Sprite)>,
) {
for (mut ball, ball_translation, sprite) in &mut ball_query.iter() {
for (mut ball, ball_translation, sprite) in ball_query.iter() {
let ball_size = sprite.size;
let velocity = &mut ball.velocity;
let mut collision = None;
// check collision with walls
for (_wall, translation, sprite) in &mut wall_query.iter() {
for (_wall, translation, sprite) in wall_query.iter() {
if collision.is_some() {
break;
}
@ -209,7 +209,7 @@ fn ball_collision_system(
}
// check collision with paddle(s)
for (_paddle, translation, sprite) in &mut paddle_query.iter() {
for (_paddle, translation, sprite) in paddle_query.iter() {
if collision.is_some() {
break;
}
@ -218,7 +218,7 @@ fn ball_collision_system(
}
// check collision with bricks
for (brick_entity, _brick, translation, sprite) in &mut brick_query.iter() {
for (brick_entity, _brick, translation, sprite) in brick_query.iter() {
if collision.is_some() {
break;
}

View file

@ -93,7 +93,7 @@ fn load_scene_right_now_system(world: &mut World, resources: &mut Resources) {
// You should immediately see the changes appear in the console.
fn print_system(mut query: Query<(Entity, &ComponentA)>) {
println!("Current World State:");
for (entity, component_a) in &mut query.iter() {
for (entity, component_a) in query.iter() {
println!(" Entity({})", entity.id());
println!(
" ComponentA: {{ x: {} y: {} }}\n",

View file

@ -44,7 +44,7 @@ fn button_system(
)>,
text_query: Query<&mut Text>,
) {
for (_button, hover, click, mut material, children) in &mut hover_query.iter() {
for (_button, hover, click, mut material, children) in hover_query.iter() {
let mut text = text_query.get_mut::<Text>(children[0]).unwrap();
match *hover {
Hover::Hovered => {
@ -65,7 +65,7 @@ fn button_system(
}
}
for (_button, click, hover, mut material, children) in &mut click_query.iter() {
for (_button, click, hover, mut material, children) in click_query.iter() {
let mut text = text_query.get_mut::<Text>(children[0]).unwrap();
match *click {
Click::Pressed => {

View file

@ -51,7 +51,7 @@ fn atlas_render_system(
}
fn text_update_system(mut state: ResMut<State>, time: Res<Time>, mut query: Query<&mut Text>) {
for mut text in &mut query.iter() {
for mut text in query.iter() {
state.timer.tick(time.delta_seconds);
if state.timer.finished {
text.value = format!("{}", rand::random::<u8>() as char);

View file

@ -13,7 +13,7 @@ fn main() {
}
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text>) {
for mut text in &mut query.iter() {
for mut text in query.iter() {
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
if let Some(average) = fps.average() {
text.value = format!("FPS: {:.2}", average);

View file

@ -13,7 +13,7 @@ fn placement_system(
materials: Res<Assets<ColorMaterial>>,
mut query: Query<(&mut Node, &Handle<ColorMaterial>)>,
) {
for (mut node, material_handle) in &mut query.iter() {
for (mut node, material_handle) in query.iter() {
let material = materials.get(&material_handle).unwrap();
if material.color.r > 0.2 {
node.position += Vec2::new(0.1 * time.delta_seconds, 0.0);