Skip to content

Commit 061062f

Browse files
committed
glorified stash of the mess
1 parent 1e1fe6d commit 061062f

30 files changed

+45
-981
lines changed

src/controller/controldevice/controller/mapping/ControllerMapping.h

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class ControllerMapping {
1616
~ControllerMapping();
1717
virtual std::string GetPhysicalDeviceName();
1818
ShipDeviceType GetShipDeviceType();
19-
virtual bool PhysicalDeviceIsConnected() = 0;
2019

2120
protected:
2221
ShipDeviceType mShipDeviceType;

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

+1-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "public/bridge/consolevariablebridge.h"
1010
#include "utils/StringHelper.h"
1111
#include "Context.h"
12-
#include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h"
1312

1413
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
1514
#include "controller/controldevice/controller/mapping/mouse/WheelHandler.h"
@@ -130,15 +129,6 @@ AxisDirectionMappingFactory::CreateDefaultKeyboardAxisDirectionMappings(uint8_t
130129
std::vector<std::shared_ptr<ControllerAxisDirectionMapping>>
131130
AxisDirectionMappingFactory::CreateDefaultSDLAxisDirectionMappings(ShipDeviceType shipDeviceIndex, uint8_t portIndex,
132131
StickIndex stickIndex) {
133-
auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(
134-
Context::GetInstance()
135-
->GetControlDeck()
136-
->GetDeviceIndexMappingManager()
137-
->GetDeviceIndexMappingFromShipDeviceIndex(shipDeviceIndex));
138-
if (sdlIndexMapping == nullptr) {
139-
return std::vector<std::shared_ptr<ControllerAxisDirectionMapping>>();
140-
}
141-
142132
std::vector<std::shared_ptr<ControllerAxisDirectionMapping>> mappings = {
143133
std::make_shared<SDLAxisDirectionToAxisDirectionMapping>(portIndex, stickIndex, LEFT,
144134
stickIndex == LEFT_STICK ? 0 : 2, -1),
@@ -156,7 +146,7 @@ AxisDirectionMappingFactory::CreateDefaultSDLAxisDirectionMappings(ShipDeviceTyp
156146
std::shared_ptr<ControllerAxisDirectionMapping>
157147
AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(uint8_t portIndex, StickIndex stickIndex,
158148
Direction direction) {
159-
std::unordered_map<ShipDeviceType, SDL_GameController*> sdlControllers;
149+
std::vector<SDL_GameController*> sdlControllers;
160150
std::shared_ptr<ControllerAxisDirectionMapping> mapping = nullptr;
161151
for (auto [lusIndex, indexMapping] :
162152
Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {

src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAnyMapping.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,4 @@ bool KeyboardKeyToAnyMapping::ProcessKeyboardEvent(KbEventType eventType, KbScan
4242
std::string KeyboardKeyToAnyMapping::GetPhysicalDeviceName() {
4343
return "Keyboard";
4444
}
45-
46-
bool KeyboardKeyToAnyMapping::PhysicalDeviceIsConnected() {
47-
// todo: handle non-keyboard devices?
48-
return true;
49-
}
5045
} // namespace Ship

src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAnyMapping.h

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class KeyboardKeyToAnyMapping : virtual public ControllerInputMapping {
1111
std::string GetPhysicalInputName() override;
1212
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
1313
std::string GetPhysicalDeviceName() override;
14-
bool PhysicalDeviceIsConnected() override;
1514

1615
protected:
1716
KbScancode mKeyboardScancode;

src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,4 @@ bool MouseButtonToAnyMapping::ProcessMouseButtonEvent(bool isPressed, MouseBtn b
2828
std::string MouseButtonToAnyMapping::GetPhysicalDeviceName() {
2929
return "Mouse";
3030
}
31-
32-
bool MouseButtonToAnyMapping::PhysicalDeviceIsConnected() {
33-
return true;
34-
}
3531
} // namespace Ship

src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.h

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class MouseButtonToAnyMapping : virtual public ControllerInputMapping {
1111
std::string GetPhysicalInputName() override;
1212
bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button);
1313
std::string GetPhysicalDeviceName() override;
14-
bool PhysicalDeviceIsConnected() override;
1514

1615
protected:
1716
MouseBtn mButton;

src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,4 @@ std::string MouseWheelToAnyMapping::GetPhysicalInputName() {
1919
std::string MouseWheelToAnyMapping::GetPhysicalDeviceName() {
2020
return "Mouse";
2121
}
22-
23-
bool MouseWheelToAnyMapping::PhysicalDeviceIsConnected() {
24-
return true;
25-
}
2622
} // namespace Ship

src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.h

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class MouseWheelToAnyMapping : virtual public ControllerInputMapping {
1010
~MouseWheelToAnyMapping();
1111
std::string GetPhysicalInputName() override;
1212
std::string GetPhysicalDeviceName() override;
13-
bool PhysicalDeviceIsConnected() override;
1413

1514
protected:
1615
WheelDirection mWheelDirection;

src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAnyMapping.cpp

+5-31
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,22 @@ SDLAxisDirectionToAnyMapping::~SDLAxisDirectionToAnyMapping() {
1616
std::string SDLAxisDirectionToAnyMapping::GetPhysicalInputName() {
1717
switch (mControllerAxis) {
1818
case SDL_CONTROLLER_AXIS_LEFTX:
19-
return StringHelper::Sprintf(UsesGameCubeLayout() ? "Analog Stick %s" : "Left Stick %s",
19+
return StringHelper::Sprintf("Left Stick %s",
2020
mAxisDirection == NEGATIVE ? ICON_FA_ARROW_LEFT : ICON_FA_ARROW_RIGHT);
2121
case SDL_CONTROLLER_AXIS_LEFTY:
22-
return StringHelper::Sprintf(UsesGameCubeLayout() ? "Analog Stick %s" : "Left Stick %s",
22+
return StringHelper::Sprintf("Left Stick %s",
2323
mAxisDirection == NEGATIVE ? ICON_FA_ARROW_UP : ICON_FA_ARROW_DOWN);
2424
case SDL_CONTROLLER_AXIS_RIGHTX:
25-
return StringHelper::Sprintf(UsesGameCubeLayout() ? "C Stick %s" : "Right Stick %s",
25+
return StringHelper::Sprintf("Right Stick %s",
2626
mAxisDirection == NEGATIVE ? ICON_FA_ARROW_LEFT : ICON_FA_ARROW_RIGHT);
2727
case SDL_CONTROLLER_AXIS_RIGHTY:
28-
return StringHelper::Sprintf(UsesGameCubeLayout() ? "C Stick %s" : "Right Stick %s",
28+
return StringHelper::Sprintf("Right Stick %s",
2929
mAxisDirection == NEGATIVE ? ICON_FA_ARROW_UP : ICON_FA_ARROW_DOWN);
3030
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
31-
if (UsesPlaystationLayout()) {
32-
return "L2";
33-
}
34-
if (UsesSwitchLayout()) {
35-
return "ZL";
36-
}
37-
if (UsesXboxLayout()) {
3831
return "LT";
39-
}
40-
if (UsesGameCubeLayout()) {
41-
return "L";
42-
}
4332
break;
4433
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
45-
if (UsesPlaystationLayout()) {
46-
return "R2";
47-
}
48-
if (UsesSwitchLayout()) {
49-
return "ZR";
50-
}
51-
if (UsesXboxLayout()) {
5234
return "RT";
53-
}
54-
if (UsesGameCubeLayout()) {
55-
return "R";
56-
}
5735
break;
5836
default:
5937
break;
@@ -64,11 +42,7 @@ std::string SDLAxisDirectionToAnyMapping::GetPhysicalInputName() {
6442
}
6543

6644
std::string SDLAxisDirectionToAnyMapping::GetPhysicalDeviceName() {
67-
return GetSDLDeviceName();
68-
}
69-
70-
bool SDLAxisDirectionToAnyMapping::PhysicalDeviceIsConnected() {
71-
return ControllerLoaded();
45+
return "SDL Gamepad";
7246
}
7347

7448
bool SDLAxisDirectionToAnyMapping::AxisIsTrigger() {

src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAnyMapping.h

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class SDLAxisDirectionToAnyMapping : virtual public ControllerInputMapping, publ
1010
~SDLAxisDirectionToAnyMapping();
1111
std::string GetPhysicalInputName() override;
1212
std::string GetPhysicalDeviceName() override;
13-
bool PhysicalDeviceIsConnected() override;
1413
bool AxisIsTrigger();
1514
bool AxisIsStick();
1615

src/controller/controldevice/controller/mapping/sdl/SDLButtonToAnyMapping.cpp

+4-161
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,6 @@ SDLButtonToAnyMapping::~SDLButtonToAnyMapping() {
1313
}
1414

1515
std::string SDLButtonToAnyMapping::GetPhysicalInputName() {
16-
if (UsesPlaystationLayout()) {
17-
return GetPlaystationButtonName();
18-
}
19-
20-
if (UsesSwitchLayout()) {
21-
return GetSwitchButtonName();
22-
}
23-
24-
if (UsesXboxLayout()) {
25-
return GetXboxButtonName();
26-
}
27-
28-
if (UsesGameCubeLayout()) {
29-
return GetGameCubeButtonName();
30-
}
31-
32-
return GetGenericButtonName();
33-
}
34-
35-
std::string SDLButtonToAnyMapping::GetGenericButtonName() {
36-
return StringHelper::Sprintf("B%d", mControllerButton);
37-
}
38-
39-
std::string SDLButtonToAnyMapping::GetGameCubeButtonName() {
4016
switch (mControllerButton) {
4117
case SDL_CONTROLLER_BUTTON_A:
4218
return "A";
@@ -46,144 +22,11 @@ std::string SDLButtonToAnyMapping::GetGameCubeButtonName() {
4622
return "X";
4723
case SDL_CONTROLLER_BUTTON_Y:
4824
return "Y";
49-
case SDL_CONTROLLER_BUTTON_START:
50-
return "Start";
51-
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
52-
return "Z";
53-
case SDL_CONTROLLER_BUTTON_DPAD_UP:
54-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_UP);
55-
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
56-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_DOWN);
57-
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
58-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_LEFT);
59-
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
60-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_RIGHT);
61-
default:
62-
break;
63-
}
64-
65-
return GetGenericButtonName();
66-
}
67-
68-
std::string SDLButtonToAnyMapping::GetPlaystationButtonName() {
69-
switch (mControllerButton) {
70-
case SDL_CONTROLLER_BUTTON_A:
71-
return StringHelper::Sprintf("%s", ICON_FA_TIMES);
72-
case SDL_CONTROLLER_BUTTON_B:
73-
return StringHelper::Sprintf("%s", ICON_FA_CIRCLE_O);
74-
case SDL_CONTROLLER_BUTTON_X:
75-
return StringHelper::Sprintf("%s", ICON_FA_SQUARE_O);
76-
case SDL_CONTROLLER_BUTTON_Y:
77-
return "Triangle"; // imgui default font doesn't have Δ, and font-awesome 4 doesn't have a triangle
7825
case SDL_CONTROLLER_BUTTON_BACK:
79-
if (GetSDLControllerType() == SDL_CONTROLLER_TYPE_PS3) {
80-
return "Select";
81-
}
82-
if (GetSDLControllerType() == SDL_CONTROLLER_TYPE_PS4) {
83-
return "Share";
84-
}
85-
return "Create";
86-
case SDL_CONTROLLER_BUTTON_GUIDE:
87-
return "PS";
88-
case SDL_CONTROLLER_BUTTON_START:
89-
if (GetSDLControllerType() == SDL_CONTROLLER_TYPE_PS3) {
90-
return "Start";
91-
}
92-
if (GetSDLControllerType() == SDL_CONTROLLER_TYPE_PS4) {
93-
return "Options";
94-
}
95-
return StringHelper::Sprintf("%s", ICON_FA_BARS);
96-
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
97-
return "L3"; // it seems the official term is just long for these
98-
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
99-
return "R3"; // it seems the official term is just long for these
100-
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
101-
return "L1";
102-
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
103-
return "R1";
104-
case SDL_CONTROLLER_BUTTON_DPAD_UP:
105-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_UP);
106-
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
107-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_DOWN);
108-
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
109-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_LEFT);
110-
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
111-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_RIGHT);
112-
case SDL_CONTROLLER_BUTTON_MISC1:
113-
if (GetSDLControllerType() == SDL_CONTROLLER_TYPE_PS5) {
114-
return StringHelper::Sprintf("%s", ICON_FA_MICROPHONE_SLASH);
115-
}
116-
break;
117-
default:
118-
break;
119-
}
120-
121-
return GetGenericButtonName();
122-
}
123-
124-
std::string SDLButtonToAnyMapping::GetSwitchButtonName() {
125-
switch (mControllerButton) {
126-
case SDL_CONTROLLER_BUTTON_A:
127-
return "A";
128-
case SDL_CONTROLLER_BUTTON_B:
129-
return "B";
130-
case SDL_CONTROLLER_BUTTON_X:
131-
return "X";
132-
case SDL_CONTROLLER_BUTTON_Y:
133-
return "Y";
134-
case SDL_CONTROLLER_BUTTON_BACK:
135-
return StringHelper::Sprintf("%s", ICON_FA_MINUS);
136-
case SDL_CONTROLLER_BUTTON_GUIDE:
137-
return StringHelper::Sprintf("%s", ICON_FA_HOME);
138-
case SDL_CONTROLLER_BUTTON_START:
139-
return StringHelper::Sprintf("%s", ICON_FA_PLUS);
140-
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
141-
return "Left Stick Press"; // it seems the official term is just long for these
142-
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
143-
return "Right Stick Press"; // it seems the official term is just long for these
144-
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
145-
return "L";
146-
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
147-
return "R";
148-
case SDL_CONTROLLER_BUTTON_DPAD_UP:
149-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_UP);
150-
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
151-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_DOWN);
152-
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
153-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_LEFT);
154-
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
155-
return StringHelper::Sprintf("D-Pad %s", ICON_FA_ARROW_RIGHT);
156-
case SDL_CONTROLLER_BUTTON_MISC1:
157-
return "Capture"; /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button,
158-
Amazon Luna microphone button */
159-
default:
160-
break;
161-
}
162-
163-
return GetGenericButtonName();
164-
}
165-
166-
std::string SDLButtonToAnyMapping::GetXboxButtonName() {
167-
switch (mControllerButton) {
168-
case SDL_CONTROLLER_BUTTON_A:
169-
return "A";
170-
case SDL_CONTROLLER_BUTTON_B:
171-
return "B";
172-
case SDL_CONTROLLER_BUTTON_X:
173-
return "X";
174-
case SDL_CONTROLLER_BUTTON_Y:
175-
return "Y";
176-
case SDL_CONTROLLER_BUTTON_BACK:
177-
if (GetSDLControllerType() == SDL_CONTROLLER_TYPE_XBOX360) {
178-
return "Back";
179-
}
18026
return "View";
18127
case SDL_CONTROLLER_BUTTON_GUIDE:
18228
return "Xbox";
18329
case SDL_CONTROLLER_BUTTON_START:
184-
if (GetSDLControllerType() == SDL_CONTROLLER_TYPE_XBOX360) {
185-
return "Start";
186-
}
18730
return StringHelper::Sprintf("%s", ICON_FA_BARS);
18831
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
18932
return "LS";
@@ -219,11 +62,11 @@ std::string SDLButtonToAnyMapping::GetXboxButtonName() {
21962
return GetGenericButtonName();
22063
}
22164

222-
std::string SDLButtonToAnyMapping::GetPhysicalDeviceName() {
223-
return GetSDLDeviceName();
65+
std::string SDLButtonToAnyMapping::GetGenericButtonName() {
66+
return StringHelper::Sprintf("B%d", mControllerButton);
22467
}
22568

226-
bool SDLButtonToAnyMapping::PhysicalDeviceIsConnected() {
227-
return ControllerLoaded();
69+
std::string SDLButtonToAnyMapping::GetPhysicalDeviceName() {
70+
return "SDL Gamepad";
22871
}
22972
} // namespace Ship

src/controller/controldevice/controller/mapping/sdl/SDLButtonToAnyMapping.h

-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ class SDLButtonToAnyMapping : virtual public ControllerInputMapping, public SDLM
1010
~SDLButtonToAnyMapping();
1111
std::string GetPhysicalInputName() override;
1212
std::string GetPhysicalDeviceName() override;
13-
bool PhysicalDeviceIsConnected() override;
1413

1514
protected:
1615
SDL_GameControllerButton mControllerButton;
1716

1817
private:
19-
std::string GetPlaystationButtonName();
20-
std::string GetSwitchButtonName();
21-
std::string GetXboxButtonName();
22-
std::string GetGameCubeButtonName();
2318
std::string GetGenericButtonName();
2419
};
2520
} // namespace Ship

src/controller/controldevice/controller/mapping/sdl/SDLGyroMapping.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ void SDLGyroMapping::EraseFromConfig() {
7878
}
7979

8080
std::string SDLGyroMapping::GetPhysicalDeviceName() {
81-
return GetSDLDeviceName();
82-
}
83-
84-
bool SDLGyroMapping::PhysicalDeviceIsConnected() {
85-
return ControllerLoaded();
81+
return "SDL Gamepad";
8682
}
8783
} // namespace Ship

src/controller/controldevice/controller/mapping/sdl/SDLGyroMapping.h

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class SDLGyroMapping final : public ControllerGyroMapping, public SDLMapping {
1212
std::string GetGyroMappingId() override;
1313

1414
std::string GetPhysicalDeviceName() override;
15-
bool PhysicalDeviceIsConnected() override;
1615

1716
private:
1817
float mNeutralPitch;

0 commit comments

Comments
 (0)