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

Add gamepad rumble support to bevy_input #8398

Merged
merged 57 commits into from Apr 24, 2023

Conversation

johanhelsing
Copy link
Contributor

@johanhelsing johanhelsing commented Apr 16, 2023

Objective

Provide the ability to trigger controller rumbling (force-feedback) with a cross-platform API.

Solution

This adds the GamepadRumbleRequest event to bevy_input and adds a system in bevy_gilrs to read them and rumble controllers accordingly.

It's a relatively primitive API with a duration in seconds and GamepadRumbleIntensity with values for the weak and strong gamepad motors. It's is an almost 1-to-1 mapping to platform APIs. Some platforms refer to these motors as left and right, and low frequency and high frequency, but by convention, they're usually the same.

I used #3868 as a starting point, updated to main, removed the low-level gilrs effect API, and moved the requests to bevy_input and exposed the strong and weak intensities.

I intend this to hopefully be a non-controversial cross-platform starting point we can build upon to eventually support more fine-grained control (closer to the gilrs effect API)


Changelog

Added

  • Gamepads can now be rumbled by sending the GamepadRumbleRequest event.

nicopap and others added 13 commits February 5, 2022 14:05
This adds the `RumbleRequest` event and a system to read them and rumble
controllers accordingly.

It gives users two ways of controlling controller rumble:
1. A very primitive API with `RumbleIntensity` that is easy to
   understand and use.
2. A direct access to the girls `ff::Effect` system for complete
   fine-grained control over how the gamepad rumbles.
Conflicts:
	crates/bevy_gilrs/Cargo.toml
	crates/bevy_gilrs/src/lib.rs
	crates/bevy_gilrs/src/rumble.rs
	examples/README.md
	examples/input/gamepad_rumble.rs
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
@github-actions
Copy link
Contributor

You added a new example but didn't add metadata for it. Please update the root Cargo.toml file.

Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

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

Looks good, just need to adjust the clamping and IMO it's good to go.

crates/bevy_gilrs/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_input/src/gamepad.rs Outdated Show resolved Hide resolved
examples/input/gamepad_rumble.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

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

I actually didn't know that f32 as u16 did round (therefore clamp) the value.

LGTM

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

We need to clamp in to_gilrs_magnitude still. Once that's resolved, this LGTM and I'll merge!

@johanhelsing
Copy link
Contributor Author

We need to clamp in to_gilrs_magnitude still. Once that's resolved, this LGTM and I'll merge!

How so? As far as i understand it shouldn't be needed: rust-lang/rust#71269

Or do you mean for clarity of intent?

Co-authored-by: Bruce Reif (Buswolley) <bruce.reif@dynata.com>
@alice-i-cecile
Copy link
Member

Ah, TIL. Can we add tests for it instead then?

@johanhelsing
Copy link
Contributor Author

Ah, TIL. Can we add tests for it instead then?

There already are some ;)

@nicopap
Copy link
Contributor

nicopap commented Apr 23, 2023

I think a single line comment on the as u16 conversion in to_gilrs_magnitude saying "value is clamped by property of rust f32 to integer conversion" would avoid all future confusion.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Apr 23, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 24, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 24, 2023
@alice-i-cecile alice-i-cecile removed this pull request from the merge queue due to a manual request Apr 24, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 24, 2023
Merged via the queue into bevyengine:main with commit a1e442c Apr 24, 2023
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Enhancement A new feature S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants