Skip to content

Commit 618c77c

Browse files
committed
fix mapping axis from input
1 parent 9be3448 commit 618c77c

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

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

+1-24
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,9 @@ AxisDirectionMappingFactory::CreateDefaultSDLAxisDirectionMappings(PhysicalDevic
156156
std::shared_ptr<ControllerAxisDirectionMapping>
157157
AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(uint8_t portIndex, StickIndex stickIndex,
158158
Direction direction) {
159-
std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllers;
160159
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);
164160

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)) {
181162
for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
182163
if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
183164
mapping = std::make_shared<SDLButtonToAxisDirectionMapping>(portIndex, stickIndex, direction, button);
@@ -209,10 +190,6 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(uint8_t port
209190
}
210191
}
211192

212-
for (auto [i, controller] : sdlControllers) {
213-
SDL_GameControllerClose(controller);
214-
}
215-
216193
return mapping;
217194
}
218195

0 commit comments

Comments
 (0)