From 6024631e28698f24a6b7b5b661d1bd56a3b448c7 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sun, 8 Jan 2023 00:07:19 +0100 Subject: [PATCH] early-access version 3299 --- README.md | 2 +- src/common/input.h | 3 --- src/core/hid/emulated_controller.cpp | 10 ------- src/input_common/drivers/tas_input.cpp | 12 ++++++--- src/input_common/drivers/tas_input.h | 2 +- .../helpers/stick_from_buttons.cpp | 17 +++++++----- src/input_common/main.cpp | 26 ++++++++++++++++++ src/yuzu/main.cpp | 27 ++++++++++++++++--- src/yuzu/main.h | 4 +++ 9 files changed, 76 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index dca667390..ae2e90693 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3298. +This is the source code for early-access 3299. ## Legal Notice diff --git a/src/common/input.h b/src/common/input.h index 3f5040760..1f9db5af2 100755 --- a/src/common/input.h +++ b/src/common/input.h @@ -304,9 +304,6 @@ class InputDevice { public: virtual ~InputDevice() = default; - // Request input device to update if necessary - virtual void SoftUpdate() {} - // Force input device to update data regardless of the current state virtual void ForceUpdate() {} diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 305ba9551..cb5390e35 100755 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -1583,16 +1583,6 @@ AnalogSticks EmulatedController::GetSticks() const { return {}; } - // Some drivers like stick from buttons need constant refreshing - for (auto& device : stick_devices) { - if (!device) { - continue; - } - lock.unlock(); - device->SoftUpdate(); - lock.lock(); - } - return controller.analog_stick_state; } diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp index dcd1ca2a6..bf99b5fc7 100755 --- a/src/input_common/drivers/tas_input.cpp +++ b/src/input_common/drivers/tas_input.cpp @@ -156,10 +156,12 @@ void Tas::RecordInput(u64 buttons, TasAnalog left_axis, TasAnalog right_axis) { }; } -std::tuple Tas::GetStatus() const { +std::tuple> Tas::GetStatus() const { TasState state; + std::array lengths{0}; if (is_recording) { - return {TasState::Recording, 0, record_commands.size()}; + lengths[0] = record_commands.size(); + return {TasState::Recording, record_commands.size(), lengths}; } if (is_running) { @@ -168,7 +170,11 @@ std::tuple Tas::GetStatus() const { state = TasState::Stopped; } - return {state, current_command, script_length}; + for (size_t i = 0; i < PLAYER_NUMBER; i++) { + lengths[i] = commands[i].size(); + } + + return {state, current_command, lengths}; } void Tas::UpdateThread() { diff --git a/src/input_common/drivers/tas_input.h b/src/input_common/drivers/tas_input.h index 4d44a7480..a861de781 100755 --- a/src/input_common/drivers/tas_input.h +++ b/src/input_common/drivers/tas_input.h @@ -124,7 +124,7 @@ public: * Current playback progress ; * Total length of script file currently loaded or being recorded */ - std::tuple GetStatus() const; + std::tuple> GetStatus() const; private: enum class TasAxis : u8; diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp index 902856190..7b7623960 100755 --- a/src/input_common/helpers/stick_from_buttons.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp @@ -13,11 +13,11 @@ class Stick final : public Common::Input::InputDevice { public: using Button = std::unique_ptr; - Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, + Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, Button updater_, float modifier_scale_, float modifier_angle_) : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), - right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), - modifier_angle(modifier_angle_) { + right(std::move(right_)), modifier(std::move(modifier_)), updater(std::move(updater_)), + modifier_scale(modifier_scale_), modifier_angle(modifier_angle_) { up->SetCallback({ .on_change = [this](const Common::Input::CallbackStatus& callback_) { @@ -48,6 +48,9 @@ public: UpdateModButtonStatus(callback_); }, }); + updater->SetCallback({ + .on_change = [this](const Common::Input::CallbackStatus& callback_) { SoftUpdate(); }, + }); last_x_axis_value = 0.0f; last_y_axis_value = 0.0f; } @@ -248,7 +251,7 @@ public: modifier->ForceUpdate(); } - void SoftUpdate() override { + void SoftUpdate() { Common::Input::CallbackStatus status{ .type = Common::Input::InputType::Stick, .stick_status = GetStatus(), @@ -308,6 +311,7 @@ private: Button left; Button right; Button modifier; + Button updater; float modifier_scale{}; float modifier_angle{}; float angle{}; @@ -331,11 +335,12 @@ std::unique_ptr StickFromButton::Create( auto left = Common::Input::CreateInputDeviceFromString(params.Get("left", null_engine)); auto right = Common::Input::CreateInputDeviceFromString(params.Get("right", null_engine)); auto modifier = Common::Input::CreateInputDeviceFromString(params.Get("modifier", null_engine)); + auto updater = Common::Input::CreateInputDeviceFromString("engine:updater,button:0"); auto modifier_scale = params.Get("modifier_scale", 0.5f); auto modifier_angle = params.Get("modifier_angle", 5.5f); return std::make_unique(std::move(up), std::move(down), std::move(left), - std::move(right), std::move(modifier), modifier_scale, - modifier_angle); + std::move(right), std::move(modifier), std::move(updater), + modifier_scale, modifier_angle); } } // namespace InputCommon diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index d176ba1a1..0c0ae7760 100755 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -29,6 +29,28 @@ namespace InputCommon { +/// Dummy engine to get periodic updates +class UpdateEngine final : public InputEngine { +public: + explicit UpdateEngine(std::string input_engine_) : InputEngine(std::move(input_engine_)) { + PreSetController(identifier); + } + + void PumpEvents() { + SetButton(identifier, 0, last_state); + last_state = !last_state; + } + +private: + static constexpr PadIdentifier identifier = { + .guid = Common::UUID{}, + .port = 0, + .pad = 0, + }; + + bool last_state{}; +}; + struct InputSubsystem::Impl { template void RegisterEngine(std::string name, std::shared_ptr& engine) { @@ -46,6 +68,7 @@ struct InputSubsystem::Impl { void Initialize() { mapping_factory = std::make_shared(); + RegisterEngine("updater", update_engine); RegisterEngine("keyboard", keyboard); RegisterEngine("mouse", mouse); RegisterEngine("touch", touch_screen); @@ -76,6 +99,7 @@ struct InputSubsystem::Impl { } void Shutdown() { + UnregisterEngine(update_engine); UnregisterEngine(keyboard); UnregisterEngine(mouse); UnregisterEngine(touch_screen); @@ -265,6 +289,7 @@ struct InputSubsystem::Impl { } void PumpEvents() const { + update_engine->PumpEvents(); #ifdef HAVE_SDL2 sdl->PumpEvents(); #endif @@ -276,6 +301,7 @@ struct InputSubsystem::Impl { std::shared_ptr mapping_factory; + std::shared_ptr update_engine; std::shared_ptr keyboard; std::shared_ptr mouse; std::shared_ptr touch_screen; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index de5461d1c..07681ee8d 100755 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -3729,15 +3729,36 @@ void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_vie } } +std::string GMainWindow::CreateTASFramesString( + std::array frames) const { + std::string string = ""; + size_t maxPlayerIndex = 0; + for (size_t i = 0; i < frames.size(); i++) { + if (frames[i] != 0) { + if (maxPlayerIndex != 0) + string += ", "; + while (maxPlayerIndex++ != i) + string += "0, "; + string += std::to_string(frames[i]); + } + } + return string; +} + QString GMainWindow::GetTasStateDescription() const { auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus(); + std::string tas_frames_string = CreateTASFramesString(total_tas_frames); switch (tas_status) { case InputCommon::TasInput::TasState::Running: - return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames); + return tr("TAS state: Running %1/%2") + .arg(current_tas_frame) + .arg(QString::fromStdString(tas_frames_string)); case InputCommon::TasInput::TasState::Recording: - return tr("TAS state: Recording %1").arg(total_tas_frames); + return tr("TAS state: Recording %1").arg(total_tas_frames[0]); case InputCommon::TasInput::TasState::Stopped: - return tr("TAS state: Idle %1/%2").arg(current_tas_frame).arg(total_tas_frames); + return tr("TAS state: Idle %1/%2") + .arg(current_tas_frame) + .arg(QString::fromStdString(tas_frames_string)); default: return tr("TAS State: Invalid"); } diff --git a/src/yuzu/main.h b/src/yuzu/main.h index e9c2ecef7..2e9d92da4 100755 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -12,6 +12,7 @@ #include "common/announce_multiplayer_room.h" #include "common/common_types.h" +#include "input_common/drivers/tas_input.h" #include "yuzu/compatibility_list.h" #include "yuzu/hotkeys.h" @@ -266,6 +267,9 @@ private: void changeEvent(QEvent* event) override; void closeEvent(QCloseEvent* event) override; + std::string CreateTASFramesString( + std::array frames) const; + #ifdef __unix__ void SetupSigInterrupts(); static void HandleSigInterrupt(int);