From d6eb64745176c42cd225492405df25b0e42793b3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 17 Nov 2020 22:40:18 +0100 Subject: [PATCH] Misc cleanups (#879) * Remove cfg!(feature = "metal-auto-capture") This cfg! has existed since the initial commit, but the corresponding feature has never been part of Cargo.toml * Remove unnecessary handle_create_window_events call * Remove EventLoopProxyPtr wrapper * Remove unnecessary statics * Fix unrelated deprecation warning to fix CI --- crates/bevy_audio/src/audio_source.rs | 3 +- crates/bevy_gltf/src/loader.rs | 3 +- crates/bevy_math/src/geometry.rs | 8 ++-- .../src/camera/visible_entities.rs | 2 +- crates/bevy_render/src/color.rs | 38 +++++++++--------- crates/bevy_render/src/lib.rs | 10 ++--- crates/bevy_render/src/mesh/mesh.rs | 24 +++++------ .../render_graph/nodes/texture_copy_node.rs | 6 +-- .../src/texture/hdr_texture_loader.rs | 3 +- .../src/texture/image_texture_loader.rs | 3 +- crates/bevy_render/src/texture/texture.rs | 8 ++-- .../src/texture/texture_descriptor.rs | 4 +- crates/bevy_scene/src/scene_loader.rs | 3 +- crates/bevy_sprite/src/collide_aabb.rs | 38 ++++++++---------- .../src/dynamic_texture_atlas_builder.rs | 12 +++--- crates/bevy_sprite/src/rect.rs | 4 +- crates/bevy_sprite/src/texture_atlas.rs | 14 +++---- .../bevy_sprite/src/texture_atlas_builder.rs | 12 +++--- crates/bevy_text/src/font_loader.rs | 3 +- crates/bevy_ui/src/flex/mod.rs | 8 ++-- crates/bevy_ui/src/focus.rs | 6 +-- crates/bevy_ui/src/update.rs | 2 +- crates/bevy_ui/src/widget/image.rs | 4 +- crates/bevy_winit/src/lib.rs | 20 +--------- examples/2d/contributors.rs | 28 ++++++------- examples/ecs/parallel_query.rs | 8 ++-- examples/game/breakout.rs | 40 +++++++++---------- examples/tools/bevymark.rs | 18 ++++----- examples/wasm/assets_wasm.rs | 3 +- 29 files changed, 154 insertions(+), 181 deletions(-) diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index d1ea527394..7f36276a00 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -30,8 +30,7 @@ impl AssetLoader for Mp3Loader { } fn extensions(&self) -> &[&str] { - static EXTENSIONS: &[&str] = &["mp3", "flac", "wav", "ogg"]; - EXTENSIONS + &["mp3", "flac", "wav", "ogg"] } } diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 454159b181..295a83a308 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -66,8 +66,7 @@ impl AssetLoader for GltfLoader { } fn extensions(&self) -> &[&str] { - static EXTENSIONS: &[&str] = &["gltf", "glb"]; - EXTENSIONS + &["gltf", "glb"] } } diff --git a/crates/bevy_math/src/geometry.rs b/crates/bevy_math/src/geometry.rs index cd91e9dd69..2ded532e06 100644 --- a/crates/bevy_math/src/geometry.rs +++ b/crates/bevy_math/src/geometry.rs @@ -65,8 +65,8 @@ where fn add(self, rhs: Vec2) -> Self::Output { Self { - width: self.width + rhs.x(), - height: self.height + rhs.y(), + width: self.width + rhs.x, + height: self.height + rhs.y, } } } @@ -76,7 +76,7 @@ where T: AddAssign, { fn add_assign(&mut self, rhs: Vec2) { - self.width += rhs.x(); - self.height += rhs.y(); + self.width += rhs.x; + self.height += rhs.y; } } diff --git a/crates/bevy_render/src/camera/visible_entities.rs b/crates/bevy_render/src/camera/visible_entities.rs index 775f0dc58e..7a79e469bb 100644 --- a/crates/bevy_render/src/camera/visible_entities.rs +++ b/crates/bevy_render/src/camera/visible_entities.rs @@ -43,7 +43,7 @@ pub fn visible_entities_system( let position = global_transform.translation; // smaller distances are sorted to lower indices by using the distance from the camera FloatOrd(match camera.depth_calculation { - DepthCalculation::ZDifference => camera_position.z() - position.z(), + DepthCalculation::ZDifference => camera_position.z - position.z, DepthCalculation::Distance => (camera_position - position).length(), }) } else { diff --git a/crates/bevy_render/src/color.rs b/crates/bevy_render/src/color.rs index 52c3714f44..640e44efe7 100644 --- a/crates/bevy_render/src/color.rs +++ b/crates/bevy_render/src/color.rs @@ -293,10 +293,10 @@ impl Add for Color { fn add(self, rhs: Vec4) -> Self::Output { Color { - red: self.red + rhs.x(), - green: self.green + rhs.y(), - blue: self.blue + rhs.z(), - alpha: self.alpha + rhs.w(), + red: self.red + rhs.x, + green: self.green + rhs.y, + blue: self.blue + rhs.z, + alpha: self.alpha + rhs.w, } } } @@ -321,7 +321,7 @@ impl From for Vec4 { impl From for Color { fn from(vec4: Vec4) -> Self { - Color::rgba(vec4.x(), vec4.y(), vec4.z(), vec4.w()) + Color::rgba(vec4.x, vec4.y, vec4.z, vec4.w) } } @@ -346,20 +346,20 @@ impl Mul for Color { fn mul(self, rhs: Vec4) -> Self::Output { Color::rgba( - self.r() * rhs.x(), - self.g() * rhs.y(), - self.b() * rhs.z(), - self.a() * rhs.w(), + self.r() * rhs.x, + self.g() * rhs.y, + self.b() * rhs.z, + self.a() * rhs.w, ) } } impl MulAssign for Color { fn mul_assign(&mut self, rhs: Vec4) { - self.set_r(self.r() * rhs.x()); - self.set_g(self.g() * rhs.y()); - self.set_b(self.b() * rhs.z()); - self.set_a(self.a() * rhs.w()); + self.set_r(self.r() * rhs.x); + self.set_g(self.g() * rhs.y); + self.set_b(self.b() * rhs.z); + self.set_a(self.a() * rhs.w); } } @@ -368,9 +368,9 @@ impl Mul for Color { fn mul(self, rhs: Vec3) -> Self::Output { Color::rgba( - self.r() * rhs.x(), - self.g() * rhs.y(), - self.b() * rhs.z(), + self.r() * rhs.x, + self.g() * rhs.y, + self.b() * rhs.z, self.a(), ) } @@ -378,9 +378,9 @@ impl Mul for Color { impl MulAssign for Color { fn mul_assign(&mut self, rhs: Vec3) { - self.set_r(self.r() * rhs.x()); - self.set_g(self.g() * rhs.y()); - self.set_b(self.b() * rhs.z()); + self.set_r(self.r() * rhs.x); + self.set_g(self.g() * rhs.y); + self.set_b(self.b() * rhs.z); } } diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 9fd0ecda6d..fc3937ef44 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -54,13 +54,13 @@ use texture::TextureResourceSystemState; /// The names of "render" App stages pub mod stage { /// Stage where render resources are set up - pub static RENDER_RESOURCE: &str = "render_resource"; + pub const RENDER_RESOURCE: &str = "render_resource"; /// Stage where Render Graph systems are run. In general you shouldn't add systems to this stage manually. - pub static RENDER_GRAPH_SYSTEMS: &str = "render_graph_systems"; + pub const RENDER_GRAPH_SYSTEMS: &str = "render_graph_systems"; // Stage where draw systems are executed. This is generally where Draw components are setup - pub static DRAW: &str = "draw"; - pub static RENDER: &str = "render"; - pub static POST_RENDER: &str = "post_render"; + pub const DRAW: &str = "draw"; + pub const RENDER: &str = "render"; + pub const POST_RENDER: &str = "post_render"; } /// Adds core render types and systems to an App diff --git a/crates/bevy_render/src/mesh/mesh.rs b/crates/bevy_render/src/mesh/mesh.rs index c529c01793..0f1ba85f23 100644 --- a/crates/bevy_render/src/mesh/mesh.rs +++ b/crates/bevy_render/src/mesh/mesh.rs @@ -324,8 +324,8 @@ pub mod shape { impl From for Mesh { fn from(quad: Quad) -> Self { - let extent_x = quad.size.x() / 2.0; - let extent_y = quad.size.y() / 2.0; + let extent_x = quad.size.x / 2.0; + let extent_y = quad.size.y / 2.0; let north_west = vec2(-extent_x, extent_y); let north_east = vec2(extent_x, extent_y); @@ -334,22 +334,22 @@ pub mod shape { let vertices = if quad.flip { [ ( - [south_east.x(), south_east.y(), 0.0], + [south_east.x, south_east.y, 0.0], [0.0, 0.0, 1.0], [1.0, 1.0], ), ( - [north_east.x(), north_east.y(), 0.0], + [north_east.x, north_east.y, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0], ), ( - [north_west.x(), north_west.y(), 0.0], + [north_west.x, north_west.y, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0], ), ( - [south_west.x(), south_west.y(), 0.0], + [south_west.x, south_west.y, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0], ), @@ -357,22 +357,22 @@ pub mod shape { } else { [ ( - [south_west.x(), south_west.y(), 0.0], + [south_west.x, south_west.y, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0], ), ( - [north_west.x(), north_west.y(), 0.0], + [north_west.x, north_west.y, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0], ), ( - [north_east.x(), north_east.y(), 0.0], + [north_east.x, north_east.y, 0.0], [0.0, 0.0, 1.0], [1.0, 0.0], ), ( - [south_east.x(), south_east.y(), 0.0], + [south_east.x, south_east.y, 0.0], [0.0, 0.0, 1.0], [1.0, 1.0], ), @@ -467,8 +467,8 @@ pub mod shape { ); } let hexasphere = Hexasphere::new(sphere.subdivisions, |point| { - let inclination = point.z().acos(); - let azumith = point.y().atan2(point.x()); + let inclination = point.z.acos(); + let azumith = point.y.atan2(point.x); let norm_inclination = 1.0 - (inclination / std::f32::consts::PI); let norm_azumith = (azumith / std::f32::consts::PI) * 0.5; diff --git a/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs b/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs index 61f463eb2d..d68a6729ec 100644 --- a/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs @@ -34,13 +34,13 @@ impl Node for TextureCopyNode { } let texture_descriptor: TextureDescriptor = texture.into(); - let width = texture.size.x() as usize; + let width = texture.size.x as usize; let aligned_width = render_context .resources() - .get_aligned_texture_size(texture.size.x() as usize); + .get_aligned_texture_size(texture.size.x as usize); let format_size = texture.format.pixel_size(); let mut aligned_data = - vec![0; format_size * aligned_width * texture.size.y() as usize]; + vec![0; format_size * aligned_width * texture.size.y as usize]; texture .data .chunks_exact(format_size * width) diff --git a/crates/bevy_render/src/texture/hdr_texture_loader.rs b/crates/bevy_render/src/texture/hdr_texture_loader.rs index 42b341608f..f3929892e6 100644 --- a/crates/bevy_render/src/texture/hdr_texture_loader.rs +++ b/crates/bevy_render/src/texture/hdr_texture_loader.rs @@ -48,7 +48,6 @@ impl AssetLoader for HdrTextureLoader { } fn extensions(&self) -> &[&str] { - static EXTENSIONS: &[&str] = &["hdr"]; - EXTENSIONS + &["hdr"] } } diff --git a/crates/bevy_render/src/texture/image_texture_loader.rs b/crates/bevy_render/src/texture/image_texture_loader.rs index b0e8f00d97..0f33507f1e 100644 --- a/crates/bevy_render/src/texture/image_texture_loader.rs +++ b/crates/bevy_render/src/texture/image_texture_loader.rs @@ -155,7 +155,6 @@ impl AssetLoader for ImageTextureLoader { } fn extensions(&self) -> &[&str] { - static EXTENSIONS: &[&str] = &["png"]; - EXTENSIONS + &["png"] } } diff --git a/crates/bevy_render/src/texture/texture.rs b/crates/bevy_render/src/texture/texture.rs index 61d25284af..4a39f365b4 100644 --- a/crates/bevy_render/src/texture/texture.rs +++ b/crates/bevy_render/src/texture/texture.rs @@ -35,7 +35,7 @@ impl Default for Texture { impl Texture { pub fn new(size: Vec2, data: Vec, format: TextureFormat) -> Self { debug_assert_eq!( - size.x() as usize * size.y() as usize * format.pixel_size(), + size.x as usize * size.y as usize * format.pixel_size(), data.len(), "Pixel data, size and format have to match", ); @@ -71,13 +71,13 @@ impl Texture { } pub fn aspect(&self) -> f32 { - self.size.y() / self.size.x() + self.size.y / self.size.x } pub fn resize(&mut self, size: Vec2) { self.size = size; - let width = size.x() as usize; - let height = size.y() as usize; + let width = size.x as usize; + let height = size.y as usize; self.data .resize(width * height * self.format.pixel_size(), 0); } diff --git a/crates/bevy_render/src/texture/texture_descriptor.rs b/crates/bevy_render/src/texture/texture_descriptor.rs index e43cce08d1..82515d4f89 100644 --- a/crates/bevy_render/src/texture/texture_descriptor.rs +++ b/crates/bevy_render/src/texture/texture_descriptor.rs @@ -15,8 +15,8 @@ impl From<&Texture> for TextureDescriptor { fn from(texture: &Texture) -> Self { TextureDescriptor { size: Extent3d { - width: texture.size.x() as u32, - height: texture.size.y() as u32, + width: texture.size.x as u32, + height: texture.size.y as u32, depth: 1, }, mip_level_count: 1, diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index 72baa8d4ba..2daa54475f 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -42,7 +42,6 @@ impl AssetLoader for SceneLoader { } fn extensions(&self) -> &[&str] { - static EXTENSIONS: &[&str] = &["scn"]; - EXTENSIONS + &["scn"] } } diff --git a/crates/bevy_sprite/src/collide_aabb.rs b/crates/bevy_sprite/src/collide_aabb.rs index 6027ffe750..489fdfd2c9 100644 --- a/crates/bevy_sprite/src/collide_aabb.rs +++ b/crates/bevy_sprite/src/collide_aabb.rs @@ -18,30 +18,26 @@ pub fn collide(a_pos: Vec3, a_size: Vec2, b_pos: Vec3, b_size: Vec2) -> Option b_min.x() - && a_min.y() < b_max.y() - && a_max.y() > b_min.y() - { + if a_min.x < b_max.x && a_max.x > b_min.x && a_min.y < b_max.y && a_max.y > b_min.y { // check to see if we hit on the left or right side - let (x_collision, x_depth) = - if a_min.x() < b_min.x() && a_max.x() > b_min.x() && a_max.x() < b_max.x() { - (Some(Collision::Left), b_min.x() - a_max.x()) - } else if a_min.x() > b_min.x() && a_min.x() < b_max.x() && a_max.x() > b_max.x() { - (Some(Collision::Right), a_min.x() - b_max.x()) - } else { - (None, 0.0) - }; + let (x_collision, x_depth) = if a_min.x < b_min.x && a_max.x > b_min.x && a_max.x < b_max.x + { + (Some(Collision::Left), b_min.x - a_max.x) + } else if a_min.x > b_min.x && a_min.x < b_max.x && a_max.x > b_max.x { + (Some(Collision::Right), a_min.x - b_max.x) + } else { + (None, 0.0) + }; // check to see if we hit on the top or bottom side - let (y_collision, y_depth) = - if a_min.y() < b_min.y() && a_max.y() > b_min.y() && a_max.y() < b_max.y() { - (Some(Collision::Bottom), b_min.y() - a_max.y()) - } else if a_min.y() > b_min.y() && a_min.y() < b_max.y() && a_max.y() > b_max.y() { - (Some(Collision::Top), a_min.y() - b_max.y()) - } else { - (None, 0.0) - }; + let (y_collision, y_depth) = if a_min.y < b_min.y && a_max.y > b_min.y && a_max.y < b_max.y + { + (Some(Collision::Bottom), b_min.y - a_max.y) + } else if a_min.y > b_min.y && a_min.y < b_max.y && a_max.y > b_max.y { + (Some(Collision::Top), a_min.y - b_max.y) + } else { + (None, 0.0) + }; // if we had an "x" and a "y" collision, pick the "primary" side using penetration depth match (x_collision, y_collision) { diff --git a/crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs b/crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs index 3bcbd327d4..be5cdd2c27 100644 --- a/crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs +++ b/crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs @@ -24,15 +24,15 @@ impl DynamicTextureAtlasBuilder { texture: &Texture, ) -> Option { let allocation = self.atlas_allocator.allocate(size2( - texture.size.x() as i32 + self.padding, - texture.size.y() as i32 + self.padding, + texture.size.x as i32 + self.padding, + texture.size.y as i32 + self.padding, )); if let Some(allocation) = allocation { let atlas_texture = textures.get_mut(&texture_atlas.texture).unwrap(); self.place_texture(atlas_texture, allocation, texture); let mut rect: Rect = allocation.rectangle.into(); - *rect.max.x_mut() -= self.padding as f32; - *rect.max.y_mut() -= self.padding as f32; + rect.max.x -= self.padding as f32; + rect.max.y -= self.padding as f32; texture_atlas.add_texture(rect); Some((texture_atlas.len() - 1) as u32) } else { @@ -72,7 +72,7 @@ impl DynamicTextureAtlasBuilder { let mut rect = allocation.rectangle; rect.max.x -= self.padding; rect.max.y -= self.padding; - let atlas_width = atlas_texture.size.x() as usize; + let atlas_width = atlas_texture.size.x as usize; let rect_width = rect.width() as usize; let format_size = atlas_texture.format.pixel_size(); @@ -97,5 +97,5 @@ impl From for Rect { } fn to_size2(vec2: Vec2) -> guillotiere::Size { - guillotiere::Size::new(vec2.x() as i32, vec2.y() as i32) + guillotiere::Size::new(vec2.x as i32, vec2.y as i32) } diff --git a/crates/bevy_sprite/src/rect.rs b/crates/bevy_sprite/src/rect.rs index 07ef60e8e1..5a2254efff 100644 --- a/crates/bevy_sprite/src/rect.rs +++ b/crates/bevy_sprite/src/rect.rs @@ -13,11 +13,11 @@ pub struct Rect { impl Rect { pub fn width(&self) -> f32 { - self.max.x() - self.min.x() + self.max.x - self.min.x } pub fn height(&self) -> f32 { - self.max.y() - self.min.y() + self.max.y - self.min.y } } diff --git a/crates/bevy_sprite/src/texture_atlas.rs b/crates/bevy_sprite/src/texture_atlas.rs index e798c61e1e..48fa75adb1 100644 --- a/crates/bevy_sprite/src/texture_atlas.rs +++ b/crates/bevy_sprite/src/texture_atlas.rs @@ -91,29 +91,29 @@ impl TextureAtlas { for y in 0..rows { if y > 0 { - y_padding = padding.y(); + y_padding = padding.y; } for x in 0..columns { if x > 0 { - x_padding = padding.x(); + x_padding = padding.x; } let rect_min = Vec2::new( - (tile_size.x() + x_padding) * x as f32, - (tile_size.y() + y_padding) * y as f32, + (tile_size.x + x_padding) * x as f32, + (tile_size.y + y_padding) * y as f32, ); sprites.push(Rect { min: rect_min, - max: Vec2::new(rect_min.x() + tile_size.x(), rect_min.y() + tile_size.y()), + max: Vec2::new(rect_min.x + tile_size.x, rect_min.y + tile_size.y), }) } } TextureAtlas { size: Vec2::new( - ((tile_size.x() + x_padding) * columns as f32) - x_padding, - ((tile_size.y() + y_padding) * rows as f32) - y_padding, + ((tile_size.x + x_padding) * columns as f32) - x_padding, + ((tile_size.y + y_padding) * rows as f32) - y_padding, ), textures: sprites, texture, diff --git a/crates/bevy_sprite/src/texture_atlas_builder.rs b/crates/bevy_sprite/src/texture_atlas_builder.rs index 7c104953b3..c50553e772 100644 --- a/crates/bevy_sprite/src/texture_atlas_builder.rs +++ b/crates/bevy_sprite/src/texture_atlas_builder.rs @@ -43,7 +43,7 @@ impl TextureAtlasBuilder { self.rects_to_place.push_rect( texture_handle, None, - RectToInsert::new(texture.size.x() as u32, texture.size.y() as u32, 1), + RectToInsert::new(texture.size.x as u32, texture.size.y as u32, 1), ) } @@ -57,7 +57,7 @@ impl TextureAtlasBuilder { let rect_height = packed_location.height() as usize; let rect_x = packed_location.x() as usize; let rect_y = packed_location.y() as usize; - let atlas_width = atlas_texture.size.x() as usize; + let atlas_width = atlas_texture.size.x as usize; let format_size = atlas_texture.format.pixel_size(); for (texture_y, bound_y) in (rect_y..rect_y + rect_height).enumerate() { @@ -74,10 +74,10 @@ impl TextureAtlasBuilder { mut self, textures: &mut Assets, ) -> Result { - let initial_width = self.initial_size.x() as u32; - let initial_height = self.initial_size.y() as u32; - let max_width = self.max_size.x() as u32; - let max_height = self.max_size.y() as u32; + let initial_width = self.initial_size.x as u32; + let initial_height = self.initial_size.y as u32; + let max_width = self.max_size.x as u32; + let max_height = self.max_size.y as u32; let mut current_width = initial_width; let mut current_height = initial_height; diff --git a/crates/bevy_text/src/font_loader.rs b/crates/bevy_text/src/font_loader.rs index be4d314458..39b02d0adc 100644 --- a/crates/bevy_text/src/font_loader.rs +++ b/crates/bevy_text/src/font_loader.rs @@ -20,7 +20,6 @@ impl AssetLoader for FontLoader { } fn extensions(&self) -> &[&str] { - static EXTENSIONS: &[&str] = &["ttf"]; - EXTENSIONS + &["ttf"] } } diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 368cd294c8..abc9bc6084 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -207,12 +207,12 @@ pub fn flex_node_system( let layout = flex_surface.get_layout(entity).unwrap(); node.size = Vec2::new(layout.size.width, layout.size.height); let position = &mut transform.translation; - position.set_x(layout.location.x + layout.size.width / 2.0); - position.set_y(layout.location.y + layout.size.height / 2.0); + position.x = layout.location.x + layout.size.width / 2.0; + position.y = layout.location.y + layout.size.height / 2.0; if let Some(parent) = parent { if let Ok(parent_layout) = flex_surface.get_layout(parent.0) { - *position.x_mut() -= parent_layout.size.width / 2.0; - *position.y_mut() -= parent_layout.size.height / 2.0; + position.x -= parent_layout.size.width / 2.0; + position.y -= parent_layout.size.height / 2.0; } } } diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index a4eca190c7..5ced61ebd9 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -85,10 +85,10 @@ pub fn ui_focus_system( let min = ui_position - extents; let max = ui_position + extents; // if the current cursor position is within the bounds of the node, consider it for clicking - if (min.x()..max.x()).contains(&state.cursor_position.x()) - && (min.y()..max.y()).contains(&state.cursor_position.y()) + if (min.x..max.x).contains(&state.cursor_position.x) + && (min.y..max.y).contains(&state.cursor_position.y) { - Some((entity, focus_policy, interaction, FloatOrd(position.z()))) + Some((entity, focus_policy, interaction, FloatOrd(position.z))) } else { if let Some(mut interaction) = interaction { if *interaction == Interaction::Hovered { diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index 103fcb168a..b0dde1566e 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -42,7 +42,7 @@ fn update_node_entity( let global_z = z + parent_global_z; if let Ok(mut transform) = node_query.get_component_mut::(entity) { - transform.translation.set_z(z); + transform.translation.z = z; } Some(global_z) diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index 81b2961aa4..cde64fe0a3 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -28,8 +28,8 @@ pub fn image_node_system( .and_then(|texture_handle| textures.get(texture_handle)) { calculated_size.size = Size { - width: texture.size.x(), - height: texture.size.y(), + width: texture.size.x, + height: texture.size.y, }; } } diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index e0c001fe07..f5c05e8db6 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -25,9 +25,6 @@ use winit::{ #[derive(Default)] pub struct WinitPlugin; -#[derive(Debug)] -pub struct EventLoopProxyPtr(pub usize); - impl Plugin for WinitPlugin { fn build(&self, app: &mut AppBuilder) { app @@ -148,16 +145,7 @@ pub fn winit_runner(mut app: App) { let mut create_window_event_reader = EventReader::::default(); let mut app_exit_event_reader = EventReader::::default(); - app.resources - .insert_thread_local(EventLoopProxyPtr( - Box::into_raw(Box::new(event_loop.create_proxy())) as usize, - )); - - handle_create_window_events( - &mut app.resources, - &event_loop, - &mut create_window_event_reader, - ); + app.resources.insert_thread_local(event_loop.create_proxy()); app.initialize(); @@ -171,11 +159,7 @@ pub fn winit_runner(mut app: App) { let event_handler = move |event: Event<()>, event_loop: &EventLoopWindowTarget<()>, control_flow: &mut ControlFlow| { - *control_flow = if cfg!(feature = "metal-auto-capture") { - ControlFlow::Exit - } else { - ControlFlow::Poll - }; + *control_flow = ControlFlow::Poll; if let Some(app_exit_events) = app.resources.get_mut::>() { if app_exit_event_reader.latest(&app_exit_events).is_some() { diff --git a/examples/2d/contributors.rs b/examples/2d/contributors.rs index c13361e8c3..5941c82dad 100644 --- a/examples/2d/contributors.rs +++ b/examples/2d/contributors.rs @@ -75,7 +75,7 @@ fn setup( let flipped = rnd.gen_bool(0.5); let mut transform = Transform::from_translation(Vec3::new(pos.0, pos.1, 0.0)); - *transform.scale.x_mut() *= if flipped { -1.0 } else { 1.0 }; + transform.scale.x *= if flipped { -1.0 } else { 1.0 }; commands .spawn((Contributor { color: col },)) @@ -192,7 +192,7 @@ fn select( let mat = materials.get_mut(mat_handle)?; mat.color = COL_SELECTED * cont.color; - trans.translation.set_z(100.0); + trans.translation.z = 100.0; text.value = format!("Contributor: {}", name); @@ -210,7 +210,7 @@ fn deselect( let mat = materials.get_mut(mat_handle)?; mat.color = COL_DESELECTED * cont.color; - trans.translation.set_z(0.0); + trans.translation.z = 0.0; Some(()) } @@ -244,29 +244,29 @@ fn collision_system( let wall_right = (win.width() / 2) as f32; for (mut v, mut t) in q.iter_mut() { - let left = t.translation.x() - SPRITE_SIZE / 2.0; - let right = t.translation.x() + SPRITE_SIZE / 2.0; - let top = t.translation.y() + SPRITE_SIZE / 2.0; - let bottom = t.translation.y() - SPRITE_SIZE / 2.0; + let left = t.translation.x - SPRITE_SIZE / 2.0; + let right = t.translation.x + SPRITE_SIZE / 2.0; + let top = t.translation.y + SPRITE_SIZE / 2.0; + let bottom = t.translation.y - SPRITE_SIZE / 2.0; // clamp the translation to not go out of the bounds if bottom < ground { - t.translation.set_y(ground + SPRITE_SIZE / 2.0); + t.translation.y = ground + SPRITE_SIZE / 2.0; // apply an impulse upwards - *v.translation.y_mut() = rnd.gen_range(700.0, 1000.0); + v.translation.y = rnd.gen_range(700.0, 1000.0); } if top > ceiling { - t.translation.set_y(ceiling - SPRITE_SIZE / 2.0); + t.translation.y = ceiling - SPRITE_SIZE / 2.0; } // on side walls flip the horizontal velocity if left < wall_left { - t.translation.set_x(wall_left + SPRITE_SIZE / 2.0); - *v.translation.x_mut() *= -1.0; + t.translation.x = wall_left + SPRITE_SIZE / 2.0; + v.translation.x *= -1.0; v.rotation *= -1.0; } if right > wall_right { - t.translation.set_x(wall_right - SPRITE_SIZE / 2.0); - *v.translation.x_mut() *= -1.0; + t.translation.x = wall_right - SPRITE_SIZE / 2.0; + v.translation.x *= -1.0; v.rotation *= -1.0; } } diff --git a/examples/ecs/parallel_query.rs b/examples/ecs/parallel_query.rs index 066131972e..3beb470d42 100644 --- a/examples/ecs/parallel_query.rs +++ b/examples/ecs/parallel_query.rs @@ -60,10 +60,10 @@ fn bounce_system( .par_iter_mut(32) // Filter out sprites that don't need to be bounced .filter(|(transform, _)| { - !(left < transform.translation.x() - && transform.translation.x() < right - && bottom < transform.translation.y() - && transform.translation.y() < top) + !(left < transform.translation.x + && transform.translation.x < right + && bottom < transform.translation.y + && transform.translation.y < top) }) // For simplicity, just reverse the velocity; don't use realistic bounces .for_each(&pool, |(_, mut v)| { diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index bf89101da1..6fb27c6e11 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -97,32 +97,32 @@ fn setup( // left .spawn(SpriteBundle { material: wall_material.clone(), - transform: Transform::from_translation(Vec3::new(-bounds.x() / 2.0, 0.0, 0.0)), - sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y() + wall_thickness)), + transform: Transform::from_translation(Vec3::new(-bounds.x / 2.0, 0.0, 0.0)), + sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)), ..Default::default() }) .with(Collider::Solid) // right .spawn(SpriteBundle { material: wall_material.clone(), - transform: Transform::from_translation(Vec3::new(bounds.x() / 2.0, 0.0, 0.0)), - sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y() + wall_thickness)), + transform: Transform::from_translation(Vec3::new(bounds.x / 2.0, 0.0, 0.0)), + sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y + wall_thickness)), ..Default::default() }) .with(Collider::Solid) // bottom .spawn(SpriteBundle { material: wall_material.clone(), - transform: Transform::from_translation(Vec3::new(0.0, -bounds.y() / 2.0, 0.0)), - sprite: Sprite::new(Vec2::new(bounds.x() + wall_thickness, wall_thickness)), + transform: Transform::from_translation(Vec3::new(0.0, -bounds.y / 2.0, 0.0)), + sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)), ..Default::default() }) .with(Collider::Solid) // top .spawn(SpriteBundle { material: wall_material, - transform: Transform::from_translation(Vec3::new(0.0, bounds.y() / 2.0, 0.0)), - sprite: Sprite::new(Vec2::new(bounds.x() + wall_thickness, wall_thickness)), + transform: Transform::from_translation(Vec3::new(0.0, bounds.y / 2.0, 0.0)), + sprite: Sprite::new(Vec2::new(bounds.x + wall_thickness, wall_thickness)), ..Default::default() }) .with(Collider::Solid); @@ -132,15 +132,15 @@ fn setup( let brick_columns = 5; let brick_spacing = 20.0; let brick_size = Vec2::new(150.0, 30.0); - let bricks_width = brick_columns as f32 * (brick_size.x() + brick_spacing) - brick_spacing; + let bricks_width = brick_columns as f32 * (brick_size.x + brick_spacing) - brick_spacing; // center the bricks and move them up a bit - let bricks_offset = Vec3::new(-(bricks_width - brick_size.x()) / 2.0, 100.0, 0.0); + let bricks_offset = Vec3::new(-(bricks_width - brick_size.x) / 2.0, 100.0, 0.0); let brick_material = materials.add(Color::rgb(0.5, 0.5, 1.0).into()); for row in 0..brick_rows { - let y_position = row as f32 * (brick_size.y() + brick_spacing); + let y_position = row as f32 * (brick_size.y + brick_spacing); for column in 0..brick_columns { let brick_position = Vec3::new( - column as f32 * (brick_size.x() + brick_spacing), + column as f32 * (brick_size.x + brick_spacing), y_position, 0.0, ) + bricks_offset; @@ -174,9 +174,9 @@ fn paddle_movement_system( let translation = &mut transform.translation; // move the paddle horizontally - *translation.x_mut() += time.delta_seconds * direction * paddle.speed; + translation.x += time.delta_seconds * direction * paddle.speed; // bound the paddle within the walls - *translation.x_mut() = translation.x().min(380.0).max(-380.0); + translation.x = translation.x.min(380.0).max(-380.0); } } @@ -226,20 +226,20 @@ fn ball_collision_system( // only reflect if the ball's velocity is going in the opposite direction of the collision match collision { - Collision::Left => reflect_x = velocity.x() > 0.0, - Collision::Right => reflect_x = velocity.x() < 0.0, - Collision::Top => reflect_y = velocity.y() < 0.0, - Collision::Bottom => reflect_y = velocity.y() > 0.0, + Collision::Left => reflect_x = velocity.x > 0.0, + Collision::Right => reflect_x = velocity.x < 0.0, + Collision::Top => reflect_y = velocity.y < 0.0, + Collision::Bottom => reflect_y = velocity.y > 0.0, } // reflect velocity on the x-axis if we hit something on the x-axis if reflect_x { - *velocity.x_mut() = -velocity.x(); + velocity.x = -velocity.x; } // reflect velocity on the y-axis if we hit something on the y-axis if reflect_y { - *velocity.y_mut() = -velocity.y(); + velocity.y = -velocity.y; } // break if this collide is on a solid, otherwise continue check whether a solid is also in collision diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index 3994f5b837..da9dab64b8 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -118,9 +118,9 @@ fn mouse_handler( fn movement_system(time: Res