Overview
Comment: | OFGameController: Use more generic button names |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | gamecontroller |
Files: | files | file ages | folders |
SHA3-256: |
2c2412d3df2a3d7707631c826f88d164 |
User & Date: | js on 2024-05-14 20:41:28 |
Other Links: | branch diff | manifest | tags |
Context
2024-05-14
| ||
20:56 | OFGameController: Try all XInput versions check-in: 6032aeea55 user: js tags: gamecontroller | |
20:41 | OFGameController: Use more generic button names check-in: 2c2412d3df user: js tags: gamecontroller | |
2024-05-13
| ||
22:07 | Fix ObjFWTest on Nintendo (3)DS check-in: f75c7058f7 user: js tags: gamecontroller | |
Changes
Modified src/hid/OFGameController.h from [c7833087c0] to [f60cc4462d].
︙ | ︙ | |||
39 40 41 42 43 44 45 | @class OFSet OF_GENERIC(ObjectType); /** * @brief A button on a controller. * * Possible values are: * | | | | | > > > > | > | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < | | | | | | | | < < < < < < < < < < < < < < < | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | | | | | > | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | @class OFSet OF_GENERIC(ObjectType); /** * @brief A button on a controller. * * Possible values are: * * * @ref OFGameControllerNorthButton * * @ref OFGameControllerSouthButton * * @ref OFGameControllerWestButton * * @ref OFGameControllerEastButton * * @ref OFGameControllerLeftTriggerButton * * @ref OFGameControllerRightTriggerButton * * @ref OFGameControllerLeftShoulderButton * * @ref OFGameControllerRightShoulderButton * * @ref OFGameControllerLeftStickButton * * @ref OFGameControllerRightStickButton * * @ref OFGameControllerDPadUpButton * * @ref OFGameControllerDPadDownButton * * @ref OFGameControllerDPadLeftButton * * @ref OFGameControllerDPadRightButton * * @ref OFGameControllerStartButton * * @ref OFGameControllerSelectButton * * @ref OFGameControllerHomeButton * * @ref OFGameControllerCaptureButton * * @ref OFGameControllerAButton * * @ref OFGameControllerBButton * * @ref OFGameControllerCButton * * @ref OFGameControllerXButton * * @ref OFGameControllerYButton * * @ref OFGameControllerZButton * * @ref OFGameControllerCPadUpButton * * @ref OFGameControllerCPadDownButton * * @ref OFGameControllerCPadLeftButton * * @ref OFGameControllerCPadRightButton * * @ref OFGameControllerPlusButton * * @ref OFGameControllerMinusButton * * @ref OFGameControllerSLButton * * @ref OFGameControllerSRButton * * @ref OFGameControllerModeButton */ typedef OFConstantString *OFGameControllerButton; #ifdef __cplusplus extern "C" { #endif /** * @brief The north button on a game controller's diamond pad. */ extern const OFGameControllerButton OFGameControllerNorthButton; /** * @brief The south button on a game controller's diamond pad. */ extern const OFGameControllerButton OFGameControllerSouthButton; /** * @brief The west button on a game controller's diamond pad. */ extern const OFGameControllerButton OFGameControllerWestButton; /** * @brief The east button on a game controller's diamond pad. */ extern const OFGameControllerButton OFGameControllerEastButton; /** * @brief The left trigger button on a game controller. */ extern const OFGameControllerButton OFGameControllerLeftTriggerButton; /** * @brief The right trigger button on a game controller. */ extern const OFGameControllerButton OFGameControllerRightTriggerButton; /** * @brief The left shoulder button on a game controller. */ extern const OFGameControllerButton OFGameControllerLeftShoulderButton; /** * @brief The right shoulder button on a game controller. */ extern const OFGameControllerButton OFGameControllerRightShoulderButton; /** * @brief The left stick button (pressing the left stick) on a game controller. */ extern const OFGameControllerButton OFGameControllerLeftStickButton; /** * @brief The right stick button (pressing the right stick) on a game * controller. */ extern const OFGameControllerButton OFGameControllerRightStickButton; /** * @brief The D-Pad Up button on a game controller. */ extern const OFGameControllerButton OFGameControllerDPadUpButton; /** * @brief The D-Pad Down button on a game controller. */ extern const OFGameControllerButton OFGameControllerDPadDownButton; /** * @brief The D-Pad Left button on a game controller. */ extern const OFGameControllerButton OFGameControllerDPadLeftButton; /** * @brief The D-Pad Right button on a game controller. */ extern const OFGameControllerButton OFGameControllerDPadRightButton; /** * @brief The Start button on a game controller. */ extern const OFGameControllerButton OFGameControllerStartButton; /** * @brief The Select button on a game controller. */ extern const OFGameControllerButton OFGameControllerSelectButton; /** * @brief The Home button on a game controller. */ extern const OFGameControllerButton OFGameControllerHomeButton; /** * @brief The Capture button on a game controller. */ extern const OFGameControllerButton OFGameControllerCaptureButton; /** * @brief The A button on a game controller. */ extern const OFGameControllerButton OFGameControllerAButton; /** * @brief The B button on a game controller. */ extern const OFGameControllerButton OFGameControllerBButton; /** * @brief The C button on a game controller. */ extern const OFGameControllerButton OFGameControllerCButton; /** * @brief The X button on a game controller. */ extern const OFGameControllerButton OFGameControllerXButton; /** * @brief The Y button on a game controller. */ extern const OFGameControllerButton OFGameControllerYButton; /** * @brief The Z button on a game controller. */ extern const OFGameControllerButton OFGameControllerZButton; /** * @brief The C-Pad Up button on a game controller. */ extern const OFGameControllerButton OFGameControllerCPadUpButton; /** * @brief The C-Pad Down button on a game controller. */ extern const OFGameControllerButton OFGameControllerCPadDownButton; /** * @brief The C-Pad Left button on a game controller. */ extern const OFGameControllerButton OFGameControllerCPadLeftButton; /** * @brief The C-Pad Right button on a game controller. */ extern const OFGameControllerButton OFGameControllerCPadRightButton; /** * @brief The + button on a game controller. */ extern const OFGameControllerButton OFGameControllerPlusButton; /** * @brief The - button on a game controller. */ extern const OFGameControllerButton OFGameControllerMinusButton; /** * @brief The SL button on a game controller. */ extern const OFGameControllerButton OFGameControllerSLButton; /** * @brief The SR button on a game controller. */ extern const OFGameControllerButton OFGameControllerSRButton; /** * @brief The Mode button on a game controller. */ extern const OFGameControllerButton OFGameControllerModeButton; #ifdef __cplusplus } #endif /** * @brief A class for reading state from a game controller. */ OF_SUBCLASSING_RESTRICTED @interface OFGameController: OFObject { #if defined(OF_LINUX) OFString *_path; int _fd; uint16_t _vendorID, _productID; OFString *_name; OFMutableSet *_buttons, *_pressedButtons; bool _hasLeftAnalogStick, _hasRightAnalogStick; bool _hasLeftTriggerPressure, _hasRightTriggerPressure; OFPoint _leftAnalogStickPosition, _rightAnalogStickPosition; float _leftTriggerPressure, _rightTriggerPressure; int32_t _leftAnalogStickMinX, _leftAnalogStickMaxX; int32_t _leftAnalogStickMinY, _leftAnalogStickMaxY; int32_t _rightAnalogStickMinX, _rightAnalogStickMaxX; int32_t _rightAnalogStickMinY, _rightAnalogStickMaxY; int32_t _leftTriggerMinPressure, _leftTriggerMaxPressure; int32_t _rightTriggerMinPressure, _rightTriggerMaxPressure; #elif defined(OF_NINTENDO_DS) OFMutableSet *_pressedButtons; #elif defined(OF_NINTENDO_3DS) OFMutableSet *_pressedButtons; OFPoint _leftAnalogStickPosition; #elif defined(OF_WINDOWS) DWORD _index; OFNumber *_Nullable _vendorID, *_Nullable productID; OFMutableSet *_pressedButtons; OFPoint _leftAnalogStickPosition, _rightAnalogStickPosition; float _leftTriggerPressure, _rightTriggerPressure; #endif } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFArray <OFGameController *> *controllers; #endif |
︙ | ︙ | |||
312 313 314 315 316 317 318 | /** * @brief The position of the right analog stick. * * The range is from (-1, -1) to (1, 1). */ @property (readonly, nonatomic) OFPoint rightAnalogStickPosition; | < < < < < < < < < < < < < < < < < < < < < < < < | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | /** * @brief The position of the right analog stick. * * The range is from (-1, -1) to (1, 1). */ @property (readonly, nonatomic) OFPoint rightAnalogStickPosition; /** * @brief Returns the available controllers. * * @return The available controllers */ + (OFArray OF_GENERIC(OFGameController *) *)controllers; |
︙ | ︙ |
Modified src/hid/OFGameController.m from [c4bdc74964] to [7d1cdb7cca].
︙ | ︙ | |||
18 19 20 21 22 23 24 | */ #include "config.h" #import "OFGameController.h" #import "OFArray.h" | | | | | | > | > | > | > | | | | | > | | | | | | | | | | | | > > > | | | | < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | */ #include "config.h" #import "OFGameController.h" #import "OFArray.h" const OFGameControllerButton OFGameControllerNorthButton = @"North"; const OFGameControllerButton OFGameControllerSouthButton = @"South"; const OFGameControllerButton OFGameControllerWestButton = @"West"; const OFGameControllerButton OFGameControllerEastButton = @"East"; const OFGameControllerButton OFGameControllerLeftTriggerButton = @"Left Trigger"; const OFGameControllerButton OFGameControllerRightTriggerButton = @"Right Trigger"; const OFGameControllerButton OFGameControllerLeftShoulderButton = @"Left Shoulder"; const OFGameControllerButton OFGameControllerRightShoulderButton = @"Right Shoulder"; const OFGameControllerButton OFGameControllerLeftStickButton = @"Left Stick"; const OFGameControllerButton OFGameControllerRightStickButton = @"Right Stick"; const OFGameControllerButton OFGameControllerDPadUpButton = @"D-Pad Up"; const OFGameControllerButton OFGameControllerDPadDownButton = @"D-Pad Down"; const OFGameControllerButton OFGameControllerDPadLeftButton = @"D-Pad Left"; const OFGameControllerButton OFGameControllerDPadRightButton = @"D-Pad Right"; const OFGameControllerButton OFGameControllerStartButton = @"Start"; const OFGameControllerButton OFGameControllerSelectButton = @"Select"; const OFGameControllerButton OFGameControllerHomeButton = @"Home"; const OFGameControllerButton OFGameControllerCaptureButton = @"Capture"; const OFGameControllerButton OFGameControllerAButton = @"A"; const OFGameControllerButton OFGameControllerBButton = @"B"; const OFGameControllerButton OFGameControllerCButton = @"C"; const OFGameControllerButton OFGameControllerXButton = @"X"; const OFGameControllerButton OFGameControllerYButton = @"Y"; const OFGameControllerButton OFGameControllerZButton = @"Z"; const OFGameControllerButton OFGameControllerCPadUpButton = @"C-Pad Up"; const OFGameControllerButton OFGameControllerCPadDownButton = @"C-Pad Down"; const OFGameControllerButton OFGameControllerCPadLeftButton = @"C-Pad Left"; const OFGameControllerButton OFGameControllerCPadRightButton = @"C-Pad Right"; const OFGameControllerButton OFGameControllerPlusButton = @"+"; const OFGameControllerButton OFGameControllerMinusButton = @"-"; const OFGameControllerButton OFGameControllerSLButton = @"SL"; const OFGameControllerButton OFGameControllerSRButton = @"SR"; const OFGameControllerButton OFGameControllerModeButton = @"Mode"; #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include "platform/Linux/OFGameController.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFGameController.m" #elif defined(OF_NINTENDO_DS) # include "platform/NintendoDS/OFGameController.m" #elif defined(OF_NINTENDO_3DS) # include "platform/Nintendo3DS/OFGameController.m" #else @implementation OFGameController @dynamic name, buttons, pressedButtons, hasLeftAnalogStick; @dynamic leftAnalogStickPosition, hasRightAnalogStick, rightAnalogStickPosition; + (OFArray OF_GENERIC(OFGameController *) *)controllers { return [OFArray array]; } - (instancetype)init |
︙ | ︙ |
Modified src/hid/platform/Linux/OFGameController.m from [cec84b63cd] to [91b0510999].
︙ | ︙ | |||
57 58 59 60 61 62 63 | static OFGameControllerButton buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID) { if (vendorID == vendorIDNintendo && productID == productIDLeftJoycon) { switch (button) { case BTN_SELECT: | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | static OFGameControllerButton buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID) { if (vendorID == vendorIDNintendo && productID == productIDLeftJoycon) { switch (button) { case BTN_SELECT: return OFGameControllerMinusButton; case BTN_Z: return OFGameControllerCaptureButton; case BTN_TR: return OFGameControllerSLButton; case BTN_TR2: return OFGameControllerSRButton; } } else if (vendorID == vendorIDNintendo && productID == productIDRightJoycon) { switch (button) { case BTN_X: return OFGameControllerNorthButton; case BTN_Y: return OFGameControllerWestButton; case BTN_START: return OFGameControllerPlusButton; case BTN_TL: return OFGameControllerSLButton; case BTN_TL2: return OFGameControllerSRButton; } } else if (vendorID == vendorIDNintendo && productID == productIDN64Controller) { switch (button) { case BTN_A: return OFGameControllerAButton; case BTN_B: return OFGameControllerBButton; case BTN_SELECT: return OFGameControllerCPadUpButton; case BTN_X: return OFGameControllerCPadDownButton; case BTN_Y: return OFGameControllerCPadLeftButton; case BTN_C: return OFGameControllerCPadRightButton; case BTN_Z: return OFGameControllerCaptureButton; } } switch (button) { case BTN_Y: return OFGameControllerNorthButton; case BTN_A: return OFGameControllerSouthButton; case BTN_X: return OFGameControllerWestButton; case BTN_B: return OFGameControllerEastButton; case BTN_TL2: return OFGameControllerLeftTriggerButton; case BTN_TR2: return OFGameControllerRightTriggerButton; case BTN_TL: return OFGameControllerLeftShoulderButton; case BTN_TR: return OFGameControllerRightShoulderButton; case BTN_THUMBL: return OFGameControllerLeftStickButton; case BTN_THUMBR: return OFGameControllerRightStickButton; case BTN_DPAD_UP: return OFGameControllerDPadUpButton; case BTN_DPAD_DOWN: return OFGameControllerDPadDownButton; case BTN_DPAD_LEFT: return OFGameControllerDPadLeftButton; case BTN_DPAD_RIGHT: return OFGameControllerDPadRightButton; case BTN_START: return OFGameControllerStartButton; case BTN_SELECT: return OFGameControllerSelectButton; case BTN_MODE: return OFGameControllerHomeButton; case BTN_C: return OFGameControllerCButton; case BTN_Z: return OFGameControllerZButton; } return nil; } static float scale(float value, float min, float max) |
︙ | ︙ | |||
313 314 315 316 317 318 319 | _rightAnalogStickMinY = infoY.minimum; _rightAnalogStickMaxY = infoY.maximum; } if (OFBitSetIsSet(absBits, ABS_HAT0X) && OFBitSetIsSet(absBits, ABS_HAT0Y)) { [_buttons addObject: | | | | | | | | | > | | | | > | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | _rightAnalogStickMinY = infoY.minimum; _rightAnalogStickMaxY = infoY.maximum; } if (OFBitSetIsSet(absBits, ABS_HAT0X) && OFBitSetIsSet(absBits, ABS_HAT0Y)) { [_buttons addObject: OFGameControllerDPadLeftButton]; [_buttons addObject: OFGameControllerDPadRightButton]; [_buttons addObject: OFGameControllerDPadUpButton]; [_buttons addObject: OFGameControllerDPadDownButton]; } if (OFBitSetIsSet(absBits, ABS_Z)) { struct input_absinfo info; _hasLeftTriggerPressure = true; if (ioctl(_fd, EVIOCGABS(ABS_Z), &info) == -1) @throw [OFInitializationFailedException exception]; _leftTriggerMinPressure = info.minimum; _leftTriggerMaxPressure = info.maximum; [_buttons addObject: OFGameControllerLeftTriggerButton]; } if (OFBitSetIsSet(absBits, ABS_RZ)) { struct input_absinfo info; _hasRightTriggerPressure = true; if (ioctl(_fd, EVIOCGABS(ABS_RZ), &info) == -1) @throw [OFInitializationFailedException exception]; _rightTriggerMinPressure = info.minimum; _rightTriggerMaxPressure = info.maximum; [_buttons addObject: OFGameControllerRightTriggerButton]; } } [_buttons makeImmutable]; [self retrieveState]; } @catch (id e) { |
︙ | ︙ | |||
437 438 439 440 441 442 443 | _rightAnalogStickPosition.y = scale(event.value, _rightAnalogStickMinY, _rightAnalogStickMaxY); break; case ABS_HAT0X: if (event.value < 0) { [_pressedButtons addObject: | | | | | | | | | | | | | | > | | | | | > | | | | | 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | _rightAnalogStickPosition.y = scale(event.value, _rightAnalogStickMinY, _rightAnalogStickMaxY); break; case ABS_HAT0X: if (event.value < 0) { [_pressedButtons addObject: OFGameControllerDPadLeftButton]; [_pressedButtons removeObject: OFGameControllerDPadRightButton]; } else if (event.value > 0) { [_pressedButtons addObject: OFGameControllerDPadRightButton]; [_pressedButtons removeObject: OFGameControllerDPadLeftButton]; } else { [_pressedButtons removeObject: OFGameControllerDPadLeftButton]; [_pressedButtons removeObject: OFGameControllerDPadRightButton]; } break; case ABS_HAT0Y: if (event.value < 0) { [_pressedButtons addObject: OFGameControllerDPadUpButton]; [_pressedButtons removeObject: OFGameControllerDPadDownButton]; } else if (event.value > 0) { [_pressedButtons addObject: OFGameControllerDPadDownButton]; [_pressedButtons removeObject: OFGameControllerDPadUpButton]; } else { [_pressedButtons removeObject: OFGameControllerDPadUpButton]; [_pressedButtons removeObject: OFGameControllerDPadDownButton]; } break; case ABS_Z: _leftTriggerPressure = scale(event.value, _leftTriggerMinPressure, _leftTriggerMaxPressure); if (_leftTriggerPressure > 0) [_pressedButtons addObject: OFGameControllerLeftTriggerButton]; else [_pressedButtons removeObject: OFGameControllerLeftTriggerButton]; break; case ABS_RZ: _rightTriggerPressure = scale(event.value, _rightTriggerMinPressure, _rightTriggerMaxPressure); if (_rightTriggerPressure > 0) [_pressedButtons addObject: OFGameControllerRightTriggerButton]; else [_pressedButtons removeObject: OFGameControllerRightTriggerButton]; break; } break; } } } |
︙ | ︙ | |||
525 526 527 528 529 530 531 | - (OFSet *)pressedButtons { return [[_pressedButtons copy] autorelease]; } - (float)pressureForButton: (OFGameControllerButton)button { | | | > | | > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | - (OFSet *)pressedButtons { return [[_pressedButtons copy] autorelease]; } - (float)pressureForButton: (OFGameControllerButton)button { if (button == OFGameControllerLeftTriggerButton && _hasLeftTriggerPressure) return _leftTriggerPressure; if (button == OFGameControllerRightTriggerButton && _hasRightTriggerPressure) return _rightTriggerPressure; return ([self.pressedButtons containsObject: button] ? 1 : 0); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Modified src/hid/platform/Nintendo3DS/OFGameController.m from [4e207caf2f] to [f3681e2d31].
︙ | ︙ | |||
95 96 97 98 99 100 101 | hidScanInput(); keys = hidKeysHeld(); hidCircleRead(&pos); [_pressedButtons removeAllObjects]; | | | | | | | | | | | | | | < < | < | | | | | | | | | | | | | | | > > > > | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | hidScanInput(); keys = hidKeysHeld(); hidCircleRead(&pos); [_pressedButtons removeAllObjects]; if (keys & KEY_X) [_pressedButtons addObject: OFGameControllerNorthButton]; if (keys & KEY_B) [_pressedButtons addObject: OFGameControllerSouthButton]; if (keys & KEY_Y) [_pressedButtons addObject: OFGameControllerWestButton]; if (keys & KEY_A) [_pressedButtons addObject: OFGameControllerEastButton]; if (keys & KEY_ZL) [_pressedButtons addObject: OFGameControllerLeftTriggerButton]; if (keys & KEY_ZR) [_pressedButtons addObject: OFGameControllerRightTriggerButton]; if (keys & KEY_L) [_pressedButtons addObject: OFGameControllerLeftShoulderButton]; if (keys & KEY_R) [_pressedButtons addObject: OFGameControllerRightShoulderButton]; if (keys & KEY_DUP) [_pressedButtons addObject: OFGameControllerDPadUpButton]; if (keys & KEY_DDOWN) [_pressedButtons addObject: OFGameControllerDPadDownButton]; if (keys & KEY_DLEFT) [_pressedButtons addObject: OFGameControllerDPadLeftButton]; if (keys & KEY_DRIGHT) [_pressedButtons addObject: OFGameControllerDPadRightButton]; if (keys & KEY_START) [_pressedButtons addObject: OFGameControllerStartButton]; if (keys & KEY_SELECT) [_pressedButtons addObject: OFGameControllerSelectButton]; if (keys & KEY_CSTICK_UP) [_pressedButtons addObject: OFGameControllerCPadUpButton]; if (keys & KEY_CSTICK_DOWN) [_pressedButtons addObject: OFGameControllerCPadDownButton]; if (keys & KEY_CSTICK_LEFT) [_pressedButtons addObject: OFGameControllerCPadLeftButton]; if (keys & KEY_CSTICK_RIGHT) [_pressedButtons addObject: OFGameControllerCPadRightButton]; _leftAnalogStickPosition = OFMakePoint( (float)pos.dx / (pos.dx < 0 ? -INT16_MIN : INT16_MAX), (float)pos.dy / (pos.dy < 0 ? -INT16_MIN : INT16_MAX)); } - (OFString *)name |
︙ | ︙ | |||
154 155 156 157 158 159 160 | - (OFNumber *)productID { return nil; } - (OFSet OF_GENERIC(OFGameControllerButton) *)buttons { | | | | | | > > > > | > > > | | > | | > | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | - (OFNumber *)productID { return nil; } - (OFSet OF_GENERIC(OFGameControllerButton) *)buttons { return [OFSet setWithObjects: OFGameControllerNorthButton, OFGameControllerSouthButton, OFGameControllerWestButton, OFGameControllerEastButton, OFGameControllerLeftTriggerButton, OFGameControllerRightTriggerButton, OFGameControllerRightShoulderButton, OFGameControllerLeftShoulderButton, OFGameControllerDPadUpButton, OFGameControllerDPadDownButton, OFGameControllerDPadLeftButton, OFGameControllerDPadRightButton, OFGameControllerStartButton, OFGameControllerSelectButton, OFGameControllerCPadRightButton, OFGameControllerCPadLeftButton, OFGameControllerCPadUpButton, OFGameControllerCPadDownButton, nil]; } - (OFSet OF_GENERIC(OFGameControllerButton) *)pressedButtons { return [[_pressedButtons copy] autorelease]; } |
︙ | ︙ | |||
186 187 188 189 190 191 192 | } - (float)pressureForButton: (OFGameControllerButton)button { return ([self.pressedButtons containsObject: button] ? 1 : 0); } | < < < < < < < < < < < < < < < < < < < < | 196 197 198 199 200 201 202 203 204 205 206 207 | } - (float)pressureForButton: (OFGameControllerButton)button { return ([self.pressedButtons containsObject: button] ? 1 : 0); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Modified src/hid/platform/NintendoDS/OFGameController.m from [2d083ad50e] to [4b910e9db0].
︙ | ︙ | |||
91 92 93 94 95 96 97 | uint32 keys; scanKeys(); keys = keysCurrent(); [_pressedButtons removeAllObjects]; | | | | | | | | | | | | > | | | | | | | | | | | | | | | > > | > > > | > | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | uint32 keys; scanKeys(); keys = keysCurrent(); [_pressedButtons removeAllObjects]; if (keys & KEY_X) [_pressedButtons addObject: OFGameControllerNorthButton]; if (keys & KEY_B) [_pressedButtons addObject: OFGameControllerSouthButton]; if (keys & KEY_Y) [_pressedButtons addObject: OFGameControllerWestButton]; if (keys & KEY_A) [_pressedButtons addObject: OFGameControllerEastButton]; if (keys & KEY_L) [_pressedButtons addObject: OFGameControllerLeftShoulderButton]; if (keys & KEY_R) [_pressedButtons addObject: OFGameControllerRightShoulderButton]; if (keys & KEY_UP) [_pressedButtons addObject: OFGameControllerDPadUpButton]; if (keys & KEY_DOWN) [_pressedButtons addObject: OFGameControllerDPadDownButton]; if (keys & KEY_LEFT) [_pressedButtons addObject: OFGameControllerDPadLeftButton]; if (keys & KEY_RIGHT) [_pressedButtons addObject: OFGameControllerDPadRightButton]; if (keys & KEY_START) [_pressedButtons addObject: OFGameControllerStartButton]; if (keys & KEY_SELECT) [_pressedButtons addObject: OFGameControllerSelectButton]; } - (OFString *)name { return @"Nintendo DS"; } - (OFNumber *)vendorID { return nil; } - (OFNumber *)productID { return nil; } - (OFSet OF_GENERIC(OFGameControllerButton) *)buttons { return [OFSet setWithObjects: OFGameControllerNorthButton, OFGameControllerSouthButton, OFGameControllerWestButton, OFGameControllerEastButton, OFGameControllerLeftShoulderButton, OFGameControllerRightShoulderButton, OFGameControllerDPadUpButton, OFGameControllerDPadDownButton, OFGameControllerDPadLeftButton, OFGameControllerDPadRightButton, OFGameControllerStartButton, OFGameControllerSelectButton, nil]; } - (OFSet OF_GENERIC(OFGameControllerButton) *)pressedButtons { return [[_pressedButtons copy] autorelease]; } |
︙ | ︙ | |||
163 164 165 166 167 168 169 | } - (float)pressureForButton: (OFGameControllerButton)button { return ([self.pressedButtons containsObject: button] ? 1 : 0); } | < < < < < < < < < < < < < < < < < < < < | 170 171 172 173 174 175 176 177 178 179 180 181 | } - (float)pressureForButton: (OFGameControllerButton)button { return ([self.pressedButtons containsObject: button] ? 1 : 0); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Modified src/hid/platform/Windows/OFGameController.m from [ff51d408df] to [c31f521172].
︙ | ︙ | |||
157 158 159 160 161 162 163 | if (XInputGetStateFuncPtr(_index, &state) != ERROR_SUCCESS) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(state) errNo: 0]; [_pressedButtons removeAllObjects]; | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | if (XInputGetStateFuncPtr(_index, &state) != ERROR_SUCCESS) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(state) errNo: 0]; [_pressedButtons removeAllObjects]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) [_pressedButtons addObject: OFGameControllerNorthButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) [_pressedButtons addObject: OFGameControllerSouthButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_X) [_pressedButtons addObject: OFGameControllerWestButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_B) [_pressedButtons addObject: OFGameControllerEastButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) [_pressedButtons addObject: OFGameControllerLeftShoulderButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) [_pressedButtons addObject: OFGameControllerRightShoulderButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) [_pressedButtons addObject: OFGameControllerLeftStickButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) [_pressedButtons addObject: OFGameControllerRightStickButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) [_pressedButtons addObject: OFGameControllerDPadUpButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) [_pressedButtons addObject: OFGameControllerDPadDownButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) [_pressedButtons addObject: OFGameControllerDPadLeftButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) [_pressedButtons addObject: OFGameControllerDPadRightButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_START) [_pressedButtons addObject: OFGameControllerStartButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) [_pressedButtons addObject: OFGameControllerSelectButton]; _leftTriggerPressure = (float)state.Gamepad.bLeftTrigger / 255; _rightTriggerPressure = (float)state.Gamepad.bRightTrigger / 255; if (_leftTriggerPressure > 0) [_pressedButtons addObject: OFGameControllerLeftTriggerButton]; if (_rightTriggerPressure > 0) [_pressedButtons addObject: OFGameControllerRightTriggerButton]; _leftAnalogStickPosition = OFMakePoint( (float)state.Gamepad.sThumbLX / (state.Gamepad.sThumbLX < 0 ? -INT16_MIN : INT16_MAX), -(float)state.Gamepad.sThumbLY / (state.Gamepad.sThumbLY < 0 ? -INT16_MIN : INT16_MAX)); _rightAnalogStickPosition = OFMakePoint( |
︙ | ︙ | |||
214 215 216 217 218 219 220 | { return @"XInput 1.3"; } - (OFSet OF_GENERIC(OFGameControllerButton) *)buttons { return [OFSet setWithObjects: | | | | | > > > > > > | > | | | > | | | | < < < < < < < < < < < < < < < < < < < < | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | { return @"XInput 1.3"; } - (OFSet OF_GENERIC(OFGameControllerButton) *)buttons { return [OFSet setWithObjects: OFGameControllerNorthButton, OFGameControllerSouthButton, OFGameControllerWestButton, OFGameControllerEastButton, OFGameControllerLeftTriggerButton, OFGameControllerRightTriggerButton, OFGameControllerLeftShoulderButton, OFGameControllerRightShoulderButton, OFGameControllerLeftStickButton, OFGameControllerRightStickButton, OFGameControllerDPadLeftButton, OFGameControllerDPadRightButton, OFGameControllerDPadUpButton, OFGameControllerDPadDownButton, OFGameControllerStartButton, OFGameControllerSelectButton, nil]; } - (OFSet OF_GENERIC(OFGameControllerButton) *)pressedButtons { return [[_pressedButtons copy] autorelease]; } - (bool)hasLeftAnalogStick { return true; } - (bool)hasRightAnalogStick { return true; } - (float)pressureForButton: (OFGameControllerButton)button { if (button == OFGameControllerLeftTriggerButton) return _leftTriggerPressure; if (button == OFGameControllerRightTriggerButton) return _rightTriggerPressure; return ([self.pressedButtons containsObject: button] ? 1 : 0); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Modified src/test/OTAppDelegate.m from [57fda2dee1] to [3474e8e70a].
︙ | ︙ | |||
330 331 332 333 334 335 336 | [OFStdOut writeLine: @"Press A to continue"]; for (;;) { void *pool = objc_autoreleasePoolPush(); OFGameController *controller = [[OFGameController controllers] objectAtIndex: 0]; | | > | 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | [OFStdOut writeLine: @"Press A to continue"]; for (;;) { void *pool = objc_autoreleasePoolPush(); OFGameController *controller = [[OFGameController controllers] objectAtIndex: 0]; if ([controller.pressedButtons containsObject: OFGameControllerEastButton]) break; # if defined(OF_NINTENDO_DS) swiWaitForVBlank(); # elif defined(OF_NINTENDO_3DS) gspWaitForVBlank(); # endif |
︙ | ︙ |
Modified tests/gamecontroller/GameControllerTests.m from [2e38947e29] to [77c7b12639].
︙ | ︙ | |||
55 56 57 58 59 60 61 | controller.productID != nil) { [OFStdOut setForegroundColor: [OFColor teal]]; [OFStdOut writeFormat: @" [%04X:%04X]", controller.vendorID.unsignedShortValue, controller.productID.unsignedShortValue]; } | < | < < < | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | controller.productID != nil) { [OFStdOut setForegroundColor: [OFColor teal]]; [OFStdOut writeFormat: @" [%04X:%04X]", controller.vendorID.unsignedShortValue, controller.productID.unsignedShortValue]; } [OFStdOut writeString: @"\n"]; [controller retrieveState]; for (OFGameControllerButton button in buttons) { float pressure = [controller pressureForButton: button]; |
︙ | ︙ |