Split EmuState creation to dedicated new function

This commit is contained in:
pjht 2024-01-31 10:23:27 -06:00
parent 708bc2ba87
commit 59064858cb
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -70,6 +70,20 @@ struct EmuState {
} }
impl EmuState { impl EmuState {
fn new(audio_tx: Sender<AudioMessage>, 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) { fn handle_fp_interaction(&mut self, interaction: FrontpanelInteraction) {
self.audio_tx.send(AudioMessage::PlaySwitchClick).unwrap(); self.audio_tx.send(AudioMessage::PlaySwitchClick).unwrap();
match interaction { match interaction {
@ -192,6 +206,9 @@ impl EmuState {
fn update_options(&mut self, new_opts: Options) { fn update_options(&mut self, new_opts: Options) {
self.options = new_opts; self.options = new_opts;
self.apply_options();
}
fn apply_options(&mut self) {
if self.options.mute { if self.options.mute {
self.audio_tx.send(AudioMessage::SetVolume(0.0)).unwrap(); self.audio_tx.send(AudioMessage::SetVolume(0.0)).unwrap();
} else { } else {
@ -218,26 +235,9 @@ impl AltairEmulator {
} else { } else {
eframe::get_value(cc.storage.unwrap(), "options").unwrap() 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 { Self {
textures: Textures::new(&cc.egui_ctx), textures: Textures::new(&cc.egui_ctx),
state: EmuState { state: EmuState::new(audio_tx, options),
mem,
cpu,
running: false,
audio_tx,
options,
fp_state: FrontpanelState::new(),
},
windows: HashMap::new(), windows: HashMap::new(),
} }
} }