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
This commit is contained in:
bjorn3 2020-11-17 22:40:18 +01:00 committed by GitHub
parent db2d20ec1a
commit d6eb647451
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 154 additions and 181 deletions

View file

@ -30,8 +30,7 @@ impl AssetLoader for Mp3Loader {
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["mp3", "flac", "wav", "ogg"];
EXTENSIONS
&["mp3", "flac", "wav", "ogg"]
}
}

View file

@ -66,8 +66,7 @@ impl AssetLoader for GltfLoader {
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["gltf", "glb"];
EXTENSIONS
&["gltf", "glb"]
}
}

View file

@ -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<f32>,
{
fn add_assign(&mut self, rhs: Vec2) {
self.width += rhs.x();
self.height += rhs.y();
self.width += rhs.x;
self.height += rhs.y;
}
}

View file

@ -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 {

View file

@ -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,
}
}
}
@ -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)
}
}
@ -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);
}
}
@ -368,9 +368,9 @@ 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(),
)
}
@ -378,9 +378,9 @@ impl Mul<Vec3> for Color {
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);
}
}

View file

@ -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

View file

@ -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);
@ -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;

View file

@ -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)

View file

@ -48,7 +48,6 @@ impl AssetLoader for HdrTextureLoader {
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["hdr"];
EXTENSIONS
&["hdr"]
}
}

View file

@ -155,7 +155,6 @@ impl AssetLoader for ImageTextureLoader {
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["png"];
EXTENSIONS
&["png"]
}
}

View file

@ -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",
);
@ -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);
}

View file

@ -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,

View file

@ -42,7 +42,6 @@ impl AssetLoader for SceneLoader {
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["scn"];
EXTENSIONS
&["scn"]
}
}

View file

@ -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) {

View file

@ -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 {
@ -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<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)
}

View file

@ -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
}
}

View file

@ -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,

View file

@ -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<Texture>,
) -> Result<TextureAtlas, RectanglePackError> {
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;

View file

@ -20,7 +20,6 @@ impl AssetLoader for FontLoader {
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["ttf"];
EXTENSIONS
&["ttf"]
}
}

View file

@ -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;
}
}
}

View file

@ -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 {

View file

@ -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::<Transform>(entity) {
transform.translation.set_z(z);
transform.translation.z = z;
}
Some(global_z)

View file

@ -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,
};
}
}

View file

@ -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::<CreateWindow>::default();
let mut app_exit_event_reader = EventReader::<AppExit>::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::<Events<AppExit>>() {
if app_exit_event_reader.latest(&app_exit_events).is_some() {

View file

@ -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;
}
}

View file

@ -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)| {

View file

@ -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

View file

@ -118,9 +118,9 @@ fn mouse_handler(
fn movement_system(time: Res<Time>, mut bird_query: Query<(&mut Bird, &mut Transform)>) {
for (mut bird, mut transform) in bird_query.iter_mut() {
*transform.translation.x_mut() += bird.velocity.x() * time.delta_seconds;
*transform.translation.y_mut() += bird.velocity.y() * time.delta_seconds;
*bird.velocity.y_mut() += GRAVITY * time.delta_seconds;
transform.translation.x += bird.velocity.x * time.delta_seconds;
transform.translation.y += bird.velocity.y * time.delta_seconds;
bird.velocity.y += GRAVITY * time.delta_seconds;
}
}
@ -129,18 +129,18 @@ fn collision_system(window: Res<WindowDescriptor>, mut bird_query: Query<(&mut B
let half_height = window.height as f32 * 0.5;
for (mut bird, transform) in bird_query.iter_mut() {
let x_vel = bird.velocity.x();
let y_vel = bird.velocity.y();
let x_pos = transform.translation.x();
let y_pos = transform.translation.y();
let x_vel = bird.velocity.x;
let y_vel = bird.velocity.y;
let x_pos = transform.translation.x;
let y_pos = transform.translation.y;
if (x_vel > 0. && x_pos + HALF_BIRD_SIZE > half_width)
|| (x_vel <= 0. && x_pos - HALF_BIRD_SIZE < -(half_width))
{
bird.velocity.set_x(-x_vel);
bird.velocity.x = -x_vel;
}
if y_vel < 0. && y_pos - HALF_BIRD_SIZE < -half_height {
bird.velocity.set_y(-y_vel);
bird.velocity.y = -y_vel;
}
}
}

View file

@ -63,7 +63,6 @@ impl AssetLoader for RustSourceCodeLoader {
}
fn extensions(&self) -> &[&str] {
static EXT: &[&str] = &["rs"];
EXT
&["rs"]
}
}