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 {
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) {
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(),
}
}