From 59064858cb13bf5433ac74bc5d9593977a4d87f4 Mon Sep 17 00:00:00 2001 From: pjht Date: Wed, 31 Jan 2024 10:23:27 -0600 Subject: [PATCH] Split EmuState creation to dedicated new function --- src/main.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6c5354d..725ccea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,6 +70,20 @@ struct EmuState { } impl EmuState { + fn new(audio_tx: Sender, options: Options) -> Self { + let mut mem = [0; 65536]; + rand::thread_rng().fill_bytes(&mut mem); + let mut slf = EmuState { + mem, + cpu: I8080::new(), + running: false, + audio_tx, + options, + fp_state: FrontpanelState::new() + }; + slf.apply_options(); + slf + } fn handle_fp_interaction(&mut self, interaction: FrontpanelInteraction) { self.audio_tx.send(AudioMessage::PlaySwitchClick).unwrap(); match interaction { @@ -192,6 +206,9 @@ impl EmuState { fn update_options(&mut self, new_opts: Options) { self.options = new_opts; + self.apply_options(); + } + fn apply_options(&mut self) { if self.options.mute { self.audio_tx.send(AudioMessage::SetVolume(0.0)).unwrap(); } else { @@ -218,26 +235,9 @@ impl AltairEmulator { } else { eframe::get_value(cc.storage.unwrap(), "options").unwrap() }; - if options.mute { - audio_tx.send(AudioMessage::SetVolume(0.0)).unwrap(); - } else { - audio_tx - .send(AudioMessage::SetVolume(options.volume)) - .unwrap(); - } - let mut mem = [0; 65536]; - let cpu = I8080::new(); - rand::thread_rng().fill_bytes(&mut mem); Self { textures: Textures::new(&cc.egui_ctx), - state: EmuState { - mem, - cpu, - running: false, - audio_tx, - options, - fp_state: FrontpanelState::new(), - }, + state: EmuState::new(audio_tx, options), windows: HashMap::new(), } }