| 186 | } |
| 187 | |
| 188 | void Controller::addControllerInRender(int deviceIndex) { |
| 189 | #if DORA_DEV_VIRTUAL_CONTROLLER |
| 190 | if (deviceIndex == _devVirtualDeviceIndex && _devVirtualController) return; |
| 191 | #endif // DORA_DEV_VIRTUAL_CONTROLLER |
| 192 | auto joystickId = s_cast<DeviceID>(SDL_JoystickGetDeviceInstanceID(deviceIndex)); |
| 193 | if (joystickId < 0) return; |
| 194 | auto controller = SDL_GameControllerOpen(deviceIndex); |
| 195 | if (controller) { |
| 196 | #if DORA_DEV_VIRTUAL_CONTROLLER |
| 197 | if (deviceIndex == _devVirtualDeviceIndex) { |
| 198 | _devVirtualController = controller; |
| 199 | _devVirtualJoystick = SDL_GameControllerGetJoystick(controller); |
| 200 | } |
| 201 | #endif // DORA_DEV_VIRTUAL_CONTROLLER |
| 202 | SharedApplication.invokeInLogic([controller, joystickId, this]() { |
| 203 | if (_deviceMap.contains(joystickId)) return; |
| 204 | int deviceId = -1; |
| 205 | if (!_availableDeviceIds.empty()) { |
| 206 | deviceId = _availableDeviceIds.top(); |
| 207 | _availableDeviceIds.pop(); |
| 208 | } else { |
| 209 | deviceId = s_cast<int>(_deviceMap.size()); |
| 210 | } |
| 211 | _deviceMap[joystickId] = New<Device>(deviceId, controller); |
| 212 | }); |
| 213 | } else { |
| 214 | Warn("failed to open a new controller! {}", SDL_GetError()); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | void Controller::handleDevVirtualControllerEventInRender(const SDL_Event& event) { |
| 219 | #if DORA_DEV_VIRTUAL_CONTROLLER |
nothing calls this directly
no test coverage detected