Skip to content

Commit b6a0b39

Browse files
committed
finally remove the device index dir
1 parent c8400d0 commit b6a0b39

17 files changed

+220
-1405
lines changed

src/controller/controldeck/ControlDeck.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
#include "utils/StringHelper.h"
66
#include "public/bridge/consolevariablebridge.h"
77
#include <imgui.h>
8-
#include "controller/deviceindex/ShipDeviceIndexMappingManager.h"
98
#include "controller/controldevice/controller/mapping/mouse/WheelHandler.h"
109

1110
namespace Ship {
1211

1312
ControlDeck::ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks) : mSinglePlayerMappingMode(false) {
14-
mDeviceIndexMappingManager = std::make_shared<ShipDeviceIndexMappingManager>();
1513
mConnectedPhysicalDeviceManager = std::make_shared<ConnectedPhysicalDeviceManager>();
1614
mGlobalSDLDeviceSettings = std::make_shared<GlobalSDLDeviceSettings>();
1715
}
@@ -36,8 +34,6 @@ void ControlDeck::Init(uint8_t* controllerBits) {
3634
mPorts[0]->GetConnectedController()->AddDefaultMappings(PhysicalDeviceType::Mouse);
3735
mPorts[0]->GetConnectedController()->AddDefaultMappings(PhysicalDeviceType::SDLGamepad);
3836
}
39-
40-
// Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Controller Reordering")->Show();
4137
}
4238

