summaryrefslogtreecommitdiff
path: root/src/input_common/tas/tas_input.cpp
diff options
context:
space:
mode:
authorGravatar MonsterDruide12021-06-20 00:04:34 +0200
committerGravatar MonsterDruide12021-09-18 23:22:30 +0200
commitf078b15565c8cab08587b8f8629d878615705cfb (patch)
treed6e18351980bbf1aac850831203caa127c796eba /src/input_common/tas/tas_input.cpp
parentconfig: Move TAS options to it's own menu (diff)
downloadyuzu-f078b15565c8cab08587b8f8629d878615705cfb.tar.gz
yuzu-f078b15565c8cab08587b8f8629d878615705cfb.tar.xz
yuzu-f078b15565c8cab08587b8f8629d878615705cfb.zip
input_common/tas: Fallback to simple update
Diffstat (limited to 'src/input_common/tas/tas_input.cpp')
-rw-r--r--src/input_common/tas/tas_input.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/input_common/tas/tas_input.cpp b/src/input_common/tas/tas_input.cpp
index 6efa1234a..baeb18c22 100644
--- a/src/input_common/tas/tas_input.cpp
+++ b/src/input_common/tas/tas_input.cpp
@@ -2,13 +2,8 @@
2// Licensed under GPLv2+ 2// Licensed under GPLv2+
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <chrono>
6#include <cstring> 5#include <cstring>
7#include <functional>
8#include <random>
9#include <regex> 6#include <regex>
10#include <thread>
11#include <boost/asio.hpp>
12 7
13#include "common/fs/file.h" 8#include "common/fs/file.h"
14#include "common/fs/fs_types.h" 9#include "common/fs/fs_types.h"
@@ -43,27 +38,25 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but
43}; 38};
44 39
45Tas::Tas() { 40Tas::Tas() {
41 if (!Settings::values.tas_enable) {
42 return;
43 }
46 LoadTasFiles(); 44 LoadTasFiles();
47} 45}
48 46
49Tas::~Tas() { 47Tas::~Tas() = default;
50 update_thread_running = false;
51}
52 48
53void Tas::RefreshTasFile() {
54 refresh_tas_fle = true;
55}
56void Tas::LoadTasFiles() { 49void Tas::LoadTasFiles() {
57 script_length = 0; 50 script_length = 0;
58 for (size_t i = 0; i < PLAYER_NUMBER; i++) { 51 for (size_t i = 0; i < commands.size(); i++) {
59 LoadTasFile(i); 52 LoadTasFile(i);
60 if (commands[i].size() > script_length) { 53 if (commands[i].size() > script_length) {
61 script_length = commands[i].size(); 54 script_length = commands[i].size();
62 } 55 }
63 } 56 }
64} 57}
58
65void Tas::LoadTasFile(size_t player_index) { 59void Tas::LoadTasFile(size_t player_index) {
66 LOG_DEBUG(Input, "LoadTasFile()");
67 if (!commands[player_index].empty()) { 60 if (!commands[player_index].empty()) {
68 commands[player_index].clear(); 61 commands[player_index].clear();
69 } 62 }
@@ -110,7 +103,6 @@ void Tas::LoadTasFile(size_t player_index) {
110} 103}
111 104
112void Tas::WriteTasFile() { 105void Tas::WriteTasFile() {
113 LOG_DEBUG(Input, "WriteTasFile()");
114 std::string output_text; 106 std::string output_text;
115 for (size_t frame = 0; frame < record_commands.size(); frame++) { 107 for (size_t frame = 0; frame < record_commands.size(); frame++) {
116 if (!output_text.empty()) { 108 if (!output_text.empty()) {
@@ -131,13 +123,13 @@ void Tas::WriteTasFile() {
131 } 123 }
132} 124}
133 125
134static std::pair<float, float> FlipY(std::pair<float, float> old) { 126std::pair<float, float> Tas::FlipAxisY(std::pair<float, float> old) {
135 auto [x, y] = old; 127 auto [x, y] = old;
136 return {x, -y}; 128 return {x, -y};
137} 129}
138 130
139void Tas::RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes) { 131void Tas::RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes) {
140 last_input = {buttons, FlipY(axes[0]), FlipY(axes[1])}; 132 last_input = {buttons, FlipAxisY(axes[0]), FlipAxisY(axes[1])};
141} 133}
142 134
143std::tuple<TasState, size_t, size_t> Tas::GetStatus() const { 135std::tuple<TasState, size_t, size_t> Tas::GetStatus() const {
@@ -155,21 +147,21 @@ std::tuple<TasState, size_t, size_t> Tas::GetStatus() const {
155 return {state, current_command, script_length}; 147 return {state, current_command, script_length};
156} 148}
157 149
158static std::string DebugButtons(u32 buttons) { 150std::string Tas::DebugButtons(u32 buttons) const {
159 return fmt::format("{{ {} }}", TasInput::Tas::ButtonsToString(buttons)); 151 return fmt::format("{{ {} }}", TasInput::Tas::ButtonsToString(buttons));
160} 152}
161 153
162static std::string DebugJoystick(float x, float y) { 154std::string Tas::DebugJoystick(float x, float y) const {
163 return fmt::format("[ {} , {} ]", std::to_string(x), std::to_string(y)); 155 return fmt::format("[ {} , {} ]", std::to_string(x), std::to_string(y));
164} 156}
165 157
166static std::string DebugInput(const TasData& data) { 158std::string Tas::DebugInput(const TasData& data) const {
167 return fmt::format("{{ {} , {} , {} }}", DebugButtons(data.buttons), 159 return fmt::format("{{ {} , {} , {} }}", DebugButtons(data.buttons),
168 DebugJoystick(data.axis[0], data.axis[1]), 160 DebugJoystick(data.axis[0], data.axis[1]),
169 DebugJoystick(data.axis[2], data.axis[3])); 161 DebugJoystick(data.axis[2], data.axis[3]));
170} 162}
171 163
172static std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) { 164std::string Tas::DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const {
173 std::string returns = "[ "; 165 std::string returns = "[ ";
174 for (size_t i = 0; i < arr.size(); i++) { 166 for (size_t i = 0; i < arr.size(); i++) {
175 returns += DebugInput(arr[i]); 167 returns += DebugInput(arr[i]);
@@ -180,8 +172,17 @@ static std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) {
180 return returns + "]"; 172 return returns + "]";
181} 173}
182 174
175std::string Tas::ButtonsToString(u32 button) const {
176 std::string returns;
177 for (auto [text_button, tas_button] : text_to_tas_button) {
178 if ((button & static_cast<u32>(tas_button)) != 0)
179 returns += fmt::format(", {}", text_button.substr(4));
180 }
181 return returns.empty() ? "" : returns.substr(2);
182}
183
183void Tas::UpdateThread() { 184void Tas::UpdateThread() {
184 if (!update_thread_running) { 185 if (!Settings::values.tas_enable) {
185 return; 186 return;
186 } 187 }
187 188
@@ -206,9 +207,9 @@ void Tas::UpdateThread() {
206 } 207 }
207 if (is_running) { 208 if (is_running) {
208 if (current_command < script_length) { 209 if (current_command < script_length) {
209 LOG_INFO(Input, "Playing TAS {}/{}", current_command, script_length); 210 LOG_DEBUG(Input, "Playing TAS {}/{}", current_command, script_length);
210 size_t frame = current_command++; 211 size_t frame = current_command++;
211 for (size_t i = 0; i < PLAYER_NUMBER; i++) { 212 for (size_t i = 0; i < commands.size(); i++) {
212 if (frame < commands[i].size()) { 213 if (frame < commands[i].size()) {
213 TASCommand command = commands[i][frame]; 214 TASCommand command = commands[i][frame];
214 tas_data[i].buttons = command.buttons; 215 tas_data[i].buttons = command.buttons;