Skip to content

Add some missing features from the gamepads-as-entities change that were needed to update leafwing-input-manager.#15685

Merged
alice-i-cecile merged 3 commits intobevyengine:mainfrom
pcwalton:leafwing-fixes
Oct 8, 2024
Merged

Add some missing features from the gamepads-as-entities change that were needed to update leafwing-input-manager.#15685
alice-i-cecile merged 3 commits intobevyengine:mainfrom
pcwalton:leafwing-fixes

Conversation

@pcwalton
Copy link
Copy Markdown
Contributor

@pcwalton pcwalton commented Oct 6, 2024

The gamepads-as-entities change caused several regressions. This patch fixes each of them:

  1. This PR introduces two new fields on GamepadInfo: vendor_id, and product_id, as well as associated methods. These fields are simply mirrored from the gilrs library.

  2. That PR removed the methods that allowed iterating over all pressed and released buttons, as well as the method that allowed iterating over the axis values. (It was still technically possible to do so by using reflection to access the private fields of Gamepad.)

  3. The Gamepad component wasn't marked reflectable. This PR fixes that problem.

These changes allowed me to forward port leafwing-input-manager.

@pcwalton pcwalton added A-Input Player input via keyboard, mouse, gamepad, and more P-Regression Functionality that used to work but no longer does. Add a test for this! S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 6, 2024
@pcwalton pcwalton added this to the 0.15 milestone Oct 6, 2024
needed to update `leafwing-input-manager`.

The gamepads-as-entities change caused several regressions. This patch
fixes each of them:

1. After that PR, there was no stable unique identifier available for
   gamepads. To fix this, this PR introduces several new fields on
   `GamepadInfo`: `uuid`, `vendor_id`, and `product_id`, as well as
   associated methods. These fields are simply mirrored from the `gilrs`
   library.  The UUID is the preferred way to identify gamepads across
   app invocations.

2. That PR removed the methods that allowed iterating over all pressed
   and released buttons, as well as the method that allowed iterating
   over the axis values. (It was still technically possible to do so by
   using reflection to access the private fields of `Gamepad`.)

3. The `Gamepad` component wasn't marked reflectable. This PR fixes that
   problem.

These changes allowed me to forward port `leafwing-input-manager`.
@alice-i-cecile
Copy link
Copy Markdown
Member

@s-puig can I get your review here?

@alice-i-cecile alice-i-cecile added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Oct 7, 2024
Copy link
Copy Markdown
Contributor

@bushrat011899 bushrat011899 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 to me! Just a mild bikeshed-style question around whether these methods should be named iter_x instead of get_x.

/// Returns an iterator over all digital [button]s that are pressed.
///
/// [button]: GamepadButton
pub fn get_pressed(&self) -> impl Iterator<Item = &GamepadButton> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking bikeshed question: Should these iterator methods instead be called iter_pressed, iter_just_pressed etc.?

Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile Oct 7, 2024

Choose a reason for hiding this comment

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

We should be consistent with the ButtonInput API: https://docs.rs/bevy/latest/bevy/input/struct.ButtonInput.html#method.

I do think this might be nice to change, but it should be done all at once.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perfectly reasonable!

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 7, 2024
github-merge-queue bot pushed a commit that referenced this pull request Oct 7, 2024
…ere needed to update `leafwing-input-manager`. (#15685)

The gamepads-as-entities change caused several regressions. This patch
fixes each of them:

1. After that PR, there was no stable unique identifier available for
gamepads. To fix this, this PR introduces several new fields on
`GamepadInfo`: `uuid`, `vendor_id`, and `product_id`, as well as
associated methods. These fields are simply mirrored from the `gilrs`
library. The UUID is the preferred way to identify gamepads across app
invocations.

2. That PR removed the methods that allowed iterating over all pressed
and released buttons, as well as the method that allowed iterating over
the axis values. (It was still technically possible to do so by using
reflection to access the private fields of `Gamepad`.)

3. The `Gamepad` component wasn't marked reflectable. This PR fixes that
problem.

These changes allowed me to forward port `leafwing-input-manager`.
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 7, 2024
@alice-i-cecile
Copy link
Copy Markdown
Member

alice-i-cecile commented Oct 7, 2024

Uuid isn't Reflect, so we either need to ignore it for Reflection or do some remote reflect nonsense. I vote the former, but actually the latter may be needed for serialization.

@MrGVSV
Copy link
Copy Markdown
Member

MrGVSV commented Oct 7, 2024

Uuid isn't Reflect, so we either need to ignore it for Reflection or do some remote reflect nonsense. I vote the former, but actually the latter may be needed for serialization.

It should be? Might need to add the feature?

@s-puig
Copy link
Copy Markdown
Contributor

s-puig commented Oct 7, 2024

I will take a proper look later, but we should avoid gilrs::Gamepad::uuid. See #153

@mockersf mockersf removed 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 Oct 7, 2024
@pcwalton
Copy link
Copy Markdown
Contributor Author

pcwalton commented Oct 8, 2024

@s-puig Do you want me to not expose the UUID entirely or just stop recommending it?

@s-puig
Copy link
Copy Markdown
Contributor

s-puig commented Oct 8, 2024

I would rather not expose it. It's just that broken.
Although it may be worth it to add a comment in bevy_gilrs against implementing uuid until the issue is resolved. You are sadly not its first victim.

pcwalton added a commit to pcwalton/leafwing-input-manager that referenced this pull request Oct 8, 2024
Most of the work here was fallout from the gamepads-as-entities change
(bevyengine/bevy#12770), as well as the
`PartialReflect` changes.

This relies on bevyengine/bevy#15685. That PR
must be applied to Bevy for this to build.

The most recent upstream commit is
4bf647ff3b0ca7c8ca47496db9cfe03702328473.
pcwalton added a commit to pcwalton/leafwing-input-manager that referenced this pull request Oct 8, 2024
Most of the work here was fallout from the gamepads-as-entities change
(bevyengine/bevy#12770), as well as the
`PartialReflect` changes.

This relies on bevyengine/bevy#15685. That PR
must be applied to Bevy for this to build.

The most recent upstream commit is
4bf647ff3b0ca7c8ca47496db9cfe03702328473.
@pcwalton pcwalton 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 Oct 8, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 8, 2024
Merged via the queue into bevyengine:main with commit 48e2027 Oct 8, 2024
alice-i-cecile pushed a commit to Leafwing-Studios/leafwing-input-manager that referenced this pull request Dec 9, 2024
* Upgrade to Bevy 0.15.0-dev.

Most of the work here was fallout from the gamepads-as-entities change
(bevyengine/bevy#12770), as well as the
`PartialReflect` changes.

This relies on bevyengine/bevy#15685. That PR
must be applied to Bevy for this to build.

The most recent upstream commit is
4bf647ff3b0ca7c8ca47496db9cfe03702328473.

* Switch to upstream AccumulatedFoo

* Try (unsuccessfully) to fix the failing tests

* Bumps bevy_egui requirement from 0.30 to 0.31

* Sets bevy requirement to 0.15.0

* Replaces deprecated SpriteBundle

* Applies system ordering suggestion

* Use AccumulatedMouseScroll and AccumulatedMouseMotion from bevy

* Fixes merge issues

* Runs formatter

* Gets button value from SpecificGamepadButton

* Ignores tests

* Fixes compilation issues

* Fixes docs

---------

Co-authored-by: Patrick Walton <pcwalton@mimiga.net>
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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples P-Regression Functionality that used to work but no longer does. Add a test for this! 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.

7 participants