summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/input.h4
-rw-r--r--src/core/hid/emulated_controller.cpp68
-rw-r--r--src/core/hid/emulated_controller.h6
-rw-r--r--src/input_common/drivers/tas_input.cpp24
-rw-r--r--src/input_common/drivers/tas_input.h11
5 files changed, 77 insertions, 36 deletions
diff --git a/src/common/input.h b/src/common/input.h
index 8f29026a1..f21872b0a 100644
--- a/src/common/input.h
+++ b/src/common/input.h
@@ -11,6 +11,7 @@
11#include <utility> 11#include <utility>
12#include "common/logging/log.h" 12#include "common/logging/log.h"
13#include "common/param_package.h" 13#include "common/param_package.h"
14#include "common/uuid.h"
14 15
15namespace Common::Input { 16namespace Common::Input {
16 17
@@ -81,6 +82,7 @@ struct AnalogStatus {
81}; 82};
82 83
83struct ButtonStatus { 84struct ButtonStatus {
85 Common::UUID uuid{};
84 bool value{}; 86 bool value{};
85 bool inverted{}; 87 bool inverted{};
86 bool toggle{}; 88 bool toggle{};
@@ -90,6 +92,7 @@ struct ButtonStatus {
90using BatteryStatus = BatteryLevel; 92using BatteryStatus = BatteryLevel;
91 93
92struct StickStatus { 94struct StickStatus {
95 Common::UUID uuid{};
93 AnalogStatus x{}; 96 AnalogStatus x{};
94 AnalogStatus y{}; 97 AnalogStatus y{};
95 bool left{}; 98 bool left{};
@@ -99,6 +102,7 @@ struct StickStatus {
99}; 102};
100 103
101struct TriggerStatus { 104struct TriggerStatus {
105 Common::UUID uuid{};
102 AnalogStatus analog{}; 106 AnalogStatus analog{};
103 ButtonStatus pressed{}; 107 ButtonStatus pressed{};
104}; 108};
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 2db2b4da0..6fe3744fd 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -183,8 +183,11 @@ void EmulatedController::ReloadInput() {
183 if (!button_devices[index]) { 183 if (!button_devices[index]) {
184 continue; 184 continue;
185 } 185 }
186 const auto uuid = Common::UUID{button_params[index].Get("guid", "")};
186 Common::Input::InputCallback button_callback{ 187 Common::Input::InputCallback button_callback{
187 [this, index](Common::Input::CallbackStatus callback) { SetButton(callback, index); }}; 188 [this, index, uuid](Common::Input::CallbackStatus callback) {
189 SetButton(callback, index, uuid);
190 }};
188 button_devices[index]->SetCallback(button_callback); 191 button_devices[index]->SetCallback(button_callback);
189 button_devices[index]->ForceUpdate(); 192 button_devices[index]->ForceUpdate();
190 } 193 }
@@ -193,8 +196,11 @@ void EmulatedController::ReloadInput() {
193 if (!stick_devices[index]) { 196 if (!stick_devices[index]) {
194 continue; 197 continue;
195 } 198 }
199 const auto uuid = Common::UUID{stick_params[index].Get("guid", "")};
196 Common::Input::InputCallback stick_callback{ 200 Common::Input::InputCallback stick_callback{
197 [this, index](Common::Input::CallbackStatus callback) { SetStick(callback, index); }}; 201 [this, index, uuid](Common::Input::CallbackStatus callback) {
202 SetStick(callback, index, uuid);
203 }};
198 stick_devices[index]->SetCallback(stick_callback); 204 stick_devices[index]->SetCallback(stick_callback);
199 stick_devices[index]->ForceUpdate(); 205 stick_devices[index]->ForceUpdate();
200 } 206 }
@@ -203,8 +209,11 @@ void EmulatedController::ReloadInput() {
203 if (!trigger_devices[index]) { 209 if (!trigger_devices[index]) {
204 continue; 210 continue;
205 } 211 }
212 const auto uuid = Common::UUID{trigger_params[index].Get("guid", "")};
206 Common::Input::InputCallback trigger_callback{ 213 Common::Input::InputCallback trigger_callback{
207 [this, index](Common::Input::CallbackStatus callback) { SetTrigger(callback, index); }}; 214 [this, index, uuid](Common::Input::CallbackStatus callback) {
215 SetTrigger(callback, index, uuid);
216 }};
208 trigger_devices[index]->SetCallback(trigger_callback); 217 trigger_devices[index]->SetCallback(trigger_callback);
209 trigger_devices[index]->ForceUpdate(); 218 trigger_devices[index]->ForceUpdate();
210 } 219 }
@@ -229,13 +238,18 @@ void EmulatedController::ReloadInput() {
229 motion_devices[index]->ForceUpdate(); 238 motion_devices[index]->ForceUpdate();
230 } 239 }
231 240
241 // Use a common UUID for TAS
242 const auto tas_uuid = Common::UUID{0x0, 0x7A5};
243
232 // Register TAS devices. No need to force update 244 // Register TAS devices. No need to force update
233 for (std::size_t index = 0; index < tas_button_devices.size(); ++index) { 245 for (std::size_t index = 0; index < tas_button_devices.size(); ++index) {
234 if (!tas_button_devices[index]) { 246 if (!tas_button_devices[index]) {
235 continue; 247 continue;
236 } 248 }
237 Common::Input::InputCallback button_callback{ 249 Common::Input::InputCallback button_callback{
238 [this, index](Common::Input::CallbackStatus callback) { SetButton(callback, index); }}; 250 [this, index, tas_uuid](Common::Input::CallbackStatus callback) {
251 SetButton(callback, index, tas_uuid);
252 }};
239 tas_button_devices[index]->SetCallback(button_callback); 253 tas_button_devices[index]->SetCallback(button_callback);
240 } 254 }
241 255
@@ -244,7 +258,9 @@ void EmulatedController::ReloadInput() {
244 continue; 258 continue;
245 } 259 }
246 Common::Input::InputCallback stick_callback{ 260 Common::Input::InputCallback stick_callback{
247 [this, index](Common::Input::CallbackStatus callback) { SetStick(callback, index); }}; 261 [this, index, tas_uuid](Common::Input::CallbackStatus callback) {
262 SetStick(callback, index, tas_uuid);
263 }};
248 tas_stick_devices[index]->SetCallback(stick_callback); 264 tas_stick_devices[index]->SetCallback(stick_callback);
249 } 265 }
250} 266}
@@ -423,7 +439,8 @@ void EmulatedController::SetMotionParam(std::size_t index, Common::ParamPackage
423 ReloadInput(); 439 ReloadInput();
424} 440}
425 441
426void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::size_t index) { 442void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::size_t index,
443 Common::UUID uuid) {
427 if (index >= controller.button_values.size()) { 444 if (index >= controller.button_values.size()) {
428 return; 445 return;
429 } 446 }
@@ -432,7 +449,16 @@ void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::
432 bool value_changed = false; 449 bool value_changed = false;
433 const auto new_status = TransformToButton(callback); 450 const auto new_status = TransformToButton(callback);
434 auto& current_status = controller.button_values[index]; 451 auto& current_status = controller.button_values[index];
452
453 // Only read button values that have the same uuid or are pressed once
454 if (current_status.uuid != uuid) {
455 if (!new_status.value) {
456 return;
457 }
458 }
459
435 current_status.toggle = new_status.toggle; 460 current_status.toggle = new_status.toggle;
461 current_status.uuid = uuid;
436 462
437 // Update button status with current 463 // Update button status with current
438 if (!current_status.toggle) { 464 if (!current_status.toggle) {
@@ -553,12 +579,23 @@ void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::
553 TriggerOnChange(ControllerTriggerType::Button, true); 579 TriggerOnChange(ControllerTriggerType::Button, true);
554} 580}
555 581
556void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::size_t index) { 582void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::size_t index,
583 Common::UUID uuid) {
557 if (index >= controller.stick_values.size()) { 584 if (index >= controller.stick_values.size()) {
558 return; 585 return;
559 } 586 }
560 std::lock_guard lock{mutex}; 587 std::lock_guard lock{mutex};
561 controller.stick_values[index] = TransformToStick(callback); 588 const auto stick_value = TransformToStick(callback);
589
590 // Only read stick values that have the same uuid or are over the threshold to avoid flapping
591 if (controller.stick_values[index].uuid != uuid) {
592 if (!stick_value.down && !stick_value.up && !stick_value.left && !stick_value.right) {
593 return;
594 }
595 }
596
597 controller.stick_values[index] = stick_value;
598 controller.stick_values[index].uuid = uuid;
562 599
563 if (is_configuring) { 600 if (is_configuring) {
564 controller.analog_stick_state.left = {}; 601 controller.analog_stick_state.left = {};
@@ -592,12 +629,23 @@ void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::s
592 TriggerOnChange(ControllerTriggerType::Stick, true); 629 TriggerOnChange(ControllerTriggerType::Stick, true);
593} 630}
594 631
595void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std::size_t index) { 632void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std::size_t index,
633 Common::UUID uuid) {
596 if (index >= controller.trigger_values.size()) { 634 if (index >= controller.trigger_values.size()) {
597 return; 635 return;
598 } 636 }
599 std::lock_guard lock{mutex}; 637 std::lock_guard lock{mutex};
600 controller.trigger_values[index] = TransformToTrigger(callback); 638 const auto trigger_value = TransformToTrigger(callback);
639
640 // Only read trigger values that have the same uuid or are pressed once
641 if (controller.stick_values[index].uuid != uuid) {
642 if (!trigger_value.pressed.value) {
643 return;
644 }
645 }
646
647 controller.trigger_values[index] = trigger_value;
648 controller.trigger_values[index].uuid = uuid;
601 649
602 if (is_configuring) { 650 if (is_configuring) {
603 controller.gc_trigger_state.left = 0; 651 controller.gc_trigger_state.left = 0;
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 2f7afff56..9a8bdf14d 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -313,21 +313,21 @@ private:
313 * @param callback: A CallbackStatus containing the button status 313 * @param callback: A CallbackStatus containing the button status
314 * @param index: Button ID of the to be updated 314 * @param index: Button ID of the to be updated
315 */ 315 */
316 void SetButton(Common::Input::CallbackStatus callback, std::size_t index); 316 void SetButton(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
317 317
318 /** 318 /**
319 * Updates the analog stick status of the controller 319 * Updates the analog stick status of the controller
320 * @param callback: A CallbackStatus containing the analog stick status 320 * @param callback: A CallbackStatus containing the analog stick status
321 * @param index: stick ID of the to be updated 321 * @param index: stick ID of the to be updated
322 */ 322 */
323 void SetStick(Common::Input::CallbackStatus callback, std::size_t index); 323 void SetStick(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
324 324
325 /** 325 /**
326 * Updates the trigger status of the controller 326 * Updates the trigger status of the controller
327 * @param callback: A CallbackStatus containing the trigger status 327 * @param callback: A CallbackStatus containing the trigger status
328 * @param index: trigger ID of the to be updated 328 * @param index: trigger ID of the to be updated
329 */ 329 */
330 void SetTrigger(Common::Input::CallbackStatus callback, std::size_t index); 330 void SetTrigger(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
331 331
332 /** 332 /**
333 * Updates the motion status of the controller 333 * Updates the motion status of the controller
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index d2748b240..bb9c236ea 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -71,21 +71,21 @@ Tas::~Tas() {
71void Tas::LoadTasFiles() { 71void Tas::LoadTasFiles() {
72 script_length = 0; 72 script_length = 0;
73 for (size_t i = 0; i < commands.size(); i++) { 73 for (size_t i = 0; i < commands.size(); i++) {
74 LoadTasFile(i); 74 LoadTasFile(i, 0);
75 if (commands[i].size() > script_length) { 75 if (commands[i].size() > script_length) {
76 script_length = commands[i].size(); 76 script_length = commands[i].size();
77 } 77 }
78 } 78 }
79} 79}
80 80
81void Tas::LoadTasFile(size_t player_index) { 81void Tas::LoadTasFile(size_t player_index, size_t file_index) {
82 if (!commands[player_index].empty()) { 82 if (!commands[player_index].empty()) {
83 commands[player_index].clear(); 83 commands[player_index].clear();
84 } 84 }
85 std::string file = 85 std::string file = Common::FS::ReadStringFromFile(
86 Common::FS::ReadStringFromFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / 86 Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) /
87 fmt::format("script0-{}.txt", player_index + 1), 87 fmt::format("script{}-{}.txt", file_index, player_index + 1),
88 Common::FS::FileType::BinaryFile); 88 Common::FS::FileType::BinaryFile);
89 std::stringstream command_line(file); 89 std::stringstream command_line(file);
90 std::string line; 90 std::string line;
91 int frame_no = 0; 91 int frame_no = 0;
@@ -144,15 +144,8 @@ void Tas::WriteTasFile(std::u8string file_name) {
144void Tas::RecordInput(u64 buttons, TasAnalog left_axis, TasAnalog right_axis) { 144void Tas::RecordInput(u64 buttons, TasAnalog left_axis, TasAnalog right_axis) {
145 last_input = { 145 last_input = {
146 .buttons = buttons, 146 .buttons = buttons,
147 .l_axis = FlipAxisY(left_axis), 147 .l_axis = left_axis,
148 .r_axis = FlipAxisY(right_axis), 148 .r_axis = right_axis,
149 };
150}
151
152TasAnalog Tas::FlipAxisY(TasAnalog old) {
153 return {
154 .x = old.x,
155 .y = -old.y,
156 }; 149 };
157} 150}
158 151
@@ -219,6 +212,7 @@ void Tas::UpdateThread() {
219 } 212 }
220 } else { 213 } else {
221 is_running = Settings::values.tas_loop.GetValue(); 214 is_running = Settings::values.tas_loop.GetValue();
215 LoadTasFiles();
222 current_command = 0; 216 current_command = 0;
223 ClearInput(); 217 ClearInput();
224 } 218 }
diff --git a/src/input_common/drivers/tas_input.h b/src/input_common/drivers/tas_input.h
index 82dc9d616..bfb37a638 100644
--- a/src/input_common/drivers/tas_input.h
+++ b/src/input_common/drivers/tas_input.h
@@ -138,21 +138,16 @@ private:
138 void LoadTasFiles(); 138 void LoadTasFiles();
139 139
140 /** Loads TAS file from the specified player 140 /** Loads TAS file from the specified player
141 * @param player_index: player number where data is going to be stored 141 * @param player_index: player number to save the script
142 * @param file_index: script number of the file
142 */ 143 */
143 void LoadTasFile(size_t player_index); 144 void LoadTasFile(size_t player_index, size_t file_index);
144 145
145 /** Writes a TAS file from the recorded commands 146 /** Writes a TAS file from the recorded commands
146 * @param file_name: name of the file to be written 147 * @param file_name: name of the file to be written
147 */ 148 */
148 void WriteTasFile(std::u8string file_name); 149 void WriteTasFile(std::u8string file_name);
149 150
150 /** Inverts the Y axis polarity
151 * @param old: value of the axis
152 * @return new value of the axis
153 */
154 TasAnalog FlipAxisY(TasAnalog old);
155
156 /** 151 /**
157 * Parses a string containing the axis values. X and Y have a range from -32767 to 32767 152 * Parses a string containing the axis values. X and Y have a range from -32767 to 32767
158 * @param line: string containing axis values with the following format "x;y" 153 * @param line: string containing axis values with the following format "x;y"