Split EmuState creation to dedicated new function
This commit is contained in:
parent
708bc2ba87
commit
59064858cb
36
src/main.rs
36
src/main.rs
@ -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(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user