@@ -156,28 +156,9 @@ AxisDirectionMappingFactory::CreateDefaultSDLAxisDirectionMappings(PhysicalDevic
156
156
std::shared_ptr<ControllerAxisDirectionMapping>
157
157
AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput (uint8_t portIndex, StickIndex stickIndex,
158
158
Direction direction) {
159
- std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllers;
160
159
std::shared_ptr<ControllerAxisDirectionMapping> mapping = nullptr ;
161
- for (auto [lusIndex, indexMapping] :
162
- Context::GetInstance ()->GetControlDeck ()->GetDeviceIndexMappingManager ()->GetAllDeviceIndexMappings ()) {
163
- auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
164
160
165
- if (sdlIndexMapping == nullptr ) {
166
- // this LUS index isn't mapped to an SDL index
167
- continue ;
168
- }
169
-
170
- auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex ();
171
-
172
- if (!SDL_IsGameController (sdlIndex)) {
173
- // this SDL device isn't a game controller
174
- continue ;
175
- }
176
-
177
- sdlControllers[lusIndex] = SDL_GameControllerOpen (sdlIndex);
178
- }
179
-
180
- for (auto [lusIndex, controller] : sdlControllers) {
161
+ for (auto [lusIndex, controller] : Context::GetInstance ()->GetControlDeck ()->GetConnectedPhysicalDeviceManager ()->GetConnectedSDLGamepadsForPort (portIndex)) {
181
162
for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
182
163
if (SDL_GameControllerGetButton (controller, static_cast <SDL_GameControllerButton>(button))) {
183
164
mapping = std::make_shared<SDLButtonToAxisDirectionMapping>(portIndex, stickIndex, direction, button);
@@ -209,10 +190,6 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(uint8_t port
209
190
}
210
191
}
211
192
212
- for (auto [i, controller] : sdlControllers) {
213
- SDL_GameControllerClose (controller);
214
- }
215
-
216
193
return mapping;
217
194
}
218
195
0 commit comments