Skip to content

Commit 81e2431

Browse files
committed
fix mapping buttons from input
1 parent 618c77c commit 81e2431

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp

+1-24
Original file line numberDiff line numberDiff line change
@@ -217,28 +217,9 @@ ButtonMappingFactory::CreateDefaultSDLButtonMappings(uint8_t portIndex, CONTROLL
217217

218218
std::shared_ptr<ControllerButtonMapping>
219219
ButtonMappingFactory::CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) {
220-
std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllers;
221220
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);
225221

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)) {
242223
for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
243224
if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
244225
mapping = std::make_shared<SDLButtonToButtonMapping>(portIndex, bitmask, button);
@@ -269,10 +250,6 @@ ButtonMappingFactory::CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROL
269250
}
270251
}
271252

272-
for (auto [i, controller] : sdlControllers) {
273-
SDL_GameControllerClose(controller);
274-
}
275-
276253
return mapping;
277254
}
278255

0 commit comments

Comments
 (0)