From ce957226d347fcbb2060d3070c5d7559fb58626a Mon Sep 17 00:00:00 2001 From: Benjamin Hansen Date: Sat, 27 Apr 2024 12:48:45 -0600 Subject: [PATCH] cargo fmt --- .../tutorial2-surface/src/challenge.rs | 4 +- code/beginner/tutorial2-surface/src/lib.rs | 4 +- .../tutorial3-pipeline/src/challenge.rs | 4 +- code/beginner/tutorial3-pipeline/src/lib.rs | 4 +- .../tutorial4-buffer/src/challenge.rs | 4 +- code/beginner/tutorial4-buffer/src/lib.rs | 4 +- .../tutorial5-textures/src/challenge.rs | 4 +- code/beginner/tutorial5-textures/src/lib.rs | 4 +- .../tutorial6-uniforms/src/challenge.rs | 4 +- code/beginner/tutorial6-uniforms/src/lib.rs | 4 +- .../tutorial7-instancing/src/challenge.rs | 4 +- code/beginner/tutorial7-instancing/src/lib.rs | 4 +- .../beginner/tutorial8-depth/src/challenge.rs | 4 +- code/beginner/tutorial8-depth/src/lib.rs | 4 +- code/beginner/tutorial8-depth/src/texture.rs | 5 +- code/beginner/tutorial9-models/src/lib.rs | 5 +- .../tutorial10-lighting/src/lib.rs | 5 +- .../tutorial10-lighting/src/texture.rs | 2 +- .../tutorial11-normals/src/lib.rs | 5 +- .../tutorial11-normals/src/texture.rs | 2 +- .../intermediate/tutorial12-camera/src/lib.rs | 5 +- code/intermediate/tutorial13-hdr/src/lib.rs | 13 +- .../tutorial13-hdr/src/resources.rs | 9 +- .../tutorial13-hdr/src/texture.rs | 2 +- code/intermediate/wip-terrain/src/lib.rs | 5 +- code/intermediate/wip-terrain/src/texture.rs | 2 +- code/showcase/compute/src/main.rs | 5 +- code/showcase/compute/src/texture.rs | 2 +- code/showcase/framework/src/lib.rs | 4 +- code/showcase/mouse-picking/src/lib.rs | 5 +- code/showcase/mouse-picking/src/texture.rs | 2 +- code/showcase/pong/src/lib.rs | 196 +++++++++--------- code/showcase/pong/src/render/mod.rs | 6 +- code/showcase/pong/src/system.rs | 2 +- code/showcase/threading/src/lib.rs | 5 +- code/showcase/threading/src/texture.rs | 2 +- code/wasm-builder/src/main.rs | 5 +- 37 files changed, 172 insertions(+), 178 deletions(-) diff --git a/code/beginner/tutorial2-surface/src/challenge.rs b/code/beginner/tutorial2-surface/src/challenge.rs index 4d0ce873..5cbb1b1e 100644 --- a/code/beginner/tutorial2-surface/src/challenge.rs +++ b/code/beginner/tutorial2-surface/src/challenge.rs @@ -28,9 +28,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial2-surface/src/lib.rs b/code/beginner/tutorial2-surface/src/lib.rs index 42d38ccf..5d7639a7 100644 --- a/code/beginner/tutorial2-surface/src/lib.rs +++ b/code/beginner/tutorial2-surface/src/lib.rs @@ -29,9 +29,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial3-pipeline/src/challenge.rs b/code/beginner/tutorial3-pipeline/src/challenge.rs index 89c64016..cc186bc3 100644 --- a/code/beginner/tutorial3-pipeline/src/challenge.rs +++ b/code/beginner/tutorial3-pipeline/src/challenge.rs @@ -26,9 +26,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial3-pipeline/src/lib.rs b/code/beginner/tutorial3-pipeline/src/lib.rs index 68fa9415..1eefa721 100644 --- a/code/beginner/tutorial3-pipeline/src/lib.rs +++ b/code/beginner/tutorial3-pipeline/src/lib.rs @@ -28,9 +28,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial4-buffer/src/challenge.rs b/code/beginner/tutorial4-buffer/src/challenge.rs index b48de4f5..09bd0fea 100644 --- a/code/beginner/tutorial4-buffer/src/challenge.rs +++ b/code/beginner/tutorial4-buffer/src/challenge.rs @@ -89,9 +89,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial4-buffer/src/lib.rs b/code/beginner/tutorial4-buffer/src/lib.rs index d6645b31..59c0d2d7 100644 --- a/code/beginner/tutorial4-buffer/src/lib.rs +++ b/code/beginner/tutorial4-buffer/src/lib.rs @@ -85,9 +85,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial5-textures/src/challenge.rs b/code/beginner/tutorial5-textures/src/challenge.rs index d15f3cb2..98c039ef 100644 --- a/code/beginner/tutorial5-textures/src/challenge.rs +++ b/code/beginner/tutorial5-textures/src/challenge.rs @@ -91,9 +91,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial5-textures/src/lib.rs b/code/beginner/tutorial5-textures/src/lib.rs index c28b3575..c2ab41b6 100644 --- a/code/beginner/tutorial5-textures/src/lib.rs +++ b/code/beginner/tutorial5-textures/src/lib.rs @@ -91,9 +91,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial6-uniforms/src/challenge.rs b/code/beginner/tutorial6-uniforms/src/challenge.rs index d71fb468..e1401f9e 100644 --- a/code/beginner/tutorial6-uniforms/src/challenge.rs +++ b/code/beginner/tutorial6-uniforms/src/challenge.rs @@ -241,9 +241,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial6-uniforms/src/lib.rs b/code/beginner/tutorial6-uniforms/src/lib.rs index bee7e8b6..246d2a2c 100644 --- a/code/beginner/tutorial6-uniforms/src/lib.rs +++ b/code/beginner/tutorial6-uniforms/src/lib.rs @@ -241,9 +241,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial7-instancing/src/challenge.rs b/code/beginner/tutorial7-instancing/src/challenge.rs index ef6ce670..95911edf 100644 --- a/code/beginner/tutorial7-instancing/src/challenge.rs +++ b/code/beginner/tutorial7-instancing/src/challenge.rs @@ -295,9 +295,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial7-instancing/src/lib.rs b/code/beginner/tutorial7-instancing/src/lib.rs index b5b6ba0f..76053099 100644 --- a/code/beginner/tutorial7-instancing/src/lib.rs +++ b/code/beginner/tutorial7-instancing/src/lib.rs @@ -302,9 +302,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial8-depth/src/challenge.rs b/code/beginner/tutorial8-depth/src/challenge.rs index 9433717f..b8bd1229 100644 --- a/code/beginner/tutorial8-depth/src/challenge.rs +++ b/code/beginner/tutorial8-depth/src/challenge.rs @@ -494,9 +494,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial8-depth/src/lib.rs b/code/beginner/tutorial8-depth/src/lib.rs index 9d9bd7a7..24264dfa 100644 --- a/code/beginner/tutorial8-depth/src/lib.rs +++ b/code/beginner/tutorial8-depth/src/lib.rs @@ -312,9 +312,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/beginner/tutorial8-depth/src/texture.rs b/code/beginner/tutorial8-depth/src/texture.rs index c09a098b..29ca9561 100644 --- a/code/beginner/tutorial8-depth/src/texture.rs +++ b/code/beginner/tutorial8-depth/src/texture.rs @@ -15,7 +15,8 @@ impl Texture { device: &wgpu::Device, config: &wgpu::SurfaceConfiguration, label: &str, - ) -> Self {let size = wgpu::Extent3d { + ) -> Self { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, @@ -58,7 +59,7 @@ impl Texture { config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { -let size = wgpu::Extent3d { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, diff --git a/code/beginner/tutorial9-models/src/lib.rs b/code/beginner/tutorial9-models/src/lib.rs index 4fcc2894..513436e1 100644 --- a/code/beginner/tutorial9-models/src/lib.rs +++ b/code/beginner/tutorial9-models/src/lib.rs @@ -253,9 +253,9 @@ impl<'a> State<'a> { // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU log::warn!("WGPU setup"); let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -312,7 +312,6 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ diff --git a/code/intermediate/tutorial10-lighting/src/lib.rs b/code/intermediate/tutorial10-lighting/src/lib.rs index f6748212..0f0e8bc1 100644 --- a/code/intermediate/tutorial10-lighting/src/lib.rs +++ b/code/intermediate/tutorial10-lighting/src/lib.rs @@ -347,9 +347,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -403,7 +403,6 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ diff --git a/code/intermediate/tutorial10-lighting/src/texture.rs b/code/intermediate/tutorial10-lighting/src/texture.rs index 00bc3ac1..f5b7a784 100644 --- a/code/intermediate/tutorial10-lighting/src/texture.rs +++ b/code/intermediate/tutorial10-lighting/src/texture.rs @@ -15,7 +15,7 @@ impl Texture { config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { -let size = wgpu::Extent3d { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, diff --git a/code/intermediate/tutorial11-normals/src/lib.rs b/code/intermediate/tutorial11-normals/src/lib.rs index a266fa01..8a646cbf 100644 --- a/code/intermediate/tutorial11-normals/src/lib.rs +++ b/code/intermediate/tutorial11-normals/src/lib.rs @@ -347,9 +347,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -403,7 +403,6 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ diff --git a/code/intermediate/tutorial11-normals/src/texture.rs b/code/intermediate/tutorial11-normals/src/texture.rs index fd8f5244..18158716 100644 --- a/code/intermediate/tutorial11-normals/src/texture.rs +++ b/code/intermediate/tutorial11-normals/src/texture.rs @@ -15,7 +15,7 @@ impl Texture { config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { -let size = wgpu::Extent3d { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, diff --git a/code/intermediate/tutorial12-camera/src/lib.rs b/code/intermediate/tutorial12-camera/src/lib.rs index 78634118..d02638df 100644 --- a/code/intermediate/tutorial12-camera/src/lib.rs +++ b/code/intermediate/tutorial12-camera/src/lib.rs @@ -227,9 +227,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -283,7 +283,6 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ diff --git a/code/intermediate/tutorial13-hdr/src/lib.rs b/code/intermediate/tutorial13-hdr/src/lib.rs index 91ea6fb6..c128c8fd 100644 --- a/code/intermediate/tutorial13-hdr/src/lib.rs +++ b/code/intermediate/tutorial13-hdr/src/lib.rs @@ -247,7 +247,7 @@ impl<'a> State<'a> { // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { // UPDATED - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::BROWSER_WEBGPU, @@ -300,7 +300,6 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ @@ -713,12 +712,10 @@ impl<'a> State<'a> { fn render(&mut self) -> Result<(), wgpu::SurfaceError> { let output = self.surface.get_current_texture()?; - let view = output - .texture - .create_view(&wgpu::TextureViewDescriptor { - format: Some(self.config.format.add_srgb_suffix()), - ..Default::default() - }); + let view = output.texture.create_view(&wgpu::TextureViewDescriptor { + format: Some(self.config.format.add_srgb_suffix()), + ..Default::default() + }); let mut encoder = self .device diff --git a/code/intermediate/tutorial13-hdr/src/resources.rs b/code/intermediate/tutorial13-hdr/src/resources.rs index df9a4f6b..d0809c31 100644 --- a/code/intermediate/tutorial13-hdr/src/resources.rs +++ b/code/intermediate/tutorial13-hdr/src/resources.rs @@ -286,8 +286,8 @@ impl HdrLoader { ) -> anyhow::Result { let hdr_decoder = HdrDecoder::new(Cursor::new(data))?; let meta = hdr_decoder.metadata(); - - #[cfg(not(target_arch="wasm32"))] + + #[cfg(not(target_arch = "wasm32"))] let pixels = { let mut pixels = vec![[0.0, 0.0, 0.0, 0.0]; meta.width as usize * meta.height as usize]; hdr_decoder.read_image_transform( @@ -299,8 +299,9 @@ impl HdrLoader { )?; pixels }; - #[cfg(target_arch="wasm32")] - let pixels = hdr_decoder.read_image_native()? + #[cfg(target_arch = "wasm32")] + let pixels = hdr_decoder + .read_image_native()? .into_iter() .map(|pix| { let rgb = pix.to_hdr(); diff --git a/code/intermediate/tutorial13-hdr/src/texture.rs b/code/intermediate/tutorial13-hdr/src/texture.rs index c003d8c0..929aedb3 100644 --- a/code/intermediate/tutorial13-hdr/src/texture.rs +++ b/code/intermediate/tutorial13-hdr/src/texture.rs @@ -16,7 +16,7 @@ impl Texture { config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { -let size = wgpu::Extent3d { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, diff --git a/code/intermediate/wip-terrain/src/lib.rs b/code/intermediate/wip-terrain/src/lib.rs index 758b2dcf..bbff2868 100644 --- a/code/intermediate/wip-terrain/src/lib.rs +++ b/code/intermediate/wip-terrain/src/lib.rs @@ -228,9 +228,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -284,7 +284,6 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ diff --git a/code/intermediate/wip-terrain/src/texture.rs b/code/intermediate/wip-terrain/src/texture.rs index bd4acfc4..5b509793 100644 --- a/code/intermediate/wip-terrain/src/texture.rs +++ b/code/intermediate/wip-terrain/src/texture.rs @@ -16,7 +16,7 @@ impl Texture { config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { -let size = wgpu::Extent3d { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, diff --git a/code/showcase/compute/src/main.rs b/code/showcase/compute/src/main.rs index 74feac63..cb9069f5 100644 --- a/code/showcase/compute/src/main.rs +++ b/code/showcase/compute/src/main.rs @@ -166,9 +166,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -222,7 +222,6 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ diff --git a/code/showcase/compute/src/texture.rs b/code/showcase/compute/src/texture.rs index ec72c3b3..bfd5802b 100644 --- a/code/showcase/compute/src/texture.rs +++ b/code/showcase/compute/src/texture.rs @@ -30,7 +30,7 @@ impl Texture { config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { -let size = wgpu::Extent3d { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, diff --git a/code/showcase/framework/src/lib.rs b/code/showcase/framework/src/lib.rs index 6bdd7b5e..673613f4 100644 --- a/code/showcase/framework/src/lib.rs +++ b/code/showcase/framework/src/lib.rs @@ -36,9 +36,9 @@ impl<'a> Display<'a> { pub async fn new(window: &'a Window) -> Result, Error> { let size = window.inner_size(); let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); diff --git a/code/showcase/mouse-picking/src/lib.rs b/code/showcase/mouse-picking/src/lib.rs index 1209a4bf..0f6b4d53 100644 --- a/code/showcase/mouse-picking/src/lib.rs +++ b/code/showcase/mouse-picking/src/lib.rs @@ -232,9 +232,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -288,7 +288,6 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ diff --git a/code/showcase/mouse-picking/src/texture.rs b/code/showcase/mouse-picking/src/texture.rs index d9bd8770..5790af27 100644 --- a/code/showcase/mouse-picking/src/texture.rs +++ b/code/showcase/mouse-picking/src/texture.rs @@ -15,7 +15,7 @@ impl Texture { config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { -let size = wgpu::Extent3d { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, diff --git a/code/showcase/pong/src/lib.rs b/code/showcase/pong/src/lib.rs index b656f93e..b2c94aec 100644 --- a/code/showcase/pong/src/lib.rs +++ b/code/showcase/pong/src/lib.rs @@ -158,113 +158,115 @@ pub fn start() { let window = &window; let mut last_time = instant::Instant::now(); - event_loop.run(move |event, control_flow| { - match event { - Event::WindowEvent { - event: WindowEvent::CloseRequested, - .. - } => { - state.game_state = state::GameState::Quiting; - } - Event::WindowEvent { - event: - WindowEvent::KeyboardInput { - event: - KeyEvent { - state: element_state, - physical_key: PhysicalKey::Code(key), - .. - }, - .. - }, - .. - } => { - let input_handled = match state.game_state { - state::GameState::Quiting => true, - _ => input.update(key, element_state), - }; - if !input_handled { - process_input(element_state, key, control_flow); + event_loop + .run(move |event, control_flow| { + match event { + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => { + state.game_state = state::GameState::Quiting; } - } - Event::WindowEvent { - event: WindowEvent::Resized(size), - .. - } => { - render.resize(size); - events.push(state::Event::Resize(size.width as f32, size.height as f32)); - } - Event::WindowEvent { - event: WindowEvent::RedrawRequested, - .. - } => { - let dt = last_time.elapsed(); - last_time = instant::Instant::now(); - window.request_redraw(); - for event in &events { - match event { - state::Event::FocusChanged | state::Event::ButtonPressed => { - sound_system.queue(sound_pack.bounce()); - } - state::Event::BallBounce(_pos) => { - sound_system.queue(sound_pack.bounce()); - } - state::Event::Score(_) => { - sound_system.queue(sound_pack.bounce()); - } - state::Event::Resize(width, height) => { - // TODO: there should be a system that handles this - state.player1_score.position = (width * 0.25, 20.0).into(); - state.player2_score.position = (width * 0.75, 20.0).into(); - state.win_text.position = (width * 0.5, height * 0.5).into(); - } + Event::WindowEvent { + event: + WindowEvent::KeyboardInput { + event: + KeyEvent { + state: element_state, + physical_key: PhysicalKey::Code(key), + .. + }, + .. + }, + .. + } => { + let input_handled = match state.game_state { + state::GameState::Quiting => true, + _ => input.update(key, element_state), + }; + if !input_handled { + process_input(element_state, key, control_flow); } } - events.clear(); - - visiblity_system.update_state(&input, dt, &mut state, &mut events); - match state.game_state { - state::GameState::MainMenu => { - menu_system.update_state(&input, dt, &mut state, &mut events); - if state.game_state == state::GameState::Serving { - serving_system.start(&mut state); + Event::WindowEvent { + event: WindowEvent::Resized(size), + .. + } => { + render.resize(size); + events.push(state::Event::Resize(size.width as f32, size.height as f32)); + } + Event::WindowEvent { + event: WindowEvent::RedrawRequested, + .. + } => { + let dt = last_time.elapsed(); + last_time = instant::Instant::now(); + window.request_redraw(); + for event in &events { + match event { + state::Event::FocusChanged | state::Event::ButtonPressed => { + sound_system.queue(sound_pack.bounce()); + } + state::Event::BallBounce(_pos) => { + sound_system.queue(sound_pack.bounce()); + } + state::Event::Score(_) => { + sound_system.queue(sound_pack.bounce()); + } + state::Event::Resize(width, height) => { + // TODO: there should be a system that handles this + state.player1_score.position = (width * 0.25, 20.0).into(); + state.player2_score.position = (width * 0.75, 20.0).into(); + state.win_text.position = (width * 0.5, height * 0.5).into(); + } } } - state::GameState::Serving => { - serving_system.update_state(&input, dt, &mut state, &mut events); - play_system.update_state(&input, dt, &mut state, &mut events); - if state.game_state == state::GameState::Playing { - play_system.start(&mut state); + events.clear(); + + visiblity_system.update_state(&input, dt, &mut state, &mut events); + match state.game_state { + state::GameState::MainMenu => { + menu_system.update_state(&input, dt, &mut state, &mut events); + if state.game_state == state::GameState::Serving { + serving_system.start(&mut state); + } } - } - state::GameState::Playing => { - ball_system.update_state(&input, dt, &mut state, &mut events); - play_system.update_state(&input, dt, &mut state, &mut events); - if state.game_state == state::GameState::Serving { - serving_system.start(&mut state); - } else if state.game_state == state::GameState::GameOver { - game_over_system.start(&mut state); + state::GameState::Serving => { + serving_system.update_state(&input, dt, &mut state, &mut events); + play_system.update_state(&input, dt, &mut state, &mut events); + if state.game_state == state::GameState::Playing { + play_system.start(&mut state); + } } - } - state::GameState::GameOver => { - game_over_system.update_state(&input, dt, &mut state, &mut events); - if state.game_state == state::GameState::MainMenu { - menu_system.start(&mut state); + state::GameState::Playing => { + ball_system.update_state(&input, dt, &mut state, &mut events); + play_system.update_state(&input, dt, &mut state, &mut events); + if state.game_state == state::GameState::Serving { + serving_system.start(&mut state); + } else if state.game_state == state::GameState::GameOver { + game_over_system.start(&mut state); + } + } + state::GameState::GameOver => { + game_over_system.update_state(&input, dt, &mut state, &mut events); + if state.game_state == state::GameState::MainMenu { + menu_system.start(&mut state); + } + } + state::GameState::Quiting => { + control_flow.exit(); } } - state::GameState::Quiting => { - control_flow.exit(); - } - } - render.render_state(&state); - if state.game_state != state::GameState::Quiting { - window.request_redraw(); + render.render_state(&state); + if state.game_state != state::GameState::Quiting { + window.request_redraw(); + } } + _ => {} } - _ => {} - } - }).unwrap(); + }) + .unwrap(); } fn process_input( @@ -273,9 +275,7 @@ fn process_input( control_flow: &EventLoopWindowTarget<()>, ) { match (keycode, element_state) { - (KeyCode::Escape, ElementState::Pressed) => { - control_flow.exit() - } + (KeyCode::Escape, ElementState::Pressed) => control_flow.exit(), _ => {} } } diff --git a/code/showcase/pong/src/render/mod.rs b/code/showcase/pong/src/render/mod.rs index ade2e50d..0b2b0ad0 100644 --- a/code/showcase/pong/src/render/mod.rs +++ b/code/showcase/pong/src/render/mod.rs @@ -41,9 +41,9 @@ impl<'a> Render<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -63,7 +63,7 @@ impl<'a> Render<'a> { &wgpu::DeviceDescriptor { label: None, required_features: wgpu::Features::empty(), - required_limits: wgpu::Limits::downlevel_webgl2_defaults(), + required_limits: wgpu::Limits::downlevel_webgl2_defaults(), }, None, // Trace path ) diff --git a/code/showcase/pong/src/system.rs b/code/showcase/pong/src/system.rs index 6406faf3..54118ff0 100644 --- a/code/showcase/pong/src/system.rs +++ b/code/showcase/pong/src/system.rs @@ -144,7 +144,7 @@ impl System for BallSystem { events: &mut Vec, ) { let dt = dt.as_secs_f32(); - + // bounce the ball off the players if state.player1.contains(&state.ball) { events.push(state::Event::BallBounce(state.ball.position)); diff --git a/code/showcase/threading/src/lib.rs b/code/showcase/threading/src/lib.rs index 8230ae8f..da5de271 100644 --- a/code/showcase/threading/src/lib.rs +++ b/code/showcase/threading/src/lib.rs @@ -226,9 +226,9 @@ impl<'a> State<'a> { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - #[cfg(not(target_arch="wasm32"))] + #[cfg(not(target_arch = "wasm32"))] backends: wgpu::Backends::PRIMARY, - #[cfg(target_arch="wasm32")] + #[cfg(target_arch = "wasm32")] backends: wgpu::Backends::GL, ..Default::default() }); @@ -282,7 +282,6 @@ impl<'a> State<'a> { view_formats: vec![], }; - let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ diff --git a/code/showcase/threading/src/texture.rs b/code/showcase/threading/src/texture.rs index d9bd8770..5790af27 100644 --- a/code/showcase/threading/src/texture.rs +++ b/code/showcase/threading/src/texture.rs @@ -15,7 +15,7 @@ impl Texture { config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { -let size = wgpu::Extent3d { + let size = wgpu::Extent3d { width: config.width.max(1), height: config.height.max(1), depth_or_array_layers: 1, diff --git a/code/wasm-builder/src/main.rs b/code/wasm-builder/src/main.rs index 7e183104..24a87bf7 100644 --- a/code/wasm-builder/src/main.rs +++ b/code/wasm-builder/src/main.rs @@ -1,4 +1,7 @@ -use std::{path::PathBuf, process::{Command, ExitStatus}}; +use std::{ + path::PathBuf, + process::{Command, ExitStatus}, +}; use anyhow::bail; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};