Compare commits

..

1 commit

Author SHA1 Message Date
62d9090274 Update Rust crate ron to 0.9.0 2025-03-27 12:02:12 +00:00
4 changed files with 34 additions and 29 deletions

View file

@ -49,7 +49,7 @@ hostname = { version = "0.4.0" }
trust-dns-resolver = { version = "0.23.2" } trust-dns-resolver = { version = "0.23.2" }
openxr = { version = "0.19.0", default-features = false, features = ["static"] } openxr = { version = "0.19.0", default-features = false, features = ["static"] }
openvr = { version = "0.7.0" } openvr = { version = "0.7.0" }
sdl3 = { version = "0.14.20" } sdl3 = { version = "0.14.19" }
syn = { version = "2.0.67", features = ["extra-traits", "full"] } syn = { version = "2.0.67", features = ["extra-traits", "full"] }
quote = "1.0.35" quote = "1.0.35"
proc-macro2 = "1.0.86" proc-macro2 = "1.0.86"

View file

@ -55,12 +55,13 @@ impl Controller {
id: u32, id: u32,
deadzones: ControllerDeadzones, deadzones: ControllerDeadzones,
) -> Result<Controller> { ) -> Result<Controller> {
if controller_subsystem.is_game_controller(id) {
let sdl2_controller = controller_subsystem.open(id)?; let sdl2_controller = controller_subsystem.open(id)?;
let controller_axis = ControllerAxis::default(); let controller_axis = ControllerAxis::default();
Ok(Controller { Ok(Controller {
name: sdl2_controller.name().unwrap_or_default(), name: sdl2_controller.name(),
id, id,
_sdl2_controller: sdl2_controller, _sdl2_controller: sdl2_controller,
@ -77,6 +78,9 @@ impl Controller {
deadzones, deadzones,
}) })
} else {
Err(anyhow::Error::msg("Not a game controller"))
}
} }
pub fn name(&self) -> &String { pub fn name(&self) -> &String {

View file

@ -40,10 +40,6 @@ fn convert_button(button: Button) -> ControllerButton {
Button::RightStick => ControllerButton::RightStick, Button::RightStick => ControllerButton::RightStick,
Button::Misc1 => ControllerButton::Misc, Button::Misc1 => ControllerButton::Misc,
Button::Misc2 => todo!(),
Button::Misc3 => todo!(),
Button::Misc4 => todo!(),
Button::Misc5 => todo!(),
Button::RightPaddle1 => ControllerButton::Paddle1, Button::RightPaddle1 => ControllerButton::Paddle1,
Button::RightPaddle2 => ControllerButton::Paddle2, Button::RightPaddle2 => ControllerButton::Paddle2,
@ -120,15 +116,20 @@ impl EventSystem {
.joysticks() .joysticks()
.map_err(|s| anyhow::Error::msg(s))? .map_err(|s| anyhow::Error::msg(s))?
.into_iter() .into_iter()
.map(|id| Ok((id, Joystick::new(&event_system.joystick_subsystem, id)?))) .map(|instance| {
Ok((
instance.id,
Joystick::new(&event_system.joystick_subsystem, instance)?,
))
})
.collect::<Result<HashMap<_, _>>>()?; .collect::<Result<HashMap<_, _>>>()?;
event_system.connected_controllers = event_system event_system.connected_controllers = (0..event_system
.controller_subsystem .controller_subsystem
.gamepads() .num_gamepads()
.map_err(|s| anyhow::Error::msg(s))? .map_err(|s| anyhow::Error::msg(s))?)
.into_iter() .into_iter()
// .filter(|i| event_system.controller_subsystem.is_game_controller(*i)) .filter(|i| event_system.controller_subsystem.is_game_controller(*i))
.map(|i| { .map(|i| {
Ok(( Ok((
i, i,
@ -336,7 +337,7 @@ impl EventSystem {
.joysticks() .joysticks()
.map_err(|_| anyhow!("failed querying joysticks"))? .map_err(|_| anyhow!("failed querying joysticks"))?
.into_iter() .into_iter()
.find(|id| *id == which) .find(|instance| instance.id == which)
{ {
let joystick = Joystick::new(&self.joystick_subsystem, joystick_instance)?; let joystick = Joystick::new(&self.joystick_subsystem, joystick_instance)?;

View file

@ -1,5 +1,5 @@
use anyhow::Result; use anyhow::Result;
use sdl3::{JoystickSubsystem, joystick::JoystickId}; use sdl3::{JoystickSubsystem, joystick::JoystickInstance};
pub struct Joystick { pub struct Joystick {
sdl2_joystick: sdl3::joystick::Joystick, sdl2_joystick: sdl3::joystick::Joystick,
@ -8,8 +8,8 @@ pub struct Joystick {
} }
impl Joystick { impl Joystick {
pub fn new(joystick_subsystem: &JoystickSubsystem, id: JoystickId) -> Result<Self> { pub fn new(joystick_subsystem: &JoystickSubsystem, instance: JoystickInstance) -> Result<Self> {
let sdl2_joystick = joystick_subsystem.open(id)?; let sdl2_joystick = joystick_subsystem.open(instance)?;
Ok(Self { Ok(Self {
name: sdl2_joystick.name(), name: sdl2_joystick.name(),
@ -18,7 +18,7 @@ impl Joystick {
} }
pub fn id(&self) -> u32 { pub fn id(&self) -> u32 {
self.sdl2_joystick.id() self.sdl2_joystick.instance_id()
} }
pub fn name(&self) -> &str { pub fn name(&self) -> &str {