Differences From Artifact [c422cbe7b4]:
- File src/hid/OHXInputGameController.m — part of check-in [256c4a696f] at 2024-06-08 19:36:39 on branch trunk — ObjFWHID: Ignore Guide button on XInput 9.1.0 (user: js, size: 6685) [annotate] [blame] [check-ins using]
To Artifact [7c14afb2ff]:
- File
src/hid/OHXInputGameController.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: 6975) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
22 23 24 25 26 27 28 | #import "OHXInputGameController.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 | #import "OHXInputGameController.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OHGameControllerAxis.h" #import "OHGameControllerButton.h" #import "OHGameControllerDirectionalPad.h" #import "OHXInputExtendedGamepad.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #include <xinput.h> #ifndef XINPUT_GAMEPAD_GUIDE |
︙ | ︙ | |||
48 49 50 51 52 53 54 | int OHXInputVersion; static WINAPI DWORD (*XInputGetStateFuncPtr)(DWORD, XINPUT_STATE *); static WINAPI DWORD (*XInputGetCapabilitiesExFuncPtr)(DWORD, DWORD, DWORD, struct XInputCapabilitiesEx *); @implementation OHXInputGameController | | > | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | int OHXInputVersion; static WINAPI DWORD (*XInputGetStateFuncPtr)(DWORD, XINPUT_STATE *); static WINAPI DWORD (*XInputGetCapabilitiesExFuncPtr)(DWORD, DWORD, DWORD, struct XInputCapabilitiesEx *); @implementation OHXInputGameController @synthesize vendorID = _vendorID, productID = _productID; @synthesize extendedGamepad = _extendedGamepad; + (void)initialize { HMODULE module; if (self != [OHXInputGameController class]) return; |
︙ | ︙ | |||
136 137 138 139 140 141 142 | capabilities.vendorID]; _productID = [[OFNumber alloc] initWithUnsignedShort: capabilities.productID]; } } | | | | | | | | | | | | | | | | | | | | | | | | | > > > > > | 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 | capabilities.vendorID]; _productID = [[OFNumber alloc] initWithUnsignedShort: capabilities.productID]; } } _extendedGamepad = [[OHXInputExtendedGamepad alloc] init]; [self retrieveState]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_vendorID release]; [_productID release]; [_extendedGamepad release]; [super dealloc]; } - (void)retrieveState { XINPUT_STATE state = { 0 }; if (XInputGetStateFuncPtr(_index, &state) != ERROR_SUCCESS) @throw [OFReadFailedException exceptionWithObject: self requestedLength: sizeof(state) errNo: 0]; _extendedGamepad.northButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y); _extendedGamepad.southButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_A); _extendedGamepad.westButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_X); _extendedGamepad.eastButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_B); _extendedGamepad.leftShoulderButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER); _extendedGamepad.rightShoulderButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER); _extendedGamepad.leftThumbstickButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB); _extendedGamepad.rightThumbstickButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB); _extendedGamepad.menuButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_START); _extendedGamepad.optionsButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK); if (OHXInputVersion != 910) _extendedGamepad.homeButton.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE); _extendedGamepad.leftTriggerButton.value = (float)state.Gamepad.bLeftTrigger / 255; _extendedGamepad.rightTriggerButton.value = (float)state.Gamepad.bRightTrigger / 255; _extendedGamepad.leftThumbstick.xAxis.value = (float)state.Gamepad.sThumbLX / (state.Gamepad.sThumbLX < 0 ? -INT16_MIN : INT16_MAX); _extendedGamepad.leftThumbstick.yAxis.value = -(float)state.Gamepad.sThumbLY / (state.Gamepad.sThumbLY < 0 ? -INT16_MIN : INT16_MAX); _extendedGamepad.rightThumbstick.xAxis.value = (float)state.Gamepad.sThumbRX / (state.Gamepad.sThumbRX < 0 ? -INT16_MIN : INT16_MAX); _extendedGamepad.rightThumbstick.yAxis.value = -(float)state.Gamepad.sThumbRY / (state.Gamepad.sThumbRY < 0 ? -INT16_MIN : INT16_MAX); _extendedGamepad.dPad.up.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP); _extendedGamepad.dPad.down.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN); _extendedGamepad.dPad.left.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT); _extendedGamepad.dPad.right.value = !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT); } - (OFString *)name { switch (OHXInputVersion) { case 14: return @"XInput 1.4 device"; case 13: return @"XInput 1.3 device"; case 910: return @"XInput 9.1.0 device"; } return nil; } - (OHGameControllerProfile *)rawProfile { return _extendedGamepad; } - (OHGamepad *)gamepad { return _extendedGamepad; } @end |