diff options
| author | 2021-06-27 14:02:38 -0500 | |
|---|---|---|
| committer | 2021-09-18 23:22:42 +0200 | |
| commit | e6c4bf52f0eb2c9c78e983ffbc667891463d3253 (patch) | |
| tree | d01a5189842a1c210b98588cb2b38ad89a11a322 /src/input_common/tas/tas_input.cpp | |
| parent | input_common/tas: overwrite file dialog (diff) | |
| download | yuzu-e6c4bf52f0eb2c9c78e983ffbc667891463d3253.tar.gz yuzu-e6c4bf52f0eb2c9c78e983ffbc667891463d3253.tar.xz yuzu-e6c4bf52f0eb2c9c78e983ffbc667891463d3253.zip | |
input_common/tas: Add swap controller
Diffstat (limited to 'src/input_common/tas/tas_input.cpp')
| -rw-r--r-- | src/input_common/tas/tas_input.cpp | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/src/input_common/tas/tas_input.cpp b/src/input_common/tas/tas_input.cpp index eb3327520..aceb13adc 100644 --- a/src/input_common/tas/tas_input.cpp +++ b/src/input_common/tas/tas_input.cpp | |||
| @@ -61,8 +61,8 @@ void Tas::LoadTasFile(size_t player_index) { | |||
| 61 | commands[player_index].clear(); | 61 | commands[player_index].clear(); |
| 62 | } | 62 | } |
| 63 | std::string file = | 63 | std::string file = |
| 64 | Common::FS::ReadStringFromFile(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir) + | 64 | Common::FS::ReadStringFromFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / |
| 65 | "script0-" + std::to_string(player_index + 1) + ".txt", | 65 | fmt::format("script0-{}.txt", player_index + 1), |
| 66 | Common::FS::FileType::BinaryFile); | 66 | Common::FS::FileType::BinaryFile); |
| 67 | std::stringstream command_line(file); | 67 | std::stringstream command_line(file); |
| 68 | std::string line; | 68 | std::string line; |
| @@ -102,7 +102,7 @@ void Tas::LoadTasFile(size_t player_index) { | |||
| 102 | LOG_INFO(Input, "TAS file loaded! {} frames", frame_no); | 102 | LOG_INFO(Input, "TAS file loaded! {} frames", frame_no); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | void Tas::WriteTasFile(std::string file_name) { | 105 | void Tas::WriteTasFile(std::u8string file_name) { |
| 106 | std::string output_text; | 106 | std::string output_text; |
| 107 | for (size_t frame = 0; frame < record_commands.size(); frame++) { | 107 | for (size_t frame = 0; frame < record_commands.size(); frame++) { |
| 108 | if (!output_text.empty()) { | 108 | if (!output_text.empty()) { |
| @@ -112,8 +112,8 @@ void Tas::WriteTasFile(std::string file_name) { | |||
| 112 | output_text += std::to_string(frame) + " " + WriteCommandButtons(line.buttons) + " " + | 112 | output_text += std::to_string(frame) + " " + WriteCommandButtons(line.buttons) + " " + |
| 113 | WriteCommandAxis(line.l_axis) + " " + WriteCommandAxis(line.r_axis); | 113 | WriteCommandAxis(line.l_axis) + " " + WriteCommandAxis(line.r_axis); |
| 114 | } | 114 | } |
| 115 | const size_t bytes_written = Common::FS::WriteStringToFile( | 115 | const auto bytes_written = Common::FS::WriteStringToFile( |
| 116 | Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir) + file_name, | 116 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / file_name, |
| 117 | Common::FS::FileType::TextFile, output_text); | 117 | Common::FS::FileType::TextFile, output_text); |
| 118 | if (bytes_written == output_text.size()) { | 118 | if (bytes_written == output_text.size()) { |
| 119 | LOG_INFO(Input, "TAS file written to file!"); | 119 | LOG_INFO(Input, "TAS file written to file!"); |
| @@ -217,6 +217,9 @@ void Tas::UpdateThread() { | |||
| 217 | is_running = Settings::values.tas_loop; | 217 | is_running = Settings::values.tas_loop; |
| 218 | current_command = 0; | 218 | current_command = 0; |
| 219 | tas_data.fill({}); | 219 | tas_data.fill({}); |
| 220 | if (!is_running) { | ||
| 221 | SwapToStoredController(); | ||
| 222 | } | ||
| 220 | } | 223 | } |
| 221 | } else { | 224 | } else { |
| 222 | tas_data.fill({}); | 225 | tas_data.fill({}); |
| @@ -290,6 +293,52 @@ std::string Tas::WriteCommandButtons(u32 data) const { | |||
| 290 | 293 | ||
| 291 | void Tas::StartStop() { | 294 | void Tas::StartStop() { |
| 292 | is_running = !is_running; | 295 | is_running = !is_running; |
| 296 | if (is_running) { | ||
| 297 | SwapToTasController(); | ||
| 298 | } else { | ||
| 299 | SwapToStoredController(); | ||
| 300 | } | ||
| 301 | } | ||
| 302 | |||
| 303 | void Tas::SwapToTasController() { | ||
| 304 | if (!Settings::values.tas_swap_controllers) { | ||
| 305 | return; | ||
| 306 | } | ||
| 307 | auto& players = Settings::values.players.GetValue(); | ||
| 308 | for (std::size_t index = 0; index < players.size(); index++) { | ||
| 309 | auto& player = players[index]; | ||
| 310 | player_mappings[index] = player; | ||
| 311 | |||
| 312 | // Only swap active controllers | ||
| 313 | if (!player.connected) { | ||
| 314 | continue; | ||
| 315 | } | ||
| 316 | |||
| 317 | auto tas_param = Common::ParamPackage{{"pad", static_cast<u8>(index)}}; | ||
| 318 | auto button_mapping = GetButtonMappingForDevice(tas_param); | ||
| 319 | auto analog_mapping = GetAnalogMappingForDevice(tas_param); | ||
| 320 | auto& buttons = player.buttons; | ||
| 321 | auto& analogs = player.analogs; | ||
| 322 | |||
| 323 | for (std::size_t i = 0; i < buttons.size(); ++i) { | ||
| 324 | buttons[i] = button_mapping[static_cast<Settings::NativeButton::Values>(i)].Serialize(); | ||
| 325 | } | ||
| 326 | for (std::size_t i = 0; i < analogs.size(); ++i) { | ||
| 327 | analogs[i] = analog_mapping[static_cast<Settings::NativeAnalog::Values>(i)].Serialize(); | ||
| 328 | } | ||
| 329 | } | ||
| 330 | Settings::values.is_device_reload_pending.store(true); | ||
| 331 | } | ||
| 332 | |||
| 333 | void Tas::SwapToStoredController() { | ||
| 334 | if (!Settings::values.tas_swap_controllers) { | ||
| 335 | return; | ||
| 336 | } | ||
| 337 | auto& players = Settings::values.players.GetValue(); | ||
| 338 | for (std::size_t index = 0; index < players.size(); index++) { | ||
| 339 | players[index] = player_mappings[index]; | ||
| 340 | } | ||
| 341 | Settings::values.is_device_reload_pending.store(true); | ||
| 293 | } | 342 | } |
| 294 | 343 | ||
| 295 | void Tas::Reset() { | 344 | void Tas::Reset() { |
| @@ -308,9 +357,9 @@ void Tas::SaveRecording(bool overwrite_file) { | |||
| 308 | if (record_commands.empty()) { | 357 | if (record_commands.empty()) { |
| 309 | return; | 358 | return; |
| 310 | } | 359 | } |
| 311 | WriteTasFile("record.txt"); | 360 | WriteTasFile(u8"record.txt"); |
| 312 | if (overwrite_file) { | 361 | if (overwrite_file) { |
| 313 | WriteTasFile("script0-1.txt"); | 362 | WriteTasFile(u8"script0-1.txt"); |
| 314 | } | 363 | } |
| 315 | needs_reset = true; | 364 | needs_reset = true; |
| 316 | record_commands.clear(); | 365 | record_commands.clear(); |