@property (readonly) Config *currentConfig;
@property (readonly) JSAction *selectedAction;
@property (readonly) NSMutableArray *joysticks;
-@property (readonly) NSMutableArray *runningTargets;
@property (assign) NSPoint mouseLoc;
@property (assign) BOOL frontWindowOnly;
@implementation JoystickController {
IOHIDManagerRef hidManager;
NSTimer *continuousTimer;
+ NSMutableArray *runningTargets;
}
@synthesize joysticks;
-@synthesize runningTargets;
@synthesize selectedAction;
@synthesize frontWindowOnly;
@synthesize mouseLoc;
}
- (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
- (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.");
#import "JoystickController.h"
-@implementation TargetMouseMove
+@implementation TargetMouseMove {
+ int sign;
+}
-(BOOL) isContinuous {
return true;
}
- (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;
}
CFRelease(move);
- return dx || dy;
+ return YES;
}
@end