-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - bevy_input: Fix process touch event #4352
Conversation
self.just_released.insert(event.id, event.into()); | ||
self.pressed.remove_entry(&event.id); | ||
if let Some((_, v)) = self.pressed.remove_entry(&event.id) { | ||
self.just_released.insert(event.id, v); |
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.
Shouldn't we update the touch phase before inserting? (Same on canceled)
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.
The touch info is from self.pressed
or event, so I think this is fine.
I can change this if you prefer to update it first.
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.
Actually, the touch info should come from self.pressed
.
If not found in self.pressed
, there may be some error occurred, set it to default just to get rid of panic.
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.
The touch info is from
self.pressed
or event, so I think this is fine.
You mean it already reflects the Ended
/Canceled
phase? I haven't used touches in Bevy before but I assume the event returned from just_released
would be one of those phases.
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.
The info is updated from phase TouchPhase::Moved
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.
Oh interesting. See I'd think that one should also update the phase to Moved
. 🤔
But maybe I'm just mistaken in how the touch system is supposed to work.
Requesting review from @HackerFoo, who has by far the most practical experience with Bevy's touch APIs. |
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.
I couldn't understand the PR description. It would be good to update this to make this easier for other reviewers.
From looking at the code and test, it looks like this makes sure .position
/.force
gets moved to .prev_position
/.prev_force
for TouchPhase::Ended
(the last update in a motion) as it is in other phases. Before this change, the current position would be assigned to both in this phase.
So this change makes sense and is useful to get a correct delta on the last update.
touches.process_touch_event(&end_touch_event); | ||
|
||
assert!(touches.just_released.get(&touch_event.id).is_some()); | ||
assert!(touches.pressed.get(&touch_event.id).is_none()); | ||
let touch = touches.just_released.get(&touch_event.id).unwrap(); | ||
assert!(touch.previous_position != touch.position); |
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.
It would be good to add an explanation for this assertion.
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.
updated
dfeaa8d
to
166fd50
Compare
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.
If you're around, could you try to improve the PR description and add comments to the if let
blocks added? This change is correct, and I won't block on it, but it would be nice to clean it up as we go.
I'll merge this once that's done or next Monday.
df24196
to
52856a8
Compare
`TouchPhase::Ended` and `TouchPhase::Cancelled` should use the position info from `pressed`. Otherwise, it'll not update. The position info is updated from `TouchPhase::Moved`.
52856a8
to
b47cddb
Compare
Rebased and add comments to |
Thanks a ton, and no worries :)
This is actually quite good now! Thank you very much. bors r+ |
# Objective - `process_touch_event` in `bevy_input` don't update position info. `TouchPhase::Ended` and `TouchPhase::Cancelled` should use the position info from `pressed`. Otherwise, it'll not update. The position info is updated from `TouchPhase::Moved`. ## Solution - Use updated touch info. --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, feel free to skip this section. - Fixed: bevy_input, fix process touch event, update touch info
Pull request successfully merged into main. Build succeeded: |
# Objective - `process_touch_event` in `bevy_input` don't update position info. `TouchPhase::Ended` and `TouchPhase::Cancelled` should use the position info from `pressed`. Otherwise, it'll not update. The position info is updated from `TouchPhase::Moved`. ## Solution - Use updated touch info. --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, feel free to skip this section. - Fixed: bevy_input, fix process touch event, update touch info
# Objective - `process_touch_event` in `bevy_input` don't update position info. `TouchPhase::Ended` and `TouchPhase::Cancelled` should use the position info from `pressed`. Otherwise, it'll not update. The position info is updated from `TouchPhase::Moved`. ## Solution - Use updated touch info. --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, feel free to skip this section. - Fixed: bevy_input, fix process touch event, update touch info
# Objective - `process_touch_event` in `bevy_input` don't update position info. `TouchPhase::Ended` and `TouchPhase::Cancelled` should use the position info from `pressed`. Otherwise, it'll not update. The position info is updated from `TouchPhase::Moved`. ## Solution - Use updated touch info. --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, feel free to skip this section. - Fixed: bevy_input, fix process touch event, update touch info
# Objective - `process_touch_event` in `bevy_input` don't update position info. `TouchPhase::Ended` and `TouchPhase::Cancelled` should use the position info from `pressed`. Otherwise, it'll not update. The position info is updated from `TouchPhase::Moved`. ## Solution - Use updated touch info. --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, feel free to skip this section. - Fixed: bevy_input, fix process touch event, update touch info
Objective
process_touch_event
inbevy_input
don't update position info.TouchPhase::Ended
andTouchPhase::Cancelled
should use the position info frompressed
. Otherwise, it'll not update. The position info is updated fromTouchPhase::Moved
.Solution
Changelog