diff options
| author | 2021-07-25 20:52:19 -0500 | |
|---|---|---|
| committer | 2021-09-18 23:23:03 +0200 | |
| commit | 75d8ec1e9f474ce6c2bfc0b8ebe574ca44f9f3d8 (patch) | |
| tree | a11be198f5f4933a68c8cc5cfc183e08c3b01fcb /src/input_common | |
| parent | input_common/tas: new update method (diff) | |
| download | yuzu-75d8ec1e9f474ce6c2bfc0b8ebe574ca44f9f3d8.tar.gz yuzu-75d8ec1e9f474ce6c2bfc0b8ebe574ca44f9f3d8.tar.xz yuzu-75d8ec1e9f474ce6c2bfc0b8ebe574ca44f9f3d8.zip | |
UI: Relocate tas menu and add brief description
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/main.cpp | 2 | ||||
| -rw-r--r-- | src/input_common/tas/tas_input.cpp | 88 | ||||
| -rw-r--r-- | src/input_common/tas/tas_input.h | 48 |
3 files changed, 83 insertions, 55 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 3b9906b53..18d7d8817 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -117,7 +117,7 @@ struct InputSubsystem::Impl { | |||
| 117 | Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}}, | 117 | Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}}, |
| 118 | }; | 118 | }; |
| 119 | if (Settings::values.tas_enable) { | 119 | if (Settings::values.tas_enable) { |
| 120 | devices.push_back( | 120 | devices.emplace_back( |
| 121 | Common::ParamPackage{{"display", "TAS Controller"}, {"class", "tas"}}); | 121 | Common::ParamPackage{{"display", "TAS Controller"}, {"class", "tas"}}); |
| 122 | } | 122 | } |
| 123 | #ifdef HAVE_SDL2 | 123 | #ifdef HAVE_SDL2 |
diff --git a/src/input_common/tas/tas_input.cpp b/src/input_common/tas/tas_input.cpp index 877d35088..1598092b6 100644 --- a/src/input_common/tas/tas_input.cpp +++ b/src/input_common/tas/tas_input.cpp | |||
| @@ -40,12 +40,15 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but | |||
| 40 | 40 | ||
| 41 | Tas::Tas() { | 41 | Tas::Tas() { |
| 42 | if (!Settings::values.tas_enable) { | 42 | if (!Settings::values.tas_enable) { |
| 43 | needs_reset = true; | ||
| 43 | return; | 44 | return; |
| 44 | } | 45 | } |
| 45 | LoadTasFiles(); | 46 | LoadTasFiles(); |
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | Tas::~Tas() = default; | 49 | Tas::~Tas() { |
| 50 | Stop(); | ||
| 51 | }; | ||
| 49 | 52 | ||
| 50 | void Tas::LoadTasFiles() { | 53 | void Tas::LoadTasFiles() { |
| 51 | script_length = 0; | 54 | script_length = 0; |
| @@ -184,6 +187,9 @@ std::string Tas::ButtonsToString(u32 button) const { | |||
| 184 | 187 | ||
| 185 | void Tas::UpdateThread() { | 188 | void Tas::UpdateThread() { |
| 186 | if (!Settings::values.tas_enable) { | 189 | if (!Settings::values.tas_enable) { |
| 190 | if (is_running) { | ||
| 191 | Stop(); | ||
| 192 | } | ||
| 187 | return; | 193 | return; |
| 188 | } | 194 | } |
| 189 | 195 | ||
| @@ -196,34 +202,35 @@ void Tas::UpdateThread() { | |||
| 196 | LoadTasFiles(); | 202 | LoadTasFiles(); |
| 197 | LOG_DEBUG(Input, "tas_reset done"); | 203 | LOG_DEBUG(Input, "tas_reset done"); |
| 198 | } | 204 | } |
| 199 | if (is_running) { | 205 | |
| 200 | if (current_command < script_length) { | 206 | if (!is_running) { |
| 201 | LOG_DEBUG(Input, "Playing TAS {}/{}", current_command, script_length); | 207 | tas_data.fill({}); |
| 202 | size_t frame = current_command++; | 208 | return; |
| 203 | for (size_t i = 0; i < commands.size(); i++) { | 209 | } |
| 204 | if (frame < commands[i].size()) { | 210 | if (current_command < script_length) { |
| 205 | TASCommand command = commands[i][frame]; | 211 | LOG_DEBUG(Input, "Playing TAS {}/{}", current_command, script_length); |
| 206 | tas_data[i].buttons = command.buttons; | 212 | size_t frame = current_command++; |
| 207 | auto [l_axis_x, l_axis_y] = command.l_axis; | 213 | for (size_t i = 0; i < commands.size(); i++) { |
| 208 | tas_data[i].axis[0] = l_axis_x; | 214 | if (frame < commands[i].size()) { |
| 209 | tas_data[i].axis[1] = l_axis_y; | 215 | TASCommand command = commands[i][frame]; |
| 210 | auto [r_axis_x, r_axis_y] = command.r_axis; | 216 | tas_data[i].buttons = command.buttons; |
| 211 | tas_data[i].axis[2] = r_axis_x; | 217 | auto [l_axis_x, l_axis_y] = command.l_axis; |
| 212 | tas_data[i].axis[3] = r_axis_y; | 218 | tas_data[i].axis[0] = l_axis_x; |
| 213 | } else { | 219 | tas_data[i].axis[1] = l_axis_y; |
| 214 | tas_data[i] = {}; | 220 | auto [r_axis_x, r_axis_y] = command.r_axis; |
| 215 | } | 221 | tas_data[i].axis[2] = r_axis_x; |
| 216 | } | 222 | tas_data[i].axis[3] = r_axis_y; |
| 217 | } else { | 223 | } else { |
| 218 | is_running = Settings::values.tas_loop.GetValue(); | 224 | tas_data[i] = {}; |
| 219 | current_command = 0; | ||
| 220 | tas_data.fill({}); | ||
| 221 | if (!is_running) { | ||
| 222 | SwapToStoredController(); | ||
| 223 | } | 225 | } |
| 224 | } | 226 | } |
| 225 | } else { | 227 | } else { |
| 228 | is_running = Settings::values.tas_loop.GetValue(); | ||
| 229 | current_command = 0; | ||
| 226 | tas_data.fill({}); | 230 | tas_data.fill({}); |
| 231 | if (!is_running) { | ||
| 232 | SwapToStoredController(); | ||
| 233 | } | ||
| 227 | } | 234 | } |
| 228 | LOG_DEBUG(Input, "TAS inputs: {}", DebugInputs(tas_data)); | 235 | LOG_DEBUG(Input, "TAS inputs: {}", DebugInputs(tas_data)); |
| 229 | } | 236 | } |
| @@ -237,8 +244,8 @@ TasAnalog Tas::ReadCommandAxis(const std::string& line) const { | |||
| 237 | seglist.push_back(segment); | 244 | seglist.push_back(segment); |
| 238 | } | 245 | } |
| 239 | 246 | ||
| 240 | const float x = std::stof(seglist.at(0)) / 32767.f; | 247 | const float x = std::stof(seglist.at(0)) / 32767.0f; |
| 241 | const float y = std::stof(seglist.at(1)) / 32767.f; | 248 | const float y = std::stof(seglist.at(1)) / 32767.0f; |
| 242 | 249 | ||
| 243 | return {x, y}; | 250 | return {x, y}; |
| 244 | } | 251 | } |
| @@ -293,14 +300,22 @@ std::string Tas::WriteCommandButtons(u32 data) const { | |||
| 293 | } | 300 | } |
| 294 | 301 | ||
| 295 | void Tas::StartStop() { | 302 | void Tas::StartStop() { |
| 296 | is_running = !is_running; | 303 | if (!Settings::values.tas_enable) { |
| 304 | return; | ||
| 305 | } | ||
| 297 | if (is_running) { | 306 | if (is_running) { |
| 298 | SwapToTasController(); | 307 | Stop(); |
| 299 | } else { | 308 | } else { |
| 300 | SwapToStoredController(); | 309 | is_running = true; |
| 310 | SwapToTasController(); | ||
| 301 | } | 311 | } |
| 302 | } | 312 | } |
| 303 | 313 | ||
| 314 | void Tas::Stop() { | ||
| 315 | is_running = false; | ||
| 316 | SwapToStoredController(); | ||
| 317 | } | ||
| 318 | |||
| 304 | void Tas::SwapToTasController() { | 319 | void Tas::SwapToTasController() { |
| 305 | if (!Settings::values.tas_swap_controllers) { | 320 | if (!Settings::values.tas_swap_controllers) { |
| 306 | return; | 321 | return; |
| @@ -315,7 +330,8 @@ void Tas::SwapToTasController() { | |||
| 315 | continue; | 330 | continue; |
| 316 | } | 331 | } |
| 317 | 332 | ||
| 318 | auto tas_param = Common::ParamPackage{{"pad", static_cast<u8>(index)}}; | 333 | Common::ParamPackage tas_param; |
| 334 | tas_param.Set("pad", static_cast<u8>(index)); | ||
| 319 | auto button_mapping = GetButtonMappingForDevice(tas_param); | 335 | auto button_mapping = GetButtonMappingForDevice(tas_param); |
| 320 | auto analog_mapping = GetAnalogMappingForDevice(tas_param); | 336 | auto analog_mapping = GetAnalogMappingForDevice(tas_param); |
| 321 | auto& buttons = player.buttons; | 337 | auto& buttons = player.buttons; |
| @@ -328,25 +344,33 @@ void Tas::SwapToTasController() { | |||
| 328 | analogs[i] = analog_mapping[static_cast<Settings::NativeAnalog::Values>(i)].Serialize(); | 344 | analogs[i] = analog_mapping[static_cast<Settings::NativeAnalog::Values>(i)].Serialize(); |
| 329 | } | 345 | } |
| 330 | } | 346 | } |
| 347 | is_old_input_saved = true; | ||
| 331 | Settings::values.is_device_reload_pending.store(true); | 348 | Settings::values.is_device_reload_pending.store(true); |
| 332 | } | 349 | } |
| 333 | 350 | ||
| 334 | void Tas::SwapToStoredController() { | 351 | void Tas::SwapToStoredController() { |
| 335 | if (!Settings::values.tas_swap_controllers) { | 352 | if (!is_old_input_saved) { |
| 336 | return; | 353 | return; |
| 337 | } | 354 | } |
| 338 | auto& players = Settings::values.players.GetValue(); | 355 | auto& players = Settings::values.players.GetValue(); |
| 339 | for (std::size_t index = 0; index < players.size(); index++) { | 356 | for (std::size_t index = 0; index < players.size(); index++) { |
| 340 | players[index] = player_mappings[index]; | 357 | players[index] = player_mappings[index]; |
| 341 | } | 358 | } |
| 359 | is_old_input_saved = false; | ||
| 342 | Settings::values.is_device_reload_pending.store(true); | 360 | Settings::values.is_device_reload_pending.store(true); |
| 343 | } | 361 | } |
| 344 | 362 | ||
| 345 | void Tas::Reset() { | 363 | void Tas::Reset() { |
| 364 | if (!Settings::values.tas_enable) { | ||
| 365 | return; | ||
| 366 | } | ||
| 346 | needs_reset = true; | 367 | needs_reset = true; |
| 347 | } | 368 | } |
| 348 | 369 | ||
| 349 | bool Tas::Record() { | 370 | bool Tas::Record() { |
| 371 | if (!Settings::values.tas_enable) { | ||
| 372 | return true; | ||
| 373 | } | ||
| 350 | is_recording = !is_recording; | 374 | is_recording = !is_recording; |
| 351 | return is_recording; | 375 | return is_recording; |
| 352 | } | 376 | } |
diff --git a/src/input_common/tas/tas_input.h b/src/input_common/tas/tas_input.h index 52d000db4..3e2db8f00 100644 --- a/src/input_common/tas/tas_input.h +++ b/src/input_common/tas/tas_input.h | |||
| @@ -13,8 +13,8 @@ | |||
| 13 | 13 | ||
| 14 | /* | 14 | /* |
| 15 | To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below | 15 | To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below |
| 16 | Emulation -> Configure TAS. The file itself has normal text format and has to be called | 16 | Tools -> Configure TAS. The file itself has normal text format and has to be called script0-1.txt |
| 17 | script0-1.txt for controller 1, script0-2.txt for controller 2 and so forth (with max. 8 players). | 17 | for controller 1, script0-2.txt for controller 2 and so forth (with max. 8 players). |
| 18 | 18 | ||
| 19 | A script file has the same format as TAS-nx uses, so final files will look like this: | 19 | A script file has the same format as TAS-nx uses, so final files will look like this: |
| 20 | 20 | ||
| @@ -56,26 +56,26 @@ enum class TasState { | |||
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | enum class TasButton : u32 { | 58 | enum class TasButton : u32 { |
| 59 | BUTTON_A = 0x000001, | 59 | BUTTON_A = 1U << 0, |
| 60 | BUTTON_B = 0x000002, | 60 | BUTTON_B = 1U << 1, |
| 61 | BUTTON_X = 0x000004, | 61 | BUTTON_X = 1U << 2, |
| 62 | BUTTON_Y = 0x000008, | 62 | BUTTON_Y = 1U << 3, |
| 63 | STICK_L = 0x000010, | 63 | STICK_L = 1U << 4, |
| 64 | STICK_R = 0x000020, | 64 | STICK_R = 1U << 5, |
| 65 | TRIGGER_L = 0x000040, | 65 | TRIGGER_L = 1U << 6, |
| 66 | TRIGGER_R = 0x000080, | 66 | TRIGGER_R = 1U << 7, |
| 67 | TRIGGER_ZL = 0x000100, | 67 | TRIGGER_ZL = 1U << 8, |
| 68 | TRIGGER_ZR = 0x000200, | 68 | TRIGGER_ZR = 1U << 9, |
| 69 | BUTTON_PLUS = 0x000400, | 69 | BUTTON_PLUS = 1U << 10, |
| 70 | BUTTON_MINUS = 0x000800, | 70 | BUTTON_MINUS = 1U << 11, |
| 71 | BUTTON_LEFT = 0x001000, | 71 | BUTTON_LEFT = 1U << 12, |
| 72 | BUTTON_UP = 0x002000, | 72 | BUTTON_UP = 1U << 13, |
| 73 | BUTTON_RIGHT = 0x004000, | 73 | BUTTON_RIGHT = 1U << 14, |
| 74 | BUTTON_DOWN = 0x008000, | 74 | BUTTON_DOWN = 1U << 15, |
| 75 | BUTTON_SL = 0x010000, | 75 | BUTTON_SL = 1U << 16, |
| 76 | BUTTON_SR = 0x020000, | 76 | BUTTON_SR = 1U << 17, |
| 77 | BUTTON_HOME = 0x040000, | 77 | BUTTON_HOME = 1U << 18, |
| 78 | BUTTON_CAPTURE = 0x080000, | 78 | BUTTON_CAPTURE = 1U << 19, |
| 79 | }; | 79 | }; |
| 80 | 80 | ||
| 81 | enum class TasAxes : u8 { | 81 | enum class TasAxes : u8 { |
| @@ -105,6 +105,9 @@ public: | |||
| 105 | // Sets the flag to start or stop the TAS command excecution and swaps controllers profiles | 105 | // Sets the flag to start or stop the TAS command excecution and swaps controllers profiles |
| 106 | void StartStop(); | 106 | void StartStop(); |
| 107 | 107 | ||
| 108 | // Stop the TAS and reverts any controller profile | ||
| 109 | void Stop(); | ||
| 110 | |||
| 108 | // Sets the flag to reload the file and start from the begining in the next update | 111 | // Sets the flag to reload the file and start from the begining in the next update |
| 109 | void Reset(); | 112 | void Reset(); |
| 110 | 113 | ||
| @@ -219,6 +222,7 @@ private: | |||
| 219 | 222 | ||
| 220 | size_t script_length{0}; | 223 | size_t script_length{0}; |
| 221 | std::array<TasData, PLAYER_NUMBER> tas_data; | 224 | std::array<TasData, PLAYER_NUMBER> tas_data; |
| 225 | bool is_old_input_saved{false}; | ||
| 222 | bool is_recording{false}; | 226 | bool is_recording{false}; |
| 223 | bool is_running{false}; | 227 | bool is_running{false}; |
| 224 | bool needs_reset{false}; | 228 | bool needs_reset{false}; |