mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Remove hacks, clean up crufty code
Former-commit-id: 7c10103235e8d9e2967baa1f8e33d68995bdf4d5
This commit is contained in:
parent
affa5c081e
commit
e78ae4fefc
@ -25,10 +25,13 @@ pub struct AudioFrontend {
|
||||
|
||||
impl AudioFrontend {
|
||||
pub fn new(settings: &AudioSettings) -> Self {
|
||||
let mut device = rodio::output_devices()
|
||||
.find(|x| x.name() == settings.audio_device)
|
||||
.or_else(rodio::default_output_device)
|
||||
.expect("No Audio devices found");
|
||||
let mut device = match &settings.audio_device {
|
||||
Some(dev) => rodio::output_devices()
|
||||
.find(|x| &x.name() == dev)
|
||||
.or_else(rodio::default_output_device)
|
||||
.expect("No Audio devices found"),
|
||||
None => rodio::default_output_device().expect("No audio devices found"),
|
||||
};
|
||||
|
||||
let mut sink =
|
||||
rodio::SpatialSink::new(&device, [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]);
|
||||
@ -38,7 +41,7 @@ impl AudioFrontend {
|
||||
device,
|
||||
// streams: HashMap::<String, SpatialSink>::new(),
|
||||
stream: sink,
|
||||
devices: AudioFrontend::get_devices_raw(),
|
||||
devices: AudioFrontend::list_devices_raw(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,18 +79,18 @@ impl AudioFrontend {
|
||||
|
||||
/// Returns a vec of the audio devices available.
|
||||
/// Does not return rodio Device struct in case our audio backend changes.
|
||||
pub fn get_devices(&self) -> Vec<String> {
|
||||
pub fn list_device_names(&self) -> Vec<String> {
|
||||
self.devices.iter().map(|x| x.name()).collect()
|
||||
}
|
||||
|
||||
/// Returns vec of devices
|
||||
fn get_devices_raw() -> Vec<Device> {
|
||||
fn list_devices_raw() -> Vec<Device> {
|
||||
rodio::output_devices().collect()
|
||||
}
|
||||
|
||||
/// Caches vec of devices for later reference
|
||||
fn collect_devices(&mut self) {
|
||||
self.devices = AudioFrontend::get_devices_raw()
|
||||
fn maintain_devices(&mut self) {
|
||||
self.devices = AudioFrontend::list_devices_raw()
|
||||
}
|
||||
|
||||
/// Returns the default audio device.
|
||||
@ -100,7 +103,7 @@ impl AudioFrontend {
|
||||
|
||||
/// Returns the name of the current audio device.
|
||||
/// Does not return rodio Device struct in case our audio backend changes.
|
||||
pub fn get_device(&self) -> String {
|
||||
pub fn get_device_name(&self) -> String {
|
||||
self.device.name()
|
||||
}
|
||||
|
||||
|
@ -562,8 +562,8 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
}
|
||||
|
||||
// Audio Device Selector --------------------------------------------
|
||||
let device = self.global_state.audio.get_device();
|
||||
let device_list = self.global_state.audio.get_devices();
|
||||
let device = self.global_state.audio.get_device_name();
|
||||
let device_list = self.global_state.audio.list_device_names();
|
||||
Text::new("Volume")
|
||||
.down_from(state.ids.audio_volume_slider, 10.0)
|
||||
.font_size(14)
|
||||
|
@ -159,8 +159,8 @@ fn main() {
|
||||
default_hook(panic_info);
|
||||
}));
|
||||
|
||||
if settings.audio.audio_device == "" {
|
||||
settings.audio.audio_device = AudioFrontend::get_default_device();
|
||||
if settings.audio.audio_device == None {
|
||||
settings.audio.audio_device = Some(AudioFrontend::get_default_device());
|
||||
}
|
||||
|
||||
let mut global_state = GlobalState {
|
||||
|
@ -202,7 +202,7 @@ impl PlayState for SessionState {
|
||||
HudEvent::ChangeAudioDevice(name) => {
|
||||
global_state.audio.set_device(name.clone());
|
||||
|
||||
global_state.settings.audio.audio_device = name;
|
||||
global_state.settings.audio.audio_device = Some(name);
|
||||
global_state.settings.save_to_file();
|
||||
}
|
||||
}
|
||||
|
@ -60,20 +60,14 @@ pub struct GraphicsSettings {
|
||||
}
|
||||
|
||||
/// AudioSettings controls the volume of different audio subsystems and which
|
||||
/// which device is used.
|
||||
/// device is used.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct AudioSettings {
|
||||
pub music_volume: f32,
|
||||
pub sfx_volume: f32,
|
||||
|
||||
/// Audio Device that Voxygen wil use to play audio.
|
||||
pub audio_device: String,
|
||||
|
||||
/// Audio devices that are available. Listed here so that it can be accessed
|
||||
/// from the settings editor in the HUD, but skipped over because it is a
|
||||
/// runtime specific detail that should not be persisted.
|
||||
#[serde(skip)]
|
||||
pub audio_devices: Vec<String>,
|
||||
/// Audio Device that Voxygen will use to play audio.
|
||||
pub audio_device: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
@ -114,8 +108,7 @@ impl Default for Settings {
|
||||
audio: AudioSettings {
|
||||
music_volume: 0.5,
|
||||
sfx_volume: 0.5,
|
||||
audio_device: "".to_string(),
|
||||
audio_devices: vec![],
|
||||
audio_device: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user