diff --git a/voxygen/src/audio/channel.rs b/voxygen/src/audio/channel.rs index ea918a54b0..5adaff6e7d 100644 --- a/voxygen/src/audio/channel.rs +++ b/voxygen/src/audio/channel.rs @@ -1,7 +1,7 @@ -use rodio::{SpatialSink, Decoder, Device, Source, Sample}; -use std::io::BufReader; -use std::fs::File; use crate::audio::fader::Fader; +use rodio::{Decoder, Device, Sample, Source, SpatialSink}; +use std::fs::File; +use std::io::BufReader; use vek::*; #[derive(PartialEq, Clone, Copy)] @@ -27,7 +27,7 @@ pub struct Channel { audio_type: AudioType, state: ChannelState, fader: Fader, - pub pos: Vec3::, + pub pos: Vec3, } // TODO: Implement asynchronous loading @@ -60,7 +60,7 @@ impl Channel { } } - pub fn sfx(id: usize, sink: SpatialSink, pos: Vec3::) -> Self { + pub fn sfx(id: usize, sink: SpatialSink, pos: Vec3) -> Self { Self { id, sink, @@ -76,7 +76,7 @@ impl Channel { S: Source + Send + 'static, S::Item: Sample, S::Item: Send, - ::Item: std::fmt::Debug, + ::Item: std::fmt::Debug, { self.state = ChannelState::Playing; self.sink.append(source); @@ -121,19 +121,17 @@ impl Channel { pub fn update(&mut self, dt: f32) { match self.state { - ChannelState::Init | ChannelState::ToPlay | ChannelState::Loading => { - - } - ChannelState::Playing => {}, - ChannelState::Stopping => { + ChannelState::Init | ChannelState::ToPlay | ChannelState::Loading => {} + ChannelState::Playing => {} + ChannelState::Stopping => { self.fader.update(dt); self.sink.set_volume(self.fader.get_volume()); if self.fader.is_finished() { self.state = ChannelState::Stopped; } - }, - ChannelState::Stopped => {}, + } + ChannelState::Stopped => {} } } } diff --git a/voxygen/src/audio/fader.rs b/voxygen/src/audio/fader.rs index b0e7fe9709..5adf960c5a 100644 --- a/voxygen/src/audio/fader.rs +++ b/voxygen/src/audio/fader.rs @@ -1,15 +1,14 @@ - #[derive(PartialEq, Clone, Copy)] pub struct Fader { length: f32, running_time: f32, volume_from: f32, volume_to: f32, - is_running: bool + is_running: bool, } fn lerp(t: f32, a: f32, b: f32) -> f32 { - (1.0 - t) * a + t * b + (1.0 - t) * a + t * b } impl Fader { @@ -54,7 +53,11 @@ impl Fader { } pub fn get_volume(&self) -> f32 { - lerp(self.running_time / self.length, self.volume_from, self.volume_to) + lerp( + self.running_time / self.length, + self.volume_from, + self.volume_to, + ) } pub fn is_finished(&self) -> bool { diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 00c079fbb6..ba63da5250 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -1,16 +1,15 @@ -pub mod fader; pub mod channel; +pub mod fader; pub mod soundcache; -use fader::Fader; use channel::{AudioType, Channel}; +use fader::Fader; use soundcache::SoundCache; use common::assets; use rodio::{Decoder, Device, SpatialSink}; use vek::*; -const FALLOFF : f32 = 0.13; - +const FALLOFF: f32 = 0.13; pub struct AudioFrontend { pub device: String, @@ -24,8 +23,8 @@ pub struct AudioFrontend { sfx_volume: f32, music_volume: f32, - listener_pos: Vec3::, - listener_ori: Vec3::, + listener_pos: Vec3, + listener_ori: Vec3, listener_pos_left: [f32; 3], listener_pos_right: [f32; 3], @@ -90,7 +89,7 @@ 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: String, pos: Vec3) -> usize { let id = self.next_channel_id; self.next_channel_id += 1; @@ -120,7 +119,7 @@ impl AudioFrontend { id } - pub fn set_listener_pos(&mut self, pos: &Vec3::, ori: &Vec3::) { + pub fn set_listener_pos(&mut self, pos: &Vec3, ori: &Vec3) { self.listener_pos = pos.clone(); self.listener_ori = ori.normalized(); diff --git a/voxygen/src/audio/soundcache.rs b/voxygen/src/audio/soundcache.rs index 3ed26e33a3..451761c2a3 100644 --- a/voxygen/src/audio/soundcache.rs +++ b/voxygen/src/audio/soundcache.rs @@ -1,14 +1,14 @@ -use rodio; +use common::assets; use hashbrown::HashMap; +use rodio; +use std::convert::AsRef; use std::io; use std::io::Read; -use std::convert::AsRef; -use common::assets; use std::sync::Arc; // Implementation of sound taken from this github issue: // https://github.com/RustAudio/rodio/issues/141 -pub struct Sound (Arc>); +pub struct Sound(Arc>); impl AsRef<[u8]> for Sound { fn as_ref(&self) -> &[u8] { @@ -40,7 +40,7 @@ pub struct SoundCache { impl SoundCache { pub fn new() -> Self { Self { - sounds: HashMap::new() + sounds: HashMap::new(), } }