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::{
frontend::{Frontend, FrontendInterface, HwGlInitData},
input_devices::{InputDevice, RetroPad},
input_devices::{AnalogRetroPad, InputDevice},
libretro_sys_new,
};
@ -47,7 +47,7 @@ extern "system" fn opengl_message_callback(
pub struct RetroState {
frontend: Option<Box<Frontend>>,
pad: RetroPad,
pad: AnalogRetroPad,
// EGL state
egl_context: Arc<Mutex<DeviceContext>>,
@ -73,7 +73,7 @@ impl RetroState {
) -> Box<Self> {
let mut boxed = Box::new(Self {
frontend: None,
pad: RetroPad::new(),
pad: AnalogRetroPad::new(),
egl_context: device_context.clone(),
software_framebuffer: Surface::new(),
@ -283,9 +283,8 @@ impl FrontendInterface for RetroState {
.bind_to_thread()
.expect("Failed to bind CUDA device to thread");
let mut mapped_cuda_resource = cuda_resource
.map()
.expect("Failed to map CUDA resource");
let mut mapped_cuda_resource =
cuda_resource.map().expect("Failed to map CUDA resource");
let array = mapped_cuda_resource
.get_mapped_array()
@ -320,7 +319,7 @@ impl FrontendInterface for RetroState {
.result()
.expect("fucking");
mapped_cuda_resource.unmap().expect("fuck you asshole");
mapped_cuda_resource.unmap().expect("fuck you asshole");
}
let _ = self.event_tx.blocking_send(RetroEvent::Frame);
@ -414,6 +413,70 @@ impl FrontendInterface for RetroState {
.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,
}
#[derive(Debug)]
pub struct Point {
pub x: u32,
pub y: u32,
}
//#[derive(Debug)]
//pub struct Point {
// pub x: u32,
// pub y: u32,
//}
#[derive(Clone, Debug)]
pub struct Size {