@@ -217,28 +217,9 @@ ButtonMappingFactory::CreateDefaultSDLButtonMappings(uint8_t portIndex, CONTROLL
217
217
218
218
std::shared_ptr<ControllerButtonMapping>
219
219
ButtonMappingFactory::CreateButtonMappingFromSDLInput (uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) {
220
- std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllers;
221
220
std::shared_ptr<ControllerButtonMapping> mapping = nullptr ;
222
- for (auto [lusIndex, indexMapping] :
223
- Context::GetInstance ()->GetControlDeck ()->GetDeviceIndexMappingManager ()->GetAllDeviceIndexMappings ()) {
224
- auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
225
221
226
- if (sdlIndexMapping == nullptr ) {
227
- // this LUS index isn't mapped to an SDL index
228
- continue ;
229
- }
230
-
231
- auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex ();
232
-
233
- if (!SDL_IsGameController (sdlIndex)) {
234
- // this SDL device isn't a game controller
235
- continue ;
236
- }
237
-
238
- sdlControllers[lusIndex] = SDL_GameControllerOpen (sdlIndex);
239
- }
240
-
241
- for (auto [lusIndex, controller] : sdlControllers) {
222
+ for (auto [lusIndex, controller] : Context::GetInstance ()->GetControlDeck ()->GetConnectedPhysicalDeviceManager ()->GetConnectedSDLGamepadsForPort (portIndex)) {
242
223
for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
243
224
if (SDL_GameControllerGetButton (controller, static_cast <SDL_GameControllerButton>(button))) {
244
225
mapping = std::make_shared<SDLButtonToButtonMapping>(portIndex, bitmask, button);
@@ -269,10 +250,6 @@ ButtonMappingFactory::CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROL
269
250
}
270
251
}
271
252
272
- for (auto [i, controller] : sdlControllers) {
273
- SDL_GameControllerClose (controller);
274
- }
275
-
276
253
return mapping;
277
254
}
278
255
0 commit comments