Skip to content

Commit

Permalink
Misc cleanups (bevyengine#879)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bjorn3 authored Nov 17, 2020
1 parent db2d20e commit d6eb647
Show file tree
Hide file tree
Showing 29 changed files with 154 additions and 181 deletions.
3 changes: 1 addition & 2 deletions crates/bevy_audio/src/audio_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ impl AssetLoader for Mp3Loader {
}

fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["mp3", "flac", "wav", "ogg"];
EXTENSIONS
&["mp3", "flac", "wav", "ogg"]
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl AssetLoader for GltfLoader {
}

fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["gltf", "glb"];
EXTENSIONS
&["gltf", "glb"]
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_math/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand All @@ -76,7 +76,7 @@ where
T: AddAssign<f32>,
{
fn add_assign(&mut self, rhs: Vec2) {
self.width += rhs.x();
self.height += rhs.y();
self.width += rhs.x;
self.height += rhs.y;
}
}
2 changes: 1 addition & 1 deletion crates/bevy_render/src/camera/visible_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 19 additions & 19 deletions crates/bevy_render/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ impl Add<Vec4> 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,
}
}
}
Expand All @@ -321,7 +321,7 @@ impl From<Color> for Vec4 {

impl From<Vec4> 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)
}
}

Expand All @@ -346,20 +346,20 @@ impl Mul<Vec4> 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<Vec4> 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);
}
}

Expand All @@ -368,19 +368,19 @@ impl Mul<Vec3> 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(),
)
}
}

impl MulAssign<Vec3> 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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions crates/bevy_render/src/mesh/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ pub mod shape {

impl From<Quad> 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);
Expand All @@ -334,45 +334,45 @@ 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],
),
]
} 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],
),
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_render/src/texture/hdr_texture_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl AssetLoader for HdrTextureLoader {
}

fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["hdr"];
EXTENSIONS
&["hdr"]
}
}
3 changes: 1 addition & 2 deletions crates/bevy_render/src/texture/image_texture_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ impl AssetLoader for ImageTextureLoader {
}

fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["png"];
EXTENSIONS
&["png"]
}
}
8 changes: 4 additions & 4 deletions crates/bevy_render/src/texture/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Default for Texture {
impl Texture {
pub fn new(size: Vec2, data: Vec<u8>, 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",
);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/texture/texture_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_scene/src/scene_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl AssetLoader for SceneLoader {
}

fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["scn"];
EXTENSIONS
&["scn"]
}
}
38 changes: 17 additions & 21 deletions crates/bevy_sprite/src/collide_aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,26 @@ pub fn collide(a_pos: Vec3, a_size: Vec2, b_pos: Vec3, b_size: Vec2) -> Option<C
let b_max = b_pos.truncate() + b_size / 2.0;

// check to see if the two rectangles are intersecting
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()
{
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) {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ impl DynamicTextureAtlasBuilder {
texture: &Texture,
) -> Option<u32> {
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 {
Expand Down Expand Up @@ -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();

Expand All @@ -97,5 +97,5 @@ impl From<guillotiere::Rectangle> 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)
}
Loading

0 comments on commit d6eb647

Please sign in to comment.