Comment: | ObjFWHID: Change prefix to OH
Let's leave 3 letter prefixes to 3rd parties. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
afae3291bff5cad99191b902e6e4e81c |
User & Date: | js on 2024-06-03 19:39:51 |
Other Links: | manifest | tags |
2024-06-03
| ||
19:45 | Rename OHGameController{Mapping -> Profile} check-in: f333689336 user: js tags: trunk | |
19:39 | ObjFWHID: Change prefix to OH check-in: afae3291bf user: js tags: trunk | |
00:31 | Make GCC happy again check-in: 4bee9b1b32 user: js tags: trunk | |
Modified Doxyfile from [9675d9af4d] to [92b4e406bf].
︙ | ︙ | |||
45 46 47 48 49 50 51 | OF_WARN_UNUSED_RESULT= \ OF_WEAK_UNAVAILABLE= \ SIGHUP \ SIGUSR1 \ SIGUSR2 MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES | | | 45 46 47 48 49 50 51 52 53 | OF_WARN_UNUSED_RESULT= \ OF_WEAK_UNAVAILABLE= \ SIGHUP \ SIGUSR1 \ SIGUSR2 MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES IGNORE_PREFIX = OF OF_ OH OT OT_ EXTRACT_STATIC = yes |
Modified src/hid/Makefile from [02731ab3d0] to [044fff7e3a].
1 2 3 4 5 6 7 8 9 10 11 | include ../../extra.mk DISTCLEAN = Info.plist SHARED_LIB = ${OBJFWHID_SHARED_LIB} STATIC_LIB = ${OBJFWHID_STATIC_LIB} FRAMEWORK = ${OBJFWHID_FRAMEWORK} LIB_MAJOR = ${OBJFWHID_LIB_MAJOR} LIB_MINOR = ${OBJFWHID_LIB_MINOR} LIB_PATCH = ${OBJFWHID_LIB_PATCH} | | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | include ../../extra.mk DISTCLEAN = Info.plist SHARED_LIB = ${OBJFWHID_SHARED_LIB} STATIC_LIB = ${OBJFWHID_STATIC_LIB} FRAMEWORK = ${OBJFWHID_FRAMEWORK} LIB_MAJOR = ${OBJFWHID_LIB_MAJOR} LIB_MINOR = ${OBJFWHID_LIB_MINOR} LIB_PATCH = ${OBJFWHID_LIB_PATCH} SRCS = OHGameController.m \ OHGameControllerAxis.m \ OHGameControllerButton.m \ OHGameControllerDirectionalPad.m \ OHGameControllerElement.m \ OHGameControllerMapping.m INCLUDES := ${SRCS:.m=.h} \ ObjFWHID.h SRCS += OHGameControllerEmulatedAxis.m \ OHGameControllerEmulatedButton.m includesubdir = ObjFWHID include ../../buildsys.mk install-extra: i=ObjFWHID.oc; \ |
︙ | ︙ |
Renamed and modified src/hid/HIDEvdevGameController.h [40e78502c5] to src/hid/OHEvdevGameController.h [80bc5a0e55].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "OHGameController.h" OF_ASSUME_NONNULL_BEGIN @class OHGameControllerMapping; @interface OHEvdevGameController: OHGameController { OFString *_path; int _fd; bool _discardUntilReport; unsigned long *_evBits, *_keyBits, *_absBits; uint16_t _vendorID, _productID; OFString *_name; OHGameControllerMapping *_mapping; } - (instancetype)of_initWithPath: (OFString *)path OF_METHOD_FAMILY(init); - (void)of_pollState; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/HIDEvdevGameController.m [3e3a114e9f] to src/hid/OHEvdevGameController.m [a90f4bebdd].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #include "config.h" #include <errno.h> #include <fcntl.h> #include <unistd.h> | | | | | | | | 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 | #include "config.h" #include <errno.h> #include <fcntl.h> #include <unistd.h> #import "OHEvdevGameController.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerMapping.h" #include <sys/ioctl.h> #include <linux/input.h> #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" @interface OHEvdevGameControllerAxis: OHGameControllerAxis { @public int32_t _minValue, _maxValue; } @end @interface OHEvdevGameControllerMapping: OHGameControllerMapping - (instancetype)of_initWithButtons: (OFDictionary *)buttons axes: (OFDictionary *)axes OF_METHOD_FAMILY(init); @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, |
︙ | ︙ | |||
262 263 264 265 266 267 268 | value = min; if (value > max) value = max; return ((value - min) / (max - min) * 2) - 1; } | | | | | | 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 294 295 | value = min; if (value > max) value = max; return ((value - min) / (max - min) * 2) - 1; } @implementation OHEvdevGameController @synthesize name = _name, unmappedMapping = _mapping; + (OFArray OF_GENERIC(OHGameController *) *)controllers { OFMutableArray *controllers = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (OFString *device in [[OFFileManager defaultManager] contentsOfDirectoryAtPath: @"/dev/input"]) { OFString *path; OHGameController *controller; if (![device hasPrefix: @"event"]) continue; path = [@"/dev/input" stringByAppendingPathComponent: device]; @try { controller = [[[OHEvdevGameController alloc] of_initWithPath: path] autorelease]; } @catch (OFOpenItemFailedException *e) { if (e.errNo == EACCES) continue; @throw e; } @catch (OFInvalidArgumentException *e) { |
︙ | ︙ | |||
364 365 366 367 368 369 370 | encoding: encoding]; buttons = [OFMutableDictionary dictionary]; for (size_t i = 0; i < sizeof(buttonIDs) / sizeof(*buttonIDs); i++) { if (OFBitSetIsSet(_keyBits, buttonIDs[i])) { OFString *buttonName; | | | | 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | encoding: encoding]; buttons = [OFMutableDictionary dictionary]; for (size_t i = 0; i < sizeof(buttonIDs) / sizeof(*buttonIDs); i++) { if (OFBitSetIsSet(_keyBits, buttonIDs[i])) { OFString *buttonName; OHGameControllerButton *button; buttonName = buttonToName(buttonIDs[i]); if (buttonName == nil) continue; button = [[[OHGameControllerButton alloc] initWithName: buttonName] autorelease]; [buttons setObject: button forKey: buttonName]; } } [buttons makeImmutable]; |
︙ | ︙ | |||
394 395 396 397 398 399 400 | @throw [OFInitializationFailedException exception]; for (size_t i = 0; i < sizeof(axisIDs) / sizeof(*axisIDs); i++) { if (OFBitSetIsSet(_absBits, axisIDs[i])) { OFString *axisName; | | | | | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | @throw [OFInitializationFailedException exception]; for (size_t i = 0; i < sizeof(axisIDs) / sizeof(*axisIDs); i++) { if (OFBitSetIsSet(_absBits, axisIDs[i])) { OFString *axisName; OHEvdevGameControllerAxis *axis; axisName = axisToName(axisIDs[i]); if (axisName == nil) continue; axis = [[[OHEvdevGameControllerAxis alloc] initWithName: axisName] autorelease]; [axes setObject: axis forKey: axisName]; } } } [axes makeImmutable]; _mapping = [[OHEvdevGameControllerMapping alloc] of_initWithButtons: buttons axes: axes]; [self of_pollState]; objc_autoreleasePoolPop(pool); } @catch (id e) { |
︙ | ︙ | |||
466 467 468 469 470 471 472 | exceptionWithObject: self requestedLength: sizeof(keyState) errNo: errno]; for (size_t i = 0; i < sizeof(buttonIDs) / sizeof(*buttonIDs); i++) { OFString *name; | | | 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | exceptionWithObject: self requestedLength: sizeof(keyState) errNo: errno]; for (size_t i = 0; i < sizeof(buttonIDs) / sizeof(*buttonIDs); i++) { OFString *name; OHGameControllerButton *button; if (!OFBitSetIsSet(_keyBits, buttonIDs[i])) continue; name = buttonToName(buttonIDs[i]); if (name == nil) continue; |
︙ | ︙ | |||
490 491 492 493 494 495 496 | } if (OFBitSetIsSet(_evBits, EV_ABS)) { for (size_t i = 0; i < sizeof(axisIDs) / sizeof(*axisIDs); i++) { struct input_absinfo info; OFString *name; | | | | 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | } if (OFBitSetIsSet(_evBits, EV_ABS)) { for (size_t i = 0; i < sizeof(axisIDs) / sizeof(*axisIDs); i++) { struct input_absinfo info; OFString *name; OHEvdevGameControllerAxis *axis; if (!OFBitSetIsSet(_absBits, axisIDs[i])) continue; name = axisToName(axisIDs[i]); if (name == nil) continue; axis = (OHEvdevGameControllerAxis *) [_mapping.axes objectForKey: name]; if (axis == nil) continue; if (ioctl(_fd, EVIOCGABS(axisIDs[i]), &info) == -1) @throw [OFReadFailedException exceptionWithObject: self |
︙ | ︙ | |||
525 526 527 528 529 530 531 | - (void)retrieveState { void *pool = objc_autoreleasePoolPush(); struct input_event event; for (;;) { OFString *name; | | | | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | - (void)retrieveState { void *pool = objc_autoreleasePoolPush(); struct input_event event; for (;;) { OFString *name; OHGameControllerButton *button; OHEvdevGameControllerAxis *axis; errno = 0; if (read(_fd, &event, sizeof(event)) < (int)sizeof(event)) { if (errno == EWOULDBLOCK) return; |
︙ | ︙ | |||
576 577 578 579 580 581 582 | break; case EV_ABS: name = axisToName(event.code); if (name == nil) continue; | | | | | | | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 | break; case EV_ABS: name = axisToName(event.code); if (name == nil) continue; axis = (OHEvdevGameControllerAxis *) [_mapping.axes objectForKey: name]; if (axis == nil) continue; axis.value = scale(event.value, axis->_minValue, axis->_maxValue); break; } } objc_autoreleasePoolPop(pool); } - (OFComparisonResult)compare: (OHEvdevGameController *)otherController { unsigned long long selfIndex, otherIndex; if (![otherController isKindOfClass: [OHEvdevGameController class]]) @throw [OFInvalidArgumentException exception]; selfIndex = [_path substringFromIndex: 16].unsignedLongLongValue; otherIndex = [otherController->_path substringFromIndex: 16] .unsignedLongLongValue; if (selfIndex > otherIndex) return OFOrderedDescending; if (selfIndex < otherIndex) return OFOrderedAscending; return OFOrderedSame; } @end @implementation OHEvdevGameControllerAxis @end @implementation OHEvdevGameControllerMapping - (instancetype)of_initWithButtons: (OFDictionary *)buttons axes: (OFDictionary *)axes { self = [super init]; @try { _buttons = [buttons retain]; |
︙ | ︙ |
Renamed and modified src/hid/HIDGameController.h [e37811cd3f] to src/hid/OHGameController.h [5ae1f17798].
︙ | ︙ | |||
27 28 29 30 31 32 33 | # import <ObjFW/OFObject.h> # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN | < > | | | | 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 | # import <ObjFW/OFObject.h> # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFNumber; @class OHGameControllerMapping; /** * @class OHGameController OHGameController.h ObjFWHID/OHGameController.h * * @brief A class for reading state from a game controller. */ @interface OHGameController: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFArray <OHGameController *> *controllers; #endif /** * @brief The name of the controller. */ @property (readonly, nonatomic, copy) OFString *name; |
︙ | ︙ | |||
61 62 63 64 65 66 67 | */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *productID; /** * @brief An unmapped mapping for the game controller, meaning no remapping is * being performed. */ | | | | | 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 | */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *productID; /** * @brief An unmapped mapping for the game controller, meaning no remapping is * being performed. */ @property (readonly, nonatomic) OHGameControllerMapping *unmappedMapping; /** * @brief Returns the available controllers. * * @return The available controllers */ + (OFArray OF_GENERIC(OHGameController *) *)controllers; /** * @brief Retrieves the current state from the game controller. * * The state returned by @ref OHGameController's methods does not change until * this method is called. * * @throw OFReadFailedException The controller's state could not be read */ - (void)retrieveState; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/HIDGameController.m [1e275c1bfa] to src/hid/OHGameController.m [b33f3a4512].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" | | | | | | | | 15 16 17 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 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameController.h" #import "OFArray.h" #import "OFNumber.h" #import "OFSet.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include "OHEvdevGameController.h" #endif @implementation OHGameController @dynamic name, unmappedMapping; + (OFArray OF_GENERIC(OHGameController *) *)controllers { #if defined(OF_LINUX) && defined(OF_HAVE_FILES) return [OHEvdevGameController controllers]; #else return [OFArray array]; #endif } - (instancetype)init { if ([self isMemberOfClass: [OHGameController class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
81 82 83 84 85 86 87 | else return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end #if defined(OF_LINUX) && defined(OF_HAVE_FILES) | | | 81 82 83 84 85 86 87 88 89 | else return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include "OHEvdevGameController.m" #endif |
Renamed and modified src/hid/HIDGameControllerAxis.h [876c2397e0] to src/hid/OHGameControllerAxis.h [a18496dca4].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "OHGameControllerElement.h" OF_ASSUME_NONNULL_BEGIN /** * @class OHGameControllerAxis \ * OHGameControllerAxis.h ObjFWHID/OHGameControllerAxis.h * * @brief An axis of a game controller. */ @interface OHGameControllerAxis: OHGameControllerElement { float _value; OF_RESERVE_IVARS(OHGameControllerButton, 4) } /** * @brief The value of the axis. */ @property (nonatomic) float value; @end |
︙ | ︙ |
Renamed and modified src/hid/HIDGameControllerAxis.m [9b1e5938fe] to src/hid/OHGameControllerAxis.m [0113b75889].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameControllerAxis.h" @implementation OHGameControllerAxis @synthesize value = _value; - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end |
Renamed and modified src/hid/HIDGameControllerButton.h [e6d7487002] to src/hid/OHGameControllerButton.h [1613a4493a].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "OHGameControllerElement.h" OF_ASSUME_NONNULL_BEGIN /** * @class OHGameControllerButton \ * OHGameControllerButton.h ObjFWHID/OHGameControllerButton.h * * @brief A button of a game controller. */ @interface OHGameControllerButton: OHGameControllerElement { float _value; OF_RESERVE_IVARS(OHGameControllerButton, 4) } /** * @brief Whether the game controller button is pressed. */ @property (readonly, nonatomic, getter=isPressed) bool pressed; |
︙ | ︙ |
Renamed and modified src/hid/HIDGameControllerButton.m [64b22e0918] to src/hid/OHGameControllerButton.m [558ba95814].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameControllerButton.h" @implementation OHGameControllerButton @synthesize value = _value; - (bool)isPressed { return (_value > 0); } |
︙ | ︙ |
Renamed and modified src/hid/HIDGameControllerDirectionalPad.h [2c2bbf2751] to src/hid/OHGameControllerDirectionalPad.h [773f283b6a].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | | | | | | | | | | | | | | | | | | | | | | 13 14 15 16 17 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 82 83 84 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "OHGameControllerElement.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" OF_ASSUME_NONNULL_BEGIN /** * @class OHGameControllerDirectionalPad \ * OHGameControllerDirectionalPad.h * ObjFWHID/OHGameControllerDirectionalPad.h * * @brief An directional pad or thumb stick of a game controller. */ OF_SUBCLASSING_RESTRICTED @interface OHGameControllerDirectionalPad: OHGameControllerElement { OHGameControllerAxis *_xAxis, *_yAxis; OHGameControllerButton *_upButton, *_downButton; OHGameControllerButton *_leftButton, *_rightButton; } /** * @brief The X axis of the directional pad. */ @property (readonly, nonatomic) OHGameControllerAxis *xAxis; /** * @brief The Y axis of the directional pad. */ @property (readonly, nonatomic) OHGameControllerAxis *yAxis; /** * @brief The up button of the directional pad. */ @property (readonly, nonatomic) OHGameControllerButton *upButton; /** * @brief The down button of the directional pad. */ @property (readonly, nonatomic) OHGameControllerButton *downButton; /** * @brief The left button of the directional pad. */ @property (readonly, nonatomic) OHGameControllerButton *leftButton; /** * @brief The right button of the directional pad. */ @property (readonly, nonatomic) OHGameControllerButton *rightButton; - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName: (OFString *)name xAxis: (OHGameControllerAxis *)xAxis yAxis: (OHGameControllerAxis *)yAxis; - (instancetype)initWithName: (OFString *)name upButton: (OHGameControllerButton *)upButton downButton: (OHGameControllerButton *)downButton leftButton: (OHGameControllerButton *)leftButton rightButton: (OHGameControllerButton *)rightButton; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/HIDGameControllerDirectionalPad.m [6db9de440f] to src/hid/OHGameControllerDirectionalPad.m [f54e2d335a].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" | | | | | | | | | | | | | | | | | | 15 16 17 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 82 83 84 85 86 87 88 89 90 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameControllerDirectionalPad.h" #import "OHGameControllerEmulatedAxis.h" #import "OHGameControllerEmulatedButton.h" @implementation OHGameControllerDirectionalPad @synthesize xAxis = _xAxis, yAxis = _yAxis; @synthesize upButton = _upButton, downButton = _downButton; @synthesize leftButton = _leftButton, rightButton = _rightButton; - (instancetype)initWithName: (OFString *)name { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name xAxis: (OHGameControllerAxis *)xAxis yAxis: (OHGameControllerAxis *)yAxis { self = [super initWithName: name]; @try { _xAxis = [xAxis retain]; _yAxis = [yAxis retain]; _upButton = [[OHGameControllerEmulatedButton alloc] initWithAxis: _yAxis positive: false]; _downButton = [[OHGameControllerEmulatedButton alloc] initWithAxis: _yAxis positive: true]; _leftButton = [[OHGameControllerEmulatedButton alloc] initWithAxis: _xAxis positive: false]; _rightButton = [[OHGameControllerEmulatedButton alloc] initWithAxis: _xAxis positive: true]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithName: (OFString *)name upButton: (OHGameControllerButton *)upButton downButton: (OHGameControllerButton *)downButton leftButton: (OHGameControllerButton *)leftButton rightButton: (OHGameControllerButton *)rightButton { self = [super initWithName: name]; @try { _upButton = [upButton retain]; _downButton = [downButton retain]; _leftButton = [leftButton retain]; _rightButton = [rightButton retain]; _xAxis = [[OHGameControllerEmulatedAxis alloc] initWithNegativeButton: _leftButton positiveButton: _rightButton]; _yAxis = [[OHGameControllerEmulatedAxis alloc] initWithNegativeButton: _upButton positiveButton: _downButton]; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ |
Renamed and modified src/hid/HIDGameControllerElement.h [721f4d8e3b] to src/hid/OHGameControllerElement.h [32fde53c9e].
︙ | ︙ | |||
28 29 30 31 32 33 34 | # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN /** | | | | | | 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 | # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN /** * @class OHGameControllerElement \ * OHGameControllerElement.h ObjFWHID/OHGameControllerElement.h * * @brief An element of a game controller, e.g. a button, an axis or a * directional pad. */ @interface OHGameControllerElement: OFObject { OFString *_name; bool _analog; OF_RESERVE_IVARS(OHGameControllerElement, 4) } /** * @brief The name of the game controller element. */ @property (readonly, nonatomic) OFString *name; |
︙ | ︙ |
Renamed and modified src/hid/HIDGameControllerElement.m [35eace7e5e] to src/hid/OHGameControllerElement.m [e28f3ca624].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameControllerElement.h" @implementation OHGameControllerElement @synthesize name = _name, analog = _analog; - (instancetype)init { OF_INVALID_INIT_METHOD } |
︙ | ︙ |
Renamed and modified src/hid/HIDGameControllerEmulatedAxis.h [f06104d6f6] to src/hid/OHGameControllerEmulatedAxis.h [a0f65c5e9a].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "OHGameControllerAxis.h" OF_ASSUME_NONNULL_BEGIN @class OHGameControllerButton; OF_SUBCLASSING_RESTRICTED @interface OHGameControllerEmulatedAxis: OHGameControllerAxis { OHGameControllerButton *_negativeButton, *_positiveButton; } - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; - (instancetype) initWithNegativeButton: (OHGameControllerButton *)negativeButton positiveButton: (OHGameControllerButton *)positiveButton; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/HIDGameControllerEmulatedAxis.m [01c06a1ab0] to src/hid/OHGameControllerEmulatedAxis.m [d60d8c7150].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "config.h" | | | | < | | | | 15 16 17 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 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "config.h" #import "OHGameControllerEmulatedAxis.h" #import "OHGameControllerButton.h" @implementation OHGameControllerEmulatedAxis - (instancetype)initWithName: (OFString *)name { OF_INVALID_INIT_METHOD } - (instancetype)initWithNegativeButton: (OHGameControllerButton *)negativeButton positiveButton: (OHGameControllerButton *)positiveButton { void *pool = objc_autoreleasePoolPush(); OFString *name; @try { name = [OFString stringWithFormat: @"%@ and %@ as emulated axis", negativeButton.name, positiveButton.name]; } @catch (id e) { [self release]; |
︙ | ︙ |
Renamed and modified src/hid/HIDGameControllerEmulatedButton.h [3f0e6ab4ac] to src/hid/OHGameControllerEmulatedButton.h [1f52540e1f].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "OHGameControllerButton.h" OF_ASSUME_NONNULL_BEGIN @class OHGameControllerAxis; OF_SUBCLASSING_RESTRICTED @interface OHGameControllerEmulatedButton: OHGameControllerButton { OHGameControllerAxis *_axis; bool _positive; } - (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE; - (instancetype)initWithAxis: (OHGameControllerAxis *)axis positive: (bool)positive; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/HIDGameControllerEmulatedButton.m [921a669bf3] to src/hid/OHGameControllerEmulatedButton.m [1d9492427b].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" | | | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameControllerEmulatedButton.h" #import "OHGameControllerAxis.h" @implementation OHGameControllerEmulatedButton: OHGameControllerButton - (instancetype)initWithName: (OFString *)name { OF_INVALID_INIT_METHOD } - (instancetype)initWithAxis: (OHGameControllerAxis *)axis positive: (bool)positive { void *pool = objc_autoreleasePoolPush(); OFString *name; @try { name = [OFString stringWithFormat: |
︙ | ︙ |
Renamed and modified src/hid/HIDGameControllerMapping.h [9d245e3712] to src/hid/OHGameControllerMapping.h [c9756630f5].
︙ | ︙ | |||
27 28 29 30 31 32 33 | # import <ObjFW/OFObject.h> # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN | > | | | < | | | | | < | | | > | < | | | | | | | 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 | # import <ObjFW/OFObject.h> # import <ObjFW/OFString.h> # endif #endif OF_ASSUME_NONNULL_BEGIN @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OHGameControllerAxis; @class OHGameControllerButton; @class OHGameControllerDirectionalPad; /** * @class OHGameControllerMapping \ * OHGameControllerMapping.h ObjFWHID/OHGameControllerMapping.h * * @brief A mapping for a @ref OHGameController. */ @interface OHGameControllerMapping: OFObject { OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons; OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *_axes; OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *) *_directionalPads; OF_RESERVE_IVARS(OHGameControllerMapping, 4) } /** * @brief A map of all button names to their @ref OHGameControllerButton. */ @property (readonly, nonatomic) OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *buttons; /** * @brief A map of all axis names to their @ref OHGameControllerAxis. */ @property (readonly, nonatomic) OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *axes; /** * @brief A map of all directional pads to their * @ref OHGameControllerDirectionalPad. */ @property (readonly, nonatomic) OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *) *directionalPads; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/hid/HIDGameControllerMapping.m [16d8c69c01] to src/hid/OHGameControllerMapping.m [f68efd6f5e].
︙ | ︙ | |||
15 16 17 18 19 20 21 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameControllerMapping.h" #import "OFDictionary.h" @implementation OHGameControllerMapping: OFObject @synthesize buttons = _buttons, axes = _axes; @synthesize directionalPads = _directionalPads; - (void)dealloc { [_buttons release]; [_axes release]; |
︙ | ︙ |
Modified src/hid/ObjFWHID.h from [d1a844bf10] to [2704e96f7e].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 | * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #import "OHGameController.h" #import "OHGameControllerElement.h" #import "OHGameControllerButton.h" #import "OHGameControllerAxis.h" #import "OHGameControllerDirectionalPad.h" |
Modified src/test/OTAppDelegate.m from [e739358c29] to [c2558fe049].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #import "OFSet.h" #import "OFStdIOStream.h" #import "OFThread.h" #import "OFValue.h" #import "OTTestCase.h" | | | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #import "OFSet.h" #import "OFStdIOStream.h" #import "OFThread.h" #import "OFValue.h" #import "OTTestCase.h" #import "OHGameController.h" #import "OHGameControllerButton.h" #import "OHGameControllerMapping.h" #import "OTAssertionFailedException.h" #import "OTTestSkippedException.h" #ifdef OF_IOS # include <CoreFoundation/CoreFoundation.h> #endif |
︙ | ︙ | |||
281 282 283 284 285 286 287 | if (status == StatusFailed) { #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { void *pool = objc_autoreleasePoolPush(); | | | | | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | if (status == StatusFailed) { #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { void *pool = objc_autoreleasePoolPush(); OHGameController *controller = [[OHGameController controllers] objectAtIndex: 0]; OHGameControllerButton *button = [controller.unmappedMapping.buttons objectForKey: @"A"]; [controller retrieveState]; if (button.pressed) break; |
︙ | ︙ | |||
545 546 547 548 549 550 551 | [OFStdOut writeLine: @"Press Home button to exit"]; # else [OFStdOut writeLine: @"Press Start button to exit"]; # endif for (;;) { void *pool = objc_autoreleasePoolPush(); | | | | | 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | [OFStdOut writeLine: @"Press Home button to exit"]; # else [OFStdOut writeLine: @"Press Start button to exit"]; # endif for (;;) { void *pool = objc_autoreleasePoolPush(); OHGameController *controller = [[OHGameController controllers] objectAtIndex: 0]; OHGameControllerButton *button = # ifdef OF_WII [controller.unmappedMapping.buttons objectForKey: @"Home"]; # else [controller.unmappedMapping.buttons objectForKey: @"Start"]; # endif [controller retrieveState]; |
︙ | ︙ |
Modified tests/gamecontroller/GameControllerTests.m from [563268e4f8] to [f7c9148fed].
︙ | ︙ | |||
24 25 26 27 28 29 30 | #import "OFColor.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFStdIOStream.h" #import "OFThread.h" | | | | | | | 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 | #import "OFColor.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFStdIOStream.h" #import "OFThread.h" #import "OHGameController.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerMapping.h" #import "OFReadFailedException.h" #if defined(OF_NINTENDO_DS) static size_t buttonsPerLine = 2; #elif defined(OF_NINTENDO_3DS) static size_t buttonsPerLine = 3; #else static size_t buttonsPerLine = 5; #endif #if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) # define red maroon # define yellow olive # define gray silver #endif @interface GameControllerTests: OFObject <OFApplicationDelegate> { OFMutableArray OF_GENERIC(OHGameController *) *_controllers; OFDate *_lastControllersUpdate; } @end OF_APPLICATION_DELEGATE(GameControllerTests) @implementation GameControllerTests |
︙ | ︙ | |||
69 70 71 72 73 74 75 | void *pool = objc_autoreleasePoolPush(); if (_lastControllersUpdate == nil || -[_lastControllersUpdate timeIntervalSinceNow] > 1) { [_controllers release]; [_lastControllersUpdate release]; | | | | | | 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 | void *pool = objc_autoreleasePoolPush(); if (_lastControllersUpdate == nil || -[_lastControllersUpdate timeIntervalSinceNow] > 1) { [_controllers release]; [_lastControllersUpdate release]; _controllers = [[OHGameController controllers] mutableCopy]; _lastControllersUpdate = [[OFDate alloc] init]; [OFStdOut clear]; } [OFStdOut setCursorPosition: OFMakePoint(0, 0)]; for (OHGameController *controller in _controllers) { OHGameControllerMapping *mapping = controller.unmappedMapping; OFArray OF_GENERIC(OFString *) *buttons = mapping.buttons.allKeys.sortedArray; OFArray OF_GENERIC(OFString *) *axes = mapping.axes.allKeys.sortedArray; size_t i; [OFStdOut setForegroundColor: [OFColor green]]; [OFStdOut writeString: controller.description]; @try { [controller retrieveState]; } @catch (OFReadFailedException *e) { [OFStdOut setForegroundColor: [OFColor red]]; [OFStdOut writeFormat: @"\n%@", e.description]; continue; } i = 0; for (OFString *name in buttons) { OHGameControllerButton *button = [mapping.buttons objectForKey: name]; if (i == 0) [OFStdOut writeString: @"\n"]; if (button.value == 1) [OFStdOut setForegroundColor: |
︙ | ︙ | |||
131 132 133 134 135 136 137 | [OFStdOut writeString: @" "]; } [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeString: @"\n"]; i = 0; for (OFString *name in axes) { | | | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | [OFStdOut writeString: @" "]; } [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeString: @"\n"]; i = 0; for (OFString *name in axes) { OHGameControllerAxis *axis = [mapping.axes objectForKey: name]; if (i == 0) [OFStdOut writeString: @"\n"]; [OFStdOut writeFormat: @"%@: %5.2f ", name, axis.value]; |
︙ | ︙ |