Prevent framerate drop when accessing settings menu

Former-commit-id: f51d1b700cd328b8156c7df97d6524277cc0718b
This commit is contained in:
Louis Pearson 2019-05-20 23:07:57 -06:00
parent 4dfebb779e
commit eeceef12ef
2 changed files with 16 additions and 3 deletions

View File

@ -17,6 +17,8 @@ use vek::*;
pub struct AudioFrontend { pub struct AudioFrontend {
device: Device, device: Device,
// Performance optimisation, iterating through available audio devices takes time
devices: Vec<Device>,
// streams: HashMap<String, SpatialSink>, //always use SpatialSink even if no possition is used for now // streams: HashMap<String, SpatialSink>, //always use SpatialSink even if no possition is used for now
stream: SpatialSink, stream: SpatialSink,
} }
@ -36,6 +38,7 @@ impl AudioFrontend {
device, device,
// streams: HashMap::<String, SpatialSink>::new(), // streams: HashMap::<String, SpatialSink>::new(),
stream: sink, stream: sink,
devices: AudioFrontend::get_devices_raw(),
} }
} }
@ -73,8 +76,18 @@ impl AudioFrontend {
/// Returns a vec of the audio devices available. /// Returns a vec of the audio devices available.
/// Does not return rodio Device struct in case our audio backend changes. /// Does not return rodio Device struct in case our audio backend changes.
pub fn get_devices() -> Vec<String> { pub fn get_devices(&self) -> Vec<String> {
rodio::output_devices().map(|x| x.name()).collect() self.devices.iter().map(|x| x.name()).collect()
}
/// Returns vec of devices
fn get_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()
} }
/// Returns the default audio device. /// Returns the default audio device.

View File

@ -563,7 +563,7 @@ impl<'a> Widget for SettingsWindow<'a> {
// Audio Device Selector -------------------------------------------- // Audio Device Selector --------------------------------------------
let device = self.global_state.audio.get_device(); 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") Text::new("Volume")
.down_from(state.ids.audio_volume_slider, 10.0) .down_from(state.ids.audio_volume_slider, 10.0)
.font_size(14) .font_size(14)