summaryrefslogtreecommitdiffstats
path: root/src/input_common/tas
diff options
context:
space:
mode:
authorMonsterDruide1 <5958456@gmail.com>2021-06-20 00:04:34 +0200
committerMonsterDruide1 <5958456@gmail.com>2021-09-18 23:22:30 +0200
commitf078b15565c8cab08587b8f8629d878615705cfb (patch)
treed6e18351980bbf1aac850831203caa127c796eba /src/input_common/tas
parentconfig: Move TAS options to it's own menu (diff)
downloadyuzu-f078b15565c8cab08587b8f8629d878615705cfb.tar
yuzu-f078b15565c8cab08587b8f8629d878615705cfb.tar.gz
yuzu-f078b15565c8cab08587b8f8629d878615705cfb.tar.bz2
yuzu-f078b15565c8cab08587b8f8629d878615705cfb.tar.lz
yuzu-f078b15565c8cab08587b8f8629d878615705cfb.tar.xz
yuzu-f078b15565c8cab08587b8f8629d878615705cfb.tar.zst
yuzu-f078b15565c8cab08587b8f8629d878615705cfb.zip
Diffstat (limited to 'src/input_common/tas')
-rw-r--r--src/input_common/tas/tas_input.cpp47
-rw-r--r--src/input_common/tas/tas_input.h59
2 files changed, 33 insertions, 73 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 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
-#include <chrono>
#include <cstring>
-#include <functional>
-#include <random>
#include <regex>
-#include <thread>
-#include <boost/asio.hpp>
#include "common/fs/file.h"
#include "common/fs/fs_types.h"
@@ -43,27 +38,25 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but
};
Tas::Tas() {
+ if (!Settings::values.tas_enable) {
+ return;
+ }
LoadTasFiles();
}
-Tas::~Tas() {
- update_thread_running = false;
-}
+Tas::~Tas() = default;
-void Tas::RefreshTasFile() {
- refresh_tas_fle = true;
-}
void Tas::LoadTasFiles() {
script_length = 0;
- for (size_t i = 0; i < PLAYER_NUMBER; i++) {
+ for (size_t i = 0; i < commands.size(); i++) {
LoadTasFile(i);
if (commands[i].size() > script_length) {
script_length = commands[i].size();
}
}
}
+
void Tas::LoadTasFile(size_t player_index) {
- LOG_DEBUG(Input, "LoadTasFile()");
if (!commands[player_index].empty()) {
commands[player_index].clear();
}
@@ -110,7 +103,6 @@ void Tas::LoadTasFile(size_t player_index) {
}
void Tas::WriteTasFile() {
- LOG_DEBUG(Input, "WriteTasFile()");
std::string output_text;
for (size_t frame = 0; frame < record_commands.size(); frame++) {
if (!output_text.empty()) {
@@ -131,13 +123,13 @@ void Tas::WriteTasFile() {
}
}
-static std::pair<float, float> FlipY(std::pair<float, float> old) {
+std::pair<float, float> Tas::FlipAxisY(std::pair<float, float> old) {
auto [x, y] = old;
return {x, -y};
}
void Tas::RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes) {
- last_input = {buttons, FlipY(axes[0]), FlipY(axes[1])};
+ last_input = {buttons, FlipAxisY(axes[0]), FlipAxisY(axes[1])};
}
std::tuple<TasState, size_t, size_t> Tas::GetStatus() const {
@@ -155,21 +147,21 @@ std::tuple<TasState, size_t, size_t> Tas::GetStatus() const {
return {state, current_command, script_length};
}
-static std::string DebugButtons(u32 buttons) {
+std::string Tas::DebugButtons(u32 buttons) const {
return fmt::format("{{ {} }}", TasInput::Tas::ButtonsToString(buttons));
}
-static std::string DebugJoystick(float x, float y) {
+std::string Tas::DebugJoystick(float x, float y) const {
return fmt::format("[ {} , {} ]", std::to_string(x), std::to_string(y));
}
-static std::string DebugInput(const TasData& data) {
+std::string Tas::DebugInput(const TasData& data) const {
return fmt::format("{{ {} , {} , {} }}", DebugButtons(data.buttons),
DebugJoystick(data.axis[0], data.axis[1]),
DebugJoystick(data.axis[2], data.axis[3]));
}
-static std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) {
+std::string Tas::DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const {
std::string returns = "[ ";
for (size_t i = 0; i < arr.size(); i++) {
returns += DebugInput(arr[i]);
@@ -180,8 +172,17 @@ static std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) {
return returns + "]";
}
+std::string Tas::ButtonsToString(u32 button) const {
+ std::string returns;
+ for (auto [text_button, tas_button] : text_to_tas_button) {
+ if ((button & static_cast<u32>(tas_button)) != 0)
+ returns += fmt::format(", {}", text_button.substr(4));
+ }
+ return returns.empty() ? "" : returns.substr(2);
+}
+
void Tas::UpdateThread() {
- if (!update_thread_running) {
+ if (!Settings::values.tas_enable) {
return;
}
@@ -206,9 +207,9 @@ void Tas::UpdateThread() {
}
if (is_running) {
if (current_command < script_length) {
- LOG_INFO(Input, "Playing TAS {}/{}", current_command, script_length);
+ LOG_DEBUG(Input, "Playing TAS {}/{}", current_command, script_length);
size_t frame = current_command++;
- for (size_t i = 0; i < PLAYER_NUMBER; i++) {
+ for (size_t i = 0; i < commands.size(); i++) {
if (frame < commands[i].size()) {
TASCommand command = commands[i][frame];
tas_data[i].buttons = command.buttons;
diff --git a/src/input_common/tas/tas_input.h b/src/input_common/tas/tas_input.h
index 49ef10ff9..e011e559e 100644
--- a/src/input_common/tas/tas_input.h
+++ b/src/input_common/tas/tas_input.h
@@ -5,8 +5,6 @@
#pragma once
#include <array>
-#include <mutex>
-#include <thread>
#include "common/common_types.h"
#include "core/frontend/input.h"
@@ -65,53 +63,6 @@ public:
Tas();
~Tas();
- static std::string ButtonsToString(u32 button) {
- std::string returns;
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_A)) != 0)
- returns += ", A";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_B)) != 0)
- returns += ", B";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_X)) != 0)
- returns += ", X";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_Y)) != 0)
- returns += ", Y";
- if ((button & static_cast<u32>(TasInput::TasButton::STICK_L)) != 0)
- returns += ", STICK_L";
- if ((button & static_cast<u32>(TasInput::TasButton::STICK_R)) != 0)
- returns += ", STICK_R";
- if ((button & static_cast<u32>(TasInput::TasButton::TRIGGER_L)) != 0)
- returns += ", TRIGGER_L";
- if ((button & static_cast<u32>(TasInput::TasButton::TRIGGER_R)) != 0)
- returns += ", TRIGGER_R";
- if ((button & static_cast<u32>(TasInput::TasButton::TRIGGER_ZL)) != 0)
- returns += ", TRIGGER_ZL";
- if ((button & static_cast<u32>(TasInput::TasButton::TRIGGER_ZR)) != 0)
- returns += ", TRIGGER_ZR";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_PLUS)) != 0)
- returns += ", PLUS";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_MINUS)) != 0)
- returns += ", MINUS";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_LEFT)) != 0)
- returns += ", LEFT";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_UP)) != 0)
- returns += ", UP";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_RIGHT)) != 0)
- returns += ", RIGHT";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_DOWN)) != 0)
- returns += ", DOWN";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_SL)) != 0)
- returns += ", SL";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_SR)) != 0)
- returns += ", SR";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_HOME)) != 0)
- returns += ", HOME";
- if ((button & static_cast<u32>(TasInput::TasButton::BUTTON_CAPTURE)) != 0)
- returns += ", CAPTURE";
- return returns.empty() ? "" : returns.substr(2);
- }
-
- void RefreshTasFile();
- void LoadTasFiles();
void RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes);
void UpdateThread();
@@ -137,6 +88,7 @@ private:
TasAnalog l_axis{};
TasAnalog r_axis{};
};
+ void LoadTasFiles();
void LoadTasFile(size_t player_index);
void WriteTasFile();
TasAnalog ReadCommandAxis(const std::string& line) const;
@@ -144,9 +96,16 @@ private:
std::string WriteCommandButtons(u32 data) const;
std::string WriteCommandAxis(TasAnalog data) const;
+ std::pair<float, float> FlipAxisY(std::pair<float, float> old);
+
+ std::string DebugButtons(u32 buttons) const;
+ std::string DebugJoystick(float x, float y) const;
+ std::string DebugInput(const TasData& data) const;
+ std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const;
+ std::string ButtonsToString(u32 button) const;
+
size_t script_length{0};
std::array<TasData, PLAYER_NUMBER> tas_data;
- bool update_thread_running{true};
bool refresh_tas_fle{false};
bool is_recording{false};
bool is_running{false};