From c5ca59dc4d5c9f791e202c0c64e885328889209a Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 5 May 2020 18:44:32 -0700 Subject: [PATCH] cargo fmt --- Cargo.toml | 12 +-- crates/bevy_app/src/app_builder.rs | 5 +- crates/bevy_app/src/schedule_runner.rs | 4 +- crates/bevy_asset/src/handle.rs | 3 +- crates/bevy_core/src/bytes.rs | 3 +- crates/bevy_derive/src/lib.rs | 2 +- crates/bevy_diagnostic/src/lib.rs | 3 +- crates/bevy_glam/benches/vec3.rs | 40 +++++----- crates/bevy_glam/src/f32/glam_zerocopy.rs | 76 +++++++++++-------- crates/bevy_glam/tests/vec2.rs | 7 +- crates/bevy_glam/tests/vec3.rs | 7 +- crates/bevy_glam/tests/vec4.rs | 7 +- crates/bevy_pbr/src/nodes/lights_node.rs | 2 +- .../bevy_render/src/base_render_graph/mod.rs | 16 ++-- crates/bevy_render/src/batch/batcher.rs | 2 +- crates/bevy_render/src/batch/mod.rs | 2 +- crates/bevy_render/src/color.rs | 2 +- .../assigned_meshes_draw_target.rs | 4 +- crates/bevy_render/src/mesh.rs | 4 +- .../src/pipeline/pipeline_compiler.rs | 5 +- .../bevy_render/src/render_graph/command.rs | 1 + .../src/render_graph/nodes/camera2d_node.rs | 2 +- .../src/render_graph/nodes/camera_node.rs | 4 +- .../src/render_graph/nodes/uniform_node.rs | 2 +- crates/bevy_render/src/renderer/mod.rs | 4 +- .../src/renderer/render_resource_context.rs | 9 ++- crates/bevy_render/src/shader/shader.rs | 7 +- crates/bevy_render/src/texture/texture.rs | 2 +- crates/bevy_ui/src/color_material.rs | 2 +- crates/bevy_ui/src/entity.rs | 8 +- crates/bevy_ui/src/node.rs | 8 +- crates/bevy_ui/src/rect.rs | 8 +- crates/bevy_ui/src/sprite.rs | 4 +- crates/bevy_wgpu/src/diagnostic/mod.rs | 2 +- .../wgpu_resource_diagnostics_plugin.rs | 42 ++-------- crates/bevy_wgpu/src/lib.rs | 8 +- crates/glsl-to-spirv/build/build.rs | 10 +-- crates/glsl-to-spirv/src/lib.rs | 13 ++-- examples/2d/sprite.rs | 5 +- examples/ecs/ecs_guide.rs | 3 +- examples/ecs/startup_system.rs | 5 +- src/add_default_plugins.rs | 2 +- src/prelude.rs | 6 +- 43 files changed, 176 insertions(+), 187 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 013eb68681..ec42aca9e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,12 @@ wgpu = ["bevy_wgpu"] winit = ["bevy_winit"] more-system-fns = ["legion/more-system-fns"] +[workspace] +members = [ + "crates/*", + "examples/app/dynamic_plugin_loading/example_plugin" +] + [dependencies] # bevy bevy_app = { path = "crates/bevy_app" } @@ -45,12 +51,6 @@ glam = { path = "crates/bevy_glam" } # other log = { version = "0.4", features = ["release_max_level_info"] } -[workspace] -members = [ - "crates/*", - "examples/app/dynamic_plugin_loading/example_plugin" -] - [dev-dependencies] rand = "0.7.2" serde = { version = "1", features = ["derive"]} diff --git a/crates/bevy_app/src/app_builder.rs b/crates/bevy_app/src/app_builder.rs index 925a0ad728..f4c2940a6a 100644 --- a/crates/bevy_app/src/app_builder.rs +++ b/crates/bevy_app/src/app_builder.rs @@ -151,10 +151,7 @@ impl AppBuilder { self } - pub fn init_startup_system( - &mut self, - build: impl FnMut(&mut Resources) -> T, - ) -> &mut Self + pub fn init_startup_system(&mut self, build: impl FnMut(&mut Resources) -> T) -> &mut Self where T: Into, { diff --git a/crates/bevy_app/src/schedule_runner.rs b/crates/bevy_app/src/schedule_runner.rs index 91cdc76e3b..9fffa72037 100644 --- a/crates/bevy_app/src/schedule_runner.rs +++ b/crates/bevy_app/src/schedule_runner.rs @@ -28,7 +28,9 @@ impl ScheduleRunnerPlugin { pub fn run_loop(wait_duration: Duration) -> Self { ScheduleRunnerPlugin { - run_mode: RunMode::Loop { wait: Some(wait_duration) }, + run_mode: RunMode::Loop { + wait: Some(wait_duration), + }, } } } diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index 4a06c97bc3..dfeaa3d839 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -8,7 +8,8 @@ use uuid::Uuid; #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] pub struct HandleId(pub Uuid); -pub const DEFAULT_HANDLE_ID: HandleId = HandleId(Uuid::from_u128(240940089166493627844978703213080810552)); +pub const DEFAULT_HANDLE_ID: HandleId = + HandleId(Uuid::from_u128(240940089166493627844978703213080810552)); impl HandleId { pub fn new() -> HandleId { diff --git a/crates/bevy_core/src/bytes.rs b/crates/bevy_core/src/bytes.rs index c5a7843bf5..e64d245487 100644 --- a/crates/bevy_core/src/bytes.rs +++ b/crates/bevy_core/src/bytes.rs @@ -1,4 +1,4 @@ -use glam::{Mat4, Vec4, Vec3, Vec2}; +use glam::{Mat4, Vec2, Vec3, Vec4}; use zerocopy::AsBytes; pub trait GetBytes { @@ -64,7 +64,6 @@ impl GetBytes for Vec2 { } } - impl GetBytes for Vec4 { fn get_bytes(&self) -> Vec { let vec4_array: [f32; 4] = (*self).into(); diff --git a/crates/bevy_derive/src/lib.rs b/crates/bevy_derive/src/lib.rs index 2a0793ffeb..40eb1529c8 100644 --- a/crates/bevy_derive/src/lib.rs +++ b/crates/bevy_derive/src/lib.rs @@ -2,9 +2,9 @@ extern crate proc_macro; mod modules; -use modules::{get_modules, get_path}; use darling::FromMeta; use inflector::Inflector; +use modules::{get_modules, get_path}; use proc_macro::TokenStream; use quote::{format_ident, quote}; use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Field, Fields, Ident, Path, Type}; diff --git a/crates/bevy_diagnostic/src/lib.rs b/crates/bevy_diagnostic/src/lib.rs index 5da995c17e..6cb111fac6 100644 --- a/crates/bevy_diagnostic/src/lib.rs +++ b/crates/bevy_diagnostic/src/lib.rs @@ -1,7 +1,6 @@ mod diagnostic; -mod print_diagnostics_plugin; mod frame_time_diagnostics_plugin; -pub use diagnostic::*; +mod print_diagnostics_plugin; pub use diagnostic::*; pub use frame_time_diagnostics_plugin::FrameTimeDiagnosticsPlugin; pub use print_diagnostics_plugin::PrintDiagnosticsPlugin; diff --git a/crates/bevy_glam/benches/vec3.rs b/crates/bevy_glam/benches/vec3.rs index 4f26b230cf..9a7b19ab32 100644 --- a/crates/bevy_glam/benches/vec3.rs +++ b/crates/bevy_glam/benches/vec3.rs @@ -46,32 +46,32 @@ fn vec3_into_tuple(v: Vec3) -> (f32, f32, f32) { } bench_func!( - vec3_to_rgb, - "vec3 to rgb", - op => vec3_to_rgb_op, - from => random_vec3 - ); +vec3_to_rgb, +"vec3 to rgb", +op => vec3_to_rgb_op, +from => random_vec3 +); bench_func!( - vec3_to_array_accessors, - "vec3 into array slow", - op => vec3_accessors, - from => random_vec3 - ); +vec3_to_array_accessors, +"vec3 into array slow", +op => vec3_accessors, +from => random_vec3 +); bench_func!( - vec3_to_array_into, - "vec3 into array fast", - op => vec3_into_array, - from => random_vec3 - ); +vec3_to_array_into, +"vec3 into array fast", +op => vec3_into_array, +from => random_vec3 +); bench_func!( - vec3_to_tuple_into, - "vec3 into tuple fast", - op => vec3_into_tuple, - from => random_vec3 - ); +vec3_to_tuple_into, +"vec3 into tuple fast", +op => vec3_into_tuple, +from => random_vec3 +); euler!(vec3_euler, "vec3 euler", ty => Vec3, storage => Vec3, zero => Vec3::zero(), rand => random_vec3); diff --git a/crates/bevy_glam/src/f32/glam_zerocopy.rs b/crates/bevy_glam/src/f32/glam_zerocopy.rs index cf91034fd7..c6504fc632 100644 --- a/crates/bevy_glam/src/f32/glam_zerocopy.rs +++ b/crates/bevy_glam/src/f32/glam_zerocopy.rs @@ -1,100 +1,114 @@ -use zerocopy::{FromBytes, AsBytes}; -use crate::{Vec2, Vec3, Vec4, Mat2, Mat3, Mat4, Quat}; +use crate::{Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec4}; +use zerocopy::{AsBytes, FromBytes}; unsafe impl AsBytes for Vec2 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl FromBytes for Vec2 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl AsBytes for Vec3 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl FromBytes for Vec3 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl AsBytes for Vec4 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl FromBytes for Vec4 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl AsBytes for Mat2 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl FromBytes for Mat2 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl AsBytes for Mat3 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl FromBytes for Mat3 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl AsBytes for Mat4 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl FromBytes for Mat4 { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl AsBytes for Quat { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - + Self: Sized, + { + } } unsafe impl FromBytes for Quat { fn only_derive_is_allowed_to_implement_this_trait() where - Self: Sized {} - -} \ No newline at end of file + Self: Sized, + { + } +} diff --git a/crates/bevy_glam/tests/vec2.rs b/crates/bevy_glam/tests/vec2.rs index 2a16cd9ed2..24f67b7380 100644 --- a/crates/bevy_glam/tests/vec2.rs +++ b/crates/bevy_glam/tests/vec2.rs @@ -345,9 +345,10 @@ fn test_vec2mask_eq() { #[test] fn test_vec2mask_hash() { - use std::collections::hash_map::DefaultHasher; - use std::hash::Hash; - use std::hash::Hasher; + use std::{ + collections::hash_map::DefaultHasher, + hash::{Hash, Hasher}, + }; let a = Vec2Mask::new(true, false); let b = Vec2Mask::new(true, false); diff --git a/crates/bevy_glam/tests/vec3.rs b/crates/bevy_glam/tests/vec3.rs index dd5954d35e..42d0770681 100644 --- a/crates/bevy_glam/tests/vec3.rs +++ b/crates/bevy_glam/tests/vec3.rs @@ -449,9 +449,10 @@ fn test_vec3mask_eq() { #[test] fn test_vec3mask_hash() { - use std::collections::hash_map::DefaultHasher; - use std::hash::Hash; - use std::hash::Hasher; + use std::{ + collections::hash_map::DefaultHasher, + hash::{Hash, Hasher}, + }; let a = Vec3Mask::new(true, false, true); let b = Vec3Mask::new(true, false, true); diff --git a/crates/bevy_glam/tests/vec4.rs b/crates/bevy_glam/tests/vec4.rs index eb206ccb21..5b90a59787 100644 --- a/crates/bevy_glam/tests/vec4.rs +++ b/crates/bevy_glam/tests/vec4.rs @@ -494,9 +494,10 @@ fn test_vec4mask_eq() { #[test] fn test_vec4mask_hash() { - use std::collections::hash_map::DefaultHasher; - use std::hash::Hash; - use std::hash::Hasher; + use std::{ + collections::hash_map::DefaultHasher, + hash::{Hash, Hasher}, + }; let a = Vec4Mask::new(true, false, true, false); let b = Vec4Mask::new(true, false, true, false); diff --git a/crates/bevy_pbr/src/nodes/lights_node.rs b/crates/bevy_pbr/src/nodes/lights_node.rs index 5bbc9891b5..e0ebeb70aa 100644 --- a/crates/bevy_pbr/src/nodes/lights_node.rs +++ b/crates/bevy_pbr/src/nodes/lights_node.rs @@ -1,7 +1,7 @@ use bevy_render::{ render_graph::{CommandQueue, Node, ResourceSlots, SystemNode}, render_resource::{resource_name, BufferInfo, BufferUsage, RenderResourceAssignments}, - renderer::{RenderResources, RenderContext}, + renderer::{RenderContext, RenderResources}, }; use crate::light::{Light, LightRaw}; diff --git a/crates/bevy_render/src/base_render_graph/mod.rs b/crates/bevy_render/src/base_render_graph/mod.rs index b292fc6269..8c04a3af4a 100644 --- a/crates/bevy_render/src/base_render_graph/mod.rs +++ b/crates/bevy_render/src/base_render_graph/mod.rs @@ -4,10 +4,7 @@ use crate::{ RenderPassDepthStencilAttachmentDescriptor, StoreOp, TextureAttachment, }, render_graph::{ - nodes::{ - Camera2dNode, CameraNode, PassNode, WindowSwapChainNode, - WindowTextureNode, - }, + nodes::{Camera2dNode, CameraNode, PassNode, WindowSwapChainNode, WindowTextureNode}, RenderGraph, }, texture::{Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsage}, @@ -18,10 +15,10 @@ use bevy_window::{WindowCreated, WindowReference, WindowResized}; use legion::prelude::Resources; pub struct BaseRenderGraphConfig { - add_2d_camera: bool, - add_3d_camera: bool, - add_main_pass: bool, - connect_main_pass_to_swapchain: bool, + pub add_2d_camera: bool, + pub add_3d_camera: bool, + pub add_main_pass: bool, + pub connect_main_pass_to_swapchain: bool, } pub mod node { @@ -123,13 +120,12 @@ impl BaseRenderGraphBuilder for RenderGraph { if config.add_3d_camera { self.add_node_edge(node::CAMERA, node::MAIN_PASS).unwrap(); } - + if config.add_2d_camera { self.add_node_edge(node::CAMERA2D, node::MAIN_PASS).unwrap(); } } - self.add_node_named( node::PRIMARY_SWAP_CHAIN, WindowSwapChainNode::new( diff --git a/crates/bevy_render/src/batch/batcher.rs b/crates/bevy_render/src/batch/batcher.rs index d28ef633b6..2945f34050 100644 --- a/crates/bevy_render/src/batch/batcher.rs +++ b/crates/bevy_render/src/batch/batcher.rs @@ -154,7 +154,7 @@ where #[cfg(test)] mod tests { use super::{Batch, BatchKey, Batcher}; - use bevy_asset::{Handle, HandleUntyped, HandleId}; + use bevy_asset::{Handle, HandleId, HandleUntyped}; #[derive(Debug, Eq, PartialEq)] struct A; diff --git a/crates/bevy_render/src/batch/mod.rs b/crates/bevy_render/src/batch/mod.rs index c7bbb36c8f..766b24a360 100644 --- a/crates/bevy_render/src/batch/mod.rs +++ b/crates/bevy_render/src/batch/mod.rs @@ -6,4 +6,4 @@ mod batcher; // pub use asset_batcher::*; // pub use asset_batcher2::*; pub use batch::*; -pub use batcher::*; \ No newline at end of file +pub use batcher::*; diff --git a/crates/bevy_render/src/color.rs b/crates/bevy_render/src/color.rs index 28063d12a6..183a79caac 100644 --- a/crates/bevy_render/src/color.rs +++ b/crates/bevy_render/src/color.rs @@ -137,4 +137,4 @@ impl GetBytes for ColorSource { ColorSource::Texture(ref texture) => texture.get_bytes_ref(), // Texture is not a uniform } } -} \ No newline at end of file +} diff --git a/crates/bevy_render/src/draw_target/draw_targets/assigned_meshes_draw_target.rs b/crates/bevy_render/src/draw_target/draw_targets/assigned_meshes_draw_target.rs index 57604be21a..69a23eb6bf 100644 --- a/crates/bevy_render/src/draw_target/draw_targets/assigned_meshes_draw_target.rs +++ b/crates/bevy_render/src/draw_target/draw_targets/assigned_meshes_draw_target.rs @@ -101,7 +101,9 @@ impl DrawTarget for AssignedMeshesDrawTarget { pipeline_assignments.assignments.get(&pipeline_handle); let global_render_resource_assignments = resources.get::().unwrap(); - render_context.resources().setup_bind_groups(pipeline_descriptor, &global_render_resource_assignments); + render_context + .resources() + .setup_bind_groups(pipeline_descriptor, &global_render_resource_assignments); if let Some(assigned_render_resource_assignments) = assigned_render_resource_assignments { for assignment_id in assigned_render_resource_assignments.iter() { let entity = entity_render_resource_assignments diff --git a/crates/bevy_render/src/mesh.rs b/crates/bevy_render/src/mesh.rs index 604136b817..63ff28b80b 100644 --- a/crates/bevy_render/src/mesh.rs +++ b/crates/bevy_render/src/mesh.rs @@ -4,7 +4,7 @@ use crate::{ VertexBufferDescriptor, VertexBufferDescriptors, VertexFormat, }, render_resource::{BufferInfo, BufferUsage, RenderResourceAssignments}, - renderer::{RenderResources, RenderResourceContext}, + renderer::{RenderResourceContext, RenderResources}, shader::AsUniforms, Renderable, Vertex, }; @@ -384,7 +384,7 @@ pub fn mesh_resource_provider_system(resources: &mut Resources) -> Box>() .with_query(<(Read>, Write)>::query()) .build( - move |_, world, (render_resource_context, meshes,/* asset_batchers*/), query| { + move |_, world, (render_resource_context, meshes /* asset_batchers*/), query| { let render_resources = &*render_resource_context.context; // TODO: remove this once batches are pipeline specific and deprecate assigned_meshes draw target for (handle, mut renderable) in query.iter_mut(world) { diff --git a/crates/bevy_render/src/pipeline/pipeline_compiler.rs b/crates/bevy_render/src/pipeline/pipeline_compiler.rs index c1ded289a8..8d8eb77938 100644 --- a/crates/bevy_render/src/pipeline/pipeline_compiler.rs +++ b/crates/bevy_render/src/pipeline/pipeline_compiler.rs @@ -6,7 +6,7 @@ use crate::{ render_resource::{ BufferInfo, RenderResourceAssignments, RenderResourceAssignmentsId, ResourceInfo, }, - renderer::{RenderResources, RenderResourceContext}, + renderer::{RenderResourceContext, RenderResources}, shader::{Shader, ShaderSource}, Renderable, }; @@ -289,8 +289,7 @@ pub fn update_shader_assignments(world: &mut World, resources: &Resources) { let mut pipeline_compiler = resources.get_mut::().unwrap(); let mut shader_storage = resources.get_mut::>().unwrap(); let vertex_buffer_descriptors = resources.get::().unwrap(); - let render_resources = - resources.get::().unwrap(); + let render_resources = resources.get::().unwrap(); let mut pipeline_descriptor_storage = resources .get_mut::>() .unwrap(); diff --git a/crates/bevy_render/src/render_graph/command.rs b/crates/bevy_render/src/render_graph/command.rs index d944330c0e..e368107e44 100644 --- a/crates/bevy_render/src/render_graph/command.rs +++ b/crates/bevy_render/src/render_graph/command.rs @@ -1,6 +1,7 @@ use crate::{render_resource::RenderResource, renderer::RenderContext, texture::Extent3d}; use std::sync::{Arc, Mutex}; +#[derive(Clone, Debug)] pub enum Command { CopyBufferToBuffer { source_buffer: RenderResource, diff --git a/crates/bevy_render/src/render_graph/nodes/camera2d_node.rs b/crates/bevy_render/src/render_graph/nodes/camera2d_node.rs index db0e0710f1..5ce7990a7c 100644 --- a/crates/bevy_render/src/render_graph/nodes/camera2d_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/camera2d_node.rs @@ -5,7 +5,7 @@ use crate::{ camera::{ActiveCamera2d, Camera}, render_graph::{CommandQueue, Node, ResourceSlots, SystemNode}, render_resource::{resource_name, BufferInfo, BufferUsage, RenderResourceAssignments}, - renderer::{RenderResources, RenderContext}, + renderer::{RenderContext, RenderResources}, }; use legion::prelude::*; diff --git a/crates/bevy_render/src/render_graph/nodes/camera_node.rs b/crates/bevy_render/src/render_graph/nodes/camera_node.rs index 7ccbd218f0..da35b1365c 100644 --- a/crates/bevy_render/src/render_graph/nodes/camera_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/camera_node.rs @@ -1,7 +1,7 @@ use crate::{ render_graph::{CommandQueue, Node, ResourceSlots, SystemNode}, render_resource::{resource_name, BufferInfo, BufferUsage, RenderResourceAssignments}, - renderer::{RenderResources, RenderContext}, + renderer::{RenderContext, RenderResources}, ActiveCamera, Camera, }; @@ -34,7 +34,7 @@ impl SystemNode for CameraNode { let mut camera_buffer = None; let mut window_resized_event_reader = resources.get_event_reader::(); let mut command_queue = self.command_queue.clone(); - + SystemBuilder::new("camera_resource_provider") .read_resource::() // TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same diff --git a/crates/bevy_render/src/render_graph/nodes/uniform_node.rs b/crates/bevy_render/src/render_graph/nodes/uniform_node.rs index 2e2a3ca615..23a884a266 100644 --- a/crates/bevy_render/src/render_graph/nodes/uniform_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/uniform_node.rs @@ -5,7 +5,7 @@ use crate::{ BufferArrayInfo, BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments, RenderResourceAssignmentsId, ResourceInfo, }, - renderer::{RenderResources, RenderContext, RenderResourceContext}, + renderer::{RenderContext, RenderResourceContext, RenderResources}, shader::{AsUniforms, FieldBindType}, texture, Renderable, }; diff --git a/crates/bevy_render/src/renderer/mod.rs b/crates/bevy_render/src/renderer/mod.rs index 2da72588e6..945f4d8e6a 100644 --- a/crates/bevy_render/src/renderer/mod.rs +++ b/crates/bevy_render/src/renderer/mod.rs @@ -1,7 +1,7 @@ +mod headless_render_resource_context; mod render_context; mod render_resource_context; -mod headless_render_resource_context; +pub use headless_render_resource_context::*; pub use render_context::*; pub use render_resource_context::*; -pub use headless_render_resource_context::*; diff --git a/crates/bevy_render/src/renderer/render_resource_context.rs b/crates/bevy_render/src/renderer/render_resource_context.rs index 2a7a9ed96a..24b1571061 100644 --- a/crates/bevy_render/src/renderer/render_resource_context.rs +++ b/crates/bevy_render/src/renderer/render_resource_context.rs @@ -1,7 +1,10 @@ use crate::{ - render_resource::{BufferInfo, RenderResource, ResourceInfo, RenderResourceAssignments, RenderResourceSetId}, + pipeline::{BindGroupDescriptor, PipelineDescriptor}, + render_resource::{ + BufferInfo, RenderResource, RenderResourceAssignments, RenderResourceSetId, ResourceInfo, + }, shader::Shader, - texture::{SamplerDescriptor, TextureDescriptor}, pipeline::{BindGroupDescriptor, PipelineDescriptor}, + texture::{SamplerDescriptor, TextureDescriptor}, }; use bevy_asset::{AssetStorage, Handle, HandleUntyped}; use bevy_window::{Window, WindowId}; @@ -103,4 +106,4 @@ impl dyn RenderResourceContext { } } -impl_downcast!(RenderResourceContext); \ No newline at end of file +impl_downcast!(RenderResourceContext); diff --git a/crates/bevy_render/src/shader/shader.rs b/crates/bevy_render/src/shader/shader.rs index 4ead61fe5e..5fee468133 100644 --- a/crates/bevy_render/src/shader/shader.rs +++ b/crates/bevy_render/src/shader/shader.rs @@ -1,8 +1,7 @@ use super::ShaderLayout; use bevy_asset::Handle; -use std::marker::Copy; use glsl_to_spirv::compile; -use std::io::Read; +use std::{io::Read, marker::Copy}; #[derive(Hash, Eq, PartialEq, Copy, Clone, Debug)] pub enum ShaderStage { Vertex, @@ -31,7 +30,9 @@ pub fn glsl_to_spirv( let mut spv_words = Vec::new(); for bytes4 in spv_bytes.chunks(4) { - spv_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]])); + spv_words.push(u32::from_le_bytes([ + bytes4[0], bytes4[1], bytes4[2], bytes4[3], + ])); } spv_words } diff --git a/crates/bevy_render/src/texture/texture.rs b/crates/bevy_render/src/texture/texture.rs index 2f0b182770..8e9234271c 100644 --- a/crates/bevy_render/src/texture/texture.rs +++ b/crates/bevy_render/src/texture/texture.rs @@ -18,7 +18,7 @@ pub struct Texture { impl Texture { pub fn aspect(&self) -> f32 { self.height as f32 / self.width as f32 - } + } } impl Asset for Texture { diff --git a/crates/bevy_ui/src/color_material.rs b/crates/bevy_ui/src/color_material.rs index cf31d04c10..285a3d1a34 100644 --- a/crates/bevy_ui/src/color_material.rs +++ b/crates/bevy_ui/src/color_material.rs @@ -52,4 +52,4 @@ impl From> for ColorMaterial { fn from(texture: Handle) -> Self { ColorMaterial::texture(texture) } -} \ No newline at end of file +} diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index 3bdae7b92d..035e8e23be 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -1,5 +1,5 @@ use super::Node; -use crate::{render::UI_PIPELINE_HANDLE, ColorMaterial, Rect, QUAD_HANDLE, sprite::Sprite}; +use crate::{render::UI_PIPELINE_HANDLE, sprite::Sprite, ColorMaterial, Rect, QUAD_HANDLE}; use bevy_asset::Handle; use bevy_derive::EntityArchetype; use bevy_render::{mesh::Mesh, Renderable}; @@ -9,7 +9,7 @@ use bevy_render::{mesh::Mesh, Renderable}; pub struct UiEntity { pub node: Node, pub rect: Rect, - pub mesh: Handle, // TODO: maybe abstract this out + pub mesh: Handle, // TODO: maybe abstract this out pub material: Handle, pub renderable: Renderable, } @@ -34,7 +34,7 @@ impl Default for UiEntity { pub struct SpriteEntity { pub sprite: Sprite, pub rect: Rect, - pub mesh: Handle, // TODO: maybe abstract this out + pub mesh: Handle, // TODO: maybe abstract this out pub material: Handle, pub renderable: Renderable, } @@ -52,4 +52,4 @@ impl Default for SpriteEntity { }, } } -} \ No newline at end of file +} diff --git a/crates/bevy_ui/src/node.rs b/crates/bevy_ui/src/node.rs index 3d287ddcc7..38d2c0b2cf 100644 --- a/crates/bevy_ui/src/node.rs +++ b/crates/bevy_ui/src/node.rs @@ -34,7 +34,13 @@ impl Node { } } - pub fn update(&mut self, rect: &mut Rect, parent_dimensions: Vec2, parent_position: Vec2, z_index: f32) { + pub fn update( + &mut self, + rect: &mut Rect, + parent_dimensions: Vec2, + parent_position: Vec2, + z_index: f32, + ) { let (rect_x, rect_width) = Self::compute_dimension_properties( self.position.x(), self.margins.left, diff --git a/crates/bevy_ui/src/rect.rs b/crates/bevy_ui/src/rect.rs index 3be26e0b01..6ec4b2f4ad 100644 --- a/crates/bevy_ui/src/rect.rs +++ b/crates/bevy_ui/src/rect.rs @@ -12,6 +12,10 @@ pub struct Rect { } impl GetBytes for Rect { - fn get_bytes(&self) -> Vec { self.as_bytes().to_vec() } - fn get_bytes_ref(&self) -> Option<&[u8]> { Some(self.as_bytes()) } + fn get_bytes(&self) -> Vec { + self.as_bytes().to_vec() + } + fn get_bytes_ref(&self) -> Option<&[u8]> { + Some(self.as_bytes()) + } } diff --git a/crates/bevy_ui/src/sprite.rs b/crates/bevy_ui/src/sprite.rs index 789c82ab9d..dc7083b273 100644 --- a/crates/bevy_ui/src/sprite.rs +++ b/crates/bevy_ui/src/sprite.rs @@ -8,9 +8,7 @@ pub struct Sprite { impl Default for Sprite { fn default() -> Self { - Sprite { - scale: 1.0 - } + Sprite { scale: 1.0 } } } diff --git a/crates/bevy_wgpu/src/diagnostic/mod.rs b/crates/bevy_wgpu/src/diagnostic/mod.rs index dd895d9d59..6037487a22 100644 --- a/crates/bevy_wgpu/src/diagnostic/mod.rs +++ b/crates/bevy_wgpu/src/diagnostic/mod.rs @@ -1,2 +1,2 @@ mod wgpu_resource_diagnostics_plugin; -pub use wgpu_resource_diagnostics_plugin::WgpuResourceDiagnosticsPlugin; \ No newline at end of file +pub use wgpu_resource_diagnostics_plugin::WgpuResourceDiagnosticsPlugin; diff --git a/crates/bevy_wgpu/src/diagnostic/wgpu_resource_diagnostics_plugin.rs b/crates/bevy_wgpu/src/diagnostic/wgpu_resource_diagnostics_plugin.rs index f4e6774cd3..a4401f522b 100644 --- a/crates/bevy_wgpu/src/diagnostic/wgpu_resource_diagnostics_plugin.rs +++ b/crates/bevy_wgpu/src/diagnostic/wgpu_resource_diagnostics_plugin.rs @@ -55,11 +55,7 @@ impl WgpuResourceDiagnosticsPlugin { 10, )); - diagnostics.add(Diagnostic::new( - Self::SWAP_CHAINS, - "swap_chains", - 10, - )); + diagnostics.add(Diagnostic::new(Self::SWAP_CHAINS, "swap_chains", 10)); diagnostics.add(Diagnostic::new( Self::SWAP_CHAIN_OUTPUTS, @@ -67,35 +63,15 @@ impl WgpuResourceDiagnosticsPlugin { 10, )); - diagnostics.add(Diagnostic::new( - Self::BUFFERS, - "buffers", - 10, - )); + diagnostics.add(Diagnostic::new(Self::BUFFERS, "buffers", 10)); - diagnostics.add(Diagnostic::new( - Self::TEXTURES, - "textures", - 10, - )); + diagnostics.add(Diagnostic::new(Self::TEXTURES, "textures", 10)); - diagnostics.add(Diagnostic::new( - Self::TEXTURE_VIEWS, - "texture_views", - 10, - )); + diagnostics.add(Diagnostic::new(Self::TEXTURE_VIEWS, "texture_views", 10)); - diagnostics.add(Diagnostic::new( - Self::SAMPLERS, - "samplers", - 10, - )); + diagnostics.add(Diagnostic::new(Self::SAMPLERS, "samplers", 10)); - diagnostics.add(Diagnostic::new( - Self::BIND_GROUPS, - "bind_groups", - 10, - )); + diagnostics.add(Diagnostic::new(Self::BIND_GROUPS, "bind_groups", 10)); diagnostics.add(Diagnostic::new( Self::BIND_GROUP_LAYOUTS, @@ -103,11 +79,7 @@ impl WgpuResourceDiagnosticsPlugin { 10, )); - diagnostics.add(Diagnostic::new( - Self::SHADER_MODULES, - "shader_modules", - 10, - )); + diagnostics.add(Diagnostic::new(Self::SHADER_MODULES, "shader_modules", 10)); diagnostics.add(Diagnostic::new( Self::RENDER_PIPELINES, diff --git a/crates/bevy_wgpu/src/lib.rs b/crates/bevy_wgpu/src/lib.rs index 287f1a55ae..e9045aa2cb 100644 --- a/crates/bevy_wgpu/src/lib.rs +++ b/crates/bevy_wgpu/src/lib.rs @@ -1,5 +1,5 @@ -pub mod renderer; pub mod diagnostic; +pub mod renderer; mod wgpu_render_pass; mod wgpu_renderer; mod wgpu_resources; @@ -34,9 +34,9 @@ pub fn wgpu_render_system(resources: &mut Resources) -> impl FnMut(&mut World, & window_created_event.get_reader(), )) }; - resources.insert(RenderResources::new( - WgpuRenderResourceContext::new(wgpu_renderer.device.clone()), - )); + resources.insert(RenderResources::new(WgpuRenderResourceContext::new( + wgpu_renderer.device.clone(), + ))); move |world, resources| { wgpu_renderer.update(world, resources); } diff --git a/crates/glsl-to-spirv/build/build.rs b/crates/glsl-to-spirv/build/build.rs index 17a4853d74..a437c65699 100644 --- a/crates/glsl-to-spirv/build/build.rs +++ b/crates/glsl-to-spirv/build/build.rs @@ -1,12 +1,9 @@ extern crate cmake; extern crate sha2; -use std::env; -use std::fs; -use std::path::Path; -use std::process::Command; +use std::{env, fs, path::Path, process::Command}; -use sha2::{Sha256, Digest}; +use sha2::{Digest, Sha256}; fn main() { println!("cargo:rerun-if-changed=build/glslangValidator.exe"); @@ -15,7 +12,7 @@ fn main() { let out_file = Path::new(&env::var("OUT_DIR").unwrap()).join("glslang_validator"); let path = if target.contains("windows") { - const SHA256SUM: &'static str = + const SHA256SUM: &'static str = "90b377479fb137f4ac69460d5f5cdc54cd23bace5eb6e6812516fdfa693b25cf"; let path = Path::new("build/glslangValidator.exe").to_owned(); let content = fs::read(&path).expect("failed to open executable"); @@ -25,7 +22,6 @@ fn main() { let sha256sum = format!("{:x}", result); assert_eq!(sha256sum, SHA256SUM, "glslangValidator.exe checksum failed"); path - } else { // Try to initialize submodules. Don't care if it fails, since this code also runs for // the crates.io package. diff --git a/crates/glsl-to-spirv/src/lib.rs b/crates/glsl-to-spirv/src/lib.rs index 4f495cbaea..f8ab3fe7ba 100644 --- a/crates/glsl-to-spirv/src/lib.rs +++ b/crates/glsl-to-spirv/src/lib.rs @@ -9,20 +9,23 @@ extern crate tempfile; -use std::fs::File; -use std::io::Write; -use std::process::Command; +use std::{fs::File, io::Write, process::Command}; pub type SpirvOutput = File; -pub fn compile(code: &str, ty: ShaderType, shader_defs: Option<&[String]>) -> Result { +pub fn compile( + code: &str, + ty: ShaderType, + shader_defs: Option<&[String]>, +) -> Result { compile_inner(Some((code, ty)), shader_defs) } // Eventually the API will look like this, with an iterator for multiple shader stages. // However for the moment GLSLang doesn't like that, so we only pass one shader at a time. fn compile_inner<'a, I>(shaders: I, shader_defs: Option<&[String]>) -> Result - where I: IntoIterator +where + I: IntoIterator, { let temp_dir = tempfile::tempdir().unwrap(); let output_file = temp_dir.path().join("compilation_output.spv"); diff --git a/examples/2d/sprite.rs b/examples/2d/sprite.rs index 9630d3a8be..0dcfbe8690 100644 --- a/examples/2d/sprite.rs +++ b/examples/2d/sprite.rs @@ -9,10 +9,7 @@ fn main() { fn setup(world: &mut World, resources: &mut Resources) { let mut texture_storage = resources.get_mut::>().unwrap(); - let texture_path = concat!( - env!("CARGO_MANIFEST_DIR"), - "/assets/branding/icon.png" - ); + let texture_path = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/branding/icon.png"); let texture = Texture::load(TextureType::Png(texture_path.to_string())); let texture_handle = texture_storage.add(texture); let mut color_materials = resources.get_mut::>().unwrap(); diff --git a/examples/ecs/ecs_guide.rs b/examples/ecs/ecs_guide.rs index 2f555b0b09..65482a859e 100644 --- a/examples/ecs/ecs_guide.rs +++ b/examples/ecs/ecs_guide.rs @@ -329,7 +329,7 @@ fn main() { // However we can manually specify the stage if we want to. The following is equivalent to add_system(score_system.system()) .add_system_to_stage(stage::UPDATE, score_system.system()) // We can also create new stages. Here is what our games stage order will look like: - // "before_round": new_player_system, new_round_system + // "before_round": new_player_system, new_round_system // "update": print_message_system, score_system // "after_round": score_check_system, game_over_system .add_stage_before(stage::UPDATE, "before_round") @@ -341,7 +341,6 @@ fn main() { // score_check_system will run before game_over_system because score_check_system modifies GameState and game_over_system // reads GameState. This works, but it's a bit confusing. In practice, it would be clearer to create a new stage that runs // before "after_round" - // This call to run() starts the app we just built! .run(); } diff --git a/examples/ecs/startup_system.rs b/examples/ecs/startup_system.rs index a6ff8726e8..10a2408c98 100644 --- a/examples/ecs/startup_system.rs +++ b/examples/ecs/startup_system.rs @@ -1,7 +1,4 @@ -use bevy::{ - app::schedule_runner::ScheduleRunnerPlugin, - prelude::*, -}; +use bevy::{app::schedule_runner::ScheduleRunnerPlugin, prelude::*}; fn main() { App::build() diff --git a/src/add_default_plugins.rs b/src/add_default_plugins.rs index 5cb87f8305..56056457fc 100644 --- a/src/add_default_plugins.rs +++ b/src/add_default_plugins.rs @@ -8,7 +8,7 @@ impl AddDefaultPlugins for AppBuilder { fn add_default_plugins(&mut self) -> &mut Self { #[cfg(feature = "core")] self.add_plugin(bevy_core::CorePlugin::default()); - + #[cfg(feature = "diagnostic")] self.add_plugin(bevy_diagnostic::DiagnosticsPlugin::default()); diff --git a/src/prelude.rs b/src/prelude.rs index e3a0c167e4..51d2387237 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -32,13 +32,13 @@ pub use crate::render::{ #[cfg(feature = "transform")] pub use crate::transform::prelude::*; #[cfg(feature = "ui")] -pub use crate::ui::{entity::*, Anchors, Rect, Sprite, Margins, Node, ColorMaterial}; +pub use crate::ui::{entity::*, Anchors, ColorMaterial, Margins, Node, Rect, Sprite}; #[cfg(feature = "window")] pub use crate::window::{Window, WindowDescriptor, WindowPlugin, Windows}; pub use crate::{ app::{ - stage, App, AppBuilder, AppPlugin, EntityArchetype, EventReader, Events, GetEventReader, - System, schedule_runner::ScheduleRunnerPlugin + schedule_runner::ScheduleRunnerPlugin, stage, App, AppBuilder, AppPlugin, EntityArchetype, + EventReader, Events, GetEventReader, System, }, math::{self, Mat3, Mat4, Quat, Vec2, Vec3, Vec4}, AddDefaultPlugins,