From 3bc7c96191bb4b34eb5d2c61a75cbf3c96a719a7 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Thu, 2 Jul 2026 10:04:51 +0200 Subject: [PATCH] move input polling (#1145) * move input polling * more * more * more --- parallel-rdp/interface.cpp | 13 ++++++++----- parallel-rdp/wsi_platform.cpp | 2 +- src/device/controller.rs | 2 +- src/device/vi.rs | 1 - src/lib.rs | 2 -- src/netplay.rs | 3 +-- src/ui.rs | 12 ------------ src/ui/input.rs | 7 +------ src/ui/video.rs | 4 +--- 9 files changed, 13 insertions(+), 33 deletions(-) diff --git a/parallel-rdp/interface.cpp b/parallel-rdp/interface.cpp index 05c1e27f..47b09775 100644 --- a/parallel-rdp/interface.cpp +++ b/parallel-rdp/interface.cpp @@ -335,11 +335,11 @@ static void rdp_new_processor() { gfx_info.RDRAM_SIZE / 2, flags); g_tmem = processor->get_tmem(); if (!g_tmem) { - printf("Failed to get tmem\n"); + LOGE("Failed to get tmem\n"); } g_hidden_rdram = processor->begin_read_hidden_rdram(); if (!g_hidden_rdram) { - printf("Failed to get hidden_rdram\n"); + LOGE("Failed to get hidden_rdram\n"); } sync_signal = 0; @@ -376,7 +376,7 @@ void rdp_init(void *_window, GFX_INFO _gfx_info, const void *font, SDL_SyncWindow(window); bool result = SDL_AddEventWatch(sdl_event_filter, nullptr); if (!result) { - printf("Could not add event watch.\n"); + LOGE("Could not add event watch.\n"); return; } @@ -692,7 +692,10 @@ void rdp_update_screen() { if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) { return; } - wsi->end_frame(); + if (!wsi->end_frame()) { + LOGE("End frame failed\n"); + SDL_PumpEvents(); // For Android to trigger pause event + } wsi->begin_frame(); } @@ -787,7 +790,7 @@ uint32_t pixel_size(uint32_t pixel_type, uint32_t area) { case 3: return area * 4; default: - printf("Invalid pixel size: %u\n", pixel_type); + LOGE("Invalid pixel size: %u\n", pixel_type); return 0; } } diff --git a/parallel-rdp/wsi_platform.cpp b/parallel-rdp/wsi_platform.cpp index 89949eb8..4e18468d 100644 --- a/parallel-rdp/wsi_platform.cpp +++ b/parallel-rdp/wsi_platform.cpp @@ -46,7 +46,7 @@ uint32_t SDL_WSIPlatform::get_surface_height() { bool SDL_WSIPlatform::alive(Vulkan::WSI &wsi) { return true; } -void SDL_WSIPlatform::poll_input() {} +void SDL_WSIPlatform::poll_input() { SDL_PumpEvents(); } void SDL_WSIPlatform::poll_input_async(Granite::InputTrackerHandler *handler) {} diff --git a/src/device/controller.rs b/src/device/controller.rs index 61afd961..fead441e 100644 --- a/src/device/controller.rs +++ b/src/device/controller.rs @@ -59,7 +59,7 @@ pub fn process(device: &mut device::Device, channel: usize) { let input = if let Some(netplay) = &mut device.netplay { netplay.inputs[channel].0 } else { - ui::input::get(&mut device.ui, channel, device.speed_limiter.frame_counter) + ui::input::get(&mut device.ui, channel) }; device.pif.ram[offset..offset + 4].copy_from_slice(&input.data.to_ne_bytes()); diff --git a/src/device/vi.rs b/src/device/vi.rs index bc7a36bf..298c90e6 100644 --- a/src/device/vi.rs +++ b/src/device/vi.rs @@ -118,7 +118,6 @@ pub fn write_regs(device: &mut device::Device, address: u64, value: u32, mask: u pub fn update_screen(device: &mut device::Device) { if !netplay::in_rollback(device.netplay.as_ref()) { ui::video::render_frame(); - unsafe { sdl3_sys::events::SDL_PumpEvents() }; } let (speed_limiter_toggled, paused) = ui::video::check_callback(device); diff --git a/src/lib.rs b/src/lib.rs index c15ee71e..d9521857 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -128,8 +128,6 @@ pub fn run(args: Args, arg_count: usize) -> std::io::Result<()> { ui::sdl_hints(); if let Some(game) = args.game { - ui::disable_auto_update_joysticks(); - let file_path = std::path::Path::new(&game).to_path_buf(); let Some(rom_contents) = device::get_rom_contents(&file_path) else { return Err(Error::other(format!( diff --git a/src/netplay.rs b/src/netplay.rs index 089466b8..dc56b206 100644 --- a/src/netplay.rs +++ b/src/netplay.rs @@ -340,7 +340,7 @@ fn process_netplay(device: &mut device::Device) { fn advance_frame(device: &mut device::Device) { let netplay = device.netplay.as_mut().unwrap(); let local_input = if netplay.session.current_frame() > netplay.session.max_prediction() as i32 { - ui::input::get(&mut device.ui, 0, device.speed_limiter.frame_counter) + ui::input::get(&mut device.ui, 0) } else { //workaround for disabled rollback ui::input::InputData::default() @@ -486,7 +486,6 @@ pub fn init( message_timer = std::time::Instant::now(); } - unsafe { sdl3_sys::events::SDL_PumpEvents() }; ui::video::render_frame(); ui::video::update_screen(); std::thread::sleep(std::time::Duration::from_millis(10)); diff --git a/src/ui.rs b/src/ui.rs index fdb8433d..e673771c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -49,7 +49,6 @@ unsafe impl Sync for Audio {} #[derive(Default)] pub struct Input { pub keyboard_state: *const bool, - pub last_polled: u64, pub controllers: [input::Controllers; 4], } @@ -120,16 +119,6 @@ pub fn sdl_hints() { } } -pub fn disable_auto_update_joysticks() { - unsafe { - let hint = std::ffi::CString::new("0").unwrap(); - sdl3_sys::everything::SDL_SetHint( - sdl3_sys::everything::SDL_HINT_AUTO_UPDATE_JOYSTICKS, - hint.as_ptr(), - ); - } -} - pub fn sdl_init(flag: sdl3_sys::init::SDL_InitFlags) { unsafe { if sdl3_sys::init::SDL_WasInit(flag) == 0 && !sdl3_sys::init::SDL_InitSubSystem(flag) { @@ -195,7 +184,6 @@ impl Ui { let (vis_tx, vis_rx) = tokio::sync::mpsc::unbounded_channel(); Ui { input: Input { - last_polled: 0, controllers: [ input::Controllers { game_controller: std::ptr::null_mut(), diff --git a/src/ui/input.rs b/src/ui/input.rs index fec8fe0e..9abc0094 100644 --- a/src/ui/input.rs +++ b/src/ui/input.rs @@ -503,14 +503,9 @@ fn handle_hotkeys(keys: u32, last_key_state: u32) { } } -pub fn get(ui: &mut ui::Ui, channel: usize, vi_counter: u64) -> InputData { +pub fn get(ui: &mut ui::Ui, channel: usize) -> InputData { handle_joystick_events(ui); - if ui.input.last_polled != vi_counter { - ui.input.last_polled = vi_counter; - unsafe { sdl3_sys::joystick::SDL_UpdateJoysticks() }; - } - let profile_name = &ui.config.input.input_profile_binding[channel]; let Some(profile) = ui.config.input.input_profiles.get(profile_name) else { eprintln!("Invalid profile name: {profile_name}"); diff --git a/src/ui/video.rs b/src/ui/video.rs index 1de4f3c9..660ed50f 100644 --- a/src/ui/video.rs +++ b/src/ui/video.rs @@ -182,16 +182,14 @@ pub fn load_state(device: &mut device::Device, rdp_state: *const u8) { pub fn pause_loop(ui: &mut ui::Ui, frame_time: f64) { let mut paused = true; let mut frame_advance = false; - let mut pause_counter = 0; while paused && !frame_advance { std::thread::sleep(std::time::Duration::from_secs_f64(frame_time)); - ui::input::get(ui, 0, pause_counter); // to gather hotkey input unsafe { sdl3_sys::events::SDL_PumpEvents() }; + ui::input::get(ui, 0); // to gather hotkey input retroachievements::do_idle(); let callback = unsafe { rdp_check_callback() }; paused = callback.paused; frame_advance = callback.frame_advance; - pause_counter += 1; } }