input_common/tas: Fallback to simple update
This commit is contained in:
parent
c01a872c8e
commit
f078b15565
10 changed files with 60 additions and 102 deletions
|
@ -14,7 +14,6 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <input_common/main.h>
|
||||
#include "common/common_types.h"
|
||||
#include "common/settings_input.h"
|
||||
|
||||
|
@ -515,9 +514,9 @@ struct Values {
|
|||
|
||||
BasicSetting<bool> pause_tas_on_load { false, "pause_tas_on_load" };
|
||||
BasicSetting<bool> tas_enable{ false, "tas_enable" };
|
||||
BasicSetting<bool> tas_reset{ false, "tas_reset" };
|
||||
BasicSetting<bool> tas_record{ false, "tas_record" };
|
||||
BasicSetting<bool> is_cpu_boxted{ false, " BasicSetting<bool> is_cpu_boxted{ false, "cpuBoosted" };
|
||||
BasicSetting<bool> tas_loop{ false, "tas_loop" };
|
||||
BasicSetting<bool> tas_swap_controllers{ false, "tas_swap_controllers" };
|
||||
BasicSetting<bool> is_cpu_boosted{ false, "is_cpu_boosted" };
|
||||
" };
|
||||
|
||||
BasicSetting<bool> mouse_panning{false, "mouse_panning"};
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/logging/log.h"
|
||||
#include "common/settings.h"
|
||||
#include "core/hle/ipc_helpers.h"
|
||||
#include "core/hle/service/apm/apm.h"
|
||||
#include "core/hle/service/apm/apm_controller.h"
|
||||
|
@ -121,7 +120,6 @@ void APM_Sys::SetCpuBoostMode(Kernel::HLERequestContext& ctx) {
|
|||
|
||||
LOG_DEBUG(Service_APM, "called, mode={:08X}", mode);
|
||||
|
||||
Settings::values.is_cpu_boosted = (mode == CpuBoostMode::Full);
|
||||
controller.SetFromCpuBoostMode(mode);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
#include "core/hle/service/vi/vi_s.h"
|
||||
#include "core/hle/service/vi/vi_u.h"
|
||||
|
||||
#include "input_common/tas/tas_input.h"
|
||||
|
||||
namespace Service::VI {
|
||||
|
||||
constexpr ResultCode ERR_OPERATION_FAILED{ErrorModule::VI, 1};
|
||||
|
@ -597,7 +595,6 @@ private:
|
|||
|
||||
IGBPQueueBufferResponseParcel response{1280, 720};
|
||||
ctx.WriteBuffer(response.Serialize());
|
||||
Settings::values.input_subsystem->GetTas()->UpdateThread();
|
||||
break;
|
||||
}
|
||||
case TransactionId::Query: {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -175,6 +175,9 @@ void PlayerControlPreview::ResetInputs() {
|
|||
}
|
||||
|
||||
void PlayerControlPreview::UpdateInput() {
|
||||
if (controller_callback.update != nullptr) {
|
||||
controller_callback.update(std::move(true));
|
||||
}
|
||||
if (!is_enabled && !mapping_active) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ void ControllerDialog::refreshConfiguration() {
|
|||
constexpr std::size_t player = 0;
|
||||
widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs);
|
||||
widget->SetControllerType(players[player].controller_type);
|
||||
ControllerCallback callback{[this](ControllerInput input) { InputController(input); }};
|
||||
ControllerCallback callback{[this](ControllerInput input) { InputController(input); },
|
||||
[this](bool update) { UpdateController(update); }};
|
||||
widget->SetCallBack(callback);
|
||||
widget->repaint();
|
||||
widget->SetConnectedStatus(players[player].connected);
|
||||
|
@ -74,10 +75,6 @@ void ControllerDialog::hideEvent(QHideEvent* ev) {
|
|||
QWidget::hideEvent(ev);
|
||||
}
|
||||
|
||||
void ControllerDialog::RefreshTasFile() {
|
||||
input_subsystem->GetTas()->RefreshTasFile();
|
||||
}
|
||||
|
||||
void ControllerDialog::InputController(ControllerInput input) {
|
||||
u32 buttons = 0;
|
||||
int index = 0;
|
||||
|
@ -86,4 +83,11 @@ void ControllerDialog::InputController(ControllerInput input) {
|
|||
index++;
|
||||
}
|
||||
input_subsystem->GetTas()->RecordInput(buttons, input.axis_values);
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerDialog::UpdateController(bool update) {
|
||||
if (!update) {
|
||||
return;
|
||||
}
|
||||
input_subsystem->GetTas()->UpdateThread();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ struct ControllerInput {
|
|||
|
||||
struct ControllerCallback {
|
||||
std::function<void(ControllerInput)> input;
|
||||
std::function<void(bool)> update;
|
||||
};
|
||||
|
||||
class ControllerDialog : public QWidget {
|
||||
|
@ -43,8 +44,8 @@ protected:
|
|||
void hideEvent(QHideEvent* ev) override;
|
||||
|
||||
private:
|
||||
void RefreshTasFile();
|
||||
void InputController(ControllerInput input);
|
||||
void UpdateController(bool update);
|
||||
QAction* toggle_view_action = nullptr;
|
||||
QFileSystemWatcher* watcher = nullptr;
|
||||
PlayerControlPreview* widget;
|
||||
|
|
|
@ -196,7 +196,6 @@ GMainWindow::GMainWindow()
|
|||
config{std::make_unique<Config>()}, vfs{std::make_shared<FileSys::RealVfsFilesystem>()},
|
||||
provider{std::make_unique<FileSys::ManualContentProvider>()} {
|
||||
Common::Log::Initialize();
|
||||
Settings::values.inputSubsystem = input_subsystem;
|
||||
LoadTranslation();
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
@ -2903,16 +2902,17 @@ void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_vie
|
|||
}
|
||||
}
|
||||
|
||||
static std::string GetTasStateDescription(TasInput::TasState state) {
|
||||
switch (state) {
|
||||
QString GMainWindow::GetTasStateDescription() const {
|
||||
auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus();
|
||||
switch (tas_status) {
|
||||
case TasInput::TasState::Running:
|
||||
return "Running";
|
||||
return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames);
|
||||
case TasInput::TasState::Recording:
|
||||
return "Recording";
|
||||
return tr("TAS state: Recording %1").arg(total_tas_frames);
|
||||
case TasInput::TasState::Stopped:
|
||||
return "Stopped";
|
||||
return tr("TAS state: Idle %1/%2").arg(current_tas_frame).arg(total_tas_frames);
|
||||
default:
|
||||
return "INVALID STATE";
|
||||
return tr("INVALID TAS STATE");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2923,12 +2923,7 @@ void GMainWindow::UpdateStatusBar() {
|
|||
}
|
||||
|
||||
if (Settings::values.tas_enable) {
|
||||
auto [tas_status, current_tas_frame, total_tas_frames] =
|
||||
input_subsystem->GetTas()->GetStatus();
|
||||
tas_label->setText(tr("%1 TAS %2/%3")
|
||||
.arg(tr(GetTasStateDescription(tas_status).c_str()))
|
||||
.arg(current_tas_frame)
|
||||
.arg(total_tas_frames));
|
||||
tas_label->setText(GetTasStateDescription());
|
||||
} else {
|
||||
tas_label->clear();
|
||||
}
|
||||
|
|
|
@ -301,6 +301,7 @@ private:
|
|||
void OpenURL(const QUrl& url);
|
||||
void LoadTranslation();
|
||||
void OpenPerGameConfiguration(u64 title_id, const std::string& file_name);
|
||||
QString GetTasStateDescription() const;
|
||||
|
||||
Ui::MainWindow ui;
|
||||
|
||||
|
|
Loading…
Reference in a new issue