move joystick update (#985)

This commit is contained in:
Logan McNaughton
2026-05-29 16:51:27 +02:00
committed by GitHub
parent 31420b6777
commit 24e5a3fac4
3 changed files with 15 additions and 3 deletions
+2 -2
View File
@@ -58,12 +58,12 @@ pub fn process(device: &mut device::Device, channel: usize) {
let offset = device.pif.channels[channel].rx_buf.unwrap();
let input = if let Some(netplay) = &mut device.netplay {
if netplay.player_number as usize == channel {
let local_input = ui::input::get(&mut device.ui, 0);
let local_input = ui::input::get(&mut device.ui, 0, device.vi.vi_counter);
netplay::send_input(netplay, local_input);
}
netplay::get_input(device, channel)
} else {
ui::input::get(&mut device.ui, channel)
ui::input::get(&mut device.ui, channel, device.vi.vi_counter)
};
device.pif.ram[offset..offset + 4].copy_from_slice(&input.data.to_ne_bytes());
+7
View File
@@ -42,6 +42,7 @@ pub struct Audio {
pub struct Input {
pub keyboard_state: *const bool,
pub last_polled: u64,
pub controllers: [input::Controllers; 4],
}
@@ -97,6 +98,11 @@ pub fn sdl_hints() {
sdl3_sys::everything::SDL_HINT_ANDROID_ALLOW_RECREATE_ACTIVITY,
hint.as_ptr(),
);
let hint = std::ffi::CString::new("0").unwrap();
sdl3_sys::everything::SDL_SetHint(
sdl3_sys::everything::SDL_HINT_AUTO_UPDATE_JOYSTICKS,
hint.as_ptr(),
);
}
}
@@ -165,6 +171,7 @@ impl Ui {
let (vis_tx, vis_rx) = tokio::sync::mpsc::channel(1000);
Ui {
input: Input {
last_polled: 0,
controllers: [
input::Controllers {
game_controller: std::ptr::null_mut(),
+6 -1
View File
@@ -490,9 +490,14 @@ fn handle_hotkeys(keys: u32, last_key_state: u32) {
}
}
pub fn get(ui: &mut ui::Ui, channel: usize) -> InputData {
pub fn get(ui: &mut ui::Ui, channel: usize, vi_counter: u64) -> 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}");