diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index fe62005b69..463afc16b4 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -17,6 +17,8 @@ use vek::*; pub struct AudioFrontend { device: Device, + // Performance optimisation, iterating through available audio devices takes time + devices: Vec, // streams: HashMap, //always use SpatialSink even if no possition is used for now stream: SpatialSink, } @@ -36,6 +38,7 @@ impl AudioFrontend { device, // streams: HashMap::::new(), stream: sink, + devices: AudioFrontend::get_devices_raw(), } } @@ -73,8 +76,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() -> Vec { - rodio::output_devices().map(|x| x.name()).collect() + pub fn get_devices(&self) -> Vec { + self.devices.iter().map(|x| x.name()).collect() + } + + /// Returns vec of devices + fn get_devices_raw() -> Vec { + rodio::output_devices().collect() + } + + /// Caches vec of devices for later reference + fn collect_devices(&mut self) { + self.devices = AudioFrontend::get_devices_raw() } /// Returns the default audio device. diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 70d23d5918..5426067a74 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -563,7 +563,7 @@ impl<'a> Widget for SettingsWindow<'a> { // Audio Device Selector -------------------------------------------- let device = self.global_state.audio.get_device(); - let device_list = AudioFrontend::get_devices(); + let device_list = self.global_state.audio.get_devices(); Text::new("Volume") .down_from(state.ids.audio_volume_slider, 10.0) .font_size(14)