diff --git a/Cargo.lock b/Cargo.lock index 2636412..a90d9ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2542,9 +2542,9 @@ checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" [[package]] name = "rodio" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d98f5e557b61525057e2bc142c8cd7f0e70d75dc32852309bec440e6e046bf9" +checksum = "ec0939e9f626e6c6f1989adb6226a039c855ca483053f0ee7c98b90e41cf731e" dependencies = [ "claxon", "cpal", diff --git a/Cargo.toml b/Cargo.toml index 33c1da8..a541b80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ resolver = "2" instant = "0.1" pollster = "0.2.4" nalgebra = "0.29.0" -rodio = { version = "0.14.0", default-features = false, features = ["vorbis", "flac", "wav"] } +rodio = { version = "0.15.0", default-features = false, features = ["vorbis", "flac", "wav"] } rapier3d = "0.11.1" #serde = { version = "1", features = ["derive"] } log = "0.4.14" diff --git a/src/animation.rs b/src/animation.rs index 4053047..d9534bc 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -10,24 +10,11 @@ pub enum InOutAnimationState { impl PartialEq for InOutAnimationState { fn eq(&self, other: &Self) -> bool { match self { - InOutAnimationState::Stopped => match other { - InOutAnimationState::Stopped => true, - _ => false, - }, - InOutAnimationState::Foward(_) => match other { - InOutAnimationState::Foward(_) => true, - _ => false, - }, - InOutAnimationState::Backward(_) => match other { - InOutAnimationState::Backward(_) => true, - _ => false, - }, + InOutAnimationState::Stopped => matches!(other, InOutAnimationState::Stopped), + InOutAnimationState::Foward(_) => matches!(other, InOutAnimationState::Foward(_)), + InOutAnimationState::Backward(_) => matches!(other, InOutAnimationState::Backward(_)), } } - - fn ne(&self, other: &Self) -> bool { - !self.eq(other) - } } pub struct InOutAnimation { diff --git a/src/audio.rs b/src/audio.rs index 230bab2..a1e78f4 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -1,3 +1,4 @@ + use std::collections::HashMap; pub const AUDIO_FILE_AWESOMENESS: &[u8] = include_bytes!("../assets/audio/awesomeness.wav"); @@ -29,6 +30,7 @@ impl Sink { } } +#[cfg(not(target_arch = "wasm32"))] pub struct AudioContext { pub output_stream_handle: rodio::OutputStreamHandle, pub output_stream: rodio::OutputStream, @@ -36,18 +38,33 @@ pub struct AudioContext { pub global_sinks_array: Vec, pub volume: f32, } +#[cfg(target_arch = "wasm32")] +pub struct AudioContext { + pub global_sinks_map: HashMap<&'static str, Sink>, + pub global_sinks_array: Vec, + pub volume: f32, +} impl AudioContext { pub fn new() -> Self { + #[cfg(not(target_arch = "wasm32"))] let (output_stream, output_stream_handle) = rodio::OutputStream::try_default().unwrap(); - Self { + #[cfg(not(target_arch = "wasm32"))] + let ret = Self { global_sinks_map: HashMap::new(), global_sinks_array: Vec::new(), volume: 1.0, output_stream, output_stream_handle, - } + }; + #[cfg(target_arch = "wasm32")] + let ret = Self { + global_sinks_map: HashMap::new(), + global_sinks_array: Vec::new(), + volume: 1.0, + }; + ret } pub fn get_volume(&self) -> f32 { @@ -55,27 +72,39 @@ impl AudioContext { } pub fn set_volume(&mut self, volume: f32) { - self.volume = volume; - for (_k, v) in self.global_sinks_map.iter_mut() { - v.set_volume(volume); - } - for sink in self.global_sinks_array.iter_mut() { - sink.set_volume(volume); + #[cfg(not(target_arch = "wasm32"))] + { + self.volume = volume; + for (_k, v) in self.global_sinks_map.iter_mut() { + v.set_volume(volume); + } + for sink in self.global_sinks_array.iter_mut() { + sink.set_volume(volume); + } } } pub fn push(&mut self, mut sink: Sink) { - sink.set_volume(self.volume); - self.global_sinks_array.push(sink); + #[cfg(not(target_arch = "wasm32"))] + { + sink.set_volume(self.volume); + self.global_sinks_array.push(sink); + } } pub fn insert(&mut self, key: &'static str, mut sink: Sink) { - sink.set_volume(self.volume); - self.global_sinks_map.insert(key, sink); + #[cfg(not(target_arch = "wasm32"))] + { + sink.set_volume(self.volume); + self.global_sinks_map.insert(key, sink); + } } pub fn clear(&mut self) { - self.global_sinks_map.retain(|_k, v| !v.empty()); - self.global_sinks_array.retain(|v| !v.empty()); + #[cfg(not(target_arch = "wasm32"))] + { + self.global_sinks_map.retain(|_k, v| !v.empty()); + self.global_sinks_array.retain(|v| !v.empty()); + } } } diff --git a/src/camera.rs b/src/camera.rs index b1c73e8..b65e844 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -69,23 +69,23 @@ impl Camera { bottom: FrustumPlane::new( self.position, nalgebra::Unit::new_normalize( - (&(&front_times_far + up * half_v_side)).cross(&right), + (&(front_times_far + up * half_v_side)).cross(&right), ), ), top: FrustumPlane::new( self.position, - nalgebra::Unit::new_normalize(right.cross(&(&front_times_far - up * half_v_side))), + nalgebra::Unit::new_normalize(right.cross(&(front_times_far - up * half_v_side))), ), left: FrustumPlane::new( self.position, nalgebra::Unit::new_normalize( - (&(&front_times_far - right.into_inner() * half_h_side)).cross(&up), + (&(front_times_far - right.into_inner() * half_h_side)).cross(&up), ), ), right: FrustumPlane::new( self.position, nalgebra::Unit::new_normalize( - (&up).cross(&(&front_times_far + right.into_inner() * half_h_side)), + (&up).cross(&(front_times_far + right.into_inner() * half_h_side)), ), ), } diff --git a/src/database.rs b/src/database.rs index 8092ee4..d7034c3 100644 --- a/src/database.rs +++ b/src/database.rs @@ -46,62 +46,55 @@ impl GameModeScores { )) .unwrap(); let mut score_rows = Vec::new(); - match output { - Payload::Select { labels, rows } => { - for row in rows { - let mut score = ClassicGameScoreDisplay::new(); - for (idx, label) in labels.iter().enumerate() { - match label.as_str() { - "accuracy" => { - score.accuracy = match row[idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "hit" => { - score.hit = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as u16; - } - "miss" => { - score.miss = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as u16; - } - "score" => { - score.score = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as i32; - } - "avg_hit_time" => { - score.avg_hit_time = match row[idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "created_at" => { - score.created_at = match row[idx] { - Value::Timestamp(x) => x, - _ => unreachable!(), - }; + if let Payload::Select { labels, rows } = output { + for row in rows { + let mut score = ClassicGameScoreDisplay::new(); + for (idx, label) in labels.iter().enumerate() { + match label.as_str() { + "accuracy" => { + score.accuracy = match row[idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "hit" => { + score.hit = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as u16; + } + "miss" => { + score.miss = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as u16; + } + "score" => { + score.score = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as i32; + } + "avg_hit_time" => { + score.avg_hit_time = match row[idx] { + Value::F64(x) => x, + _ => unreachable!(), } - "difficulty" => {} - _ => unreachable!(), + as f32; + } + "created_at" => { + score.created_at = match row[idx] { + Value::Timestamp(x) => x, + _ => unreachable!(), + }; } + "difficulty" => {} + _ => unreachable!(), } - score_rows.push(score); } + score_rows.push(score); } - _ => {} - }; + } GameModeScores::Classic(score_rows) } GameMode::Elimination => { @@ -110,76 +103,69 @@ impl GameModeScores { .execute(&format!("SELECT * FROM elimination_game_score WHERE difficulty = {} ORDER BY created_at DESC", difficulty as u8)) .unwrap(); let mut score_rows = Vec::new(); - match output { - Payload::Select { labels, rows } => { - for row in rows { - let mut score = EliminationGameScoreDisplay::new(); - for (idx, label) in labels.iter().enumerate() { - match label.as_str() { - "accuracy" => { - score.accuracy = match row[idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "hit" => { - score.hit = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as u16; - } - "miss" => { - score.miss = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as u16; - } - "score" => { - score.score = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as i32; - } - "hit_fake_target" => { - score.hit_fake_target = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as u16; - } - "running_time" => { - score.running_time = match row[idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; + if let Payload::Select { labels, rows } = output { + for row in rows { + let mut score = EliminationGameScoreDisplay::new(); + for (idx, label) in labels.iter().enumerate() { + match label.as_str() { + "accuracy" => { + score.accuracy = match row[idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "hit" => { + score.hit = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as u16; + } + "miss" => { + score.miss = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as u16; + } + "score" => { + score.score = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as i32; + } + "hit_fake_target" => { + score.hit_fake_target = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), } - "avg_hit_time" => { - score.avg_hit_time = match row[idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; + as u16; + } + "running_time" => { + score.running_time = match row[idx] { + Value::F64(x) => x, + _ => unreachable!(), } - "created_at" => { - score.created_at = match row[idx] { - Value::Timestamp(x) => x, - _ => unreachable!(), - }; + as f32; + } + "avg_hit_time" => { + score.avg_hit_time = match row[idx] { + Value::F64(x) => x, + _ => unreachable!(), } - "difficulty" => {} - _ => unreachable!(), + as f32; + } + "created_at" => { + score.created_at = match row[idx] { + Value::Timestamp(x) => x, + _ => unreachable!(), + }; } + "difficulty" => {} + _ => unreachable!(), } - score_rows.push(score); } + score_rows.push(score); } - _ => {} - }; + } GameModeScores::Elimination(score_rows) } GameMode::HitAndDodge => { @@ -188,69 +174,61 @@ impl GameModeScores { .execute(&format!("SELECT * FROM hit_and_dodge_game_score WHERE difficulty = {} ORDER BY created_at DESC", difficulty as u8)) .unwrap(); let mut score_rows = Vec::new(); - match output { - Payload::Select { labels, rows } => { - for row in rows { - let mut score = HitAndDodgeGameScoreDisplay::new(); - for (idx, label) in labels.iter().enumerate() { - match label.as_str() { - "accuracy" => { - score.accuracy = match row[idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "hit" => { - score.hit = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as u16; - } - "miss" => { - score.miss = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as u16; - } - "score" => { - score.score = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as i32; - } - "hit_taken" => { - score.hit_taken = match row[idx] { - Value::I64(x) => x, - _ => unreachable!(), - } - as u16; - } - "avg_hit_time" => { - score.avg_hit_time = match row[idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "created_at" => { - score.created_at = match row[idx] { - Value::Timestamp(x) => x, - _ => unreachable!(), - }; + if let Payload::Select { labels, rows } = output { + for row in rows { + let mut score = HitAndDodgeGameScoreDisplay::new(); + for (idx, label) in labels.iter().enumerate() { + match label.as_str() { + "accuracy" => { + score.accuracy = match row[idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "hit" => { + score.hit = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as u16; + } + "miss" => { + score.miss = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as u16; + } + "score" => { + score.score = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as i32; + } + "hit_taken" => { + score.hit_taken = match row[idx] { + Value::I64(x) => x, + _ => unreachable!(), + } as u16; + } + "avg_hit_time" => { + score.avg_hit_time = match row[idx] { + Value::F64(x) => x, + _ => unreachable!(), } - "difficulty" => {} - _ => unreachable!(), + as f32; } + "created_at" => { + score.created_at = match row[idx] { + Value::Timestamp(x) => x, + _ => unreachable!(), + }; + } + "difficulty" => {} + _ => unreachable!(), } - score_rows.push(score); } + score_rows.push(score); } - _ => {} - }; + } GameModeScores::HitAndDodge(score_rows) } } @@ -344,147 +322,134 @@ impl Database { ) .unwrap(); let output = self.glue.execute("SELECT * FROM settings").unwrap(); - match output { - Payload::Select { rows, .. } => { - if rows.is_empty() { - self.glue - .execute( - "INSERT INTO settings VALUES (1.0, 50, 3,\ + if let Payload::Select { rows, .. } = output { + if rows.is_empty() { + self.glue + .execute( + "INSERT INTO settings VALUES (1.0, 50, 3,\ 1.0, 0.0, 0.0,\ TRUE, 2.0,\ TRUE, 6.0, 20.0, 5.0,\ TRUE, 3.0, 6.0, 49.0,\ 0.5)", - ) - .unwrap(); - } + ) + .unwrap(); } - _ => {} - }; + } } pub fn init_settings(&mut self, audio_context: &mut AudioContext, renderer: &mut Renderer) { let output = self.glue.execute("SELECT * FROM settings").unwrap(); - match output { - Payload::Select { labels, rows } => { - for (idx, label) in labels.iter().enumerate() { - match label.as_str() { - "audio_volume" => { - audio_context.set_volume(match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } as f32); - } - "maximum_raymarch_step" => { - renderer.rendering_info.queuecount_raymarchmaxstep_aostep.y = - match rows[0][idx] { - Value::I64(x) => x, - _ => unreachable!(), - } as u32; - } - "ambient_occlusion_sample" => { - renderer.rendering_info.queuecount_raymarchmaxstep_aostep.z = - match rows[0][idx] { - Value::I64(x) => x, - _ => unreachable!(), - } as u32; - } - "mouse_sensitivity" => { - renderer.camera.sensitivity = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } as f32; - } - "crosshair_color_r" => { - renderer.crosshair.color.x = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } as f32; - } - "crosshair_color_g" => { - renderer.crosshair.color.y = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } as f32; - } - "crosshair_color_b" => { - renderer.crosshair.color.z = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } as f32; - } - "center_dot_enable" => { - renderer.crosshair.center_dot_enabled = match rows[0][idx] { - Value::Bool(x) => x, - _ => unreachable!(), - }; - } - "center_dot_thickness" => { - renderer.crosshair.center_dot_thickness = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "inner_line_enable" => { - renderer.crosshair.center_dot_enabled = match rows[0][idx] { - Value::Bool(x) => x, - _ => unreachable!(), - }; - } - "inner_line_thickness" => { - renderer.crosshair.inner_line_thickness = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "inner_line_length" => { - renderer.crosshair.inner_line_length = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "inner_line_offset" => { - renderer.crosshair.inner_line_offset = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "outer_line_enable" => { - renderer.crosshair.center_dot_enabled = match rows[0][idx] { - Value::Bool(x) => x, - _ => unreachable!(), - }; - } - "outer_line_thickness" => { - renderer.crosshair.outer_line_thickness = match rows[0][idx] { - Value::F64(x) => x, - _ => unreachable!(), - } - as f32; - } - "outer_line_length" => { - renderer.crosshair.outer_line_length = match rows[0][idx] { - Value::F64(x) => x, + if let Payload::Select { labels, rows } = output { + for (idx, label) in labels.iter().enumerate() { + match label.as_str() { + "audio_volume" => { + audio_context.set_volume(match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32); + } + "maximum_raymarch_step" => { + renderer.rendering_info.queuecount_raymarchmaxstep_aostep.y = + match rows[0][idx] { + Value::I64(x) => x, _ => unreachable!(), - } - as f32; - } - "outer_line_offset" => { - renderer.crosshair.outer_line_offset = match rows[0][idx] { - Value::F64(x) => x, + } as u32; + } + "ambient_occlusion_sample" => { + renderer.rendering_info.queuecount_raymarchmaxstep_aostep.z = + match rows[0][idx] { + Value::I64(x) => x, _ => unreachable!(), - } - as f32; - } - _ => unreachable!(), - }; - } + } as u32; + } + "mouse_sensitivity" => { + renderer.camera.sensitivity = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "crosshair_color_r" => { + renderer.crosshair.color.x = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "crosshair_color_g" => { + renderer.crosshair.color.y = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "crosshair_color_b" => { + renderer.crosshair.color.z = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "center_dot_enable" => { + renderer.crosshair.center_dot_enabled = match rows[0][idx] { + Value::Bool(x) => x, + _ => unreachable!(), + }; + } + "center_dot_thickness" => { + renderer.crosshair.center_dot_thickness = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "inner_line_enable" => { + renderer.crosshair.center_dot_enabled = match rows[0][idx] { + Value::Bool(x) => x, + _ => unreachable!(), + }; + } + "inner_line_thickness" => { + renderer.crosshair.inner_line_thickness = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "inner_line_length" => { + renderer.crosshair.inner_line_length = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "inner_line_offset" => { + renderer.crosshair.inner_line_offset = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "outer_line_enable" => { + renderer.crosshair.center_dot_enabled = match rows[0][idx] { + Value::Bool(x) => x, + _ => unreachable!(), + }; + } + "outer_line_thickness" => { + renderer.crosshair.outer_line_thickness = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "outer_line_length" => { + renderer.crosshair.outer_line_length = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + "outer_line_offset" => { + renderer.crosshair.outer_line_offset = match rows[0][idx] { + Value::F64(x) => x, + _ => unreachable!(), + } as f32; + } + _ => unreachable!(), + }; } - _ => {} - }; + } } } diff --git a/src/entity/enemy/gunman.rs b/src/entity/enemy/gunman.rs index b28155d..39a72e8 100644 --- a/src/entity/enemy/gunman.rs +++ b/src/entity/enemy/gunman.rs @@ -7,7 +7,7 @@ use crate::entity::HasMaterial; use crate::scene::{IN_SHOOT_ANIM_DURATION, OUT_SHOOT_ANIM_DURATION}; use crate::timer::Timer; -use nalgebra::{distance, Point, Rotation3, Unit, Vector2, Vector3}; +use nalgebra::{distance, Point, Unit, Vector2, Vector3}; use rand::distributions::Uniform; use rand::prelude::*; @@ -74,15 +74,12 @@ impl Gunman { obj_pos: &mut Vector3, player_pos: &Vector3, ) -> GunmanOp { - match self.material_state { - EnemyMaterialState::Hitted(ref mut timer) => { - timer.update(delta_time); - if timer.is_finished() { - self.material_state = EnemyMaterialState::None; - } + if let EnemyMaterialState::Hitted(ref mut timer) = self.material_state { + timer.update(delta_time); + if timer.is_finished() { + self.material_state = EnemyMaterialState::None; } - _ => {} - }; + } let current_xz_pos = obj_pos.xz(); if distance(&Point::from(self.next_dest), &Point::from(current_xz_pos)) <= 0.5 { @@ -143,12 +140,9 @@ impl Gunman { } ShootState::Shoot(ref mut anim) => { anim.update(delta_time); - match anim.get_state() { - InOutAnimationState::Stopped => { - self.shoot_state = ShootState::Idle(Timer::new(0.5)); - } - _ => {} - }; + if let InOutAnimationState::Stopped = anim.get_state() { + self.shoot_state = ShootState::Idle(Timer::new(0.5)); + } } }; op diff --git a/src/entity/enemy/swordman.rs b/src/entity/enemy/swordman.rs index 69ad9f0..3d8cfb1 100644 --- a/src/entity/enemy/swordman.rs +++ b/src/entity/enemy/swordman.rs @@ -5,7 +5,7 @@ use crate::physics::GamePhysics; use crate::renderer::render_objects::MaterialType; use crate::scene::hit_and_dodge_scene::Score; use crate::timer::Timer; -use nalgebra::{distance, Point, Rotation3, Unit, Vector3}; +use nalgebra::{distance, Point, Unit, Vector3}; use rapier3d::prelude::Ray; pub enum EnemyState { @@ -43,15 +43,12 @@ impl Swordman { physics: &GamePhysics, score: &mut Score, ) { - match self.material_state { - EnemyMaterialState::Hitted(ref mut timer) => { - timer.update(delta_time); - if timer.is_finished() { - self.material_state = EnemyMaterialState::None; - } + if let EnemyMaterialState::Hitted(ref mut timer) = self.material_state { + timer.update(delta_time); + if timer.is_finished() { + self.material_state = EnemyMaterialState::None; } - _ => {} - }; + } let current_dir = Unit::new_normalize(*player_pos - *obj_pos); match &mut self.state { diff --git a/src/entity/target.rs b/src/entity/target.rs index 38f606c..4fb3d32 100644 --- a/src/entity/target.rs +++ b/src/entity/target.rs @@ -1,7 +1,7 @@ use crate::audio::{AudioContext, Sink, AUDIO_FILE_SHOOTED}; use crate::renderer::render_objects::MaterialType; use crate::timer::Timer; -use nalgebra::{distance, Point3, Unit, Vector2, Vector3}; +use nalgebra::{distance, Point3, Unit, Vector3}; use std::io::{BufReader, Cursor}; #[derive(Clone)] @@ -103,11 +103,15 @@ impl SphereTarget { } pub fn try_shoot(&mut self, audio_context: &mut AudioContext) -> bool { - let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); - sink.append( - rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_SHOOTED.to_vec()))).unwrap(), - ); - audio_context.push(Sink::Regular(sink)); + #[cfg(not(target_arch = "wasm32"))] + { + let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); + sink.append( + rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_SHOOTED.to_vec()))) + .unwrap(), + ); + audio_context.push(Sink::Regular(sink)); + } if !self.is_invalid_target() { self.shooted = true; @@ -117,10 +121,7 @@ impl SphereTarget { } pub fn is_invalid_target(&self) -> bool { - match self.validity_state { - ValidityState::Invalid(_) => true, - _ => false, - } + matches!(self.validity_state, ValidityState::Invalid(_)) } pub fn get_material(&self) -> MaterialType { @@ -161,22 +162,20 @@ impl SphereTarget { Patrol::Linear { a, b } => { match &self.patrol_state { PatrolState::AToB => { - if distance(&Point3::from(obj_pos.clone()), &Point3::from(b.clone())) <= 0.5 - { + if distance(&Point3::from(*obj_pos), &Point3::from(*b)) <= 0.5 { self.patrol_state = PatrolState::BToA; } else { - let dir = Unit::new_normalize(*b - obj_pos.clone()); + let dir = Unit::new_normalize(*b - *obj_pos); let next_pos = dir.into_inner() * SPEED_LIN * delta_time; obj_pos.x += next_pos.x; obj_pos.z += next_pos.y; } } PatrolState::BToA => { - if distance(&Point3::from(obj_pos.clone()), &Point3::from(a.clone())) <= 0.5 - { + if distance(&Point3::from(*obj_pos), &Point3::from(*a)) <= 0.5 { self.patrol_state = PatrolState::AToB; } else { - let dir = Unit::new_normalize(*a - obj_pos.clone()); + let dir = Unit::new_normalize(*a - *obj_pos); let next_pos = dir.into_inner() * SPEED_LIN * delta_time; obj_pos.x += next_pos.x; obj_pos.z += next_pos.y; @@ -197,8 +196,8 @@ impl SphereTarget { if (*c - b).abs() <= SPEED_POL { self.patrol_state = PatrolState::BToA; } else { - let mut sign = (b - *c).signum(); - *c = *c + sign * SPEED_POL * delta_time; + let sign = (b - *c).signum(); + *c += sign * SPEED_POL * delta_time; obj_pos.x = r * c.cos(); obj_pos.z = r * c.sin(); obj_pos.x += or.x; @@ -209,8 +208,8 @@ impl SphereTarget { if (*c - a).abs() <= SPEED_POL { self.patrol_state = PatrolState::AToB; } else { - let mut sign = (a - *c).signum(); - *c = *c + sign * SPEED_POL * delta_time; + let sign = (a - *c).signum(); + *c += sign * SPEED_POL * delta_time; obj_pos.x = r * c.cos(); obj_pos.z = r * c.sin(); obj_pos.x += or.x; @@ -223,12 +222,9 @@ impl SphereTarget { _ => {} }; - match self.delete_timer { - Some(ref mut timer) => { - timer.update(delta_time); - } - None => {} - }; + if let Some(ref mut timer) = self.delete_timer { + timer.update(delta_time); + } } pub fn is_need_to_be_deleted(&self) -> bool { diff --git a/src/renderer/crosshair.rs b/src/renderer/crosshair.rs index 9687929..46618e2 100644 --- a/src/renderer/crosshair.rs +++ b/src/renderer/crosshair.rs @@ -1,4 +1,4 @@ -use crate::renderer::vertex::{CoordColorVertex}; +use crate::renderer::vertex::CoordColorVertex; use crate::util::any_slice_as_u8_slice; use nalgebra::{Rotation2, Vector2, Vector3, Vector4}; @@ -230,7 +230,7 @@ impl Crosshair { } pub fn vertices_len(&self) -> u32 { - 0 + if self.outer_line_enabled { 6 * 4 } else { 0 } + (if self.outer_line_enabled { 6 * 4 } else { 0 }) + if self.inner_line_enabled { 6 * 4 } else { 0 } + if self.center_dot_enabled { 6 } else { 0 } } diff --git a/src/renderer/game_renderer.rs b/src/renderer/game_renderer.rs index 18556b1..6ddfff5 100644 --- a/src/renderer/game_renderer.rs +++ b/src/renderer/game_renderer.rs @@ -1,6 +1,6 @@ use image::GenericImage; use wgpu::util::DeviceExt; -use std::ops::Range; + use crate::camera::Camera; use crate::gui::ConrodHandle; @@ -722,8 +722,8 @@ fn terrain_texture_descriptor( wgpu::TextureDescriptor { label: Some("Terrain"), size: wgpu::Extent3d { - width: width, - height: height, + width, + height, depth_or_array_layers: 1, }, mip_level_count: 1, diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 2dad6eb..b075378 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -46,7 +46,7 @@ impl Renderer { let instance = wgpu::Instance::new(if cfg!(target_arch = "wasm32") { wgpu::Backends::GL } else { - wgpu::Backends::VULKAN + wgpu::Backends::all() }); let surface = unsafe { instance.create_surface(window) }; let adapter = instance diff --git a/src/renderer/render_objects.rs b/src/renderer/render_objects.rs index e356e15..7b1d808 100644 --- a/src/renderer/render_objects.rs +++ b/src/renderer/render_objects.rs @@ -1,6 +1,7 @@ use crate::frustum::{Frustum, ObjectBound}; use nalgebra::{Matrix4, Vector3, Vector4}; +#[allow(dead_code)] #[derive(Debug, Clone, Copy)] #[repr(u32)] pub enum ShapeType { @@ -12,6 +13,7 @@ pub enum ShapeType { Gunman = 5, } +#[allow(dead_code)] #[derive(Debug, Clone, Copy)] #[repr(u32)] pub enum MaterialType { diff --git a/src/scene/classic_game_scene.rs b/src/scene/classic_game_scene.rs index 3c58ec8..830577d 100644 --- a/src/scene/classic_game_scene.rs +++ b/src/scene/classic_game_scene.rs @@ -11,7 +11,7 @@ use winit::event_loop::ControlFlow; use crate::animation::InOutAnimation; use crate::audio::{AudioContext, AUDIO_FILE_SHOOT}; -use crate::audio::{Sink, AUDIO_FILE_SHOOTED}; +use crate::audio::{Sink}; use crate::database::Database; use crate::entity::target::{Patrol, SphereTarget, Validity}; @@ -35,7 +35,7 @@ use crate::systems::target::{enqueue_target, spawn_target, update_target}; use crate::systems::update_player_movement::update_player_position; use crate::systems::wall::{enqueue_wall, spawn_wall}; use crate::timer::{Stopwatch, Timer}; -use crate::util::lerp; + use crate::window::Window; use conrod_core::widget::envelope_editor::EnvelopePoint; use conrod_core::widget::{Canvas, Text}; @@ -440,7 +440,7 @@ impl Scene for ClassicGameScene { ); if shoot_trigger { - self.shoot(&input_manager, audio_context, &renderer.camera, delta_time); + self.shoot(input_manager, audio_context, &renderer.camera, delta_time); } } @@ -513,18 +513,21 @@ impl ClassicGameScene { input_manager: &InputManager, audio_context: &mut AudioContext, camera: &Camera, - delta_time: f32, + _delta_time: f32, ) { if input_manager.is_mouse_press(&MouseButton::Left) && self.shoot_timer.is_finished() { self.shoot_animation.trigger(); self.shoot_timer.reset(0.4); - let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); - sink.append( - rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_SHOOT.to_vec()))) - .unwrap(), - ); - audio_context.push(Sink::Regular(sink)); + #[cfg(not(target_arch = "wasm32"))] + { + let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); + sink.append( + rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_SHOOT.to_vec()))) + .unwrap(), + ); + audio_context.push(Sink::Regular(sink)); + } if let Some((handle, _distance)) = shoot_ray(&self.physics, camera) { let collider = self.physics.collider_set.get(handle).unwrap(); @@ -699,9 +702,9 @@ impl ClassicGameScene { } else { None }; - let mut b = pos.clone(); + let mut b = pos; b.x = self.rng.sample(Uniform::new(-13.0, 13.0)); - let patrol = Patrol::Linear { a: pos.clone(), b }; + let patrol = Patrol::Linear { a: pos, b }; spawn_target( &mut self.world, diff --git a/src/scene/elimination_game_scene.rs b/src/scene/elimination_game_scene.rs index 60e8fb6..ca8dc04 100644 --- a/src/scene/elimination_game_scene.rs +++ b/src/scene/elimination_game_scene.rs @@ -12,7 +12,7 @@ use winit::event_loop::ControlFlow; use crate::animation::InOutAnimation; use crate::audio::{AudioContext, AUDIO_FILE_SHOOT}; -use crate::audio::{Sink, AUDIO_FILE_SHOOTED}; +use crate::audio::{Sink}; use crate::database::Database; use crate::gui::ConrodHandle; @@ -27,7 +27,7 @@ use crate::scene::{ IN_SHOOT_ANIM_DURATION, OUT_SHOOT_ANIM_DURATION, PREPARE_DURATION, }; use crate::timer::{Stopwatch, Timer}; -use crate::util::lerp; + use crate::window::Window; use conrod_core::widget::{Canvas, Text}; use conrod_core::widget_ids; @@ -406,7 +406,7 @@ impl Scene for EliminationGameScene { ); if shoot_trigger { - self.shoot(&input_manager, audio_context, &renderer.camera, delta_time); + self.shoot(input_manager, audio_context, &renderer.camera, delta_time); } } @@ -558,17 +558,21 @@ impl EliminationGameScene { input_manager: &InputManager, audio_context: &mut AudioContext, camera: &Camera, - delta_time: f32, + _delta_time: f32, ) { if input_manager.is_mouse_press(&MouseButton::Left) && self.shoot_timer.is_finished() { self.shoot_animation.trigger(); self.shoot_timer.reset(0.4); - let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); - sink.append( - rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_SHOOT.to_vec()))) - .unwrap(), - ); - audio_context.push(Sink::Regular(sink)); + + #[cfg(not(target_arch = "wasm32"))] + { + let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); + sink.append( + rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_SHOOT.to_vec()))) + .unwrap(), + ); + audio_context.push(Sink::Regular(sink)); + } if let Some((handle, _distance)) = shoot_ray(&self.physics, camera) { let collider = self.physics.collider_set.get(handle).unwrap(); let entity = Entity::from_bits(collider.user_data as u64).unwrap(); diff --git a/src/scene/game_score_scene.rs b/src/scene/game_score_scene.rs index 3c72763..34cfaa3 100644 --- a/src/scene/game_score_scene.rs +++ b/src/scene/game_score_scene.rs @@ -318,7 +318,7 @@ impl Scene for GameScoreScene { ), ]; - for (i, (id_canvas, id_label, label_text, id_value_label, value_text)) in + for (i, (id_canvas, _id_label, _label_text, _id_value_label, _value_text)) in l.iter().enumerate() { Canvas::new() @@ -400,7 +400,7 @@ impl Scene for GameScoreScene { ), ]; - for (i, (id_canvas, id_label, label_text, id_value_label, value_text)) in + for (i, (id_canvas, _id_label, _label_text, _id_value_label, _value_text)) in l.iter().enumerate() { Canvas::new() @@ -471,7 +471,7 @@ impl Scene for GameScoreScene { ), ]; - for (i, (id_canvas, id_label, label_text, id_value_label, value_text)) in + for (i, (id_canvas, _id_label, _label_text, _id_value_label, _value_text)) in l.iter().enumerate() { Canvas::new() diff --git a/src/scene/game_selection_scene.rs b/src/scene/game_selection_scene.rs index 0f9fd98..4758601 100644 --- a/src/scene/game_selection_scene.rs +++ b/src/scene/game_selection_scene.rs @@ -60,7 +60,6 @@ widget_ids! { } struct GameModeDetails { - image: conrod_core::image::Id, title: &'static str, description: &'static str, } @@ -112,21 +111,16 @@ impl Scene for GameSelectionScene { let play_3_button; let score_button; - let image_id = *conrod_handle.get_image_id_map().get("title").unwrap(); - let game_modes = [ GameModeDetails { - image: image_id, title: "Classic", description: "You have to shoot every spawned target. The target will be disappeared after you shoot it and another target will appear.", }, GameModeDetails { - image: image_id, title: "Elimination", - description: "A lot of target will appear. You have to shot all of the target.\nEasy - Static target\nMedium - Target may be transformed to invalid for a time\nHard - Target will move", + description: "A lot of target will appear around you. You have to shoot all of the target and eliminate them.", }, GameModeDetails { - image: image_id, title: "Hit and Dodge", description: "You have to shoot the gunman while avoiding the bullet and swordman attack.", }]; diff --git a/src/scene/hit_and_dodge_scene.rs b/src/scene/hit_and_dodge_scene.rs index 651a681..97a007f 100644 --- a/src/scene/hit_and_dodge_scene.rs +++ b/src/scene/hit_and_dodge_scene.rs @@ -28,7 +28,7 @@ use crate::renderer::Renderer; use crate::scene::game_score_scene::{GameModeScore, GameScoreScene, HitAndDodgeGameScoreDisplay}; use crate::scene::pause_scene::PauseScene; use crate::scene::{ - GameDifficulty, GameState, MaybeMessage, Message, Scene, SceneOp, FINISHING_DURATION, + GameDifficulty, GameState, MaybeMessage, Scene, SceneOp, FINISHING_DURATION, IN_SHOOT_ANIM_DURATION, OUT_SHOOT_ANIM_DURATION, PREPARE_DURATION, }; use crate::systems::gunman::{enqueue_bullet, enqueue_gunman, spawn_gunman, update_gunmans}; @@ -38,10 +38,10 @@ use crate::systems::target::enqueue_target; use crate::systems::update_player_movement::update_player_position; use crate::systems::wall::{enqueue_wall, spawn_wall}; use crate::timer::{Stopwatch, Timer}; -use crate::util::lerp; + use crate::window::Window; use conrod_core::widget_ids; -use gluesql::data::Value; + use nalgebra::Vector3; use crate::camera::Camera; @@ -423,7 +423,7 @@ impl Scene for HitAndDodgeGameScene { &mut self.physics.joint_set, &mut self.physics.ccd_solver, &(), - &mut self.physics.event_handler, + &self.physics.event_handler, ); self.physics.query_pipeline.update( &self.physics.island_manager, @@ -432,7 +432,7 @@ impl Scene for HitAndDodgeGameScene { ); if shoot_trigger { - self.shoot(&input_manager, audio_context, &renderer.camera, delta_time); + self.shoot(input_manager, audio_context, &renderer.camera, delta_time); } } @@ -508,17 +508,20 @@ impl HitAndDodgeGameScene { input_manager: &InputManager, audio_context: &mut AudioContext, camera: &Camera, - delta_time: f32, + _delta_time: f32, ) { if input_manager.is_mouse_press(&MouseButton::Left) && self.shoot_timer.is_finished() { self.shoot_animation.trigger(); self.shoot_timer.reset(0.4); - let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); - sink.append( - rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_SHOOT.to_vec()))) - .unwrap(), - ); - audio_context.push(Sink::Regular(sink)); + #[cfg(not(target_arch = "wasm32"))] + { + let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); + sink.append( + rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_SHOOT.to_vec()))) + .unwrap(), + ); + audio_context.push(Sink::Regular(sink)); + } if let Some((handle, _distance)) = shoot_ray(&self.physics, camera) { let collider = self.physics.collider_set.get(handle).unwrap(); if let Some(entity) = Entity::from_bits(collider.user_data as u64) { diff --git a/src/scene/main_menu_scene.rs b/src/scene/main_menu_scene.rs index f906621..33a8ac2 100644 --- a/src/scene/main_menu_scene.rs +++ b/src/scene/main_menu_scene.rs @@ -12,7 +12,7 @@ use crate::renderer::Renderer; use crate::scene::exit_confirm_scene::QuitConfirmScene; use crate::scene::game_selection_scene::GameSelectionScene; -use crate::scene::guide_scene::GuideScene; + use crate::scene::settings_scene::SettingsScene; use crate::scene::{MaybeMessage, Scene, SceneOp, Value, BUTTON_HEIGHT, BUTTON_WIDTH, MARGIN}; use crate::window::Window; @@ -49,16 +49,19 @@ pub fn play_bgm(message: &MaybeMessage, audio_context: &mut AudioContext) { } }; if play_bgm().is_none() { - let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); - sink.append( - rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_AWESOMENESS.to_vec()))) - .unwrap() - .repeat_infinite(), - ); - sink.set_volume(audio_context.get_volume()); - audio_context - .global_sinks_map - .insert("bgm", Sink::Regular(sink)); + #[cfg(not(target_arch = "wasm32"))] + { + let sink = rodio::Sink::try_new(&audio_context.output_stream_handle).unwrap(); + sink.append( + rodio::Decoder::new(BufReader::new(Cursor::new(AUDIO_FILE_AWESOMENESS.to_vec()))) + .unwrap() + .repeat_infinite(), + ); + sink.set_volume(audio_context.get_volume()); + audio_context + .global_sinks_map + .insert("bgm", Sink::Regular(sink)); + } } } diff --git a/src/scene/mod.rs b/src/scene/mod.rs index cabf85c..d14235f 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -115,6 +115,7 @@ pub trait Scene { database: &mut Database, ); + #[allow(clippy::too_many_arguments)] fn update( &mut self, window: &mut Window, diff --git a/src/scene/score_history_scene.rs b/src/scene/score_history_scene.rs index 2563e41..dd0d5cf 100644 --- a/src/scene/score_history_scene.rs +++ b/src/scene/score_history_scene.rs @@ -125,7 +125,7 @@ impl Scene for ScoreHistoryScene { .set(self.ids.canvas, &mut ui_cell); let mut score_list = |s: usize| { - let (mut score_list_event, score_list_scrollbar) = List::flow_down(s) + let (score_list_event, score_list_scrollbar) = List::flow_down(s) .wh_of(self.ids.body_canvas) .item_size(150.0) .scrollbar_color(conrod_core::color::RED) diff --git a/src/scene/settings_scene.rs b/src/scene/settings_scene.rs index d54cac5..9af703b 100644 --- a/src/scene/settings_scene.rs +++ b/src/scene/settings_scene.rs @@ -280,15 +280,12 @@ impl Scene for SettingsScene { .parent(self.ids.header_canvas) .set(self.ids.title_text, &mut ui_cell); - const GAP_BETWEEN_OPTION_SETTINGS: f64 = 30.0; - const GAP_BETWEEN_LABEL_TO_OPTION_SETTINGS: f64 = 20.0; - Text::new("Maximum raymarch step") .font_id(ropa_font_id) .mid_top_of(self.ids.max_march_step_canvas) .set(self.ids.max_march_step_slider_label, &mut ui_cell); - for value in Slider::new( + if let Some(value) = Slider::new( renderer.rendering_info.queuecount_raymarchmaxstep_aostep.y as f32, 0f32, 200f32, @@ -309,7 +306,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.ambient_occlusion_sample_canvas) .set(self.ids.ambient_occlusion_sample_slider_label, &mut ui_cell); - for value in Slider::new( + if let Some(value) = Slider::new( renderer.rendering_info.queuecount_raymarchmaxstep_aostep.z as f32, 0f32, 10f32, @@ -330,7 +327,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.mouse_sensitivity_canvas) .set(self.ids.mouse_sensitivity_slider_label, &mut ui_cell); - for value in Slider::new(renderer.camera.sensitivity, 0.1f32, 100f32) + if let Some(value) = Slider::new(renderer.camera.sensitivity, 0.1f32, 100f32) .mid_bottom_of(self.ids.mouse_sensitivity_canvas) .label(&format!("{:.3}", renderer.camera.sensitivity)) .wh(Dimensions::new(200.0, 30.0)) @@ -344,7 +341,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.volume_canvas) .set(self.ids.volume_slider_label, &mut ui_cell); - for value in Slider::new(audio_context.get_volume(), 0f32, 1f32) + if let Some(value) = Slider::new(audio_context.get_volume(), 0f32, 1f32) .mid_bottom_of(self.ids.volume_canvas) .label(&format!("{}", (audio_context.get_volume() * 100.0) as u8)) .wh(Dimensions::new(200.0, 30.0)) @@ -387,7 +384,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.center_dot_thickness_canvas) .set(self.ids.center_dot_thickness_slider_label, &mut ui_cell); - for value in Slider::new(renderer.crosshair.center_dot_thickness, 0f32, 100f32) + if let Some(value) = Slider::new(renderer.crosshair.center_dot_thickness, 0f32, 100f32) .mid_bottom_of(self.ids.center_dot_thickness_canvas) .label(&format!( "{}", @@ -433,7 +430,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.inner_line_thickness_canvas) .set(self.ids.inner_line_thickness_slider_label, &mut ui_cell); - for value in Slider::new(renderer.crosshair.inner_line_thickness, 0f32, 100f32) + if let Some(value) = Slider::new(renderer.crosshair.inner_line_thickness, 0f32, 100f32) .mid_bottom_of(self.ids.inner_line_thickness_canvas) .label(&format!( "{}", @@ -450,7 +447,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.inner_line_offset_canvas) .set(self.ids.inner_line_offset_slider_label, &mut ui_cell); - for value in Slider::new(renderer.crosshair.inner_line_offset, 0f32, 100f32) + if let Some(value) = Slider::new(renderer.crosshair.inner_line_offset, 0f32, 100f32) .mid_bottom_of(self.ids.inner_line_offset_canvas) .label(&format!("{}", renderer.crosshair.inner_line_offset as u8)) .wh(Dimensions::new(200.0, 30.0)) @@ -493,7 +490,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.outer_line_thickness_canvas) .set(self.ids.outer_line_thickness_slider_label, &mut ui_cell); - for value in Slider::new(renderer.crosshair.outer_line_thickness, 0f32, 100f32) + if let Some(value) = Slider::new(renderer.crosshair.outer_line_thickness, 0f32, 100f32) .mid_bottom_of(self.ids.outer_line_thickness_canvas) .label(&format!( "{}", @@ -510,7 +507,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.outer_line_offset_canvas) .set(self.ids.outer_line_offset_slider_label, &mut ui_cell); - for value in Slider::new(renderer.crosshair.outer_line_offset, 0f32, 100f32) + if let Some(value) = Slider::new(renderer.crosshair.outer_line_offset, 0f32, 100f32) .mid_bottom_of(self.ids.outer_line_offset_canvas) .label(&format!("{}", renderer.crosshair.outer_line_offset as u8)) .wh(Dimensions::new(200.0, 30.0)) @@ -525,7 +522,7 @@ impl Scene for SettingsScene { .mid_top_of(self.ids.crosshair_color_canvas) .set(self.ids.crosshair_color_g_label, &mut ui_cell); - for value in Slider::new(renderer.crosshair.color.y, 0f32, 1f32) + if let Some(value) = Slider::new(renderer.crosshair.color.y, 0f32, 1f32) .mid_bottom_of(self.ids.crosshair_color_canvas) .label(&format!("{:.3}", renderer.crosshair.color.y)) .wh(Dimensions::new(80.0, 30.0)) @@ -540,7 +537,7 @@ impl Scene for SettingsScene { .left_from(self.ids.crosshair_color_g_label, 50.0) .set(self.ids.crosshair_color_r_label, &mut ui_cell); - for value in Slider::new(renderer.crosshair.color.x, 0f32, 1f32) + if let Some(value) = Slider::new(renderer.crosshair.color.x, 0f32, 1f32) .label(&format!("{:.3}", renderer.crosshair.color.x)) .align_middle_x_of(self.ids.crosshair_color_r_label) .align_middle_y_of(self.ids.crosshair_color_g_slider) @@ -556,7 +553,7 @@ impl Scene for SettingsScene { .right_from(self.ids.crosshair_color_g_label, 50.0) .set(self.ids.crosshair_color_b_label, &mut ui_cell); - for value in Slider::new(renderer.crosshair.color.z, 0f32, 1f32) + if let Some(value) = Slider::new(renderer.crosshair.color.z, 0f32, 1f32) .align_middle_x_of(self.ids.crosshair_color_b_label) .align_middle_y_of(self.ids.crosshair_color_g_slider) .label(&format!("{:.3}", renderer.crosshair.color.z)) diff --git a/src/shaders/common.glsl b/src/shaders/common.glsl index 0558d4e..9e9d86c 100644 --- a/src/shaders/common.glsl +++ b/src/shaders/common.glsl @@ -180,15 +180,15 @@ vec3 n) vec3 h = normalize(l + v); float diff = max(dot(l, n), 0.0); float spec = max(dot(h, n), 0.0); - if (diff < 0.0) { - // Light not visible from this point on the surface - return vec3(0.0, 0.0, 0.0); - } - if (spec < 0.0) { - // Light reflection in opposite direction as viewer, apply only diffuse - // component - return light_intensity * (k_d * diff); - } +// if (diff < 0.0) { +// // Light not visible from this point on the surface +// return vec3(0.0, 0.0, 0.0); +// } +// if (spec < 0.0) { +// // Light reflection in opposite direction as viewer, apply only diffuse +// // component +// return light_intensity * (k_d * diff); +// } return light_intensity * (k_d * diff + k_s * pow(spec, alpha)); } diff --git a/src/shaders/main.frag b/src/shaders/main.frag index de9c978..b325b96 100644 --- a/src/shaders/main.frag +++ b/src/shaders/main.frag @@ -256,7 +256,6 @@ Distance sd_city(vec3 p) { q -= vec3(o.x, 0., o.y); d = min(d, sd_box(q, vec3(x_s, height, z_s))); - q.y -= height; // Building 2nd floor diff --git a/src/systems/container.rs b/src/systems/container.rs index 3dd743c..a7a34b5 100644 --- a/src/systems/container.rs +++ b/src/systems/container.rs @@ -4,7 +4,7 @@ use crate::physics::GamePhysics; use crate::renderer::render_objects::{MaterialType, ShapeType}; use crate::renderer::Renderer; use hecs::World; -use nalgebra::{Matrix4, Vector3}; +use nalgebra::{Vector3}; use rapier3d::prelude::*; pub fn spawn_container( diff --git a/src/systems/crate_box.rs b/src/systems/crate_box.rs index 3d53075..6a15c29 100644 --- a/src/systems/crate_box.rs +++ b/src/systems/crate_box.rs @@ -4,7 +4,7 @@ use crate::physics::GamePhysics; use crate::renderer::render_objects::{MaterialType, ShapeType}; use crate::renderer::Renderer; use hecs::World; -use nalgebra::{Matrix4, Vector3}; +use nalgebra::{Vector3}; use rapier3d::prelude::*; pub fn spawn_crate( diff --git a/src/systems/gunman.rs b/src/systems/gunman.rs index 52f3709..3807df0 100644 --- a/src/systems/gunman.rs +++ b/src/systems/gunman.rs @@ -6,10 +6,10 @@ use crate::renderer::render_objects::MaterialType; use crate::renderer::render_objects::ShapeType; use crate::renderer::Renderer; use hecs::World; -use nalgebra::{Matrix4, Point3, Vector3}; +use nalgebra::{Point3, Vector3}; use rand::prelude::SmallRng; use rapier3d::prelude::*; -use std::ops::Mul; + pub fn spawn_gunman( world: &mut World, diff --git a/src/systems/swordman.rs b/src/systems/swordman.rs index 4f6d6a3..2279585 100644 --- a/src/systems/swordman.rs +++ b/src/systems/swordman.rs @@ -7,7 +7,7 @@ use crate::renderer::render_objects::ShapeType; use crate::renderer::Renderer; use crate::scene::hit_and_dodge_scene::Score; use hecs::World; -use nalgebra::{Matrix4, Point3, Vector3}; +use nalgebra::{Point3, Vector3}; use rapier3d::prelude::*; pub fn spawn_swordman( diff --git a/src/systems/target.rs b/src/systems/target.rs index cec1e61..e9961f6 100644 --- a/src/systems/target.rs +++ b/src/systems/target.rs @@ -3,7 +3,7 @@ use crate::physics::GamePhysics; use crate::renderer::render_objects::ShapeType; use crate::renderer::Renderer; use hecs::World; -use nalgebra::{Matrix4, Vector3}; +use nalgebra::Vector3; use rand::prelude::SmallRng; use rapier3d::prelude::{ColliderBuilder, ColliderHandle, SharedShape}; @@ -28,13 +28,12 @@ pub fn spawn_target( ); } +#[allow(clippy::never_loop)] pub fn is_any_target_exists(world: &mut World) -> bool { - let mut exists = false; - for (_, (_)) in world.query_mut::<(&SphereTarget)>() { - exists = true; - break; + for (_, _) in world.query_mut::<&SphereTarget>() { + return true; } - exists + false } pub fn enqueue_target(world: &mut World, physics: &mut GamePhysics, renderer: &mut Renderer) { @@ -58,7 +57,7 @@ pub fn update_target( world: &mut World, physics: &mut GamePhysics, delta_time: f32, - rng: &mut SmallRng, + _rng: &mut SmallRng, ) { for (_id, (target, collider_handle)) in world.query_mut::<(&mut SphereTarget, &ColliderHandle)>() diff --git a/src/systems/wall.rs b/src/systems/wall.rs index 780f2d4..69e967e 100644 --- a/src/systems/wall.rs +++ b/src/systems/wall.rs @@ -4,7 +4,7 @@ use crate::physics::GamePhysics; use crate::renderer::render_objects::{MaterialType, ShapeType}; use crate::renderer::Renderer; use hecs::World; -use nalgebra::{Matrix4, Vector3}; +use nalgebra::{Vector3}; use rapier3d::prelude::*; pub fn spawn_wall(