4339
bool ControlDeck::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) {
@@ -107,10 +103,6 @@ void ControlDeck::UnblockGameInput(int32_t blockId) {
107103
mGameInputBlockers.erase(blockId);
108104
}
109105

110-
std::shared_ptr<ShipDeviceIndexMappingManager> ControlDeck::GetDeviceIndexMappingManager() {
111-
return mDeviceIndexMappingManager;
112-
}
113-
114106
std::shared_ptr<ConnectedPhysicalDeviceManager> ControlDeck::GetConnectedPhysicalDeviceManager() {
115107
return mConnectedPhysicalDeviceManager;
116108
}

src/controller/controldeck/ControlDeck.h

-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <vector>
55
#include <config/Config.h>
66
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
7-
#include "controller/deviceindex/ShipDeviceIndexMappingManager.h"
87
#include "controller/physicaldevice/ConnectedPhysicalDeviceManager.h"
98
#include "controller/physicaldevice/GlobalSDLDeviceSettings.h"
109

@@ -29,7 +28,6 @@ class ControlDeck {
2928
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
3029
bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button);
3130

32-
std::shared_ptr<ShipDeviceIndexMappingManager> GetDeviceIndexMappingManager();
3331
std::shared_ptr<ConnectedPhysicalDeviceManager> GetConnectedPhysicalDeviceManager();
3432
std::shared_ptr<GlobalSDLDeviceSettings> GetGlobalSDLDeviceSettings();
3533

@@ -41,7 +39,6 @@ class ControlDeck {
4139
uint8_t* mControllerBits = nullptr;
4240
bool mSinglePlayerMappingMode;
4341
std::unordered_map<int32_t, bool> mGameInputBlockers;
44-
std::shared_ptr<ShipDeviceIndexMappingManager> mDeviceIndexMappingManager;
4542
std::shared_ptr<ConnectedPhysicalDeviceManager> mConnectedPhysicalDeviceManager;
4643
std::shared_ptr<GlobalSDLDeviceSettings> mGlobalSDLDeviceSettings;
4744
};

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

+61-60
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "utils/StringHelper.h"
55
#include "libultraship/libultra/controller.h"
66
#include "Context.h"
7-
#include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h"
87

98
namespace Ship {
109
std::shared_ptr<ControllerGyroMapping> GyroMappingFactory::CreateGyroMappingFromConfig(uint8_t portIndex,
@@ -46,66 +45,68 @@ std::shared_ptr<ControllerGyroMapping> GyroMappingFactory::CreateGyroMappingFrom
4645
std::shared_ptr<ControllerGyroMapping> GyroMappingFactory::CreateGyroMappingFromSDLInput(uint8_t portIndex) {
4746
std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllersWithGyro;
4847
std::shared_ptr<ControllerGyroMapping> mapping = nullptr;
49-
for (auto [lusIndex, indexMapping] :
50-
Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
51-
auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
5248

53-
if (sdlIndexMapping == nullptr) {
54-
// this LUS index isn't mapped to an SDL index
55-
continue;
56-
}
57-
58-
auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();
59-
60-
if (!SDL_IsGameController(sdlIndex)) {
61-
// this SDL device isn't a game controller
62-
continue;
63-
}
64-
65-
auto controller = SDL_GameControllerOpen(sdlIndex);
66-
if (SDL_GameControllerHasSensor(controller, SDL_SENSOR_GYRO)) {
67-
sdlControllersWithGyro[lusIndex] = SDL_GameControllerOpen(sdlIndex);
68-
} else {
69-
SDL_GameControllerClose(controller);
70-
}
71-
}
72-
73-
for (auto [lusIndex, controller] : sdlControllersWithGyro) {
74-
for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
75-
if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
76-
mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
77-
mapping->Recalibrate();
78-
break;
79-
}
80-
}
81-
82-
if (mapping != nullptr) {
83-
break;
84-
}
85-
86-
for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
87-
const auto axis = static_cast<SDL_GameControllerAxis>(i);
88-
const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
89-
int32_t axisDirection = 0;
90-
if (axisValue < -0.7f) {
91-
axisDirection = NEGATIVE;
92-
} else if (axisValue > 0.7f) {
93-
axisDirection = POSITIVE;
94-
}
95-
96-
if (axisDirection == 0) {
97-
continue;
98-
}
99-
100-
mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
101-
mapping->Recalibrate();
102-
break;
103-
}
104-
}
105-
106-
for (auto [i, controller] : sdlControllersWithGyro) {
107-
SDL_GameControllerClose(controller);
108-
}
49+
// todo: gyro
50+
// for (auto [lusIndex, indexMapping] :
51+
// Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
52+
// auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
53+
54+
// if (sdlIndexMapping == nullptr) {
55+
// // this LUS index isn't mapped to an SDL index
56+
// continue;
57+
// }
58+
59+
// auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();
60+
61+
// if (!SDL_IsGameController(sdlIndex)) {
62+
// // this SDL device isn't a game controller
63+
// continue;
64+
// }
65+
66+
// auto controller = SDL_GameControllerOpen(sdlIndex);
67+
// if (SDL_GameControllerHasSensor(controller, SDL_SENSOR_GYRO)) {
68+
// sdlControllersWithGyro[lusIndex] = SDL_GameControllerOpen(sdlIndex);
69+
// } else {
70+
// SDL_GameControllerClose(controller);
71+
// }
72+
// }
73+
74+
// for (auto [lusIndex, controller] : sdlControllersWithGyro) {
75+
// for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
76+
// if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
77+
// mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
78+
// mapping->Recalibrate();
79+
// break;
80+
// }
81+
// }
82+
83+
// if (mapping != nullptr) {
84+
// break;
85+
// }
86+
87+
// for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
88+
// const auto axis = static_cast<SDL_GameControllerAxis>(i);
89+
// const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
90+
// int32_t axisDirection = 0;
91+
// if (axisValue < -0.7f) {
92+
// axisDirection = NEGATIVE;
93+
// } else if (axisValue > 0.7f) {
94+
// axisDirection = POSITIVE;
95+
// }
96+
97+
// if (axisDirection == 0) {
98+
// continue;
99+
// }
100+
101+
// mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
102+
// mapping->Recalibrate();
103+
// break;
104+
// }
105+
// }
106+
107+
// for (auto [i, controller] : sdlControllersWithGyro) {
108+
// SDL_GameControllerClose(controller);
109+
// }
109110

110111
return mapping;
111112
}

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

+59-58
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "utils/StringHelper.h"
55
#include "libultraship/libultra/controller.h"
66
#include "Context.h"
7-
#include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h"
87

