From 8f23a79d36b52c109a7d25e79f72ccc3d4a51b1e Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 24 May 2021 21:17:45 +1000 Subject: [PATCH] CommonHostInterface: Add public method to activate autofire --- src/frontend-common/common_host_interface.cpp | 28 ++++++++++++++++++- src/frontend-common/common_host_interface.h | 4 +++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 4ae269830..ed5e89b26 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1453,6 +1453,31 @@ void CommonHostInterface::SetControllerAutoFireState(u32 controller_index, s32 b } } +void CommonHostInterface::SetControllerAutoFireSlotState(u32 controller_index, u32 slot_index, bool active) +{ + for (ControllerAutoFireState& ts : m_controller_autofires) + { + if (ts.controller_index != controller_index || ts.slot_index != slot_index) + continue; + + if (!active) + { + if (ts.state) + { + Controller* controller = System::GetController(ts.controller_index); + if (controller) + controller->SetButtonState(ts.button_code, false); + } + + ts.state = false; + ts.countdown = ts.frequency; + } + + ts.active = active; + return; + } +} + void CommonHostInterface::UpdateControllerAutoFire() { for (ControllerAutoFireState& ts : m_controller_autofires) @@ -1598,7 +1623,7 @@ void CommonHostInterface::UpdateControllerInputMap(SettingsInterface& si) const std::string binding( si.GetStringValue(category, TinyString::FromFormat("AutoFire%u", turbo_button_index + 1), "")); -#ifdef __ANDROID__ +#ifndef __ANDROID__ // Android doesn't require a binding, since we can trigger it from the touchscreen controller. if (binding.empty()) continue; @@ -1613,6 +1638,7 @@ void CommonHostInterface::UpdateControllerInputMap(SettingsInterface& si) ControllerAutoFireState ts; ts.controller_index = controller_index; + ts.slot_index = turbo_button_index; ts.button_code = button_code.value(); ts.frequency = static_cast( std::clamp(si.GetIntValue(category, TinyString::FromFormat("AutoFire%uFrequency", turbo_button_index + 1), diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index f26e3bed7..0c7e2690b 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -311,6 +311,9 @@ public: /// Controller navigation, used by fullscreen mode. void SetControllerNavigationButtonState(FrontendCommon::ControllerNavigationButton button, bool pressed); + /// Alters autofire state for controllers (activates/deactivates). + void SetControllerAutoFireSlotState(u32 controller_index, u32 slot_index, bool active); + /// Toggles fast forward state. bool IsFastForwardEnabled() const { return m_fast_forward_enabled; } void SetFastForwardEnabled(bool enabled); @@ -535,6 +538,7 @@ private: struct ControllerAutoFireState { u32 controller_index; + u32 slot_index; s32 button_code; u8 frequency; u8 countdown;