From cff2575a32219d4294ab05d69ad37eb6bd7a7b2d Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 21 Aug 2024 20:38:41 +0200 Subject: refactor(engine): fix clippy lints --- engine/src/camera/fly.rs | 1 + engine/src/draw_flags.rs | 1 + engine/src/lighting.rs | 3 +++ engine/src/material.rs | 1 + engine/src/renderer/opengl.rs | 42 ++++++++++++++++++++++-------------------- engine/src/util.rs | 4 ++-- 6 files changed, 30 insertions(+), 22 deletions(-) (limited to 'engine/src') diff --git a/engine/src/camera/fly.rs b/engine/src/camera/fly.rs index 6bd5876..b6ba7aa 100644 --- a/engine/src/camera/fly.rs +++ b/engine/src/camera/fly.rs @@ -26,6 +26,7 @@ pub struct Fly { impl Fly { + #[must_use] pub fn builder() -> Builder { Builder::default() diff --git a/engine/src/draw_flags.rs b/engine/src/draw_flags.rs index 23ea22f..df5eed1 100644 --- a/engine/src/draw_flags.rs +++ b/engine/src/draw_flags.rs @@ -15,6 +15,7 @@ pub struct DrawFlags impl DrawFlags { + #[must_use] pub fn builder() -> Builder { Builder::default() diff --git a/engine/src/lighting.rs b/engine/src/lighting.rs index 81dc475..48adb0e 100644 --- a/engine/src/lighting.rs +++ b/engine/src/lighting.rs @@ -19,6 +19,7 @@ pub struct PointLight impl PointLight { + #[must_use] pub fn builder() -> PointLightBuilder { PointLightBuilder::default() @@ -57,6 +58,7 @@ pub struct AttenuationParams impl Default for AttenuationParams { + #[must_use] fn default() -> Self { Self { @@ -81,6 +83,7 @@ pub struct DirectionalLight impl DirectionalLight { + #[must_use] pub fn builder() -> DirectionalLightBuilder { DirectionalLightBuilder::default() diff --git a/engine/src/material.rs b/engine/src/material.rs index 5c59a9a..aae6003 100644 --- a/engine/src/material.rs +++ b/engine/src/material.rs @@ -192,6 +192,7 @@ pub struct Flags impl Flags { + #[must_use] pub fn builder() -> FlagsBuilder { FlagsBuilder::default() diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs index 292fd94..888f760 100644 --- a/engine/src/renderer/opengl.rs +++ b/engine/src/renderer/opengl.rs @@ -111,6 +111,7 @@ fn initialize(window: Single) enable(Capability::MultiSample); } +#[allow(clippy::too_many_arguments)] fn render( query: Query>>, point_light_query: Query<(PointLight,)>, @@ -166,21 +167,18 @@ fn render( let new_gl_objects; - let gl_objects = match gl_objects.as_deref() { - Some(gl_objects) => gl_objects, - None => { - // TODO: Account for when meshes are changed - let gl_objects = GlObjects::new(&*mesh); + let gl_objects = if let Some(gl_objects) = gl_objects.as_deref() { + gl_objects + } else { + // TODO: Account for when meshes are changed + let gl_objects = GlObjects::new(&mesh); - new_gl_objects = Some(gl_objects.clone()); + new_gl_objects = Some(gl_objects.clone()); - actions.add_components( - query.entity_uid(entity_index).unwrap(), - (gl_objects,), - ); + actions + .add_components(query.entity_uid(entity_index).unwrap(), (gl_objects,)); - &*new_gl_objects.unwrap() - } + &*new_gl_objects.unwrap() }; apply_transformation_matrices( @@ -229,10 +227,10 @@ fn render( crate::opengl::set_polygon_mode( draw_flags.polygon_mode_config.face, draw_flags.polygon_mode_config.mode, - ) + ); } - draw_mesh(&gl_objects); + draw_mesh(gl_objects); if draw_flags.is_some() { let default_polygon_mode_config = PolygonModeConfig::default(); @@ -240,7 +238,7 @@ fn render( crate::opengl::set_polygon_mode( default_polygon_mode_config.face, default_polygon_mode_config.mode, - ) + ); } } } @@ -332,7 +330,7 @@ fn create_gl_shader_program( struct GlObjects { /// Vertex and index buffer has to live as long as the vertex array - _vertex_buffer: Buffer, + vertex_buffer: Buffer, index_buffer: Option>, index_cnt: u32, @@ -388,7 +386,7 @@ impl GlObjects vertex_arr.bind_element_buffer(&index_buffer); return Self { - _vertex_buffer: vertex_buffer, + vertex_buffer, index_buffer: Some(index_buffer), index_cnt: indices.len().try_into().unwrap(), vertex_arr, @@ -396,7 +394,7 @@ impl GlObjects } Self { - _vertex_buffer: vertex_buffer, + vertex_buffer, index_buffer: None, index_cnt: 0, vertex_arr, @@ -407,7 +405,7 @@ impl GlObjects { NeverDrop::new(Self { // SAFETY: The vertex buffer will never become dropped (NeverDrop ensures it) - _vertex_buffer: unsafe { self._vertex_buffer.clone_weak() }, + vertex_buffer: unsafe { self.vertex_buffer.clone_weak() }, index_buffer: self .index_buffer .as_ref() @@ -488,6 +486,8 @@ fn apply_light( ); } + // There probably won't be more than 2147483648 directional lights + #[allow(clippy::cast_possible_wrap, clippy::cast_possible_truncation)] gl_shader_program.set_uniform_1i( cstr!("directional_light_cnt"), directional_lights.len() as i32, @@ -514,6 +514,8 @@ fn apply_light( ); } + // There probably won't be more than 2147483648 point lights + #[allow(clippy::cast_possible_wrap, clippy::cast_possible_truncation)] gl_shader_program.set_uniform_1i(cstr!("point_light_cnt"), point_lights.len() as i32); gl_shader_program.set_uniform_vec_3fv( @@ -521,7 +523,7 @@ fn apply_light( &if material_flags.use_ambient_color { material.ambient.clone() } else { - global_light.ambient.clone().into() + global_light.ambient.clone() } .into(), ); diff --git a/engine/src/util.rs b/engine/src/util.rs index 8e93982..a505a38 100644 --- a/engine/src/util.rs +++ b/engine/src/util.rs @@ -119,7 +119,7 @@ impl Deref for NeverDrop fn deref(&self) -> &Self::Target { - &*self.value + &self.value } } @@ -127,6 +127,6 @@ impl DerefMut for NeverDrop { fn deref_mut(&mut self) -> &mut Self::Target { - &mut *self.value + &mut self.value } } -- cgit v1.2.3-18-g5258