summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2021-12-13 17:07:26 +0100
committerLioncash <mathew1800@gmail.com>2021-12-13 17:45:15 +0100
commit26ef76213c81b6c2dc8eeeae11e9586f22a76011 (patch)
treef26720738aef4c6951c88e8bf1aad5b18a1ca601
parenttas_input: Use istringstream over stringstream (diff)
downloadyuzu-26ef76213c81b6c2dc8eeeae11e9586f22a76011.tar
yuzu-26ef76213c81b6c2dc8eeeae11e9586f22a76011.tar.gz
yuzu-26ef76213c81b6c2dc8eeeae11e9586f22a76011.tar.bz2
yuzu-26ef76213c81b6c2dc8eeeae11e9586f22a76011.tar.lz
yuzu-26ef76213c81b6c2dc8eeeae11e9586f22a76011.tar.xz
yuzu-26ef76213c81b6c2dc8eeeae11e9586f22a76011.tar.zst
yuzu-26ef76213c81b6c2dc8eeeae11e9586f22a76011.zip
-rw-r--r--src/input_common/drivers/tas_input.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index a7d3d0b47..d14a43b9e 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -93,27 +93,29 @@ void Tas::LoadTasFile(size_t player_index, size_t file_index) {
continue;
}
- std::istringstream linestream(line);
- std::string segment;
- std::vector<std::string> seglist;
-
- while (std::getline(linestream, segment, ' ')) {
- seglist.push_back(segment);
+ std::vector<std::string> seg_list;
+ {
+ std::istringstream line_stream(line);
+ std::string segment;
+ while (std::getline(line_stream, segment, ' ')) {
+ seg_list.push_back(std::move(segment));
+ }
}
- if (seglist.size() < 4) {
+ if (seg_list.size() < 4) {
continue;
}
- while (frame_no < std::stoi(seglist.at(0))) {
- commands[player_index].push_back({});
+ const auto num_frames = std::stoi(seg_list[0]);
+ while (frame_no < num_frames) {
+ commands[player_index].emplace_back();
frame_no++;
}
TASCommand command = {
- .buttons = ReadCommandButtons(seglist.at(1)),
- .l_axis = ReadCommandAxis(seglist.at(2)),
- .r_axis = ReadCommandAxis(seglist.at(3)),
+ .buttons = ReadCommandButtons(seg_list[1]),
+ .l_axis = ReadCommandAxis(seg_list[2]),
+ .r_axis = ReadCommandAxis(seg_list[3]),
};
commands[player_index].push_back(command);
frame_no++;
@@ -223,22 +225,23 @@ void Tas::ClearInput() {
}
TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
- std::stringstream linestream(line);
- std::string segment;
- std::vector<std::string> seglist;
-
- while (std::getline(linestream, segment, ';')) {
- seglist.push_back(segment);
+ std::vector<std::string> seg_list;
+ {
+ std::istringstream line_stream(line);
+ std::string segment;
+ while (std::getline(line_stream, segment, ';')) {
+ seg_list.push_back(std::move(segment));
+ }
}
- const float x = std::stof(seglist.at(0)) / 32767.0f;
- const float y = std::stof(seglist.at(1)) / 32767.0f;
+ const float x = std::stof(seg_list.at(0)) / 32767.0f;
+ const float y = std::stof(seg_list.at(1)) / 32767.0f;
return {x, y};
}
u64 Tas::ReadCommandButtons(const std::string& line) const {
- std::stringstream button_text(line);
+ std::istringstream button_text(line);
std::string button_line;
u64 buttons = 0;
while (std::getline(button_text, button_line, ';')) {