bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
15.12k stars 1.95k forks source link

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

Closed elvencache closed 4 months ago

elvencache commented 4 months ago

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.

2) 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.

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