cargo fmt

0.19
Benjamin Hansen 1 month ago
parent 09c1024a8f
commit ce957226d3

@ -28,9 +28,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -29,9 +29,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -26,9 +26,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -28,9 +28,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -89,9 +89,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -85,9 +85,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -91,9 +91,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -91,9 +91,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -241,9 +241,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -241,9 +241,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -295,9 +295,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -302,9 +302,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -494,9 +494,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -312,9 +312,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -15,7 +15,8 @@ impl Texture {
device: &wgpu::Device, device: &wgpu::Device,
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self {let size = wgpu::Extent3d { ) -> Self {
let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,
@ -58,7 +59,7 @@ impl Texture {
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self { ) -> Self {
let size = wgpu::Extent3d { let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,

@ -253,9 +253,9 @@ impl<'a> State<'a> {
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
log::warn!("WGPU setup"); log::warn!("WGPU setup");
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -312,7 +312,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[

@ -347,9 +347,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -403,7 +403,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[

@ -15,7 +15,7 @@ impl Texture {
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self { ) -> Self {
let size = wgpu::Extent3d { let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,

@ -347,9 +347,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -403,7 +403,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[

@ -15,7 +15,7 @@ impl Texture {
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self { ) -> Self {
let size = wgpu::Extent3d { let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,

@ -227,9 +227,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -283,7 +283,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[

@ -247,7 +247,7 @@ impl<'a> State<'a> {
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
// UPDATED // UPDATED
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::BROWSER_WEBGPU, backends: wgpu::Backends::BROWSER_WEBGPU,
@ -300,7 +300,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[
@ -713,12 +712,10 @@ impl<'a> State<'a> {
fn render(&mut self) -> Result<(), wgpu::SurfaceError> { fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
let output = self.surface.get_current_texture()?; let output = self.surface.get_current_texture()?;
let view = output let view = output.texture.create_view(&wgpu::TextureViewDescriptor {
.texture format: Some(self.config.format.add_srgb_suffix()),
.create_view(&wgpu::TextureViewDescriptor { ..Default::default()
format: Some(self.config.format.add_srgb_suffix()), });
..Default::default()
});
let mut encoder = self let mut encoder = self
.device .device

@ -286,8 +286,8 @@ impl HdrLoader {
) -> anyhow::Result<texture::CubeTexture> { ) -> anyhow::Result<texture::CubeTexture> {
let hdr_decoder = HdrDecoder::new(Cursor::new(data))?; let hdr_decoder = HdrDecoder::new(Cursor::new(data))?;
let meta = hdr_decoder.metadata(); let meta = hdr_decoder.metadata();
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
let pixels = { let pixels = {
let mut pixels = vec![[0.0, 0.0, 0.0, 0.0]; meta.width as usize * meta.height as usize]; 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( hdr_decoder.read_image_transform(
@ -299,8 +299,9 @@ impl HdrLoader {
)?; )?;
pixels pixels
}; };
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
let pixels = hdr_decoder.read_image_native()? let pixels = hdr_decoder
.read_image_native()?
.into_iter() .into_iter()
.map(|pix| { .map(|pix| {
let rgb = pix.to_hdr(); let rgb = pix.to_hdr();

@ -16,7 +16,7 @@ impl Texture {
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self { ) -> Self {
let size = wgpu::Extent3d { let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,

@ -228,9 +228,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -284,7 +284,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[

@ -16,7 +16,7 @@ impl Texture {
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self { ) -> Self {
let size = wgpu::Extent3d { let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,

@ -166,9 +166,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -222,7 +222,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[

@ -30,7 +30,7 @@ impl Texture {
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self { ) -> Self {
let size = wgpu::Extent3d { let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,

@ -36,9 +36,9 @@ impl<'a> Display<'a> {
pub async fn new(window: &'a Window) -> Result<Display<'a>, Error> { pub async fn new(window: &'a Window) -> Result<Display<'a>, Error> {
let size = window.inner_size(); let size = window.inner_size();
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });

@ -232,9 +232,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -288,7 +288,6 @@ impl<'a> State<'a> {
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[

@ -15,7 +15,7 @@ impl Texture {
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self { ) -> Self {
let size = wgpu::Extent3d { let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,

@ -158,113 +158,115 @@ pub fn start() {
let window = &window; let window = &window;
let mut last_time = instant::Instant::now(); let mut last_time = instant::Instant::now();
event_loop.run(move |event, control_flow| { event_loop
match event { .run(move |event, control_flow| {
Event::WindowEvent { match event {
event: WindowEvent::CloseRequested, Event::WindowEvent {
.. event: WindowEvent::CloseRequested,
} => { ..
state.game_state = state::GameState::Quiting; } => {
} 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::WindowEvent {
Event::WindowEvent { event:
event: WindowEvent::Resized(size), WindowEvent::KeyboardInput {
.. event:
} => { KeyEvent {
render.resize(size); state: element_state,
events.push(state::Event::Resize(size.width as f32, size.height as f32)); physical_key: PhysicalKey::Code(key),
} ..
Event::WindowEvent { },
event: WindowEvent::RedrawRequested, ..
.. },
} => { ..
let dt = last_time.elapsed(); } => {
last_time = instant::Instant::now(); let input_handled = match state.game_state {
window.request_redraw(); state::GameState::Quiting => true,
for event in &events { _ => input.update(key, element_state),
match event { };
state::Event::FocusChanged | state::Event::ButtonPressed => { if !input_handled {
sound_system.queue(sound_pack.bounce()); process_input(element_state, key, control_flow);
}
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();
}
} }
} }
events.clear(); Event::WindowEvent {
event: WindowEvent::Resized(size),
visiblity_system.update_state(&input, dt, &mut state, &mut events); ..
match state.game_state { } => {
state::GameState::MainMenu => { render.resize(size);
menu_system.update_state(&input, dt, &mut state, &mut events); events.push(state::Event::Resize(size.width as f32, size.height as f32));
if state.game_state == state::GameState::Serving { }
serving_system.start(&mut state); 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 => { events.clear();
serving_system.update_state(&input, dt, &mut state, &mut events);
play_system.update_state(&input, dt, &mut state, &mut events); visiblity_system.update_state(&input, dt, &mut state, &mut events);
if state.game_state == state::GameState::Playing { match state.game_state {
play_system.start(&mut 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::Serving => {
state::GameState::Playing => { serving_system.update_state(&input, dt, &mut state, &mut events);
ball_system.update_state(&input, dt, &mut state, &mut events); play_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 {
if state.game_state == state::GameState::Serving { play_system.start(&mut state);
serving_system.start(&mut state); }
} else if state.game_state == state::GameState::GameOver {
game_over_system.start(&mut state);
} }
} state::GameState::Playing => {
state::GameState::GameOver => { ball_system.update_state(&input, dt, &mut state, &mut events);
game_over_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::MainMenu { if state.game_state == state::GameState::Serving {
menu_system.start(&mut state); 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); render.render_state(&state);
if state.game_state != state::GameState::Quiting { if state.game_state != state::GameState::Quiting {
window.request_redraw(); window.request_redraw();
}
} }
_ => {}
} }
_ => {} })
} .unwrap();
}).unwrap();
} }
fn process_input( fn process_input(
@ -273,9 +275,7 @@ fn process_input(
control_flow: &EventLoopWindowTarget<()>, control_flow: &EventLoopWindowTarget<()>,
) { ) {
match (keycode, element_state) { match (keycode, element_state) {
(KeyCode::Escape, ElementState::Pressed) => { (KeyCode::Escape, ElementState::Pressed) => control_flow.exit(),
control_flow.exit()
}
_ => {} _ => {}
} }
} }

@ -41,9 +41,9 @@ impl<'a> Render<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -63,7 +63,7 @@ impl<'a> Render<'a> {
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
label: None, label: None,
required_features: wgpu::Features::empty(), required_features: wgpu::Features::empty(),
required_limits: wgpu::Limits::downlevel_webgl2_defaults(), required_limits: wgpu::Limits::downlevel_webgl2_defaults(),
}, },
None, // Trace path None, // Trace path
) )

@ -144,7 +144,7 @@ impl System for BallSystem {
events: &mut Vec<state::Event>, events: &mut Vec<state::Event>,
) { ) {
let dt = dt.as_secs_f32(); let dt = dt.as_secs_f32();
// bounce the ball off the players // bounce the ball off the players
if state.player1.contains(&state.ball) { if state.player1.contains(&state.ball) {
events.push(state::Event::BallBounce(state.ball.position)); events.push(state::Event::BallBounce(state.ball.position));

@ -226,9 +226,9 @@ impl<'a> State<'a> {
// The instance is a handle to our GPU // The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
backends: wgpu::Backends::PRIMARY, backends: wgpu::Backends::PRIMARY,
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
backends: wgpu::Backends::GL, backends: wgpu::Backends::GL,
..Default::default() ..Default::default()
}); });
@ -282,7 +282,6 @@ impl<'a> State<'a> {
view_formats: vec![], view_formats: vec![],
}; };
let texture_bind_group_layout = let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[ entries: &[

@ -15,7 +15,7 @@ impl Texture {
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
label: &str, label: &str,
) -> Self { ) -> Self {
let size = wgpu::Extent3d { let size = wgpu::Extent3d {
width: config.width.max(1), width: config.width.max(1),
height: config.height.max(1), height: config.height.max(1),
depth_or_array_layers: 1, depth_or_array_layers: 1,

@ -1,4 +1,7 @@
use std::{path::PathBuf, process::{Command, ExitStatus}}; use std::{
path::PathBuf,
process::{Command, ExitStatus},
};
use anyhow::bail; use anyhow::bail;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};

Loading…
Cancel
Save