From b1710f7f71dd7833384e577c69fa1196d4fb3e13 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Sun, 23 Oct 2022 03:50:07 +0200 Subject: [PATCH] Apply `cargo clippy` --- src/main.rs | 9 ++++----- src/support/camera.rs | 2 +- src/support/mod.rs | 31 ++++++++++++++----------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index a57332d..d4a9b6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -235,12 +235,11 @@ fn main() { // polling and handling the events received by the window for event in events { - match event { - glutin::event::Event::WindowEvent { event, .. } => match event { + if let glutin::event::Event::WindowEvent { event, .. } = event { + match event { glutin::event::WindowEvent::CloseRequested => action = support::Action::Stop, - ev => camera.process_input(&ev), - }, - _ => (), + ev => camera.process_input(ev), + } } } diff --git a/src/support/camera.rs b/src/support/camera.rs index 1f76287..81c916d 100644 --- a/src/support/camera.rs +++ b/src/support/camera.rs @@ -34,7 +34,7 @@ impl CameraState { } pub fn get_perspective(&self) -> [[f32; 4]; 4] { - let fov: f32 = 3.141592 / 2.0; + let fov: f32 = std::f32::consts::PI / 2.0; let zfar = 53_209.0; let znear = 1.0; //0.01; diff --git a/src/support/mod.rs b/src/support/mod.rs index 225f844..8711cb9 100644 --- a/src/support/mod.rs +++ b/src/support/mod.rs @@ -22,10 +22,10 @@ where let mut next_frame_time = Instant::now(); event_loop.run(move |event, _, control_flow| { let run_callback = match event.to_static() { - Some(Event::NewEvents(cause)) => match cause { - StartCause::ResumeTimeReached { .. } | StartCause::Init => true, - _ => false, - }, + Some(Event::NewEvents(cause)) => matches!( + cause, + StartCause::ResumeTimeReached { .. } | StartCause::Init + ), Some(event) => { events_buffer.push(event); false @@ -58,20 +58,20 @@ where fn get_biome(line: &str, index: usize) -> u32 { let biome_char = line.chars().nth(index).unwrap(); - return if '0' <= biome_char && biome_char <= '9' { + if ('0'..='9').contains(&biome_char) { biome_char.to_digit(10).unwrap() } else { - (10 + (biome_char as u8 - 'A' as u8)) as u32 - }; + (10 + (biome_char as u8 - b'A')) as u32 + } } -fn get_altitude(height_columns: &Vec<&str>, columns_index: usize) -> f32 { +fn get_altitude(height_columns: &[&str], columns_index: usize) -> f32 { let height_str = height_columns[columns_index]; - return if height_str == "N" { + if height_str == "N" { SEABED_ALTITUDE } else { height_str.parse::().unwrap() - }; + } } const SEABED_ALTITUDE: f32 = -100.0; @@ -95,9 +95,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { let ground_folder = "Extensions/LemnosLife/Map/Altis/Ground/"; let paths = fs::read_dir(ground_folder).unwrap(); - let mut i: u32 = 0; - - for path in paths { + for (i, path) in (0_u32..).zip(paths) { let file_name = path .unwrap() .path() @@ -158,10 +156,10 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { let column_below = get_altitude(&height_next_columns, columns_index); let biome_index = if lines_index % 2 == 0 { - columns_index / 2 + columns_index } else { - height_columns.len() / 2 - columns_index / 2 - }; + height_columns.len() - columns_index + } / 2; let biome = get_biome(biomes_line, biome_index); if lines_index == 0 && columns_index == 0 { @@ -205,7 +203,6 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { biome: 0, chunk, }); - i += 1; // i == 250 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BufferCreationError(OutOfMemory)', src/support/mod.rs:203:10 /*if i == 1 { break;