Fix touch input lag that occur on some devices. #2266

Merged
merged 4 commits into from Mar 13, 2014

Projects

None yet

3 participants

@nkast
Contributor
nkast commented Mar 7, 2014

This is a bug that has been reported on many occasions. I have seen it myself on a custom AMDx86 tablet but on AtivTab is not visible. Others has seen it on Surface Pro and XPS10.
This comment mono#2113 has been very helpful to track down this bug. It has been speculated that it is due to drivers firing events faster, or that on slow machines events are not consumed as fast. I would like to add the possibility that the quality of the touch screen might be a factor to why we see that on some devices and not on others. The better/more accurate a touch screen is, the more visible this bug is.

I had to close the previews PR f63da1f and resend after the recent changes on TouchPanel/TouchPanelState.

I will try to explain this as briefly as possible.
TouchPanelState.Refresh(...) is always called inside a while "ex. (touchPanelState.Refresh(...) ) {...}" by making the assumption that this functions returns false when there are no more events to process.
This function, for every preview touch id, goes through the event list and tries to find the first event with the same id, remove it, and break the loop. Then continues on with the next id and finally with the rest of the program.
In case the event hasn't changed position from last time and there are no other real events, stateChanged remains always =false and the function returns false. This breaks the caller's While() loop and wont be called until the next frame. The problem is that it removes one nonmoving event at a time while the list accumulate similar events for that id.
The fix is that we keep removing events of that id, as long as stateChanged==false, which is all nonmoving events we can find until we reach a real touch event.
The j-- of course adjust the j indexer after the removal of one element.

nkast added some commits Mar 7, 2014
@nkast nkast Fix touch input lag that occur on some devices.
mono#2113

nkast@f63da1f

I had to close the previews PR and resend after the recent changes on
TouchPanel/TouchPanelState.
fe7e06f
@nkast nkast .. 34e5226
@mgbot
Member
mgbot commented Mar 7, 2014

Can one of the admins verify this patch?

@mgbot
Member
mgbot commented Mar 7, 2014

Can one of the admins verify this patch?

@KonajuGames
Contributor

@mgbot test

@mgbot
Member
mgbot commented Mar 9, 2014

Test PASSed.
Refer to this link for build results: http://build.monogame.net/job/PullRequestTester/622/

@KonajuGames KonajuGames merged commit 7ff484b into MonoGame:develop Mar 13, 2014
@KonajuGames
Contributor

Merged.

@nkast
Contributor
nkast commented Mar 13, 2014

Thanks!

@nkast nkast deleted the unknown repository branch Mar 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment