X-Git-Url: https://git.yukkurigames.com/?a=blobdiff_plain;f=JSActionAnalog.m;h=027bd5db95f8436a7f7040e9057e7f95e6e869ab;hb=fad073260e61084c4962e172c58a0595261bd811;hp=a1c57e8533c2668737b265a9cc1902471ed939e5;hpb=530009447c5bbd360ac5023979cffc6d32a28df3;p=enjoyable.git diff --git a/JSActionAnalog.m b/JSActionAnalog.m index a1c57e8..027bd5d 100644 --- a/JSActionAnalog.m +++ b/JSActionAnalog.m @@ -9,13 +9,9 @@ - (id) initWithIndex: (int)newIndex { if(self = [super init]) { - subActions = [NSArray arrayWithObjects: - [[SubAction alloc] initWithIndex: 0 name: @"Low" base: self], + subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Low" base: self], [[SubAction alloc] initWithIndex: 1 name: @"High" base: self], - [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self], - nil - ]; - [subActions retain]; + [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self]]; index = newIndex; name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)]; } @@ -23,31 +19,36 @@ } -(id) findSubActionForValue: (IOHIDValueRef) value { - if ([[subActions objectAtIndex: 2] active]) { - return [subActions objectAtIndex: 2]; // TODO? + if ([subActions[2] active]) { + return subActions[2]; // TODO? } //Target* target = [[base->configsController currentConfig] getTargetForAction: [subActions objectAtIndex: 0]]; int raw = IOHIDValueGetIntegerValue(value); - double parsed = offset + scale * raw; + double parsed = [self getRealValue: raw]; if(parsed < -0.3) // fixed?! - return [subActions objectAtIndex: 0]; + return subActions[0]; else if(parsed > 0.3) - return [subActions objectAtIndex: 1]; + return subActions[1]; return NULL; } -(void) notifyEvent: (IOHIDValueRef) value { // Analog action is always active - [[subActions objectAtIndex: 2] setActive: true]; + [subActions[2] setActive: true]; int raw = IOHIDValueGetIntegerValue(value); - double parsed = offset + scale * raw; + double parsed = [self getRealValue: raw]; - [[subActions objectAtIndex: 0] setActive: (parsed < -0.3)]; - [[subActions objectAtIndex: 1] setActive: (parsed > 0.3)]; + [subActions[0] setActive: (parsed < -0.3)]; + [subActions[1] setActive: (parsed > 0.3)]; +} + +-(double) getRealValue: (int)value { + double parsed = offset + scale * value; + return parsed; } @synthesize offset, scale;