From: Joe Wreschnig Date: Thu, 28 Feb 2013 16:28:29 +0000 (+0100) Subject: Fix case where quick axis movements could create duplicate running targets. X-Git-Tag: version-1.0~94 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=ada313d7e31dd509c8c7be01f364c9a2ad9860d4;p=enjoyable.git Fix case where quick axis movements could create duplicate running targets. --- diff --git a/JoystickController.h b/JoystickController.h index 498ea39..c67a7c1 100644 --- a/JoystickController.h +++ b/JoystickController.h @@ -24,7 +24,6 @@ @property (readonly) Config *currentConfig; @property (readonly) JSAction *selectedAction; @property (readonly) NSMutableArray *joysticks; -@property (readonly) NSMutableArray *runningTargets; @property (assign) NSPoint mouseLoc; @property (assign) BOOL frontWindowOnly; diff --git a/JoystickController.m b/JoystickController.m index 0675075..6acc545 100644 --- a/JoystickController.m +++ b/JoystickController.m @@ -18,10 +18,10 @@ @implementation JoystickController { IOHIDManagerRef hidManager; NSTimer *continuousTimer; + NSMutableArray *runningTargets; } @synthesize joysticks; -@synthesize runningTargets; @synthesize selectedAction; @synthesize frontWindowOnly; @synthesize mouseLoc; @@ -47,8 +47,9 @@ } - (void)addRunningTarget:(Target *)target { - if (![runningTargets containsObject:target]) + if (![runningTargets containsObject:target]) { [runningTargets addObject:target]; + } if (!continuousTimer) { continuousTimer = [NSTimer scheduledTimerWithTimeInterval:1.f/60.f target:self @@ -130,11 +131,13 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD - (void)updateContinuousActions:(NSTimer *)timer { self.mouseLoc = [NSEvent mouseLocation]; - for (Target *target in [self.runningTargets copy]) { - if (![target update:self]) - [self.runningTargets removeObject:target]; + for (Target *target in [runningTargets copy]) { + if (![target update:self]) { + [runningTargets removeObject:target]; + NSLog(@"Removing action, now running %lu.", runningTargets.count); + } } - if (!self.runningTargets.count) { + if (!runningTargets.count) { [continuousTimer invalidate]; continuousTimer = nil; NSLog(@"Unscheduled continuous target timer."); diff --git a/TargetMouseMove.m b/TargetMouseMove.m index 8eeae88..d2bc943 100644 --- a/TargetMouseMove.m +++ b/TargetMouseMove.m @@ -10,7 +10,9 @@ #import "JoystickController.h" -@implementation TargetMouseMove +@implementation TargetMouseMove { + int sign; +} -(BOOL) isContinuous { return true; @@ -34,19 +36,28 @@ } - (BOOL)update:(JoystickController *)jc { - //printf("Dir %d inputValue %f\n", [self dir], [self inputValue]); - if (fabs(self.magnitude) < 0.01) + if (fabsf(self.magnitude) < 0.01) { + sign = 0; return NO; // dead zone + } + + // If the action crossed over High/Low, this target is done. + if (!sign) + sign = self.magnitude < 0 ? -1 : 1; + else if (sign / self.magnitude < 0) { + sign = 0; + return NO; + } NSRect screenRect = [[NSScreen mainScreen] frame]; NSInteger height = screenRect.size.height; // TODO - float speed = 4.0; + float speed = 4.f; if ([jc frontWindowOnly]) - speed = 12.0; - float dx = 0.0, dy = 0.0; - if ([self dir] == 0) + speed = 12.f; + float dx = 0.f, dy = 0.f; + if (self.dir == 0) dx = self.magnitude * speed; else dy = self.magnitude * speed; @@ -72,7 +83,7 @@ } CFRelease(move); - return dx || dy; + return YES; } @end