mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Format files
This commit is contained in:
parent
2bca20cf69
commit
8e5f993a5b
@ -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::<f32>,
|
||||
pub pos: Vec3<f32>,
|
||||
}
|
||||
|
||||
// TODO: Implement asynchronous loading
|
||||
@ -60,7 +60,7 @@ impl Channel {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sfx(id: usize, sink: SpatialSink, pos: Vec3::<f32>) -> Self {
|
||||
pub fn sfx(id: usize, sink: SpatialSink, pos: Vec3<f32>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
sink,
|
||||
@ -76,7 +76,7 @@ impl Channel {
|
||||
S: Source + Send + 'static,
|
||||
S::Item: Sample,
|
||||
S::Item: Send,
|
||||
<S as std::iter::Iterator>::Item: std::fmt::Debug,
|
||||
<S as std::iter::Iterator>::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 => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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::<f32>,
|
||||
listener_ori: Vec3::<f32>,
|
||||
listener_pos: Vec3<f32>,
|
||||
listener_ori: Vec3<f32>,
|
||||
|
||||
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::<f32>) -> usize {
|
||||
pub fn play_sound(&mut self, sound: String, pos: Vec3<f32>) -> 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::<f32>, ori: &Vec3::<f32>) {
|
||||
pub fn set_listener_pos(&mut self, pos: &Vec3<f32>, ori: &Vec3<f32>) {
|
||||
self.listener_pos = pos.clone();
|
||||
self.listener_ori = ori.normalized();
|
||||
|
||||
|
@ -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<Vec<u8>>);
|
||||
pub struct Sound(Arc<Vec<u8>>);
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user