From f078b15565c8cab08587b8f8629d878615705cfb Mon Sep 17 00:00:00 2001 From: MonsterDruide1 <5958456@gmail.com> Date: Sun, 20 Jun 2021 00:04:34 +0200 Subject: input_common/tas: Fallback to simple update --- src/input_common/tas/tas_input.cpp | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'src/input_common/tas/tas_input.cpp') 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 #include -#include -#include #include -#include -#include #include "common/fs/file.h" #include "common/fs/fs_types.h" @@ -43,27 +38,25 @@ constexpr std::array, 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 FlipY(std::pair old) { +std::pair Tas::FlipAxisY(std::pair old) { auto [x, y] = old; return {x, -y}; } void Tas::RecordInput(u32 buttons, const std::array, 2>& axes) { - last_input = {buttons, FlipY(axes[0]), FlipY(axes[1])}; + last_input = {buttons, FlipAxisY(axes[0]), FlipAxisY(axes[1])}; } std::tuple Tas::GetStatus() const { @@ -155,21 +147,21 @@ std::tuple 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& arr) { +std::string Tas::DebugInputs(const std::array& 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& 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(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; -- cgit v1.2.3