fix: avoid rodio API when audio is disabled

This commit is contained in:
Marli Frost 2020-03-31 18:02:26 +01:00
parent c82d1b9316
commit a83f09bd60
No known key found for this signature in database
GPG Key ID: CB0BEA7CF9BD1245
2 changed files with 19 additions and 10 deletions

View File

@ -1,4 +1,5 @@
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![feature(bool_to_option)]
#![recursion_limit = "2048"] #![recursion_limit = "2048"]
use veloren_voxygen::{ use veloren_voxygen::{
@ -44,17 +45,20 @@ fn main() {
panic!("Failed to save settings: {:?}", err); panic!("Failed to save settings: {:?}", err);
} }
let audio_device = settings let mut audio = settings
.audio
.audio_on
.then(|| {
settings
.audio .audio
.audio_device .audio_device
.as_ref() .as_ref()
.map(|s| s.clone()) .map(Clone::clone)
.or_else(audio::get_default_device); .or_else(audio::get_default_device)
})
let mut audio = match (audio_device, settings.audio.audio_on) { .flatten()
(Some(dev), true) => AudioFrontend::new(dev, settings.audio.max_sfx_channels), .map(|dev| AudioFrontend::new(dev, settings.audio.max_sfx_channels))
_ => AudioFrontend::no_audio() .unwrap_or_else(AudioFrontend::no_audio);
};
audio.set_music_volume(settings.audio.music_volume); audio.set_music_volume(settings.audio.music_volume);
audio.set_sfx_volume(settings.audio.sfx_volume); audio.set_sfx_volume(settings.audio.sfx_volume);

View File

@ -474,6 +474,11 @@ pub struct AudioSettings {
/// Audio Device that Voxygen will use to play audio. /// Audio Device that Voxygen will use to play audio.
pub audio_device: Option<String>, pub audio_device: Option<String>,
/// Veloren's audio system wont work on some systems,
/// so you can use this to disable it, and allow the
/// game to function
// If this option is disabled, functions in the rodio
// library MUST NOT be called.
pub audio_on: bool, pub audio_on: bool,
} }