-
Notifications
You must be signed in to change notification settings - Fork 252
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
Support controller analog triggers #600
base: main
Are you sure you want to change the base?
Conversation
I've tested on Xbox Series controller on Linux, there some improvements compared to current main branch, no uncontrolled rotation anymore, but now my ship is constantly moving up, like left trigger constantly pushed. If I push right trigger, ship goes down, but after release ship again goes up. |
You've mapped triggers to something like pitch? It's possible that default deadzone is too high, how does it go when you increase it here ? https://github.com/DescentDevelopers/Descent3/pull/600/files#diff-7f049cd870d2530a44058475c2746ae9ba2f1bddf3995756061cf046e72fc2cfR1332 And the mapping part goes smoothly? |
Just retested on new pilot with default configs, same thing happens. |
Ok then that's the analog trigger detection threshold that's not set correctly. Migrating to the SDL2 GameController API will solve that |
I could reproduce the problem on an actual Xbox series controller, it's a problem with the default mapping that uses a trigger as an axis. While it can be remapped easily, short-term solution is to disable this default mapping. I'll update the PR later. |
3a52d34
to
4ec78bf
Compare
Alright, finally came around to finishing this one! I'm not done at all with controllers, but at least I'm building familiarity. Triggers can be mapped to direction functions, and default mappings should not force them to be real axis anymore. XBox series controller should now work properly. Firing with trigger buttons is not supported yet. Ready for anyone to test & review! |
4ec78bf
to
12ab2a7
Compare
Default axis mappings could map controller triggers to functions that require bi-directional axis to work properly
@winterheart could you please review and test this branch? thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New code eliminates uncontrolled rotation and elevate movements. There no forward / back, up / down movements on default joystick configuration, but I think we can do more polishing in SDL_GameController()
enabling iteration.
lib/joystick.h
Outdated
@@ -66,6 +66,7 @@ | |||
#define JOYSTICK_H | |||
|
|||
#include <cstdint> | |||
#include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vector declaration is unused in header.
12ab2a7
to
deb9749
Compare
Indeed, that's the very next steps, but out of scope for this PR. Movement mapped manually is always better than uncontrolled movement that you cannot remap. Comments fixed otherwise. Thanks for testing! |
if (ctl_hlb.value > 0.0f) | ||
controls->heading_thrust += ctl_hlb.value; | ||
if (ctl_hrb.value > 0.0f) | ||
controls->heading_thrust -= ctl_hlb.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a copy-paste error? Shouldn't it be -= ctl_hrb.value
?
if (ctl_blb.value > 0.0f) | ||
controls->bank_thrust += ctl_blb.value; | ||
if (ctl_brb.value > 0.0f) | ||
controls->bank_thrust -= ctl_blb.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for -= ctl_brb.value
?
I tried with a PS5 controller on Windows 11. Analog triggers are detected as normal axis. The Line 167 in deb9749
is always 0 for all axis/triggers.
If I try to force the code to go into that I haven't found anything yet, to distinguish an analog trigger from an axis for the PS5 controller. |
Ugh that's a pain... No choice but to use the SDL2 game controller database to identify axes then. I'll update this PR for that. |
Pull Request Type
Description
Add support for analog triggers, such as those used in the xbox controllers. They are detected as axis by SDL2, but are unidirectional, so they should be mapped to functions expecting a [-1;1] range. We allow mapping them to other buttons. Button controls have also been made analog when it made sense, so triggers can have fine control over movement.
Left to do in this MR: implement
ctTime
andctDownCount
for analog triggers so they can be used for weapons, refine detection threshold for mappingsThe controller code is a mess, this will need other passes to make it better.
Related Issues
Close #496
Screenshots (if applicable)
Checklist
Additional Comments