From 27a7cb14cf2278186584f2789a6a649c47bff633 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Fri, 1 May 2020 18:36:41 +0300 Subject: [PATCH] Prettify sdl2 main loop Former-commit-id: dc925873f8a27bc8f50392659fad3cb07adde82e Former-commit-id: 50ca19536687bd058c906168b28a86a95c6a42d5 --- platform/rustboyadvance-sdl2/src/main.rs | 103 +++++++++-------------- 1 file changed, 39 insertions(+), 64 deletions(-) diff --git a/platform/rustboyadvance-sdl2/src/main.rs b/platform/rustboyadvance-sdl2/src/main.rs index 2d14726..1d17f27 100644 --- a/platform/rustboyadvance-sdl2/src/main.rs +++ b/platform/rustboyadvance-sdl2/src/main.rs @@ -255,74 +255,49 @@ fn main() -> Result<(), Box> { for event in event_pump.poll_iter() { match event { Event::KeyDown { - keycode: Some(Keycode::Space), + keycode: Some(keycode), .. - } => { - frame_limiter = false; - } + } => match keycode { + Keycode::Space => frame_limiter = false, + k => input.borrow_mut().on_keyboard_key_down(k), + }, Event::KeyUp { - keycode: Some(Keycode::Space), + keycode: Some(keycode), .. - } => { - frame_limiter = true; - } - #[cfg(feature = "debugger")] - Event::KeyUp { - keycode: Some(Keycode::F1), - .. - } => { - let mut debugger = Debugger::new(gba); - info!("starting debugger..."); - debugger.repl(matches.value_of("script_file")).unwrap(); - gba = debugger.gba; - info!("ending debugger..."); - break; - } - #[cfg(feature = "gdb")] - Event::KeyUp { - keycode: Some(Keycode::F2), - .. - } => { - spawn_and_run_gdb_server(&mut gba, DEFAULT_GDB_SERVER_ADDR)?; - } - Event::KeyUp { - keycode: Some(Keycode::F5), - .. - } => { - info!("Saving state ..."); - let save = gba.save_state()?; - write_bin_file(&savestate_path, &save)?; - info!( - "Saved to {:?} ({})", - savestate_path, - bytesize::ByteSize::b(save.len() as u64) - ); - } - Event::KeyUp { - keycode: Some(Keycode::F9), - .. - } => { - if savestate_path.is_file() { - let save = read_bin_file(&savestate_path)?; - info!("Restoring state from {:?}...", savestate_path); - gba.restore_state(&save)?; - info!("Restored!"); - } else { - info!("Savestate not created, please create one by pressing F5"); + } => match keycode { + #[cfg(feature = "debugger")] + Keycode::F1 => { + let mut debugger = Debugger::new(gba); + info!("starting debugger..."); + debugger.repl(matches.value_of("script_file")).unwrap(); + gba = debugger.gba; + info!("ending debugger...") } - } - Event::KeyDown { - keycode: Some(keycode), - .. - } => { - input.borrow_mut().on_keyboard_key_down(keycode); - } - Event::KeyUp { - keycode: Some(keycode), - .. - } => { - input.borrow_mut().on_keyboard_key_up(keycode); - } + #[cfg(feature = "gdb")] + Keycode::F2 => spawn_and_run_gdb_server(&mut gba, DEFAULT_GDB_SERVER_ADDR)?, + Keycode::F5 => { + info!("Saving state ..."); + let save = gba.save_state()?; + write_bin_file(&savestate_path, &save)?; + info!( + "Saved to {:?} ({})", + savestate_path, + bytesize::ByteSize::b(save.len() as u64) + ); + } + Keycode::F9 => { + if savestate_path.is_file() { + let save = read_bin_file(&savestate_path)?; + info!("Restoring state from {:?}...", savestate_path); + gba.restore_state(&save)?; + info!("Restored!"); + } else { + info!("Savestate not created, please create one by pressing F5"); + } + } + Keycode::Space => frame_limiter = true, + k => input.borrow_mut().on_keyboard_key_up(k), + }, Event::Quit { .. } => break 'running, Event::DropFile { filename, .. } => { // load the new rom