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

Support controller analog triggers #600

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Lgt2x
Copy link
Member

@Lgt2x Lgt2x commented Sep 22, 2024

Pull Request Type

  • GitHub Workflow changes
  • Documentation or Wiki changes
  • Build and Dependency changes
  • Runtime changes
    • Render changes
    • Audio changes
    • Input changes
    • Network changes
    • Other changes

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 and ctDownCount for analog triggers so they can be used for weapons, refine detection threshold for mappings

The controller code is a mess, this will need other passes to make it better.

Related Issues

Close #496

Screenshots (if applicable)

Checklist

  • I have tested my changes locally and verified that they work as intended.
  • I have documented any new or modified functionality.
  • I have reviewed the changes to ensure they do not introduce any unnecessary complexity or duplicate code.
  • I understand that by submitting this pull request, I am agreeing to license my contributions under the project's license.

Additional Comments

@Lgt2x Lgt2x marked this pull request as draft September 22, 2024 19:53
@Lgt2x Lgt2x changed the title Draft: Support analog triggers for Xbox controller Draft: Support controller analog triggers Sep 22, 2024
Descent3/args.cpp Outdated Show resolved Hide resolved
Descent3/args.cpp Outdated Show resolved Hide resolved
@winterheart
Copy link
Collaborator

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.

@Lgt2x
Copy link
Member Author

Lgt2x commented Sep 24, 2024

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?

@winterheart
Copy link
Collaborator

Just retested on new pilot with default configs, same thing happens.

@Lgt2x
Copy link
Member Author

Lgt2x commented Sep 24, 2024

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

@Lgt2x
Copy link
Member Author

Lgt2x commented Oct 6, 2024

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.

@Lgt2x Lgt2x force-pushed the analog-triggers branch 2 times, most recently from 3a52d34 to 4ec78bf Compare October 15, 2024 20:02
@Lgt2x Lgt2x marked this pull request as ready for review October 15, 2024 20:02
@Lgt2x
Copy link
Member Author

Lgt2x commented Oct 15, 2024

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!

@Lgt2x Lgt2x changed the title Draft: Support controller analog triggers Support controller analog triggers Oct 23, 2024
@Lgt2x
Copy link
Member Author

Lgt2x commented Oct 27, 2024

@winterheart could you please review and test this branch? thanks!

Copy link
Collaborator

@winterheart winterheart left a 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.

ddio/sdlcontroller.cpp Outdated Show resolved Hide resolved
ddio/sdlcontroller.cpp Outdated Show resolved Hide resolved
lib/joystick.h Outdated
@@ -66,6 +66,7 @@
#define JOYSTICK_H

#include <cstdint>
#include <vector>
Copy link
Collaborator

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.

@Lgt2x
Copy link
Member Author

Lgt2x commented Oct 28, 2024

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.

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;
Copy link
Contributor

@pzychotic pzychotic Oct 31, 2024

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;
Copy link
Contributor

@pzychotic pzychotic Oct 31, 2024

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?

@pzychotic
Copy link
Contributor

I tried with a PS5 controller on Windows 11.

Analog triggers are detected as normal axis. The initialVal in

if (initialVal < -32768 * 0.75) {

is always 0 for all axis/triggers.

If I try to force the code to go into that if clause for analog triggers, they don't work at all. I can't even assign them in config menu.
If I don't do that, they always fire and trying to assign a control for an axis always assigns the left trigger/ U-axis.

I haven't found anything yet, to distinguish an analog trigger from an axis for the PS5 controller.

@Lgt2x
Copy link
Member Author

Lgt2x commented Oct 31, 2024

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.

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.

[Runtime Issue]: XBox Controller registers triggers as [-1, 1] axes instead of [0, 1]
3 participants