Index: src/hid/OHEvdevGameController.h ================================================================== --- src/hid/OHEvdevGameController.h +++ src/hid/OHEvdevGameController.h @@ -31,10 +31,10 @@ uint16_t _vendorID, _productID; OFString *_name; id _rawProfile; } -- (instancetype)oh_initWithPath: (OFString *)path OF_METHOD_FAMILY(init); +- (instancetype)initWithPath: (OFString *)path; - (void)oh_pollState; @end OF_ASSUME_NONNULL_END Index: src/hid/OHEvdevGameController.m ================================================================== --- src/hid/OHEvdevGameController.m +++ src/hid/OHEvdevGameController.m @@ -59,12 +59,12 @@ { OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons; OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *_axes; } -- (instancetype)oh_initWithButtons: (OFDictionary *)buttons - axes: (OFDictionary *)axes OF_METHOD_FAMILY(init); +- (instancetype)initWithButtons: (OFDictionary *)buttons + axes: (OFDictionary *)axes; @end static const uint16_t buttonIDs[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_SELECT, BTN_START, BTN_MODE, BTN_THUMBL, BTN_THUMBR, @@ -422,11 +422,11 @@ path = [@"/dev/input" stringByAppendingPathComponent: device]; @try { controller = [[[OHEvdevGameController alloc] - oh_initWithPath: path] autorelease]; + initWithPath: path] autorelease]; } @catch (OFOpenItemFailedException *e) { if (e.errNo == EACCES) continue; @throw e; @@ -444,11 +444,11 @@ objc_autoreleasePoolPop(pool); return controllers; } -- (instancetype)oh_initWithPath: (OFString *)path +- (instancetype)initWithPath: (OFString *)path { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); @@ -552,12 +552,12 @@ } } [axes makeImmutable]; _rawProfile = [[OHEvdevGameControllerProfile alloc] - oh_initWithButtons: buttons - axes: axes]; + initWithButtons: buttons + axes: axes]; [self oh_pollState]; objc_autoreleasePoolPop(pool); } @catch (id e) { @@ -786,12 +786,12 @@ @end @implementation OHEvdevGameControllerProfile @synthesize buttons = _buttons, axes = _axes; -- (instancetype)oh_initWithButtons: (OFDictionary *)buttons - axes: (OFDictionary *)axes +- (instancetype)initWithButtons: (OFDictionary *)buttons + axes: (OFDictionary *)axes { self = [super init]; @try { _buttons = [buttons retain]; Index: src/hid/OHNintendo3DSGameController.m ================================================================== --- src/hid/OHNintendo3DSGameController.m +++ src/hid/OHNintendo3DSGameController.m @@ -80,29 +80,35 @@ [super dealloc]; } - (void)retrieveState { + void *pool = objc_autoreleasePoolPush(); + OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) + *buttons = _extendedGamepad.buttons; + OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *) + *directionalPads = _extendedGamepad.directionalPads; u32 keys; circlePosition leftPos, rightPos; + OHGameControllerDirectionalPad *directionalPad; hidScanInput(); keys = hidKeysHeld(); hidCircleRead(&leftPos); hidCstickRead(&rightPos); - [_extendedGamepad.northButton setValue: !!(keys & KEY_X)]; - [_extendedGamepad.southButton setValue: !!(keys & KEY_B)]; - [_extendedGamepad.westButton setValue: !!(keys & KEY_Y)]; - [_extendedGamepad.eastButton setValue: !!(keys & KEY_A)]; - [_extendedGamepad.leftShoulderButton setValue: !!(keys & KEY_L)]; - [_extendedGamepad.rightShoulderButton setValue: !!(keys & KEY_R)]; - [_extendedGamepad.leftTriggerButton setValue: !!(keys & KEY_ZL)]; - [_extendedGamepad.rightTriggerButton setValue: !!(keys & KEY_ZR)]; - [_extendedGamepad.menuButton setValue: !!(keys & KEY_START)]; - [_extendedGamepad.optionsButton setValue: !!(keys & KEY_SELECT)]; + [[buttons objectForKey: @"A"] setValue: !!(keys & KEY_A)]; + [[buttons objectForKey: @"B"] setValue: !!(keys & KEY_B)]; + [[buttons objectForKey: @"X"] setValue: !!(keys & KEY_X)]; + [[buttons objectForKey: @"Y"] setValue: !!(keys & KEY_Y)]; + [[buttons objectForKey: @"L"] setValue: !!(keys & KEY_L)]; + [[buttons objectForKey: @"R"] setValue: !!(keys & KEY_R)]; + [[buttons objectForKey: @"ZL"] setValue: !!(keys & KEY_ZL)]; + [[buttons objectForKey: @"ZR"] setValue: !!(keys & KEY_ZR)]; + [[buttons objectForKey: @"Start"] setValue: !!(keys & KEY_START)]; + [[buttons objectForKey: @"Select"] setValue: !!(keys & KEY_SELECT)]; if (leftPos.dx > 150) leftPos.dx = 150; if (leftPos.dx < -150) leftPos.dx = -150; @@ -118,20 +124,25 @@ if (rightPos.dy > 150) rightPos.dy = 150; if (rightPos.dy < -150) rightPos.dy = -150; - _extendedGamepad.leftThumbstick.xAxis.value = (float)leftPos.dx / 150; - _extendedGamepad.leftThumbstick.yAxis.value = -(float)leftPos.dy / 150; - _extendedGamepad.rightThumbstick.xAxis.value = (float)rightPos.dx / 150; - _extendedGamepad.rightThumbstick.yAxis.value = - -(float)rightPos.dy / 150; - - [_extendedGamepad.dPad.up setValue: !!(keys & KEY_DUP)]; - [_extendedGamepad.dPad.down setValue: !!(keys & KEY_DDOWN)]; - [_extendedGamepad.dPad.left setValue: !!(keys & KEY_DLEFT)]; - [_extendedGamepad.dPad.right setValue: !!(keys & KEY_DRIGHT)]; + directionalPad = [directionalPads objectForKey: @"Circle Pad"]; + directionalPad.xAxis.value = (float)leftPos.dx / 150; + directionalPad.yAxis.value = -(float)leftPos.dy / 150; + + directionalPad = [directionalPads objectForKey: @"C-Stick"]; + directionalPad.xAxis.value = (float)rightPos.dx / 150; + directionalPad.yAxis.value = -(float)rightPos.dy / 150; + + directionalPad = [directionalPads objectForKey: @"D-Pad"]; + [directionalPad.up setValue: !!(keys & KEY_DUP)]; + [directionalPad.down setValue: !!(keys & KEY_DDOWN)]; + [directionalPad.left setValue: !!(keys & KEY_DLEFT)]; + [directionalPad.right setValue: !!(keys & KEY_DRIGHT)]; + + objc_autoreleasePoolPop(pool); } - (OFString *)name { return @"Nintendo 3DS"; Index: src/hid/OHNintendoSwitchGameController.h ================================================================== --- src/hid/OHNintendoSwitchGameController.h +++ src/hid/OHNintendoSwitchGameController.h @@ -27,11 +27,11 @@ @class OHNintendoSwitchExtendedGamepad; @interface OHNintendoSwitchGameController: OHGameController { - PadState _padState; + PadState _pad; OHNintendoSwitchExtendedGamepad *_extendedGamepad; } - (instancetype)initWithIndex: (size_t)index; @end Index: src/hid/OHNintendoSwitchGameController.m ================================================================== --- src/hid/OHNintendoSwitchGameController.m +++ src/hid/OHNintendoSwitchGameController.m @@ -74,16 +74,15 @@ - (instancetype)initWithIndex: (size_t)index { self = [super init]; @try { - padInitialize(&_padState, HidNpadIdType_No1 + index, + padInitialize(&_pad, HidNpadIdType_No1 + index, (index == 0 ? HidNpadIdType_Handheld : 0)); - padUpdate(&_padState); + padUpdate(&_pad); - if (!(padGetAttributes(&_padState) & - HidNpadAttribute_IsConnected)) + if (!padIsConnected(&_pad)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; _extendedGamepad = [[OHNintendoSwitchExtendedGamepad alloc] init]; @@ -113,12 +112,12 @@ *directionalPads = _extendedGamepad.directionalPads; u64 keys; HidAnalogStickState stick; OHGameControllerDirectionalPad *directionalPad; - padUpdate(&_padState); - keys = padGetButtons(&_padState); + padUpdate(&_pad); + keys = padGetButtons(&_pad); [[buttons objectForKey: @"A"] setValue: !!(keys & HidNpadButton_A)]; [[buttons objectForKey: @"B"] setValue: !!(keys & HidNpadButton_B)]; [[buttons objectForKey: @"X"] setValue: !!(keys & HidNpadButton_X)]; [[buttons objectForKey: @"Y"] setValue: !!(keys & HidNpadButton_Y)]; @@ -131,18 +130,18 @@ [[buttons objectForKey: @"Right Thumbstick"] setValue: !!(keys & HidNpadButton_StickR)]; [[buttons objectForKey: @"+"] setValue: !!(keys & HidNpadButton_Plus)]; [[buttons objectForKey: @"-"] setValue: !!(keys & HidNpadButton_Minus)]; - stick = padGetStickPos(&_padState, 0); + stick = padGetStickPos(&_pad, 0); directionalPad = [directionalPads objectForKey: @"Left Thumbstick"]; [directionalPad.xAxis setValue: (float)stick.x / (stick.x < 0 ? -INT16_MIN : INT16_MAX)]; [directionalPad.yAxis setValue: -(float)stick.y / (stick.y < 0 ? -INT16_MIN : INT16_MAX)]; - stick = padGetStickPos(&_padState, 1); + stick = padGetStickPos(&_pad, 1); directionalPad = [directionalPads objectForKey: @"Right Thumbstick"]; [directionalPad.xAxis setValue: (float)stick.x / (stick.x < 0 ? -INT16_MIN : INT16_MAX)]; [directionalPad.yAxis setValue: -(float)stick.y / (stick.y < 0 ? -INT16_MIN : INT16_MAX)]; Index: src/hid/OHXInputGameController.h ================================================================== --- src/hid/OHXInputGameController.h +++ src/hid/OHXInputGameController.h @@ -30,11 +30,11 @@ DWORD _index; OFNumber *_Nullable _vendorID, *_Nullable _productID; OHXInputExtendedGamepad *_extendedGamepad; } -- (instancetype)oh_initWithIndex: (DWORD)index OF_METHOD_FAMILY(init); +- (instancetype)initWithIndex: (DWORD)index; @end #ifdef __cplusplus extern "C" { #endif Index: src/hid/OHXInputGameController.m ================================================================== --- src/hid/OHXInputGameController.m +++ src/hid/OHXInputGameController.m @@ -93,11 +93,11 @@ for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) { OHGameController *controller; @try { controller = [[[OHXInputGameController alloc] - oh_initWithIndex: i] autorelease]; + initWithIndex: i] autorelease]; } @catch (OFInitializationFailedException *e) { /* Controller does not exist. */ continue; } @@ -110,11 +110,11 @@ [controllers makeImmutable]; return controllers; } -- (instancetype)oh_initWithIndex: (DWORD)index +- (instancetype)initWithIndex: (DWORD)index { self = [super init]; @try { XINPUT_STATE state = { 0 }; Index: tests/gamecontroller/GameControllerTests.m ================================================================== --- tests/gamecontroller/GameControllerTests.m +++ tests/gamecontroller/GameControllerTests.m @@ -187,13 +187,11 @@ #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) [OFStdIOStream setUpConsole]; #endif #if defined(OF_NINTENDO_SWITCH) consoleInit(NULL); -#endif -#ifdef OF_NINTENDO_SWITCH while (appletMainLoop()) { #else for (;;) { #endif void *pool = objc_autoreleasePoolPush();