switch to analog RetroPad

I really should make this either or.
This commit is contained in:
Lily Tsuru 2024-10-15 16:41:37 -04:00
parent efc2800358
commit 889d7e42ce
2 changed files with 76 additions and 13 deletions

View file

@ -11,7 +11,7 @@ use anyhow::Result;
use retro_frontend::{ use retro_frontend::{
frontend::{Frontend, FrontendInterface, HwGlInitData}, frontend::{Frontend, FrontendInterface, HwGlInitData},
input_devices::{InputDevice, RetroPad}, input_devices::{AnalogRetroPad, InputDevice},
libretro_sys_new, libretro_sys_new,
}; };
@ -47,7 +47,7 @@ extern "system" fn opengl_message_callback(
pub struct RetroState { pub struct RetroState {
frontend: Option<Box<Frontend>>, frontend: Option<Box<Frontend>>,
pad: RetroPad, pad: AnalogRetroPad,
// EGL state // EGL state
egl_context: Arc<Mutex<DeviceContext>>, egl_context: Arc<Mutex<DeviceContext>>,
@ -73,7 +73,7 @@ impl RetroState {
) -> Box<Self> { ) -> Box<Self> {
let mut boxed = Box::new(Self { let mut boxed = Box::new(Self {
frontend: None, frontend: None,
pad: RetroPad::new(), pad: AnalogRetroPad::new(),
egl_context: device_context.clone(), egl_context: device_context.clone(),
software_framebuffer: Surface::new(), software_framebuffer: Surface::new(),
@ -283,9 +283,8 @@ impl FrontendInterface for RetroState {
.bind_to_thread() .bind_to_thread()
.expect("Failed to bind CUDA device to thread"); .expect("Failed to bind CUDA device to thread");
let mut mapped_cuda_resource = cuda_resource let mut mapped_cuda_resource =
.map() cuda_resource.map().expect("Failed to map CUDA resource");
.expect("Failed to map CUDA resource");
let array = mapped_cuda_resource let array = mapped_cuda_resource
.get_mapped_array() .get_mapped_array()
@ -414,6 +413,70 @@ impl FrontendInterface for RetroState {
.press_button(libretro_sys_new::DEVICE_ID_JOYPAD_R2, None); .press_button(libretro_sys_new::DEVICE_ID_JOYPAD_R2, None);
} }
Key::t => {
self.pad.press_analog_axis(
libretro_sys_new::DEVICE_INDEX_ANALOG_LEFT,
libretro_sys_new::DEVICE_ID_ANALOG_Y,
Some(-0x7fff),
);
}
Key::g => {
self.pad.press_analog_axis(
libretro_sys_new::DEVICE_INDEX_ANALOG_LEFT,
libretro_sys_new::DEVICE_ID_ANALOG_Y,
Some(0x7fff),
);
}
Key::f => {
self.pad.press_analog_axis(
libretro_sys_new::DEVICE_INDEX_ANALOG_LEFT,
libretro_sys_new::DEVICE_ID_ANALOG_X,
Some(-0x7fff),
);
}
Key::h => {
self.pad.press_analog_axis(
libretro_sys_new::DEVICE_INDEX_ANALOG_LEFT,
libretro_sys_new::DEVICE_ID_ANALOG_X,
Some(0x7fff),
);
}
Key::i => {
self.pad.press_analog_axis(
libretro_sys_new::DEVICE_INDEX_ANALOG_RIGHT,
libretro_sys_new::DEVICE_ID_ANALOG_Y,
Some(-0x7fff),
);
}
Key::k => {
self.pad.press_analog_axis(
libretro_sys_new::DEVICE_INDEX_ANALOG_RIGHT,
libretro_sys_new::DEVICE_ID_ANALOG_Y,
Some(0x7fff),
);
}
Key::j => {
self.pad.press_analog_axis(
libretro_sys_new::DEVICE_INDEX_ANALOG_RIGHT,
libretro_sys_new::DEVICE_ID_ANALOG_X,
Some(-0x7fff),
);
}
Key::l => {
self.pad.press_analog_axis(
libretro_sys_new::DEVICE_INDEX_ANALOG_RIGHT,
libretro_sys_new::DEVICE_ID_ANALOG_X,
Some(0x7fff),
);
}
_ => {} _ => {}
} }
} }

View file

@ -8,11 +8,11 @@ pub struct Rect {
pub height: u32, pub height: u32,
} }
#[derive(Debug)] //#[derive(Debug)]
pub struct Point { //pub struct Point {
pub x: u32, // pub x: u32,
pub y: u32, // pub y: u32,
} //}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Size { pub struct Size {