MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / addControllerInRender

Method addControllerInRender

Source/Input/Controller.cpp:188–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188void 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
218void Controller::handleDevVirtualControllerEventInRender(const SDL_Event& event) {
219#if DORA_DEV_VIRTUAL_CONTROLLER

Callers

nothing calls this directly

Calls 11

SDL_GameControllerOpenFunction · 0.85
SDL_GetErrorFunction · 0.85
invokeInLogicMethod · 0.80
topMethod · 0.80
popMethod · 0.65
WarnFunction · 0.50
containsMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected