Skip to content

Remove the id from PointerId::Touch #17847

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

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

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Feb 13, 2025

Objective

Instead of storing winit's u64 finger id for touches on the pointer entity in its PointerId component, just use the pointer entity itself to represent the touch within Bevy.

Related #17808

Solution

  • Changed touch_pick_event so its local touch_cache hashmap also tracks the entity id of touch pointers as well as the intial touch states.
  • Removed the deactivate_touch_pointers system. Instead touch_pick_event despawns the corresponding touch pointer entity when a touch ends or is cancelled.
  • Added a pointer_entity: Option<Entity> field to the PointerInput event. This is used to match events to the correct pointer for inputs that support multiple pointers. For touch it would be used to distinguish between touches for multi-touch.

Made pointer_entity optional so that this PR doesn't have to touch any of the other pointer event systems but it would probably make sense to require it (if this PR is adopted).

Testing

Works when running the bevy examples in chrome with touch enabled in dev tools.

* Removed the `deactivate_touch_pointers` system.
* `touch_pick_event` local `touch_cache` hashmap also tracks the entity id of touch pointers as well as the intial touch state.
* `touch_pick_event` despawns touch point entities when the touch ends or is cancelled.
@ickshonpe ickshonpe changed the title Remove the Remove the id from PointerId::Touch Feb 13, 2025
@ickshonpe ickshonpe added C-Code-Quality A section of code that is hard to understand or change S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Picking Pointing at and selecting objects of all sorts labels Feb 13, 2025
@alice-i-cecile
Copy link
Member

My understanding from @aevyrie is that this doesn't work because of interrupted touches. They will be despawned in Bevy but keep their identifier.

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Feb 13, 2025

I'm not sure what problems that could cause, maybe I'm misunderstanding what you mean by an interrupted touch? The winit docs say that their finger ids are only unique for the duration of a touch and that if another touch event happens after a
TouchPhase::Ended or TouchPhase::Cancelled event with the same id, it should be interpreted as a new touch event.

@alice-i-cecile
Copy link
Member

To be clear, I much prefer this solution if it works. I'm not confident on my understanding of the behavior here.

@fjkorf
Copy link
Contributor

fjkorf commented Feb 13, 2025

I worked through the code and believe I understand it. Seems sound. I was also able to run the default_picking example locally without error

@alice-i-cecile alice-i-cecile added X-Contentious There are nontrivial implications that should be thought through S-Needs-Testing Testing must be done before this is safe to merge labels Feb 14, 2025
@aevyrie
Copy link
Member

aevyrie commented Feb 16, 2025

We already have some pointer id changes in flight, and I'm a bit worried about doing a partial switch to just one type of pointer input. I think we need to better understand the lifecycle of a pointer, and evaluate if the pointer id is needed at all.

I think the split to Entity + PointerKind is probably right, but last time I used Entity to identify pointers, it was causing things to blow up when part of the system tried to access an entity that didn't exist. If I recall correctly it was something like dragging outside a window would remove the pointer when it got to the edge of the screen, and when it returned and respawned, it caused drag/up events to explode.

I don't know if this is still the case, but that's why I'd like to have a bit more of a thorough understanding of the lifecycle of a pointer (and document it!) before changing the ID. The current state of most of this stuff is an accumulation of bug fixes discovered in use, sometimes things are a bit ugly because they were needed to solve some weird edge case.

Copy link
Member

@aevyrie aevyrie left a comment

Choose a reason for hiding this comment

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

Only one real comment, other than "changing PointerId without a better understanding of pointer entity lifecycles strikes a deep fear in my heart".

@@ -270,6 +262,8 @@ pub enum PointerAction {
pub struct PointerInput {
/// The id of the pointer.
pub pointer_id: PointerId,
/// The pointer entity
pub pointer_entity: Option<Entity>,
Copy link
Member

Choose a reason for hiding this comment

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

Picking is already inconsistent enough across backends, I would strongly prefer if we didn't add more inconsistency, though I appreciate your reasoning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Picking Pointing at and selecting objects of all sorts C-Code-Quality A section of code that is hard to understand or change S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants