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 crate::audio::fader::Fader;
|
||||||
|
use rodio::{Decoder, Device, Sample, Source, SpatialSink};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::BufReader;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Copy)]
|
#[derive(PartialEq, Clone, Copy)]
|
||||||
@ -27,7 +27,7 @@ pub struct Channel {
|
|||||||
audio_type: AudioType,
|
audio_type: AudioType,
|
||||||
state: ChannelState,
|
state: ChannelState,
|
||||||
fader: Fader,
|
fader: Fader,
|
||||||
pub pos: Vec3::<f32>,
|
pub pos: Vec3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement asynchronous loading
|
// 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 {
|
Self {
|
||||||
id,
|
id,
|
||||||
sink,
|
sink,
|
||||||
@ -121,10 +121,8 @@ impl Channel {
|
|||||||
|
|
||||||
pub fn update(&mut self, dt: f32) {
|
pub fn update(&mut self, dt: f32) {
|
||||||
match self.state {
|
match self.state {
|
||||||
ChannelState::Init | ChannelState::ToPlay | ChannelState::Loading => {
|
ChannelState::Init | ChannelState::ToPlay | ChannelState::Loading => {}
|
||||||
|
ChannelState::Playing => {}
|
||||||
}
|
|
||||||
ChannelState::Playing => {},
|
|
||||||
ChannelState::Stopping => {
|
ChannelState::Stopping => {
|
||||||
self.fader.update(dt);
|
self.fader.update(dt);
|
||||||
self.sink.set_volume(self.fader.get_volume());
|
self.sink.set_volume(self.fader.get_volume());
|
||||||
@ -132,8 +130,8 @@ impl Channel {
|
|||||||
if self.fader.is_finished() {
|
if self.fader.is_finished() {
|
||||||
self.state = ChannelState::Stopped;
|
self.state = ChannelState::Stopped;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
ChannelState::Stopped => {},
|
ChannelState::Stopped => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
#[derive(PartialEq, Clone, Copy)]
|
#[derive(PartialEq, Clone, Copy)]
|
||||||
pub struct Fader {
|
pub struct Fader {
|
||||||
length: f32,
|
length: f32,
|
||||||
running_time: f32,
|
running_time: f32,
|
||||||
volume_from: f32,
|
volume_from: f32,
|
||||||
volume_to: f32,
|
volume_to: f32,
|
||||||
is_running: bool
|
is_running: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lerp(t: f32, a: f32, b: f32) -> f32 {
|
fn lerp(t: f32, a: f32, b: f32) -> f32 {
|
||||||
@ -54,7 +53,11 @@ impl Fader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_volume(&self) -> f32 {
|
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 {
|
pub fn is_finished(&self) -> bool {
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
pub mod fader;
|
|
||||||
pub mod channel;
|
pub mod channel;
|
||||||
|
pub mod fader;
|
||||||
pub mod soundcache;
|
pub mod soundcache;
|
||||||
use fader::Fader;
|
|
||||||
use channel::{AudioType, Channel};
|
use channel::{AudioType, Channel};
|
||||||
|
use fader::Fader;
|
||||||
use soundcache::SoundCache;
|
use soundcache::SoundCache;
|
||||||
|
|
||||||
use common::assets;
|
use common::assets;
|
||||||
use rodio::{Decoder, Device, SpatialSink};
|
use rodio::{Decoder, Device, SpatialSink};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
const FALLOFF : f32 = 0.13;
|
const FALLOFF: f32 = 0.13;
|
||||||
|
|
||||||
|
|
||||||
pub struct AudioFrontend {
|
pub struct AudioFrontend {
|
||||||
pub device: String,
|
pub device: String,
|
||||||
@ -24,8 +23,8 @@ pub struct AudioFrontend {
|
|||||||
sfx_volume: f32,
|
sfx_volume: f32,
|
||||||
music_volume: f32,
|
music_volume: f32,
|
||||||
|
|
||||||
listener_pos: Vec3::<f32>,
|
listener_pos: Vec3<f32>,
|
||||||
listener_ori: Vec3::<f32>,
|
listener_ori: Vec3<f32>,
|
||||||
|
|
||||||
listener_pos_left: [f32; 3],
|
listener_pos_left: [f32; 3],
|
||||||
listener_pos_right: [f32; 3],
|
listener_pos_right: [f32; 3],
|
||||||
@ -90,7 +89,7 @@ impl AudioFrontend {
|
|||||||
///```ignore
|
///```ignore
|
||||||
///audio.play_sound("voxygen.audio.sfx.step");
|
///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;
|
let id = self.next_channel_id;
|
||||||
self.next_channel_id += 1;
|
self.next_channel_id += 1;
|
||||||
|
|
||||||
@ -120,7 +119,7 @@ impl AudioFrontend {
|
|||||||
id
|
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_pos = pos.clone();
|
||||||
self.listener_ori = ori.normalized();
|
self.listener_ori = ori.normalized();
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use rodio;
|
use common::assets;
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
use rodio;
|
||||||
|
use std::convert::AsRef;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::convert::AsRef;
|
|
||||||
use common::assets;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
// Implementation of sound taken from this github issue:
|
// Implementation of sound taken from this github issue:
|
||||||
// https://github.com/RustAudio/rodio/issues/141
|
// https://github.com/RustAudio/rodio/issues/141
|
||||||
pub struct Sound (Arc<Vec<u8>>);
|
pub struct Sound(Arc<Vec<u8>>);
|
||||||
|
|
||||||
impl AsRef<[u8]> for Sound {
|
impl AsRef<[u8]> for Sound {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
@ -40,7 +40,7 @@ pub struct SoundCache {
|
|||||||
impl SoundCache {
|
impl SoundCache {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
sounds: HashMap::new()
|
sounds: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user