move input polling (#1145)

* move input polling

* more

* more

* more
This commit is contained in:
Logan McNaughton
2026-07-02 10:04:51 +02:00
committed by GitHub
parent 032bf1acf3
commit 3bc7c96191
9 changed files with 13 additions and 33 deletions
+8 -5
View File
@@ -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;
}
}
+1 -1
View File
@@ -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) {}
+1 -1
View File
@@ -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());
-1
View File
@@ -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);
-2
View File
@@ -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!(
+1 -2
View File
@@ -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));
-12
View File
@@ -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(),
+1 -6
View File
@@ -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}");
+1 -3
View File
@@ -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;
}
}