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 {
|
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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user