Skip to content
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

Resolving dropped/lost intra-frame rapid touches #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hobsynth
Copy link

I’ve been dealing with an issue of dropped/lost touches. I’m working on an app that allows for extremely rapid multiple touches.

A situation exists now in SPTouchProcessor, where when a touch’s phase changes within the period of a single frame, the last phase overwrites the previous. This may mean that you only get SPTouchPhaseEnded without ever seeing the initial SPTouchPhaseBegan. That represents a dropped touch. Of course, you really have to tap fast in order to re-create this issue. It’s easy to see if the frame rate drops a bit and you’re on a slower device.

I’m really interested to see if anyone can solve this issue in a better and more optimized way.

I’ve tried a few approaches but this one seemed to work the best.

[ Move any matching touches onto a temporary queue. Dispatch the normal queue as usually and then, right after, reprocess the matching touches queue before the next frame. Even though you’ll see these touches fire out at nearly the same time, the point is that all phases still fire and in the correct order. ]

Before we merge this, I’d really like some feedback about performance. I’m guessing there is either a better approach or at least, way to improve the performance.

Thanks in advance.

hobsynth and others added 2 commits January 30, 2016 22:39
Added excess queue to hold touches with same ID. Previously these duplicate touches just overwrote themselves, causing situations of missing touches.  This excess queue gets processed after the first queue and before the next frame.
racarone added a commit that referenced this pull request Feb 1, 2016
…he touch processor, they essentially would "overwrite" themselves causing touches to be lost in the game loop; this is now corrected by checking for duplicates and repeating processing until the queue is empty
@racarone
Copy link

racarone commented Feb 1, 2016

I took a look at this and you are right again! Touches were completely lost due to this bug. I liked your commit, but I fixed and cleaned this up in f3d44f0. Instead getting an IndexSet for the duplicate IDs, I'm just checking the _updatedTouches set for inclusion and adding the excess to a separate array and looping. Very similar, just a little more performant. Thanks for pull request, this definitely needed to be addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants