diff --git a/src/core/app/context.rs b/src/core/app/context.rs index f796563..6820613 100644 --- a/src/core/app/context.rs +++ b/src/core/app/context.rs @@ -148,7 +148,7 @@ impl ApplicationContext { /// Récupère les résolutions disponibles pub fn get_available_resolutions(&self) -> Vec<(u32, u32)> { - self.with_renderer(|renderer| Self::get_monitor_resolutions(&renderer.window())) + self.with_renderer(|renderer| Self::get_monitor_resolutions(renderer.window())) } /// Récupère le delta time actuel depuis le timer @@ -177,7 +177,7 @@ impl ApplicationContext { let renderer = vulkano_windows .get_renderer(self.window_id) .expect("Failed to get renderer"); - f(&renderer) + f(renderer) } /// Méthode utilitaire pour accéder au renderer de manière thread-safe diff --git a/src/core/app/mod.rs b/src/core/app/mod.rs index d17e84d..1be0e81 100644 --- a/src/core/app/mod.rs +++ b/src/core/app/mod.rs @@ -65,7 +65,7 @@ impl ApplicationHandler for App { .expect("Failed to lock vulkano_windows"); let window_id = vulkano_windows.create_window( event_loop, - &self.vulkan_context.vulkano_context(), + self.vulkan_context.vulkano_context(), &WindowDescriptor { title: "Rust ASH Test".to_string(), width: 800.0, diff --git a/src/core/input/mod.rs b/src/core/input/mod.rs index 227a5a1..f4a1642 100644 --- a/src/core/input/mod.rs +++ b/src/core/input/mod.rs @@ -40,11 +40,8 @@ impl InputManager { } pub fn process_device_event(&mut self, event: &DeviceEvent) { - match event { - DeviceEvent::MouseMotion { delta, .. } => { - self.mouse_position_delta += glam::Vec2::new(delta.0 as f32, delta.1 as f32); - } - _ => {} + if let DeviceEvent::MouseMotion { delta, .. } = event { + self.mouse_position_delta += glam::Vec2::new(delta.0 as f32, delta.1 as f32); } } @@ -75,7 +72,7 @@ impl InputManager { MouseScrollDelta::PixelDelta(position) => { glam::Vec2::new(position.x as f32, position.y as f32) } - MouseScrollDelta::LineDelta(x, y) => glam::Vec2::new(*x as f32, *y as f32), + MouseScrollDelta::LineDelta(x, y) => glam::Vec2::new(*x, *y), }; } _ => {} diff --git a/src/core/input/virtual_input.rs b/src/core/input/virtual_input.rs index 875d66c..dfab54d 100644 --- a/src/core/input/virtual_input.rs +++ b/src/core/input/virtual_input.rs @@ -58,7 +58,7 @@ impl VirtualInput { VirtualBinding::Keyboard(key, _) => { self.states_by_key .entry(*key) - .or_insert(Vec::new()) + .or_default() .push(state.clone()); } VirtualBinding::MouseX(_) | VirtualBinding::MouseY(_) => { @@ -67,7 +67,7 @@ impl VirtualInput { VirtualBinding::MouseButton(button, _) => { self.mouse_button_states .entry(*button) - .or_insert(Vec::new()) + .or_default() .push(state.clone()); } VirtualBinding::MouseWheelX(_) | VirtualBinding::MouseWheelY(_) => { @@ -76,7 +76,7 @@ impl VirtualInput { VirtualBinding::Axis(axis, _, _) => { self.axis_states .entry(*axis) - .or_insert(Vec::new()) + .or_default() .push(state.clone()); } } diff --git a/src/core/input/virtual_state.rs b/src/core/input/virtual_state.rs index 779b8ea..2cfd098 100644 --- a/src/core/input/virtual_state.rs +++ b/src/core/input/virtual_state.rs @@ -70,17 +70,14 @@ impl VirtualInputState { pub fn update_from_mouse_button(&mut self, button: MouseButton, button_state: ElementState) { let mut new_value = 0.0; for binding in &mut self.bindings { - match &binding.binding { - VirtualBinding::MouseButton(binding_button, direction) => { - if binding_button == &button { - if button_state == ElementState::Pressed { - binding.value = f32::from(direction); - } else { - binding.value = 0.0; - } + if let VirtualBinding::MouseButton(binding_button, direction) = &binding.binding { + if binding_button == &button { + if button_state == ElementState::Pressed { + binding.value = f32::from(direction); + } else { + binding.value = 0.0; } } - _ => {} } new_value += binding.value; } diff --git a/src/core/render/primitives/camera.rs b/src/core/render/primitives/camera.rs index e8cdf1e..f27622a 100644 --- a/src/core/render/primitives/camera.rs +++ b/src/core/render/primitives/camera.rs @@ -9,7 +9,7 @@ use vulkano::{ use crate::core::{input::InputManager, timer::Timer}; -use super::mvp::MVP; +use super::mvp::Mvp; // See docs/OPENGL_VULKAN_DIFF.md const OPENGL_TO_VULKAN_Y_AXIS_FLIP: Mat4 = Mat4 { @@ -102,7 +102,7 @@ impl Camera3D { pub fn create_buffer( &self, memory_allocator: &Arc, - ) -> Result, Validated> { + ) -> Result, Validated> { let (sin_pitch, cos_pitch) = self.rotation.x.sin_cos(); let (sin_yaw, cos_yaw) = self.rotation.y.sin_cos(); @@ -112,7 +112,7 @@ impl Camera3D { Vec3::Y, ); - MVP { + Mvp { model: OPENGL_TO_VULKAN_Y_AXIS_FLIP.to_cols_array_2d(), view: view_matrix.to_cols_array_2d(), projection: self.projection.to_cols_array_2d(), diff --git a/src/core/render/primitives/mvp.rs b/src/core/render/primitives/mvp.rs index b06b55f..192c67b 100644 --- a/src/core/render/primitives/mvp.rs +++ b/src/core/render/primitives/mvp.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use glam::Mat4; use vulkano::Validated; use vulkano::buffer::{ AllocateBufferError, Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer, @@ -9,17 +8,17 @@ use vulkano::memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, Standar #[derive(BufferContents, Clone, Copy)] #[repr(C)] -pub struct MVP { +pub struct Mvp { pub model: [[f32; 4]; 4], pub view: [[f32; 4]; 4], pub projection: [[f32; 4]; 4], } -impl MVP { +impl Mvp { pub fn into_buffer( self, memory_allocator: &Arc, - ) -> Result, Validated> { + ) -> Result, Validated> { Buffer::from_iter( memory_allocator.clone(), BufferCreateInfo { diff --git a/src/core/render/primitives/transform.rs b/src/core/render/primitives/transform.rs index 131e6f1..4d870b0 100644 --- a/src/core/render/primitives/transform.rs +++ b/src/core/render/primitives/transform.rs @@ -35,7 +35,7 @@ impl Default for Transform { impl Transform { pub fn rotate(&mut self, rotation: Quat) { - self.rotation = self.rotation * rotation; + self.rotation *= rotation; } pub fn translate(&mut self, translation: Vec3) { @@ -46,7 +46,7 @@ impl Transform { self.scale *= scale; } - pub fn into_raw(&self) -> TransformRaw { + pub fn to_raw_tranform(&self) -> TransformRaw { TransformRaw { model: (Mat4::from_translation(self.position) * Mat4::from_quat(self.rotation) @@ -59,7 +59,8 @@ impl Transform { memory_allocator: &Arc, transforms: &[Transform], ) -> Result, Validated> { - let transform_raws: Vec = transforms.iter().map(|t| t.into_raw()).collect(); + let transform_raws: Vec = + transforms.iter().map(|t| t.to_raw_tranform()).collect(); let buffer = Buffer::from_iter( memory_allocator.clone(), diff --git a/src/core/render/texture.rs b/src/core/render/texture.rs index ddf88e5..b8270da 100644 --- a/src/core/render/texture.rs +++ b/src/core/render/texture.rs @@ -78,7 +78,7 @@ impl Texture { ImageCreateInfo { image_type: ImageType::Dim2d, format: Format::R8G8B8A8_SRGB, - extent: [image_dimensions.0 as u32, image_dimensions.1 as u32, 1], + extent: [image_dimensions.0, image_dimensions.1, 1], array_layers: 1, usage: ImageUsage::TRANSFER_DST | ImageUsage::SAMPLED, ..Default::default() diff --git a/src/game/assets/square.rs b/src/game/assets/square.rs index 80a24e2..7219157 100644 --- a/src/game/assets/square.rs +++ b/src/game/assets/square.rs @@ -31,7 +31,7 @@ use vulkano::{ }; use crate::core::render::{ - primitives::{mvp::MVP, transform::TransformRaw, vertex::Vertex3D}, + primitives::{mvp::Mvp, transform::TransformRaw, vertex::Vertex3D}, texture::Texture, }; @@ -214,7 +214,7 @@ impl Square { &self, command_buffer: &mut AutoCommandBufferBuilder, descriptor_set_allocator: &Arc, - mvp_uniform: &Subbuffer<[MVP]>, + mvp_uniform: &Subbuffer<[Mvp]>, transform_uniform: &Subbuffer<[TransformRaw]>, texture: &Texture, ) -> Result<(), Box> { diff --git a/src/game/scenes/main_scene.rs b/src/game/scenes/main_scene.rs index 26e8631..00232f7 100644 --- a/src/game/scenes/main_scene.rs +++ b/src/game/scenes/main_scene.rs @@ -59,7 +59,7 @@ impl Scene for MainScene { let num_instances = 100; let instance_size = 10.0; let instance_spacing = 10.0; - let num_instances_per_row = (num_instances as f32 / instance_spacing as f32).ceil() as u32; + let num_instances_per_row = (num_instances as f32 / instance_spacing).ceil() as u32; let instances: Vec = (0..num_instances) .map(|i| Transform { position: Vec3::new( @@ -276,9 +276,7 @@ impl Scene for MainScene { }); }); - let render_future = gui.draw_on_image(render_future, swapchain_image_view.clone()); - - render_future + gui.draw_on_image(render_future, swapchain_image_view.clone()) }); Ok(render_future)