-@implementation JoystickController
-
-@synthesize joysticks, runningTargets, selectedAction, frontWindowOnly;
-
--(id) init {
- if(self=[super init]) {
- joysticks = [[NSMutableArray alloc]init];
- runningTargets = [[NSMutableArray alloc]init];
- programmaticallySelecting = NO;
- mouseLoc.x = mouseLoc.y = 0;
- }
- return self;
-}
-
--(void) dealloc {
- for(int i=0; i<[joysticks count]; i++) {
- [joysticks[i] invalidate];
- }
- IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone);
- CFRelease(hidManager);
-}
-
-static NSMutableDictionary* create_criterion( UInt32 inUsagePage, UInt32 inUsage )
-{
- NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
- dict[(NSString*)CFSTR(kIOHIDDeviceUsagePageKey)] = @(inUsagePage);
- dict[(NSString*)CFSTR(kIOHIDDeviceUsageKey)] = @(inUsage);
- return dict;
-}
-
--(void) expandRecursive: (id) handler {
- if([handler base])
- [self expandRecursive: [handler base]];
- [outlineView expandItem: handler];
-}
-
-static void timer_callback(CFRunLoopTimerRef timer, void *ctx) {
- JoystickController *jc = (__bridge JoystickController *)ctx;
- jc->mouseLoc = [NSEvent mouseLocation];
- for (Target *target in [jc runningTargets]) {
- [target update: jc];
+@implementation JoystickController {
+ IOHIDManagerRef hidManager;
+ BOOL programmaticallySelecting;
+ NSTimer *continuousTimer;
+}
+
+@synthesize joysticks;
+@synthesize runningTargets;
+@synthesize selectedAction;
+@synthesize frontWindowOnly;
+@synthesize mouseLoc;
+
+- (id)init {
+ if ((self = [super init])) {
+ joysticks = [[NSMutableArray alloc] initWithCapacity:16];
+ runningTargets = [[NSMutableArray alloc] initWithCapacity:32];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [continuousTimer invalidate];
+ IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone);
+ CFRelease(hidManager);
+}
+
+- (void)expandRecursive:(id)handler {
+ if ([handler base])
+ [self expandRecursive:[handler base]];
+ [outlineView expandItem:handler];
+}
+
+- (void)addRunningTarget:(Target *)target {
+ if (![runningTargets containsObject:target])
+ [runningTargets addObject:target];
+ if (!continuousTimer) {
+ continuousTimer = [NSTimer scheduledTimerWithTimeInterval:1.f/60.f
+ target:self
+ selector:@selector(updateContinuousActions:)
+ userInfo:nil
+ repeats:YES];
+ NSLog(@"Scheduled continuous target timer.");