Differences From Artifact [4800c3c390]:
- File src/hid/OHNintendo3DSGameController.m — part of check-in [6a6c86237d] at 2024-06-08 21:25:32 on branch trunk — ObjFWHID: Restore Nintendo DS support (user: js, size: 3571) [annotate] [blame] [check-ins using]
To Artifact [01ae2ef5f1]:
- File
src/hid/OHNintendo3DSGameController.m
— part of check-in
[998339ff24]
at
2024-06-09 11:43:49
on branch trunk
— OHGamepad: Move some elements to OHExtendedGamepad
This allows to have a profile for limited gamepads such as found on the
Nintendo DS rather than only having the raw profile for those. (user: js, size: 3830) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
22 23 24 25 26 27 28 | #import "OHNintendo3DSGameController.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" | | | | 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 | #import "OHNintendo3DSGameController.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" #import "OHNintendo3DSExtendedGamepad.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #define id id_3ds #include <3ds.h> #undef id static OFArray OF_GENERIC(OHGameController *) *controllers; @implementation OHNintendo3DSGameController @synthesize extendedGamepad = _extendedGamepad; + (void)initialize { void *pool; if (self != [OHNintendo3DSGameController class]) return; |
︙ | ︙ | |||
59 60 61 62 63 64 65 | } - (instancetype)init { self = [super init]; @try { | | | | | | | | | | | | | | | | | > | | | | | > > > > > | 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 | } - (instancetype)init { self = [super init]; @try { _extendedGamepad = [[OHNintendo3DSExtendedGamepad alloc] init]; [self retrieveState]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_extendedGamepad release]; [super dealloc]; } - (void)retrieveState { u32 keys; circlePosition leftPos, rightPos; 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)]; if (leftPos.dx > 150) leftPos.dx = 150; if (leftPos.dx < -150) leftPos.dx = -150; if (leftPos.dy > 150) leftPos.dy = 150; if (leftPos.dy < -150) leftPos.dy = -150; if (rightPos.dx > 150) rightPos.dx = 150; if (rightPos.dx < -150) rightPos.dx = -150; 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)]; } - (OFString *)name { return @"Nintendo 3DS"; } - (OHGameControllerProfile *)rawProfile { return _extendedGamepad; } - (OHGamepad *)gamepad { return _extendedGamepad; } @end |