summaryrefslogtreecommitdiff
path: root/src/core/hid/emulated_controller.cpp
diff options
context:
space:
mode:
authorGravatar german772021-10-27 00:20:28 -0500
committerGravatar Narr the Reg2021-11-24 20:30:26 -0600
commitc085e54316c5520ed7d58a92a7faa9e896bb6c71 (patch)
tree05a5798ddc25ce2afa423cd70bec979705b63143 /src/core/hid/emulated_controller.cpp
parentinput_common: Fix UDP uuid (diff)
downloadyuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.tar.gz
yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.tar.xz
yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.zip
core/hid: Add TAS input
Diffstat (limited to 'src/core/hid/emulated_controller.cpp')
-rw-r--r--src/core/hid/emulated_controller.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 916368c68..2b051ccaf 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -105,6 +105,8 @@ void EmulatedController::LoadDevices() {
105 output_params[LeftIndex].Set("output", true); 105 output_params[LeftIndex].Set("output", true);
106 output_params[RightIndex].Set("output", true); 106 output_params[RightIndex].Set("output", true);
107 107
108 LoadTASParams();
109
108 std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, 110 std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
109 button_params.begin() + Settings::NativeButton::BUTTON_NS_END, 111 button_params.begin() + Settings::NativeButton::BUTTON_NS_END,
110 button_devices.begin(), Input::CreateDevice<Input::InputDevice>); 112 button_devices.begin(), Input::CreateDevice<Input::InputDevice>);
@@ -120,6 +122,51 @@ void EmulatedController::LoadDevices() {
120 Input::CreateDevice<Input::InputDevice>); 122 Input::CreateDevice<Input::InputDevice>);
121 std::transform(output_params.begin(), output_params.end(), output_devices.begin(), 123 std::transform(output_params.begin(), output_params.end(), output_devices.begin(),
122 Input::CreateDevice<Input::OutputDevice>); 124 Input::CreateDevice<Input::OutputDevice>);
125
126 // Initialize TAS devices
127 std::transform(tas_button_params.begin(), tas_button_params.end(), tas_button_devices.begin(),
128 Input::CreateDevice<Input::InputDevice>);
129 std::transform(tas_stick_params.begin(), tas_stick_params.begin(), tas_stick_devices.begin(),
130 Input::CreateDevice<Input::InputDevice>);
131}
132
133void EmulatedController::LoadTASParams() {
134 const auto player_index = NpadIdTypeToIndex(npad_id_type);
135 Common::ParamPackage common_params{};
136 common_params.Set("engine", "tas");
137 common_params.Set("pad", static_cast<int>(player_index));
138 for (auto& param : tas_button_params) {
139 param = common_params;
140 }
141 for (auto& param : tas_stick_params) {
142 param = common_params;
143 }
144
145 tas_button_params[Settings::NativeButton::A].Set("button", 1 << 0);
146 tas_button_params[Settings::NativeButton::B].Set("button", 1 << 1);
147 tas_button_params[Settings::NativeButton::X].Set("button", 1 << 2);
148 tas_button_params[Settings::NativeButton::Y].Set("button", 1 << 3);
149 tas_button_params[Settings::NativeButton::LStick].Set("button", 1 << 4);
150 tas_button_params[Settings::NativeButton::RStick].Set("button", 1 << 5);
151 tas_button_params[Settings::NativeButton::L].Set("button", 1 << 6);
152 tas_button_params[Settings::NativeButton::R].Set("button", 1 << 7);
153 tas_button_params[Settings::NativeButton::ZL].Set("button", 1 << 8);
154 tas_button_params[Settings::NativeButton::ZR].Set("button", 1 << 9);
155 tas_button_params[Settings::NativeButton::Plus].Set("button", 1 << 10);
156 tas_button_params[Settings::NativeButton::Minus].Set("button", 1 << 11);
157 tas_button_params[Settings::NativeButton::DLeft].Set("button", 1 << 12);
158 tas_button_params[Settings::NativeButton::DUp].Set("button", 1 << 13);
159 tas_button_params[Settings::NativeButton::DRight].Set("button", 1 << 14);
160 tas_button_params[Settings::NativeButton::DDown].Set("button", 1 << 15);
161 tas_button_params[Settings::NativeButton::SL].Set("button", 1 << 16);
162 tas_button_params[Settings::NativeButton::SR].Set("button", 1 << 17);
163 tas_button_params[Settings::NativeButton::Home].Set("button", 1 << 18);
164 tas_button_params[Settings::NativeButton::Screenshot].Set("button", 1 << 19);
165
166 tas_stick_params[Settings::NativeAnalog::LStick].Set("axis_x", 0);
167 tas_stick_params[Settings::NativeAnalog::LStick].Set("axis_y", 1);
168 tas_stick_params[Settings::NativeAnalog::RStick].Set("axis_x", 2);
169 tas_stick_params[Settings::NativeAnalog::RStick].Set("axis_y", 3);
123} 170}
124 171
125void EmulatedController::ReloadInput() { 172void EmulatedController::ReloadInput() {
@@ -174,6 +221,25 @@ void EmulatedController::ReloadInput() {
174 motion_devices[index]->SetCallback(motion_callback); 221 motion_devices[index]->SetCallback(motion_callback);
175 motion_devices[index]->ForceUpdate(); 222 motion_devices[index]->ForceUpdate();
176 } 223 }
224
225 // Register TAS devices. No need to force update
226 for (std::size_t index = 0; index < tas_button_devices.size(); ++index) {
227 if (!tas_button_devices[index]) {
228 continue;
229 }
230 Input::InputCallback button_callback{
231 [this, index](Input::CallbackStatus callback) { SetButton(callback, index); }};
232 tas_button_devices[index]->SetCallback(button_callback);
233 }
234
235 for (std::size_t index = 0; index < tas_stick_devices.size(); ++index) {
236 if (!tas_stick_devices[index]) {
237 continue;
238 }
239 Input::InputCallback stick_callback{
240 [this, index](Input::CallbackStatus callback) { SetStick(callback, index); }};
241 tas_stick_devices[index]->SetCallback(stick_callback);
242 }
177} 243}
178 244
179void EmulatedController::UnloadInput() { 245void EmulatedController::UnloadInput() {
@@ -195,6 +261,12 @@ void EmulatedController::UnloadInput() {
195 for (auto& output : output_devices) { 261 for (auto& output : output_devices) {
196 output.reset(); 262 output.reset();
197 } 263 }
264 for (auto& button : tas_button_devices) {
265 button.reset();
266 }
267 for (auto& stick : tas_stick_devices) {
268 stick.reset();
269 }
198} 270}
199 271
200void EmulatedController::EnableConfiguration() { 272void EmulatedController::EnableConfiguration() {