mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
feat: configure audio output using an enum
This commit is contained in:
parent
a83f09bd60
commit
3806f08eb0
@ -8,7 +8,7 @@ use veloren_voxygen::{
|
|||||||
logging,
|
logging,
|
||||||
menu::main::MainMenuState,
|
menu::main::MainMenuState,
|
||||||
meta::Meta,
|
meta::Meta,
|
||||||
settings::Settings,
|
settings::{AudioOutput, Settings},
|
||||||
window::Window,
|
window::Window,
|
||||||
Direction, GlobalState, PlayState, PlayStateResult,
|
Direction, GlobalState, PlayState, PlayStateResult,
|
||||||
};
|
};
|
||||||
@ -45,20 +45,13 @@ fn main() {
|
|||||||
panic!("Failed to save settings: {:?}", err);
|
panic!("Failed to save settings: {:?}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut audio = settings
|
let mut audio = match settings.audio.output {
|
||||||
.audio
|
AudioOutput::Off => None,
|
||||||
.audio_on
|
AudioOutput::Automatic => audio::get_default_device(),
|
||||||
.then(|| {
|
AudioOutput::Device(ref dev) => Some(dev.clone()),
|
||||||
settings
|
}
|
||||||
.audio
|
.map(|dev| AudioFrontend::new(dev, settings.audio.max_sfx_channels))
|
||||||
.audio_device
|
.unwrap_or_else(AudioFrontend::no_audio);
|
||||||
.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_music_volume(settings.audio.music_volume);
|
||||||
audio.set_sfx_volume(settings.audio.sfx_volume);
|
audio.set_sfx_volume(settings.audio.sfx_volume);
|
||||||
|
@ -36,7 +36,7 @@ impl PlayState for MainMenuState {
|
|||||||
let mut client_init: Option<ClientInit> = None;
|
let mut client_init: Option<ClientInit> = None;
|
||||||
|
|
||||||
// Kick off title music
|
// Kick off title music
|
||||||
if global_state.settings.audio.audio_on && global_state.audio.music_enabled() {
|
if global_state.settings.audio.output.is_enabled() && global_state.audio.music_enabled() {
|
||||||
global_state.audio.play_title_music();
|
global_state.audio.play_title_music();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ use crate::{
|
|||||||
menu::char_selection::CharSelectionState,
|
menu::char_selection::CharSelectionState,
|
||||||
render::Renderer,
|
render::Renderer,
|
||||||
scene::{camera, Scene, SceneData},
|
scene::{camera, Scene, SceneData},
|
||||||
|
settings::AudioOutput,
|
||||||
window::{AnalogGameInput, Event, GameInput},
|
window::{AnalogGameInput, Event, GameInput},
|
||||||
Direction, Error, GlobalState, PlayState, PlayStateResult,
|
Direction, Error, GlobalState, PlayState, PlayStateResult,
|
||||||
};
|
};
|
||||||
@ -613,7 +614,7 @@ impl PlayState for SessionState {
|
|||||||
HudEvent::ChangeAudioDevice(name) => {
|
HudEvent::ChangeAudioDevice(name) => {
|
||||||
global_state.audio.set_device(name.clone());
|
global_state.audio.set_device(name.clone());
|
||||||
|
|
||||||
global_state.settings.audio.audio_device = Some(name);
|
global_state.settings.audio.output = AudioOutput::Device(name);
|
||||||
global_state.settings.save_to_file_warn();
|
global_state.settings.save_to_file_warn();
|
||||||
},
|
},
|
||||||
HudEvent::ChangeMaxFPS(fps) => {
|
HudEvent::ChangeMaxFPS(fps) => {
|
||||||
|
@ -461,7 +461,26 @@ impl Default for GraphicsSettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub enum AudioOutput {
|
||||||
|
/// 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.
|
||||||
|
Off,
|
||||||
|
Automatic,
|
||||||
|
Device(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AudioOutput {
|
||||||
|
pub fn is_enabled(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Off => false,
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// `AudioSettings` controls the volume of different audio subsystems and which
|
/// `AudioSettings` controls the volume of different audio subsystems and which
|
||||||
/// device is used.
|
/// device is used.
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
@ -473,13 +492,7 @@ pub struct AudioSettings {
|
|||||||
pub max_sfx_channels: usize,
|
pub max_sfx_channels: usize,
|
||||||
|
|
||||||
/// Audio Device that Voxygen will use to play audio.
|
/// Audio Device that Voxygen will use to play audio.
|
||||||
pub audio_device: Option<String>,
|
pub output: AudioOutput,
|
||||||
/// 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,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AudioSettings {
|
impl Default for AudioSettings {
|
||||||
@ -489,8 +502,7 @@ impl Default for AudioSettings {
|
|||||||
music_volume: 0.4,
|
music_volume: 0.4,
|
||||||
sfx_volume: 0.6,
|
sfx_volume: 0.6,
|
||||||
max_sfx_channels: 10,
|
max_sfx_channels: 10,
|
||||||
audio_device: None,
|
output: AudioOutput::Automatic,
|
||||||
audio_on: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user