summaryrefslogtreecommitdiff
path: root/src/input_common/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/main.cpp')
-rw-r--r--src/input_common/main.cpp57
1 files changed, 53 insertions, 4 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index ea1a1cee6..8da829132 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -12,6 +12,7 @@
12#include "input_common/main.h" 12#include "input_common/main.h"
13#include "input_common/motion_emu.h" 13#include "input_common/motion_emu.h"
14#include "input_common/touch_from_button.h" 14#include "input_common/touch_from_button.h"
15#include "input_common/udp/client.h"
15#include "input_common/udp/udp.h" 16#include "input_common/udp/udp.h"
16#ifdef HAVE_SDL2 17#ifdef HAVE_SDL2
17#include "input_common/sdl/sdl.h" 18#include "input_common/sdl/sdl.h"
@@ -21,7 +22,7 @@ namespace InputCommon {
21 22
22struct InputSubsystem::Impl { 23struct InputSubsystem::Impl {
23 void Initialize() { 24 void Initialize() {
24 auto gcadapter = std::make_shared<GCAdapter::Adapter>(); 25 gcadapter = std::make_shared<GCAdapter::Adapter>();
25 gcbuttons = std::make_shared<GCButtonFactory>(gcadapter); 26 gcbuttons = std::make_shared<GCButtonFactory>(gcadapter);
26 Input::RegisterFactory<Input::ButtonDevice>("gcpad", gcbuttons); 27 Input::RegisterFactory<Input::ButtonDevice>("gcpad", gcbuttons);
27 gcanalog = std::make_shared<GCAnalogFactory>(gcadapter); 28 gcanalog = std::make_shared<GCAnalogFactory>(gcadapter);
@@ -40,7 +41,11 @@ struct InputSubsystem::Impl {
40 sdl = SDL::Init(); 41 sdl = SDL::Init();
41#endif 42#endif
42 43
43 udp = CemuhookUDP::Init(); 44 udp = std::make_shared<InputCommon::CemuhookUDP::Client>();
45 udpmotion = std::make_shared<UDPMotionFactory>(udp);
46 Input::RegisterFactory<Input::MotionDevice>("cemuhookudp", udpmotion);
47 udptouch = std::make_shared<UDPTouchFactory>(udp);
48 Input::RegisterFactory<Input::TouchDevice>("cemuhookudp", udptouch);
44 } 49 }
45 50
46 void Shutdown() { 51 void Shutdown() {
@@ -53,12 +58,17 @@ struct InputSubsystem::Impl {
53#ifdef HAVE_SDL2 58#ifdef HAVE_SDL2
54 sdl.reset(); 59 sdl.reset();
55#endif 60#endif
56 udp.reset();
57 Input::UnregisterFactory<Input::ButtonDevice>("gcpad"); 61 Input::UnregisterFactory<Input::ButtonDevice>("gcpad");
58 Input::UnregisterFactory<Input::AnalogDevice>("gcpad"); 62 Input::UnregisterFactory<Input::AnalogDevice>("gcpad");
59 63
60 gcbuttons.reset(); 64 gcbuttons.reset();
61 gcanalog.reset(); 65 gcanalog.reset();
66
67 Input::UnregisterFactory<Input::MotionDevice>("cemuhookudp");
68 Input::UnregisterFactory<Input::TouchDevice>("cemuhookudp");
69
70 udpmotion.reset();
71 udptouch.reset();
62 } 72 }
63 73
64 [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { 74 [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const {
@@ -72,6 +82,8 @@ struct InputSubsystem::Impl {
72#endif 82#endif
73 auto udp_devices = udp->GetInputDevices(); 83 auto udp_devices = udp->GetInputDevices();
74 devices.insert(devices.end(), udp_devices.begin(), udp_devices.end()); 84 devices.insert(devices.end(), udp_devices.begin(), udp_devices.end());
85 auto gcpad_devices = gcadapter->GetInputDevices();
86 devices.insert(devices.end(), gcpad_devices.begin(), gcpad_devices.end());
75 return devices; 87 return devices;
76 } 88 }
77 89
@@ -84,6 +96,9 @@ struct InputSubsystem::Impl {
84 // TODO consider returning the SDL key codes for the default keybindings 96 // TODO consider returning the SDL key codes for the default keybindings
85 return {}; 97 return {};
86 } 98 }
99 if (params.Get("class", "") == "gcpad") {
100 return gcadapter->GetAnalogMappingForDevice(params);
101 }
87#ifdef HAVE_SDL2 102#ifdef HAVE_SDL2
88 if (params.Get("class", "") == "sdl") { 103 if (params.Get("class", "") == "sdl") {
89 return sdl->GetAnalogMappingForDevice(params); 104 return sdl->GetAnalogMappingForDevice(params);
@@ -101,6 +116,9 @@ struct InputSubsystem::Impl {
101 // TODO consider returning the SDL key codes for the default keybindings 116 // TODO consider returning the SDL key codes for the default keybindings
102 return {}; 117 return {};
103 } 118 }
119 if (params.Get("class", "") == "gcpad") {
120 return gcadapter->GetButtonMappingForDevice(params);
121 }
104#ifdef HAVE_SDL2 122#ifdef HAVE_SDL2
105 if (params.Get("class", "") == "sdl") { 123 if (params.Get("class", "") == "sdl") {
106 return sdl->GetButtonMappingForDevice(params); 124 return sdl->GetButtonMappingForDevice(params);
@@ -109,14 +127,29 @@ struct InputSubsystem::Impl {
109 return {}; 127 return {};
110 } 128 }
111 129
130 [[nodiscard]] MotionMapping GetMotionMappingForDevice(
131 const Common::ParamPackage& params) const {
132 if (!params.Has("class") || params.Get("class", "") == "any") {
133 return {};
134 }
135 if (params.Get("class", "") == "cemuhookudp") {
136 // TODO return the correct motion device
137 return {};
138 }
139 return {};
140 }
141
112 std::shared_ptr<Keyboard> keyboard; 142 std::shared_ptr<Keyboard> keyboard;
113 std::shared_ptr<MotionEmu> motion_emu; 143 std::shared_ptr<MotionEmu> motion_emu;
114#ifdef HAVE_SDL2 144#ifdef HAVE_SDL2
115 std::unique_ptr<SDL::State> sdl; 145 std::unique_ptr<SDL::State> sdl;
116#endif 146#endif
117 std::unique_ptr<CemuhookUDP::State> udp;
118 std::shared_ptr<GCButtonFactory> gcbuttons; 147 std::shared_ptr<GCButtonFactory> gcbuttons;
119 std::shared_ptr<GCAnalogFactory> gcanalog; 148 std::shared_ptr<GCAnalogFactory> gcanalog;
149 std::shared_ptr<UDPMotionFactory> udpmotion;
150 std::shared_ptr<UDPTouchFactory> udptouch;
151 std::shared_ptr<CemuhookUDP::Client> udp;
152 std::shared_ptr<GCAdapter::Adapter> gcadapter;
120}; 153};
121 154
122InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} 155InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {}
@@ -175,6 +208,22 @@ const GCButtonFactory* InputSubsystem::GetGCButtons() const {
175 return impl->gcbuttons.get(); 208 return impl->gcbuttons.get();
176} 209}
177 210
211UDPMotionFactory* InputSubsystem::GetUDPMotions() {
212 return impl->udpmotion.get();
213}
214
215const UDPMotionFactory* InputSubsystem::GetUDPMotions() const {
216 return impl->udpmotion.get();
217}
218
219UDPTouchFactory* InputSubsystem::GetUDPTouch() {
220 return impl->udptouch.get();
221}
222
223const UDPTouchFactory* InputSubsystem::GetUDPTouch() const {
224 return impl->udptouch.get();
225}
226
178void InputSubsystem::ReloadInputDevices() { 227void InputSubsystem::ReloadInputDevices() {
179 if (!impl->udp) { 228 if (!impl->udp) {
180 return; 229 return;