diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 7745398a87..ee86873d33 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -89,16 +89,12 @@ impl AudioFrontend { ///```ignore ///audio.play_sound("voxygen.audio.sfx.step"); ///``` - pub fn play_sound(&mut self, sound: String, pos: Vec3) -> usize { + pub fn play_sound(&mut self, sound: &str, pos: Vec3) -> usize { let id = self.next_channel_id; self.next_channel_id += 1; if let Some(_) = &self.audio_device { - let calc_pos = [ - (pos.x - self.listener_pos.x) * FALLOFF, - (pos.y - self.listener_pos.y) * FALLOFF, - (pos.z - self.listener_pos.z) * FALLOFF, - ]; + let calc_pos = ((pos - self.listener_pos) * FALLOFF).into_array(); let sound = self.sound_cache.load_sound(sound); @@ -112,7 +108,7 @@ impl AudioFrontend { channel.set_right_ear_position(right_ear); channel.play(sound); } else { - println!("No available channels!"); + log::warn!("No available channels!"); } } @@ -133,18 +129,16 @@ impl AudioFrontend { for channel in self.channels.iter_mut() { if channel.get_audio_type() == AudioType::Sfx { - channel.set_emitter_position([ - (channel.pos.x - self.listener_pos.x) * FALLOFF, - (channel.pos.y - self.listener_pos.y) * FALLOFF, - (channel.pos.z - self.listener_pos.z) * FALLOFF, - ]); + channel.set_emitter_position( + ((channel.pos - self.listener_pos) * FALLOFF).into_array(), + ); channel.set_left_ear_position(pos_left.into_array()); channel.set_right_ear_position(pos_right.into_array()); } } } - pub fn play_music(&mut self, sound: String) -> usize { + pub fn play_music(&mut self, sound: &str) -> usize { let id = self.next_channel_id; self.next_channel_id += 1; diff --git a/voxygen/src/audio/soundcache.rs b/voxygen/src/audio/soundcache.rs index 451761c2a3..4af0ce9a9a 100644 --- a/voxygen/src/audio/soundcache.rs +++ b/voxygen/src/audio/soundcache.rs @@ -44,10 +44,10 @@ impl SoundCache { } } - pub fn load_sound(&mut self, name: String) -> rodio::Decoder> { + pub fn load_sound(&mut self, name: &str) -> rodio::Decoder> { self.sounds - .entry(name.clone()) - .or_insert(Sound::load(&name).unwrap()) + .entry(name.to_string()) + .or_insert(Sound::load(name).unwrap()) .decoder() } } diff --git a/voxygen/src/scene/sound.rs b/voxygen/src/scene/sound.rs index 26f7ab04e4..0a9d5d6e09 100644 --- a/voxygen/src/scene/sound.rs +++ b/voxygen/src/scene/sound.rs @@ -60,7 +60,7 @@ impl SoundMgr { if state.last_step_sound.elapsed().as_secs_f64() > 0.25 { let rand_step = (rand::random::() % 7) + 1; audio.play_sound( - format!("voxygen.audio.footsteps.stepdirt_{}", rand_step), + &format!("voxygen.audio.footsteps.stepdirt_{}", rand_step), pos.0, ); state.last_step_sound = Instant::now();