dont fully reinitialise if u dont need to
This commit is contained in:
parent
11dec11079
commit
0f919c612c
|
@ -112,24 +112,32 @@ impl Plugin for GameboyEmu {
|
|||
verbose: false,
|
||||
cycle_count: false,
|
||||
};
|
||||
let (sender, receiver) = channel::<EmulatorMessage>();
|
||||
|
||||
let (output, rx) = AudioOutput::new_unfilled(buffer_config.sample_rate, false);
|
||||
if let Some(ref mut vars) = self.vars {
|
||||
let (output, rx) = AudioOutput::new_unfilled(buffer_config.sample_rate, false);
|
||||
|
||||
let (renderer, frame_receiver, key_handler) = EmulatorRenderer::new();
|
||||
vars.emulator_core.replace_output(output);
|
||||
vars.rx = rx;
|
||||
} else {
|
||||
let (sender, receiver) = channel::<EmulatorMessage>();
|
||||
|
||||
*self.frame_receiver.lock().unwrap() = Some(frame_receiver);
|
||||
*self.key_handler.lock().unwrap() = Some(key_handler);
|
||||
let (output, rx) = AudioOutput::new_unfilled(buffer_config.sample_rate, false);
|
||||
|
||||
let mut emulator_core =
|
||||
EmulatorCore::init(receiver, options, Box::new(renderer), output, None);
|
||||
emulator_core.run_until_buffer_full();
|
||||
let (renderer, frame_receiver, key_handler) = EmulatorRenderer::new();
|
||||
|
||||
self.vars = Some(EmuVars {
|
||||
rx,
|
||||
sender,
|
||||
emulator_core,
|
||||
});
|
||||
*self.frame_receiver.lock().unwrap() = Some(frame_receiver);
|
||||
*self.key_handler.lock().unwrap() = Some(key_handler);
|
||||
|
||||
let mut emulator_core =
|
||||
EmulatorCore::init(receiver, options, Box::new(renderer), output, None);
|
||||
emulator_core.run_until_buffer_full();
|
||||
|
||||
self.vars = Some(EmuVars {
|
||||
rx,
|
||||
sender,
|
||||
emulator_core,
|
||||
});
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
|
|
@ -124,6 +124,10 @@ impl<ColourFormat: From<Colour> + Clone> EmulatorCore<ColourFormat> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn replace_output(&mut self, new: AudioOutput) {
|
||||
self.cpu.memory.replace_output(new);
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
self.process_messages();
|
||||
self.cycle_num += 1;
|
||||
|
|
|
@ -226,6 +226,10 @@ impl<ColourFormat: From<Colour> + Clone> Memory<ColourFormat> {
|
|||
pub fn is_audio_buffer_full(&self) -> bool {
|
||||
self.apu.is_buffer_full()
|
||||
}
|
||||
|
||||
pub fn replace_output(&mut self, new: AudioOutput) {
|
||||
self.apu.replace_output(new);
|
||||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone> Cpu<ColourFormat> {
|
||||
|
|
|
@ -64,6 +64,11 @@ impl Apu {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn replace_output(&mut self, new: AudioOutput) {
|
||||
self.converter = Downsampler::new(new.sample_rate);
|
||||
self.output = new;
|
||||
}
|
||||
|
||||
pub fn div_apu_tick(&mut self) {
|
||||
self.div_apu = self.div_apu.wrapping_add(1);
|
||||
if self.div_apu % 8 == 0 {
|
||||
|
|
Loading…
Reference in a new issue