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