close windows
This commit is contained in:
parent
ed6ad62e22
commit
2685bc06e6
5 changed files with 23 additions and 23 deletions
|
@ -1,9 +1,8 @@
|
|||
use gb_emu_lib::connect::{EmulatorCoreTrait, EmulatorMessage};
|
||||
use gb_emu_lib::connect::EmulatorCoreTrait;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io::{self, Write},
|
||||
str::FromStr,
|
||||
sync::mpsc::Receiver,
|
||||
};
|
||||
|
||||
pub enum CommandErr {
|
||||
|
@ -49,7 +48,6 @@ impl FromStr for Commands {
|
|||
|
||||
pub struct Debugger {
|
||||
core: Box<dyn EmulatorCoreTrait>,
|
||||
debug_receiver: Receiver<EmulatorMessage>,
|
||||
stepping: bool,
|
||||
last_command: String,
|
||||
watches: HashMap<u16, u8>,
|
||||
|
@ -57,13 +55,9 @@ pub struct Debugger {
|
|||
}
|
||||
|
||||
impl Debugger {
|
||||
pub fn new(
|
||||
core: Box<dyn EmulatorCoreTrait>,
|
||||
debug_receiver: Receiver<EmulatorMessage>,
|
||||
) -> Self {
|
||||
pub fn new(core: Box<dyn EmulatorCoreTrait>) -> Self {
|
||||
Self {
|
||||
core,
|
||||
debug_receiver,
|
||||
stepping: true,
|
||||
last_command: String::from(""),
|
||||
watches: HashMap::new(),
|
||||
|
@ -72,9 +66,7 @@ impl Debugger {
|
|||
}
|
||||
|
||||
pub fn step(&mut self) {
|
||||
if let Ok(EmulatorMessage::Stop) = self.debug_receiver.try_recv() {
|
||||
self.core.run();
|
||||
}
|
||||
self.core.process_messages();
|
||||
if self.should_pause() {
|
||||
println!("cycles: {}", self.core.cycle_count());
|
||||
println!();
|
||||
|
|
|
@ -107,18 +107,19 @@ impl EmulatorHandler {
|
|||
};
|
||||
|
||||
let (sender, receiver) = channel::<EmulatorMessage>();
|
||||
let (debug_sender, debug_receiver) = channel::<EmulatorMessage>();
|
||||
|
||||
ctrlc::set_handler(move || {
|
||||
sender.send(EmulatorMessage::Stop).unwrap();
|
||||
debug_sender.send(EmulatorMessage::Stop).unwrap()
|
||||
})
|
||||
.unwrap();
|
||||
{
|
||||
let sender = sender.clone();
|
||||
ctrlc::set_handler(move || {
|
||||
sender.send(EmulatorMessage::Stop).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let (output, _stream) = audio::create_output(args.mute);
|
||||
let rom = RomFile::Path(args.rom);
|
||||
|
||||
let mut window_manager = WindowManager::new();
|
||||
let mut window_manager = WindowManager::new(sender);
|
||||
|
||||
let window = window_manager.add(factor, Some(Gilrs::new().unwrap()));
|
||||
let tile_window: Option<WindowRenderer> = if args.tile_window {
|
||||
|
@ -163,7 +164,7 @@ impl EmulatorHandler {
|
|||
let core = Box::new(EmulatorCore::init(receiver, options, Webcam::new()));
|
||||
|
||||
let emu = if args.debug {
|
||||
EmulatorTypes::Debug(Debugger::new(core, debug_receiver))
|
||||
EmulatorTypes::Debug(Debugger::new(core))
|
||||
} else {
|
||||
EmulatorTypes::Normal(core)
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
sync::{mpsc::Sender, Arc, Mutex},
|
||||
};
|
||||
|
||||
use gb_emu_lib::{
|
||||
connect::{JoypadState, Renderer},
|
||||
connect::{EmulatorMessage, JoypadState, Renderer},
|
||||
util::scale_buffer_in_place,
|
||||
};
|
||||
use gilrs::{
|
||||
|
@ -35,14 +35,16 @@ pub struct WindowManager {
|
|||
event_loop: EventLoop<()>,
|
||||
windows: HashMap<WindowId, Arc<WindowData>>,
|
||||
input: Arc<Mutex<WinitInputHelper>>,
|
||||
sender: Sender<EmulatorMessage>,
|
||||
}
|
||||
|
||||
impl WindowManager {
|
||||
pub(crate) fn new() -> Self {
|
||||
pub(crate) fn new(sender: Sender<EmulatorMessage>) -> Self {
|
||||
Self {
|
||||
event_loop: EventLoop::new(),
|
||||
windows: HashMap::new(),
|
||||
input: Arc::new(Mutex::new(WinitInputHelper::new())),
|
||||
sender,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +71,7 @@ impl WindowManager {
|
|||
event: WindowEvent::CloseRequested,
|
||||
window_id: _,
|
||||
} => {
|
||||
// quit = true;
|
||||
self.sender.send(EmulatorMessage::Stop).unwrap();
|
||||
}
|
||||
Event::MainEventsCleared => {
|
||||
control_flow.set_exit();
|
||||
|
|
|
@ -253,4 +253,5 @@ pub trait EmulatorCoreTrait {
|
|||
fn run(&mut self);
|
||||
fn run_stepped(&mut self, step_size: usize);
|
||||
fn run_until_buffer_full(&mut self);
|
||||
fn process_messages(&mut self);
|
||||
}
|
||||
|
|
|
@ -246,4 +246,8 @@ where
|
|||
self.run();
|
||||
}
|
||||
}
|
||||
|
||||
fn process_messages(&mut self) {
|
||||
self.process_messages();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue