Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Improve Gamepad DPad Button Detection #5220

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/bevy_gilrs/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ pub fn convert_axis(axis: gilrs::Axis) -> Option<GamepadAxisType> {
gilrs::Axis::RightStickX => Some(GamepadAxisType::RightStickX),
gilrs::Axis::RightStickY => Some(GamepadAxisType::RightStickY),
gilrs::Axis::RightZ => Some(GamepadAxisType::RightZ),
gilrs::Axis::DPadX => Some(GamepadAxisType::DPadX),
gilrs::Axis::DPadY => Some(GamepadAxisType::DPadY),
gilrs::Axis::Unknown => None,
// The `axis_dpad_to_button` gilrs filter should filter out all DPadX and DPadY events. If
// it doesn't then we probably need an entry added to the following repo and an update to
// GilRs to use the updated database: https://github.com/gabomdq/SDL_GameControllerDB
gilrs::Axis::Unknown | gilrs::Axis::DPadX | gilrs::Axis::DPadY => None,
}
}
9 changes: 7 additions & 2 deletions crates/bevy_gilrs/src/gilrs_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::converter::{convert_axis, convert_button, convert_gamepad_id};
use bevy_ecs::event::EventWriter;
use bevy_ecs::system::{NonSend, NonSendMut};
use bevy_input::{gamepad::GamepadEventRaw, prelude::*};
use gilrs::{EventType, Gilrs};
use gilrs::{ev::filter::axis_dpad_to_button, EventType, Filter, Gilrs};

pub fn gilrs_event_startup_system(gilrs: NonSend<Gilrs>, mut events: EventWriter<GamepadEventRaw>) {
for (id, _) in gilrs.gamepads() {
Expand All @@ -14,7 +14,12 @@ pub fn gilrs_event_startup_system(gilrs: NonSend<Gilrs>, mut events: EventWriter
}

pub fn gilrs_event_system(mut gilrs: NonSendMut<Gilrs>, mut events: EventWriter<GamepadEventRaw>) {
while let Some(gilrs_event) = gilrs.next_event() {
while let Some(gilrs_event) = gilrs
.next_event()
.filter_ev(&axis_dpad_to_button, &mut gilrs)
{
gilrs.update(&gilrs_event);

match gilrs_event.event {
EventType::Connected => {
events.send(GamepadEventRaw::new(
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_input/src/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ pub enum GamepadAxisType {
RightStickX,
RightStickY,
RightZ,
DPadX,
DPadY,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -412,15 +410,13 @@ const ALL_BUTTON_TYPES: [GamepadButtonType; 19] = [
GamepadButtonType::DPadRight,
];

const ALL_AXIS_TYPES: [GamepadAxisType; 8] = [
const ALL_AXIS_TYPES: [GamepadAxisType; 6] = [
GamepadAxisType::LeftStickX,
GamepadAxisType::LeftStickY,
GamepadAxisType::LeftZ,
GamepadAxisType::RightStickX,
GamepadAxisType::RightStickY,
GamepadAxisType::RightZ,
GamepadAxisType::DPadX,
GamepadAxisType::DPadY,
];

#[cfg(test)]
Expand Down