mirror of
https://git.h3cjp.net/H3cJP/citra.git
synced 2024-12-29 06:36:41 +00:00
tas_input: std::move strings into vector
While we're in the same area, we can also avoid performing std::stoi in a loop when it only needs to be performed once.
This commit is contained in:
parent
a515ede2af
commit
26ef76213c
|
@ -93,27 +93,29 @@ void Tas::LoadTasFile(size_t player_index, size_t file_index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istringstream linestream(line);
|
std::vector<std::string> seg_list;
|
||||||
std::string segment;
|
{
|
||||||
std::vector<std::string> seglist;
|
std::istringstream line_stream(line);
|
||||||
|
std::string segment;
|
||||||
while (std::getline(linestream, segment, ' ')) {
|
while (std::getline(line_stream, segment, ' ')) {
|
||||||
seglist.push_back(segment);
|
seg_list.push_back(std::move(segment));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seglist.size() < 4) {
|
if (seg_list.size() < 4) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (frame_no < std::stoi(seglist.at(0))) {
|
const auto num_frames = std::stoi(seg_list[0]);
|
||||||
commands[player_index].push_back({});
|
while (frame_no < num_frames) {
|
||||||
|
commands[player_index].emplace_back();
|
||||||
frame_no++;
|
frame_no++;
|
||||||
}
|
}
|
||||||
|
|
||||||
TASCommand command = {
|
TASCommand command = {
|
||||||
.buttons = ReadCommandButtons(seglist.at(1)),
|
.buttons = ReadCommandButtons(seg_list[1]),
|
||||||
.l_axis = ReadCommandAxis(seglist.at(2)),
|
.l_axis = ReadCommandAxis(seg_list[2]),
|
||||||
.r_axis = ReadCommandAxis(seglist.at(3)),
|
.r_axis = ReadCommandAxis(seg_list[3]),
|
||||||
};
|
};
|
||||||
commands[player_index].push_back(command);
|
commands[player_index].push_back(command);
|
||||||
frame_no++;
|
frame_no++;
|
||||||
|
@ -223,22 +225,23 @@ void Tas::ClearInput() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
|
TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
|
||||||
std::stringstream linestream(line);
|
std::vector<std::string> seg_list;
|
||||||
std::string segment;
|
{
|
||||||
std::vector<std::string> seglist;
|
std::istringstream line_stream(line);
|
||||||
|
std::string segment;
|
||||||
while (std::getline(linestream, segment, ';')) {
|
while (std::getline(line_stream, segment, ';')) {
|
||||||
seglist.push_back(segment);
|
seg_list.push_back(std::move(segment));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const float x = std::stof(seglist.at(0)) / 32767.0f;
|
const float x = std::stof(seg_list.at(0)) / 32767.0f;
|
||||||
const float y = std::stof(seglist.at(1)) / 32767.0f;
|
const float y = std::stof(seg_list.at(1)) / 32767.0f;
|
||||||
|
|
||||||
return {x, y};
|
return {x, y};
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 Tas::ReadCommandButtons(const std::string& line) const {
|
u64 Tas::ReadCommandButtons(const std::string& line) const {
|
||||||
std::stringstream button_text(line);
|
std::istringstream button_text(line);
|
||||||
std::string button_line;
|
std::string button_line;
|
||||||
u64 buttons = 0;
|
u64 buttons = 0;
|
||||||
while (std::getline(button_text, button_line, ';')) {
|
while (std::getline(button_text, button_line, ';')) {
|
||||||
|
|
Loading…
Reference in a new issue