98
namespace Ship {
109
std::shared_ptr<ControllerLEDMapping> LEDMappingFactory::CreateLEDMappingFromConfig(uint8_t portIndex, std::string id) {
@@ -44,64 +43,66 @@ std::shared_ptr<ControllerLEDMapping> LEDMappingFactory::CreateLEDMappingFromCon
4443
std::shared_ptr<ControllerLEDMapping> LEDMappingFactory::CreateLEDMappingFromSDLInput(uint8_t portIndex) {
4544
std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllersWithLEDs;
4645
std::shared_ptr<ControllerLEDMapping> mapping = nullptr;
47-
for (auto [lusIndex, indexMapping] :
48-
Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
49-
auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
5046

51-
if (sdlIndexMapping == nullptr) {
52-
// this LUS index isn't mapped to an SDL index
53-
continue;
54-
}
55-
56-
auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();
57-
58-
if (!SDL_IsGameController(sdlIndex)) {
59-
// this SDL device isn't a game controller
60-
continue;
61-
}
62-
63-
auto controller = SDL_GameControllerOpen(sdlIndex);
64-
if (SDL_GameControllerHasLED(controller)) {
65-
sdlControllersWithLEDs[lusIndex] = SDL_GameControllerOpen(sdlIndex);
66-
} else {
67-
SDL_GameControllerClose(controller);
68-
}
69-
}
70-
71-
for (auto [lusIndex, controller] : sdlControllersWithLEDs) {
72-
for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
73-
if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
74-
mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
75-
break;
76-
}
77-
}
78-
79-
if (mapping != nullptr) {
80-
break;
81-
}
82-
83-
for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
84-
const auto axis = static_cast<SDL_GameControllerAxis>(i);
85-
const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
86-
int32_t axisDirection = 0;
87-
if (axisValue < -0.7f) {
88-
axisDirection = NEGATIVE;
89-
} else if (axisValue > 0.7f) {
90-
axisDirection = POSITIVE;
91-
}
92-
93-
if (axisDirection == 0) {
94-
continue;
95-
}
96-
97-
mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
98-
break;
99-
}
100-
}
101-
102-
for (auto [i, controller] : sdlControllersWithLEDs) {
103-
SDL_GameControllerClose(controller);
104-
}
47+
// todo: LED
48+
// for (auto [lusIndex, indexMapping] :
49+
// Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
50+
// auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
51+
52+
// if (sdlIndexMapping == nullptr) {
53+
// // this LUS index isn't mapped to an SDL index
54+
// continue;
55+
// }
56+
57+
// auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();
58+
59+
// if (!SDL_IsGameController(sdlIndex)) {
60+
// // this SDL device isn't a game controller
61+
// continue;
62+
// }
63+
64+
// auto controller = SDL_GameControllerOpen(sdlIndex);
65+
// if (SDL_GameControllerHasLED(controller)) {
66+
// sdlControllersWithLEDs[lusIndex] = SDL_GameControllerOpen(sdlIndex);
67+
// } else {
68+
// SDL_GameControllerClose(controller);
69+
// }
70+
// }
71+
72+
// for (auto [lusIndex, controller] : sdlControllersWithLEDs) {
73+
// for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
74+
// if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
75+
// mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
76+
// break;
77+
// }
78+
// }
79+
80+
// if (mapping != nullptr) {
81+
// break;
82+
// }
83+
84+
// for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
85+
// const auto axis = static_cast<SDL_GameControllerAxis>(i);
86+
// const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
87+
// int32_t axisDirection = 0;
88+
// if (axisValue < -0.7f) {
89+
// axisDirection = NEGATIVE;
90+
// } else if (axisValue > 0.7f) {
91+
// axisDirection = POSITIVE;
92+
// }
93+
94+
// if (axisDirection == 0) {
95+
// continue;
96+
// }
97+
98+
// mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
99+
// break;
100+
// }
101+
// }
102+
103+
// for (auto [i, controller] : sdlControllersWithLEDs) {
104+
// SDL_GameControllerClose(controller);
105+
// }
105106

106107
return mapping;
107108
}

0 commit comments

Comments
 (0)