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

Fixing issues with controller in entry_sdl.cpp, introduces change in behavior. #3321

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Conversation

elvencache
Copy link
Contributor

Running into 3 issues with example entry's SDL2 implementation.

  1. SDL2's concept of GameController is a like a PS or Xbox controller, two sticks, four face buttons, etc. These are the same as the bgfx example's Gamepad. SDL also has a concept of Joystick, which could be anything, like a flight stick. Game Controllers are implemented by these lower level joysticks.

Entry SDL gets duplicate events, for both controller and the joystick implementing it. Game controller buttons are remapped to bgfx gamepad, but joystick buttons are not. This causes joystick events to produce incorrect button presses.

Additionally, the joystick z-axis behaves differently than game controller or bgfx gamepad. With at-rest value being negative, not zero.

Due to all of this, it seems like the best approach would be to ignore joystick events and only handle game controller events.

  1. Handling the joystick events by posting key events to the dpad causes both left stick and right stick events to register as dpad presses. I can see some cases where a user may want left stick and dpad to drive the same control. But I don't know when you'd want both left and right stick to be seen as dpad inputs.

I think the best approach would be to let the sticks register as sticks and the dpad to be left alone. User code could then choose to respond to left stick and dpad in the same way, or not.

Not sure if this change should be made or not, as it changes behavior for subjective reason and not correctness reason.

  1. Minor additional fix, get handle's index when using it as array index. Fixes compilation in Visual Studio.

SDL2's concept of GameController is a like a PS or Xbox controller, two sticks, four face buttons, etc. These are the same as the bgfx example's Gamepad.

SDL also has a concept of Joystick, which could be anything, like a flight stick. Game Controllers are implemented by these lower level joystick's.

Entry SDL gets duplicate events, for both controller and the joystick implementing it. Game controller buttons are remapped to bgfx gamepad, but joystick buttons are not. This causes incorrect button presses.

Additionally, the joystick z axis behaves differently than game controller or bgfx gamepad. With at-rest value being negative, not zero.

Due to all of this, it seems like the best approach would be to ignore joystick events and only handle game controller events.

Also, minor additional fix to get handle's index when using it as array index. Fixes compilation in Visual Studio.

if (isValid(handle) )
{
Key::Enum key = translateGamepad(bev.button);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JoyButtons are different than ControllerButtons. translateGamepad produces wrong key for some joy buttons.
This affects ThumbLeft/Right, ShoulderLeft/Right, Back, Start, and Guide.

, true
);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this code above stops the dpad buttons from being pressed when either stick is moved.

@bkaradzic bkaradzic merged commit 74e7edc into bkaradzic:master Jul 8, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants