Prettify sdl2 main loop

Former-commit-id: dc925873f8a27bc8f50392659fad3cb07adde82e
Former-commit-id: 50ca19536687bd058c906168b28a86a95c6a42d5
This commit is contained in:
Michel Heily 2020-05-01 18:36:41 +03:00
parent 051d5e1235
commit 27a7cb14cf

View file

@ -255,40 +255,27 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for event in event_pump.poll_iter() { for event in event_pump.poll_iter() {
match event { match event {
Event::KeyDown { Event::KeyDown {
keycode: Some(Keycode::Space), keycode: Some(keycode),
.. ..
} => { } => match keycode {
frame_limiter = false; Keycode::Space => frame_limiter = false,
} k => input.borrow_mut().on_keyboard_key_down(k),
},
Event::KeyUp { Event::KeyUp {
keycode: Some(Keycode::Space), keycode: Some(keycode),
.. ..
} => { } => match keycode {
frame_limiter = true;
}
#[cfg(feature = "debugger")] #[cfg(feature = "debugger")]
Event::KeyUp { Keycode::F1 => {
keycode: Some(Keycode::F1),
..
} => {
let mut debugger = Debugger::new(gba); let mut debugger = Debugger::new(gba);
info!("starting debugger..."); info!("starting debugger...");
debugger.repl(matches.value_of("script_file")).unwrap(); debugger.repl(matches.value_of("script_file")).unwrap();
gba = debugger.gba; gba = debugger.gba;
info!("ending debugger..."); info!("ending debugger...")
break;
} }
#[cfg(feature = "gdb")] #[cfg(feature = "gdb")]
Event::KeyUp { Keycode::F2 => spawn_and_run_gdb_server(&mut gba, DEFAULT_GDB_SERVER_ADDR)?,
keycode: Some(Keycode::F2), Keycode::F5 => {
..
} => {
spawn_and_run_gdb_server(&mut gba, DEFAULT_GDB_SERVER_ADDR)?;
}
Event::KeyUp {
keycode: Some(Keycode::F5),
..
} => {
info!("Saving state ..."); info!("Saving state ...");
let save = gba.save_state()?; let save = gba.save_state()?;
write_bin_file(&savestate_path, &save)?; write_bin_file(&savestate_path, &save)?;
@ -298,10 +285,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
bytesize::ByteSize::b(save.len() as u64) bytesize::ByteSize::b(save.len() as u64)
); );
} }
Event::KeyUp { Keycode::F9 => {
keycode: Some(Keycode::F9),
..
} => {
if savestate_path.is_file() { if savestate_path.is_file() {
let save = read_bin_file(&savestate_path)?; let save = read_bin_file(&savestate_path)?;
info!("Restoring state from {:?}...", savestate_path); info!("Restoring state from {:?}...", savestate_path);
@ -311,18 +295,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Savestate not created, please create one by pressing F5"); info!("Savestate not created, please create one by pressing F5");
} }
} }
Event::KeyDown { Keycode::Space => frame_limiter = true,
keycode: Some(keycode), k => input.borrow_mut().on_keyboard_key_up(k),
.. },
} => {
input.borrow_mut().on_keyboard_key_down(keycode);
}
Event::KeyUp {
keycode: Some(keycode),
..
} => {
input.borrow_mut().on_keyboard_key_up(keycode);
}
Event::Quit { .. } => break 'running, Event::Quit { .. } => break 'running,
Event::DropFile { filename, .. } => { Event::DropFile { filename, .. } => {
// load the new rom // load the new rom