diff options
| author | 2021-12-13 10:54:05 -0500 | |
|---|---|---|
| committer | 2021-12-13 10:54:43 -0500 | |
| commit | 6be730bdcdf875655973b1a39576e6933fd93eab (patch) | |
| tree | e1a9882a78ba837dd7e9bdd08e77e4259c581955 /src/input_common/drivers/tas_input.cpp | |
| parent | tas_input: Remove unused std::smatch variable (diff) | |
| download | yuzu-6be730bdcdf875655973b1a39576e6933fd93eab.tar.gz yuzu-6be730bdcdf875655973b1a39576e6933fd93eab.tar.xz yuzu-6be730bdcdf875655973b1a39576e6933fd93eab.zip | |
tas_input: Use u8string_view instead of u8string
Same behavior, but without the potential for extra allocations.
Diffstat (limited to 'src/input_common/drivers/tas_input.cpp')
| -rw-r--r-- | src/input_common/drivers/tas_input.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp index 0a504c484..3fdd3649b 100644 --- a/src/input_common/drivers/tas_input.cpp +++ b/src/input_common/drivers/tas_input.cpp | |||
| @@ -121,16 +121,17 @@ void Tas::LoadTasFile(size_t player_index, size_t file_index) { | |||
| 121 | LOG_INFO(Input, "TAS file loaded! {} frames", frame_no); | 121 | LOG_INFO(Input, "TAS file loaded! {} frames", frame_no); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | void Tas::WriteTasFile(std::u8string file_name) { | 124 | void Tas::WriteTasFile(std::u8string_view file_name) { |
| 125 | std::string output_text; | 125 | std::string output_text; |
| 126 | for (size_t frame = 0; frame < record_commands.size(); frame++) { | 126 | for (size_t frame = 0; frame < record_commands.size(); frame++) { |
| 127 | const TASCommand& line = record_commands[frame]; | 127 | const TASCommand& line = record_commands[frame]; |
| 128 | output_text += fmt::format("{} {} {} {}\n", frame, WriteCommandButtons(line.buttons), | 128 | output_text += fmt::format("{} {} {} {}\n", frame, WriteCommandButtons(line.buttons), |
| 129 | WriteCommandAxis(line.l_axis), WriteCommandAxis(line.r_axis)); | 129 | WriteCommandAxis(line.l_axis), WriteCommandAxis(line.r_axis)); |
| 130 | } | 130 | } |
| 131 | const auto bytes_written = Common::FS::WriteStringToFile( | 131 | |
| 132 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / file_name, | 132 | const auto tas_file_name = Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / file_name; |
| 133 | Common::FS::FileType::TextFile, output_text); | 133 | const auto bytes_written = |
| 134 | Common::FS::WriteStringToFile(tas_file_name, Common::FS::FileType::TextFile, output_text); | ||
| 134 | if (bytes_written == output_text.size()) { | 135 | if (bytes_written == output_text.size()) { |
| 135 | LOG_INFO(Input, "TAS file written to file!"); | 136 | LOG_INFO(Input, "TAS file written to file!"); |
| 136 | } else { | 137 | } else { |
| @@ -252,7 +253,7 @@ u64 Tas::ReadCommandButtons(const std::string& line) const { | |||
| 252 | } | 253 | } |
| 253 | 254 | ||
| 254 | std::string Tas::WriteCommandButtons(u64 buttons) const { | 255 | std::string Tas::WriteCommandButtons(u64 buttons) const { |
| 255 | std::string returns = ""; | 256 | std::string returns; |
| 256 | for (auto [text_button, tas_button] : text_to_tas_button) { | 257 | for (auto [text_button, tas_button] : text_to_tas_button) { |
| 257 | if ((buttons & static_cast<u64>(tas_button)) != 0) { | 258 | if ((buttons & static_cast<u64>(tas_button)) != 0) { |
| 258 | returns += fmt::format("{};", text_button); | 259 | returns += fmt::format("{};", text_button); |