Skip to content

Commit

Permalink
comments, cleanup, and fixed touch timestamp for calculating tap counts
Browse files Browse the repository at this point in the history
  • Loading branch information
racarone committed Feb 1, 2016
1 parent 96d9d43 commit 51a6931
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
48 changes: 28 additions & 20 deletions sparrow/src/Classes/SPTouchProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ - (void)advanceTime:(double)seconds
{
_elapsedTime += seconds;

// remove old taps
if (_lastTaps.count)
{
NSMutableArray *remainingTaps = [NSMutableArray array];
Expand All @@ -96,36 +97,38 @@ - (void)advanceTime:(double)seconds
SP_RELEASE_AND_RETAIN(_lastTaps, remainingTaps);
}

if (_queuedTouches.count)
while (_queuedTouches.count)
{
NSMutableArray *excessTouches = [NSMutableArray array];

// set touches that were new or moving to phase 'SPTouchPhaseStationary'
for (SPTouch *touch in _currentTouches)
if (touch.phase == SPTouchPhaseBegan || touch.phase == SPTouchPhaseMoved)
touch.phase = SPTouchPhaseStationary;

while (_queuedTouches.count)
// analyze new touches, but each ID only once
for (SPTouch *touch in _queuedTouches)
{
NSMutableArray *excessTouches = [NSMutableArray array];

for (SPTouch *touch in _queuedTouches)
if (![_updatedTouches containsObject:touch])
{
[self addCurrentTouch:touch];
[_updatedTouches addObject:touch];
}
else
{
if (![_updatedTouches containsObject:touch])
{
[self addCurrentTouch:touch];
[_updatedTouches addObject:touch];
}
else
{
[excessTouches addObject:touch];
}
[excessTouches addObject:touch];
}

[self processTouches:_updatedTouches.set];
[_updatedTouches removeAllObjects];

SP_RELEASE_AND_RETAIN(_queuedTouches, excessTouches);
}

// process the current set of touches (i.e. dispatch touch events)
[self processTouches:_updatedTouches.set];
[_updatedTouches removeAllObjects];

// remove ended touches
[self removeEndedTouches];

// switch to excess touches
SP_RELEASE_AND_RETAIN(_queuedTouches, excessTouches);
}
}

Expand Down Expand Up @@ -194,6 +197,7 @@ - (void)addCurrentTouch:(SPTouch *)touch
{
NSUInteger index = [_currentTouches indexOfObject:touch];

// add/replace
if (index != NSNotFound)
{
SPTouch *currentTouch = _currentTouches[index];
Expand All @@ -204,7 +208,11 @@ - (void)addCurrentTouch:(SPTouch *)touch
{
[_currentTouches addObject:touch];
}


// update timestamp
touch.timestamp = _elapsedTime;

// update taps
if (touch.phase == SPTouchPhaseBegan)
[self updateTapCount:touch];
}
Expand Down
2 changes: 0 additions & 2 deletions sparrow/src/Classes/SPViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,12 @@ - (void)processTouchEvent:(UIEvent *)event
float yConversion = _stage.height / viewSize.height;

// convert to SPTouches and forward to stage
double now = CACurrentMediaTime();
for (UITouch *uiTouch in [event touchesForView:_internalView])
{
CGPoint location = [uiTouch locationInView:_internalView];
CGPoint previousLocation = [uiTouch previousLocationInView:_internalView];

SPTouch *touch = [SPTouch touch];
touch.timestamp = now; // timestamp of uiTouch not compatible to Sparrow timestamp
touch.globalX = location.x * xConversion;
touch.globalY = location.y * yConversion;
touch.previousGlobalX = previousLocation.x * xConversion;
Expand Down

0 comments on commit 51a6931

Please sign in to comment.