[Merged by Bors] - bevy_input: Fix process touch event#4352
[Merged by Bors] - bevy_input: Fix process touch event#4352light4 wants to merge 1 commit intobevyengine:mainfrom
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.
Shouldn't we update the touch phase before inserting? (Same on canceled)
There was a problem hiding this comment.
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.
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.
The touch info is from
self.pressedor 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.
The info is updated from phase TouchPhase::Moved
There was a problem hiding this comment.
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. |
HackerFoo
left a comment
There was a problem hiding this comment.
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.
| 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.
It would be good to add an explanation for this assertion.
dfeaa8d to
166fd50
Compare
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_eventinbevy_inputdon't update position info.TouchPhase::EndedandTouchPhase::Cancelledshould use the position info frompressed. Otherwise, it'll not update. The position info is updated fromTouchPhase::Moved.Solution
Changelog