ecs: remove &mut requirement on query iterators
This commit is contained in:
parent
6194944153
commit
6dc1d07cbc
@ -68,7 +68,7 @@ pub fn entity_labels_system(
|
|||||||
mut query: Query<(Entity, &Labels)>,
|
mut query: Query<(Entity, &Labels)>,
|
||||||
) {
|
) {
|
||||||
let entity_labels = entity_labels.deref_mut();
|
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
|
let current_labels = entity_labels
|
||||||
.entity_labels
|
.entity_labels
|
||||||
.entry(entity)
|
.entry(entity)
|
||||||
|
@ -38,7 +38,7 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn timer_system(time: Res<Time>, mut query: Query<&mut 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);
|
timer.tick(time.delta_seconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ fn iterate_100k(b: &mut Bencher) {
|
|||||||
world.spawn((Position(-(i as f32)), Velocity(i as f32)));
|
world.spawn((Position(-(i as f32)), Velocity(i as f32)));
|
||||||
}
|
}
|
||||||
b.iter(|| {
|
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;
|
pos.0 += vel.0;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -321,7 +321,7 @@ impl<'w, Q: Query> QueryBorrow<'w, Q> {
|
|||||||
/// Execute the query
|
/// Execute the query
|
||||||
///
|
///
|
||||||
/// Must be called only once per 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();
|
self.borrow();
|
||||||
QueryIter {
|
QueryIter {
|
||||||
borrow: self,
|
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> {
|
impl<'w, Q: Query> IntoIterator for QueryBorrow<'w, Q> {
|
||||||
type Item = <Q::Fetch as Fetch<'q>>::Item;
|
type Item = <Q::Fetch as Fetch<'w>>::Item;
|
||||||
type IntoIter = QueryIter<'q, 'w, Q>;
|
type IntoIter = QueryIter<'w, Q>;
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.iter()
|
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`
|
/// Iterator over the set of entities with the components in `Q`
|
||||||
pub struct QueryIter<'q, 'w, Q: Query> {
|
pub struct QueryIter<'w, Q: Query> {
|
||||||
borrow: &'q mut QueryBorrow<'w, Q>,
|
borrow: QueryBorrow<'w, Q>,
|
||||||
archetype_index: u32,
|
archetype_index: u32,
|
||||||
iter: Option<ChunkIter<Q>>,
|
iter: Option<ChunkIter<Q>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<'q, 'w, Q: Query> Send for QueryIter<'q, 'w, Q> {}
|
unsafe impl<'w, Q: Query> Send for QueryIter<'w, Q> {}
|
||||||
unsafe impl<'q, 'w, Q: Query> Sync for QueryIter<'q, 'w, Q> {}
|
unsafe impl<'w, Q: Query> Sync for QueryIter<'w, Q> {}
|
||||||
|
|
||||||
impl<'q, 'w, Q: Query> Iterator for QueryIter<'q, 'w, Q> {
|
impl<'w, Q: Query> Iterator for QueryIter<'w, Q> {
|
||||||
type Item = <Q::Fetch as Fetch<'q>>::Item;
|
type Item = <Q::Fetch as Fetch<'w>>::Item;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
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 {
|
fn len(&self) -> usize {
|
||||||
self.borrow
|
self.borrow
|
||||||
.archetypes
|
.archetypes
|
||||||
|
@ -481,6 +481,7 @@ impl World {
|
|||||||
///
|
///
|
||||||
/// See `remove`.
|
/// See `remove`.
|
||||||
pub fn remove_one<T: Component>(&mut self, entity: Entity) -> Result<T, ComponentError> {
|
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)
|
self.remove::<(T,)>(entity).map(|(x,)| x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,17 +261,6 @@ fn clear() {
|
|||||||
assert_eq!(world.iter().count(), 0);
|
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]
|
#[test]
|
||||||
fn remove_missing() {
|
fn remove_missing() {
|
||||||
let mut world = World::new();
|
let mut world = World::new();
|
||||||
|
@ -158,6 +158,10 @@ impl<'a, Q: HecsQuery> Query<'a, Q> {
|
|||||||
.archetype_access
|
.archetype_access
|
||||||
.immutable
|
.immutable
|
||||||
.contains(location.archetype as usize)
|
.contains(location.archetype as usize)
|
||||||
|
|| self
|
||||||
|
.archetype_access
|
||||||
|
.mutable
|
||||||
|
.contains(location.archetype as usize)
|
||||||
{
|
{
|
||||||
self.world
|
self.world
|
||||||
.get(entity)
|
.get(entity)
|
||||||
|
@ -27,7 +27,7 @@ pub fn active_cameras_system(
|
|||||||
) {
|
) {
|
||||||
for (name, active_camera) in active_cameras.cameras.iter_mut() {
|
for (name, active_camera) in active_cameras.cameras.iter_mut() {
|
||||||
if let None = active_camera {
|
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 let Some(ref current_name) = camera.name {
|
||||||
if current_name == name {
|
if current_name == name {
|
||||||
*active_camera = Some(camera_entity);
|
*active_camera = Some(camera_entity);
|
||||||
|
@ -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 {
|
if let Some(window) = match camera.window {
|
||||||
WindowReference::Id(id) => {
|
WindowReference::Id(id) => {
|
||||||
if changed_window_ids.contains(&id) {
|
if changed_window_ids.contains(&id) {
|
||||||
|
@ -26,13 +26,13 @@ pub fn visible_entities_system(
|
|||||||
mut draw_query: Query<(Entity, &Draw)>,
|
mut draw_query: Query<(Entity, &Draw)>,
|
||||||
draw_transform_query: Query<(&Draw, &Transform)>,
|
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();
|
visible_entities.value.clear();
|
||||||
let camera_position = camera_transform.value.w_axis().truncate();
|
let camera_position = camera_transform.value.w_axis().truncate();
|
||||||
|
|
||||||
let mut no_transform_order = 0.0;
|
let mut no_transform_order = 0.0;
|
||||||
let mut transparent_entities = Vec::new();
|
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 {
|
if !draw.is_visible {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ pub trait Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_draw_system(mut query: Query<&mut Draw>) {
|
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();
|
draw.clear_render_commands();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -479,7 +479,7 @@ pub fn mesh_resource_provider_system(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this once batches are pipeline specific and deprecate assigned_meshes draw target
|
// 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) {
|
if let Some(mesh) = meshes.get(&handle) {
|
||||||
for render_pipeline in render_pipelines.pipelines.iter_mut() {
|
for render_pipeline in render_pipelines.pipelines.iter_mut() {
|
||||||
render_pipeline.specialization.primitive_topology = mesh.primitive_topology;
|
render_pipeline.specialization.primitive_topology = mesh.primitive_topology;
|
||||||
|
@ -106,7 +106,7 @@ pub fn draw_render_pipelines_system(
|
|||||||
mut render_resource_bindings: ResMut<RenderResourceBindings>,
|
mut render_resource_bindings: ResMut<RenderResourceBindings>,
|
||||||
mut query: Query<(&mut Draw, &mut RenderPipelines)>,
|
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 {
|
let mut drawable = DrawableRenderPipelines {
|
||||||
render_pipelines: &mut render_pipelines,
|
render_pipelines: &mut render_pipelines,
|
||||||
render_resource_bindings: &mut render_resource_bindings,
|
render_resource_bindings: &mut render_resource_bindings,
|
||||||
|
@ -422,7 +422,7 @@ fn render_resources_node_system<T: RenderResources>(
|
|||||||
let render_resource_context = &**render_resource_context;
|
let render_resource_context = &**render_resource_context;
|
||||||
state.uniform_buffer_arrays.reset_changed_item_counts();
|
state.uniform_buffer_arrays.reset_changed_item_counts();
|
||||||
// update uniforms info
|
// update uniforms info
|
||||||
for (uniforms, draw, _render_pipelines) in &mut query.iter() {
|
for (uniforms, draw, _render_pipelines) in query.iter() {
|
||||||
if !draw.is_visible {
|
if !draw.is_visible {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -438,7 +438,7 @@ fn render_resources_node_system<T: RenderResources>(
|
|||||||
.uniform_buffer_arrays
|
.uniform_buffer_arrays
|
||||||
.update_staging_buffer(render_resource_context);
|
.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 {
|
if !draw.is_visible {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -456,7 +456,7 @@ fn render_resources_node_system<T: RenderResources>(
|
|||||||
staging_buffer,
|
staging_buffer,
|
||||||
0..state.uniform_buffer_arrays.staging_buffer_size as u64,
|
0..state.uniform_buffer_arrays.staging_buffer_size as u64,
|
||||||
&mut |mut staging_buffer, _render_resource_context| {
|
&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 {
|
if !draw.is_visible {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -479,7 +479,7 @@ fn render_resources_node_system<T: RenderResources>(
|
|||||||
} else {
|
} else {
|
||||||
// TODO: can we just remove this?
|
// TODO: can we just remove this?
|
||||||
let mut staging_buffer: [u8; 0] = [];
|
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 {
|
if !draw.is_visible {
|
||||||
return;
|
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) {
|
if let Some(asset_bindings) = asset_render_resource_bindings.get(*asset_handle) {
|
||||||
render_pipelines.bindings.extend(asset_bindings);
|
render_pipelines.bindings.extend(asset_bindings);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ pub fn shader_defs_system<T>(mut query: Query<(&T, &mut RenderPipelines)>)
|
|||||||
where
|
where
|
||||||
T: ShaderDefs + Send + Sync + 'static,
|
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 shader_def in shader_defs.iter_shader_defs() {
|
||||||
for render_pipeline in render_pipelines.pipelines.iter_mut() {
|
for render_pipeline in render_pipelines.pipelines.iter_mut() {
|
||||||
render_pipeline
|
render_pipeline
|
||||||
@ -73,7 +73,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_shader_defs_system(mut query: Query<&mut RenderPipelines>) {
|
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() {
|
for render_pipeline in render_pipelines.pipelines.iter_mut() {
|
||||||
render_pipeline
|
render_pipeline
|
||||||
.specialization
|
.specialization
|
||||||
@ -90,7 +90,7 @@ pub fn asset_shader_defs_system<T>(
|
|||||||
) where
|
) where
|
||||||
T: ShaderDefs + Send + Sync + 'static,
|
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();
|
let shader_defs = assets.get(&asset_handle).unwrap();
|
||||||
for shader_def in shader_defs.iter_shader_defs() {
|
for shader_def in shader_defs.iter_shader_defs() {
|
||||||
for render_pipeline in render_pipelines.pipelines.iter_mut() {
|
for render_pipeline in render_pipelines.pipelines.iter_mut() {
|
||||||
|
@ -23,7 +23,7 @@ pub fn sprite_system(
|
|||||||
textures: Res<Assets<Texture>>,
|
textures: Res<Assets<Texture>>,
|
||||||
mut query: Query<(&mut Sprite, &Handle<ColorMaterial>)>,
|
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();
|
let material = materials.get(&handle).unwrap();
|
||||||
if let Some(texture_handle) = material.texture {
|
if let Some(texture_handle) = material.texture {
|
||||||
if let Some(texture) = textures.get(&texture_handle) {
|
if let Some(texture) = textures.get(&texture_handle) {
|
||||||
|
@ -9,7 +9,7 @@ pub fn missing_previous_parent_system(
|
|||||||
mut query: Query<Without<PreviousParent, (Entity, &Parent)>>,
|
mut query: Query<Without<PreviousParent, (Entity, &Parent)>>,
|
||||||
) {
|
) {
|
||||||
// Add missing `PreviousParent` components
|
// Add missing `PreviousParent` components
|
||||||
for (entity, _parent) in &mut query.iter() {
|
for (entity, _parent) in query.iter() {
|
||||||
log::trace!("Adding missing PreviousParent to {:?}", entity);
|
log::trace!("Adding missing PreviousParent to {:?}", entity);
|
||||||
commands.insert_one(entity, PreviousParent(None));
|
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
|
// Entities with a missing `Parent` (ie. ones that have a `PreviousParent`), remove
|
||||||
// them from the `Children` of the `PreviousParent`.
|
// 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);
|
log::trace!("Parent was removed from {:?}", entity);
|
||||||
if let Some(previous_parent_entity) = previous_parent.0 {
|
if let Some(previous_parent_entity) = previous_parent.0 {
|
||||||
if let Ok(mut previous_parent_children) =
|
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);
|
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)
|
// 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);
|
log::trace!("Parent changed for {:?}", entity);
|
||||||
|
|
||||||
// If the `PreviousParent` is not None.
|
// If the `PreviousParent` is not None.
|
||||||
|
@ -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));
|
*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));
|
*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)));
|
*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));
|
*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)>>,
|
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));
|
*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)>>,
|
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(
|
*local = LocalTransform(Mat4::from_scale_rotation_translation(
|
||||||
Vec3::new(scale.0, scale.0, scale.0),
|
Vec3::new(scale.0, scale.0, scale.0),
|
||||||
Quat::default(),
|
Quat::default(),
|
||||||
@ -86,7 +86,7 @@ pub fn local_transform_translation_non_uniform_scale_system(
|
|||||||
Without<Rotation, Without<Scale, (&mut LocalTransform, &Translation, &NonUniformScale)>>,
|
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(
|
*local = LocalTransform(Mat4::from_scale_rotation_translation(
|
||||||
non_uniform_scale.0,
|
non_uniform_scale.0,
|
||||||
Quat::default(),
|
Quat::default(),
|
||||||
@ -100,7 +100,7 @@ pub fn local_transform_rotation_scale_system(
|
|||||||
Without<Translation, Without<NonUniformScale, (&mut LocalTransform, &Rotation, &Scale)>>,
|
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(
|
*local = LocalTransform(Mat4::from_scale_rotation_translation(
|
||||||
Vec3::new(scale.0, scale.0, scale.0),
|
Vec3::new(scale.0, scale.0, scale.0),
|
||||||
rotation.0,
|
rotation.0,
|
||||||
@ -114,7 +114,7 @@ pub fn local_transform_rotation_non_uniform_scale_system(
|
|||||||
Without<Translation, Without<Scale, (&mut LocalTransform, &Rotation, &NonUniformScale)>>,
|
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(
|
*local = LocalTransform(Mat4::from_scale_rotation_translation(
|
||||||
non_uniform_scale.0,
|
non_uniform_scale.0,
|
||||||
rotation.0,
|
rotation.0,
|
||||||
@ -128,7 +128,7 @@ pub fn local_transform_translation_rotation_scale_system(
|
|||||||
Without<NonUniformScale, (&mut LocalTransform, &Translation, &Rotation, &Scale)>,
|
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(
|
*local = LocalTransform(Mat4::from_scale_rotation_translation(
|
||||||
Vec3::new(scale.0, scale.0, scale.0),
|
Vec3::new(scale.0, scale.0, scale.0),
|
||||||
rotation.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(
|
*local = LocalTransform(Mat4::from_scale_rotation_translation(
|
||||||
non_uniform_scale.0,
|
non_uniform_scale.0,
|
||||||
rotation.0,
|
rotation.0,
|
||||||
|
@ -10,7 +10,7 @@ pub fn transform_propagate_system(
|
|||||||
mut children_query: Query<&Children>,
|
mut children_query: Query<&Children>,
|
||||||
mut local_transform_query: Query<&LocalTransform>,
|
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 {
|
if let Some(local_transform) = local_transform {
|
||||||
transform.value = local_transform.0;
|
transform.value = local_transform.0;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ pub fn transform_translation_system(
|
|||||||
Without<Rotation, Without<Scale, Without<NonUniformScale, (&mut Transform, &Translation)>>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ pub fn transform_rotation_system(
|
|||||||
Without<Translation, Without<Scale, Without<NonUniformScale, (&mut Transform, &Rotation)>>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ pub fn transform_scale_system(
|
|||||||
Without<Translation, Without<Rotation, Without<NonUniformScale, (&mut Transform, &Scale)>>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ pub fn transform_non_uniform_scale_system(
|
|||||||
Without<Translation, Without<Rotation, Without<Scale, (&mut Transform, &NonUniformScale)>>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ pub fn transform_translation_rotation_system(
|
|||||||
Without<Scale, Without<NonUniformScale, (&mut Transform, &Translation, &Rotation)>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ pub fn transform_translation_scale_system(
|
|||||||
Without<Rotation, Without<NonUniformScale, (&mut Transform, &Translation, &Scale)>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ pub fn transform_translation_non_uniform_scale_system(
|
|||||||
Without<Rotation, Without<Scale, (&mut Transform, &Translation, &NonUniformScale)>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ pub fn transform_rotation_scale_system(
|
|||||||
Without<Translation, Without<NonUniformScale, (&mut Transform, &Rotation, &Scale)>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ pub fn transform_rotation_non_uniform_scale_system(
|
|||||||
Without<Translation, Without<Scale, (&mut Transform, &Rotation, &NonUniformScale)>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ pub fn transform_rotation_non_uniform_scale_system(
|
|||||||
pub fn transform_translation_rotation_scale_system(
|
pub fn transform_translation_rotation_scale_system(
|
||||||
mut query: Query<Without<NonUniformScale, (&mut Transform, &Translation, &Rotation, &Scale)>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ pub fn transform_translation_rotation_scale_system(
|
|||||||
pub fn transform_translation_rotation_non_uniform_scale_system(
|
pub fn transform_translation_rotation_non_uniform_scale_system(
|
||||||
mut query: Query<Without<Scale, (&mut Transform, &Translation, &Rotation, &NonUniformScale)>>,
|
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 {
|
if !transform.sync {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ pub fn ui_focus_system(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mouse_button_input.just_released(MouseButton::Left) {
|
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 let Some(mut click) = click {
|
||||||
if *click == Click::Pressed {
|
if *click == Click::Pressed {
|
||||||
*click = Click::Released;
|
*click = Click::Released;
|
||||||
@ -83,8 +83,9 @@ pub fn ui_focus_system(
|
|||||||
let mut hovered_entity = None;
|
let mut hovered_entity = None;
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut query_iter = node_query.iter();
|
// let mut query_iter = node_query.iter();
|
||||||
let mut moused_over_z_sorted_nodes = query_iter
|
let mut moused_over_z_sorted_nodes = node_query
|
||||||
|
.iter()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(entity, node, transform, click, hover, focus_policy)| {
|
.filter_map(|(entity, node, transform, click, hover, focus_policy)| {
|
||||||
let position = transform.value.w_axis();
|
let position = transform.value.w_axis();
|
||||||
|
@ -24,7 +24,7 @@ pub fn text_system(
|
|||||||
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
|
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
|
||||||
mut query: Query<&Text>,
|
mut query: Query<&Text>,
|
||||||
) {
|
) {
|
||||||
for text in &mut query.iter() {
|
for text in query.iter() {
|
||||||
let font_atlases = font_atlas_sets
|
let font_atlases = font_atlas_sets
|
||||||
.get_or_insert_with(Handle::from_id(text.font.id), || {
|
.get_or_insert_with(Handle::from_id(text.font.id), || {
|
||||||
FontAtlasSet::new(text.font)
|
FontAtlasSet::new(text.font)
|
||||||
@ -54,7 +54,7 @@ pub fn draw_text_system(
|
|||||||
mut asset_render_resource_bindings: ResMut<AssetRenderResourceBindings>,
|
mut asset_render_resource_bindings: ResMut<AssetRenderResourceBindings>,
|
||||||
mut query: Query<(&mut Draw, &Text, &Node, &Transform)>,
|
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 position = transform.value.w_axis().truncate() - (node.size / 2.0).extend(0.0);
|
||||||
|
|
||||||
let mut drawable_text = DrawableText {
|
let mut drawable_text = DrawableText {
|
||||||
|
@ -12,7 +12,7 @@ fn animate_sprite_system(
|
|||||||
texture_atlases: Res<Assets<TextureAtlas>>,
|
texture_atlases: Res<Assets<TextureAtlas>>,
|
||||||
mut query: Query<(&mut Timer, &mut TextureAtlasSprite, &Handle<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 {
|
if timer.finished {
|
||||||
let texture_atlas = texture_atlases.get(&texture_atlas_handle).unwrap();
|
let texture_atlas = texture_atlases.get(&texture_atlas_handle).unwrap();
|
||||||
sprite.index = ((sprite.index as usize + 1) % texture_atlas.textures.len()) as u32;
|
sprite.index = ((sprite.index as usize + 1) % texture_atlas.textures.len()) as u32;
|
||||||
|
@ -12,7 +12,7 @@ fn main() {
|
|||||||
|
|
||||||
/// rotates the parent, which will result in the child also rotating
|
/// rotates the parent, which will result in the child also rotating
|
||||||
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
|
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);
|
rotation.0 = rotation.0 * Quat::from_rotation_x(3.0 * time.delta_seconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ fn move_cubes(
|
|||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
mut query: Query<(&mut Translation, &Handle<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();
|
let material = materials.get_mut(&material_handle).unwrap();
|
||||||
translation.0 += Vec3::new(1.0, 0.0, 0.0) * time.delta_seconds;
|
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);
|
material.albedo += Color::rgb(-time.delta_seconds, -time.delta_seconds, time.delta_seconds);
|
||||||
|
@ -19,7 +19,7 @@ fn main() {
|
|||||||
|
|
||||||
/// rotates the parent, which will result in the child also rotating
|
/// rotates the parent, which will result in the child also rotating
|
||||||
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
|
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);
|
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)>,
|
mut camera_query: Query<(&Camera, &VisibleEntities)>,
|
||||||
material_query: Query<&Handle<StandardMaterial>>,
|
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() {
|
for visible_entity in visible_entities.iter() {
|
||||||
if let Ok(material_handle) =
|
if let Ok(material_handle) =
|
||||||
material_query.get::<Handle<StandardMaterial>>(visible_entity.entity)
|
material_query.get::<Handle<StandardMaterial>>(visible_entity.entity)
|
||||||
|
@ -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.
|
// This system updates the score for each entity with the "Player" and "Score" component.
|
||||||
fn score_system(mut query: Query<(&Player, &mut Score)>) {
|
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>();
|
let scored_a_point = random::<bool>();
|
||||||
if scored_a_point {
|
if scored_a_point {
|
||||||
score.value += 1;
|
score.value += 1;
|
||||||
@ -112,7 +112,7 @@ fn score_check_system(
|
|||||||
mut game_state: ResMut<GameState>,
|
mut game_state: ResMut<GameState>,
|
||||||
mut query: Query<(&Player, &Score)>,
|
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 {
|
if score.value == game_rules.winning_score {
|
||||||
game_state.winning_player = Some(player.name.clone());
|
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
|
// NOTE: this doesn't do anything relevant to our game, it is just here for illustrative purposes
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn local_state_system(mut state: Local<State>, mut query: Query<(&Player, &Score)>) {
|
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!("processed: {} {}", player.name, score.value);
|
||||||
}
|
}
|
||||||
println!("this system ran {} times", state.counter);
|
println!("this system ran {} times", state.counter);
|
||||||
|
@ -160,7 +160,7 @@ fn paddle_movement_system(
|
|||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<Input<KeyCode>>,
|
||||||
mut query: Query<(&Paddle, &mut Translation)>,
|
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;
|
let mut direction = 0.0;
|
||||||
if keyboard_input.pressed(KeyCode::Left) {
|
if keyboard_input.pressed(KeyCode::Left) {
|
||||||
direction -= 1.0;
|
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)>) {
|
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;
|
translation.0 += ball.velocity * time.delta_seconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scoreboard_system(scoreboard: Res<Scoreboard>, mut query: Query<&mut Text>) {
|
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);
|
text.value = format!("Score: {}", scoreboard.score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,13 +194,13 @@ fn ball_collision_system(
|
|||||||
mut brick_query: Query<(Entity, &Brick, &Translation, &Sprite)>,
|
mut brick_query: Query<(Entity, &Brick, &Translation, &Sprite)>,
|
||||||
mut wall_query: Query<(&Wall, &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 ball_size = sprite.size;
|
||||||
let velocity = &mut ball.velocity;
|
let velocity = &mut ball.velocity;
|
||||||
let mut collision = None;
|
let mut collision = None;
|
||||||
|
|
||||||
// check collision with walls
|
// 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() {
|
if collision.is_some() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ fn ball_collision_system(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check collision with paddle(s)
|
// 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() {
|
if collision.is_some() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -218,7 +218,7 @@ fn ball_collision_system(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check collision with bricks
|
// 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() {
|
if collision.is_some() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// You should immediately see the changes appear in the console.
|
||||||
fn print_system(mut query: Query<(Entity, &ComponentA)>) {
|
fn print_system(mut query: Query<(Entity, &ComponentA)>) {
|
||||||
println!("Current World State:");
|
println!("Current World State:");
|
||||||
for (entity, component_a) in &mut query.iter() {
|
for (entity, component_a) in query.iter() {
|
||||||
println!(" Entity({})", entity.id());
|
println!(" Entity({})", entity.id());
|
||||||
println!(
|
println!(
|
||||||
" ComponentA: {{ x: {} y: {} }}\n",
|
" ComponentA: {{ x: {} y: {} }}\n",
|
||||||
|
@ -44,7 +44,7 @@ fn button_system(
|
|||||||
)>,
|
)>,
|
||||||
text_query: Query<&mut Text>,
|
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();
|
let mut text = text_query.get_mut::<Text>(children[0]).unwrap();
|
||||||
match *hover {
|
match *hover {
|
||||||
Hover::Hovered => {
|
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();
|
let mut text = text_query.get_mut::<Text>(children[0]).unwrap();
|
||||||
match *click {
|
match *click {
|
||||||
Click::Pressed => {
|
Click::Pressed => {
|
||||||
|
@ -51,7 +51,7 @@ fn atlas_render_system(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn text_update_system(mut state: ResMut<State>, time: Res<Time>, mut query: Query<&mut Text>) {
|
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);
|
state.timer.tick(time.delta_seconds);
|
||||||
if state.timer.finished {
|
if state.timer.finished {
|
||||||
text.value = format!("{}", rand::random::<u8>() as char);
|
text.value = format!("{}", rand::random::<u8>() as char);
|
||||||
|
@ -13,7 +13,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text>) {
|
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(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
|
||||||
if let Some(average) = fps.average() {
|
if let Some(average) = fps.average() {
|
||||||
text.value = format!("FPS: {:.2}", average);
|
text.value = format!("FPS: {:.2}", average);
|
||||||
|
@ -13,7 +13,7 @@ fn placement_system(
|
|||||||
materials: Res<Assets<ColorMaterial>>,
|
materials: Res<Assets<ColorMaterial>>,
|
||||||
mut query: Query<(&mut Node, &Handle<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();
|
let material = materials.get(&material_handle).unwrap();
|
||||||
if material.color.r > 0.2 {
|
if material.color.r > 0.2 {
|
||||||
node.position += Vec2::new(0.1 * time.delta_seconds, 0.0);
|
node.position += Vec2::new(0.1 * time.delta_seconds, 0.0);
|
||||||
|
Loading…
Reference in New Issue
Block a user