Overview
Comment: | OFGameController: Support for pressure sensitivity |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | gamecontroller |
Files: | files | file ages | folders |
SHA3-256: |
336ecd9bdc597441560440f79ea358c5 |
User & Date: | js on 2024-05-09 19:46:06 |
Other Links: | branch diff | manifest | tags |
Context
2024-05-09
| ||
19:47 | Add subdir for interactive game controller tests check-in: 9e1ee38bda user: js tags: gamecontroller | |
19:46 | OFGameController: Support for pressure sensitivity check-in: 336ecd9bdc user: js tags: gamecontroller | |
19:05 | OFGameController: Add constants for buttons check-in: f02049612e user: js tags: gamecontroller | |
Changes
Modified src/OFGameController.h from [174eaaf8eb] to [62ce0aa0c9].
︙ | |||
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 | 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 | + + + - + + - + | #ifdef OF_LINUX OFString *_path; int _fd; uint16_t _vendorID, _productID; OFString *_name; OFMutableSet *_buttons, *_pressedButtons; bool _hasLeftAnalogStick, _hasRightAnalogStick; bool _hasZLPressure, _hasZRPressure; OFPoint _leftAnalogStickPosition, _rightAnalogStickPosition; float _ZLPressure, _ZRPressure; int32_t _leftAnalogStickMinX, _leftAnalogStickMaxX; int32_t _leftAnalogStickMinY, _leftAnalogStickMaxY; int32_t _rightAnalogStickMinX, _rightAnalogStickMaxX; int32_t _rightAnalogStickMinY, _rightAnalogStickMaxY; int32_t _ZLMinPressure, _ZLMaxPressure, _ZRMinPressure, _ZRMaxPressure; #endif } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFArray <OFGameController *> *controllers; #endif /** * @brief The name of the controller. */ @property (readonly, nonatomic, copy) OFString *name; /** * @brief The buttons the controller has. */ |
︙ | |||
256 257 258 259 260 261 262 263 264 265 | 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | + + + + + + + + + + | * @brief Returns the available controllers. * * @return The available controllers */ + (OFArray OF_GENERIC(OFGameController *) *)controllers; - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns how hard the specified button is pressed. * * The returned value is in the range from 0 to 1. * * @param button The button for which to return how hard it is pressed. * @return How hard the specified button is pressed */ - (float)pressureForButton: (OFGameControllerButton)button; @end OF_ASSUME_NONNULL_END |
Modified src/OFGameController.m from [b3fdaf3904] to [c9aa070e37].
︙ | |||
65 66 67 68 69 70 71 72 73 | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | + + + + + | return [OFArray array]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (float)pressureForButton: (OFGameControllerButton)button { return 0; } @end #endif |
Modified src/platform/Linux/OFGameController.m from [25579e0c0b] to [3d4dad17ed].
︙ | |||
51 52 53 54 55 56 57 | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | - + | static const uint16_t buttons[] = { 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, BTN_DPAD_UP, BTN_DPAD_DOWN, BTN_DPAD_LEFT, BTN_DPAD_RIGHT }; |
︙ | |||
240 241 242 243 244 245 246 | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | - + | _name = [[OFString alloc] initWithCString: name encoding: encoding]; _buttons = [[OFMutableSet alloc] init]; for (size_t i = 0; i < sizeof(buttons) / sizeof(*buttons); i++) { |
︙ | |||
307 308 309 310 311 312 313 | 307 308 309 310 311 312 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 | - + + + + + + + + + + + + + + - + + + + + + + + + + + + + | OFGameControllerButtonDPadRight]; [_buttons addObject: OFGameControllerButtonDPadUp]; [_buttons addObject: OFGameControllerButtonDPadDown]; } |
︙ | |||
341 342 343 344 345 346 347 | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | - + | } - (void)of_processEvents { struct input_event event; for (;;) { |
︙ | |||
422 423 424 425 426 427 428 | 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 | - + + + + - + + + + | [_pressedButtons removeObject: OFGameControllerButtonDPadUp]; [_pressedButtons removeObject: OFGameControllerButtonDPadDown]; } break; case ABS_Z: |
︙ | |||
480 481 482 483 484 485 486 487 488 489 490 491 492 | 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | + + + + + + + + + + + + + + + | } - (OFPoint)rightAnalogStickPosition { [self of_processEvents]; return _rightAnalogStickPosition; } - (float)pressureForButton: (OFGameControllerButton)button { if ([button isEqual: OFGameControllerButtonZL] && _hasZLPressure) { [self of_processEvents]; return _ZLPressure; } if ([button isEqual: OFGameControllerButtonZR] && _hasZRPressure) { [self of_processEvents]; return _ZRPressure; } return ([self.pressedButtons containsObject: button] ? 1 : 0); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Modified src/platform/Nintendo3DS/OFGameController.m from [cde2b51e73] to [adf29c8c87].
︙ | |||
69 70 71 72 73 74 75 | 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 | - + - + + - + | } - (OFString *)name { return @"Nintendo 3DS"; } |
︙ | |||
152 153 154 155 156 157 158 159 160 161 162 163 164 | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | + + + + + | circlePosition pos; hidCircleRead(&pos); return OFMakePoint( (float)pos.dx / (pos.dx < 0 ? -INT16_MIN : INT16_MAX), (float)pos.dy / (pos.dy < 0 ? -INT16_MIN : INT16_MAX)); } - (float)pressureForButton: (OFGameControllerButton)button { return ([self.pressedButtons containsObject: button] ? 1 : 0); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Modified src/platform/NintendoDS/OFGameController.m from [3f4b233e3e] to [c449fe09b2].
︙ | |||
69 70 71 72 73 74 75 | 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 | - + - + + - + | } - (OFString *)name { return @"Nintendo DS"; } |
︙ | |||
127 128 129 130 131 132 133 134 135 136 137 138 139 | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | + + + + + | return false; } - (bool)hasRightAnalogStick { return false; } - (float)pressureForButton: (OFGameControllerButton)button { return ([self.pressedButtons containsObject: button] ? 1 : 0); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Modified tests/gamecontroller/GameControllerTests.m from [6a78591319] to [234ef24ee3].
︙ | |||
39 40 41 42 43 44 45 | 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 | - + - - - + + + + - - + + + + + + + + + + + | [OFStdOut clear]; for (;;) { [OFStdOut setCursorPosition: OFMakePoint(0, 0)]; for (OFGameController *controller in controllers) { |
︙ |