diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index fe7b849782..ff5337e9dd 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -279,6 +279,7 @@ add_library(core HW/WiimoteCommon/WiimoteReport.h HW/WiimoteEmu/Camera.cpp HW/WiimoteEmu/Camera.h + HW/WiimoteEmu/DesiredWiimoteState.h HW/WiimoteEmu/Dynamics.cpp HW/WiimoteEmu/Dynamics.h HW/WiimoteEmu/EmuSubroutines.cpp diff --git a/Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.h b/Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.h new file mode 100644 index 0000000000..7a3e493603 --- /dev/null +++ b/Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.h @@ -0,0 +1,14 @@ +// Copyright 2022 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "Core/HW/WiimoteCommon/WiimoteReport.h" + +namespace WiimoteEmu +{ +struct DesiredWiimoteState +{ + WiimoteCommon::ButtonData buttons{}; // non-button state in this is ignored +}; +} // namespace WiimoteEmu diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index ca071a5e10..c30163017f 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -25,6 +25,7 @@ #include "Core/HW/WiimoteCommon/WiimoteConstants.h" #include "Core/HW/WiimoteCommon/WiimoteHid.h" +#include "Core/HW/WiimoteEmu/DesiredWiimoteState.h" #include "Core/HW/WiimoteEmu/Extension/Classic.h" #include "Core/HW/WiimoteEmu/Extension/DrawsomeTablet.h" #include "Core/HW/WiimoteEmu/Extension/Drums.h" @@ -427,20 +428,13 @@ bool Wiimote::ProcessExtensionPortEvent() return true; } -// Update buttons in status struct from user input. -void Wiimote::UpdateButtonsStatus() +void Wiimote::UpdateButtonsStatus(const DesiredWiimoteState& target_state) { - m_status.buttons.hex = 0; - - m_buttons->GetState(&m_status.buttons.hex, button_bitmasks); - m_dpad->GetState(&m_status.buttons.hex, IsSideways() ? dpad_sideways_bitmasks : dpad_bitmasks); + m_status.buttons.hex = target_state.buttons.hex & ButtonData::BUTTON_MASK; } -// This is called every ::Wiimote::UPDATE_FREQ (200hz) -void Wiimote::Update() +DesiredWiimoteState Wiimote::BuildDesiredWiimoteState() { - const auto lock = GetStateLock(); - // Hotkey / settings modifier // Data is later accessed in IsSideways and IsUpright m_hotkeys->UpdateState(); @@ -448,12 +442,26 @@ void Wiimote::Update() // Update our motion simulations. StepDynamics(); + DesiredWiimoteState wiimote_state; + + // Fetch pressed buttons from user input. + m_buttons->GetState(&wiimote_state.buttons.hex, button_bitmasks); + m_dpad->GetState(&wiimote_state.buttons.hex, + IsSideways() ? dpad_sideways_bitmasks : dpad_bitmasks); + + return wiimote_state; +} + +// This is called every ::Wiimote::UPDATE_FREQ (200hz) +void Wiimote::Update() +{ + const auto lock = GetStateLock(); + + // Build target state. + auto target_state = BuildDesiredWiimoteState(); + // Update buttons in the status struct which is sent in 99% of input reports. - // FYI: Movies only sync button updates in data reports. - if (!Core::WantsDeterminism()) - { - UpdateButtonsStatus(); - } + UpdateButtonsStatus(target_state); // If a new extension is requested in the GUI the change will happen here. HandleExtensionSwap(); @@ -518,12 +526,6 @@ void Wiimote::SendDataReport() // Core buttons: if (rpt_builder.HasCore()) { - if (Core::WantsDeterminism()) - { - // When running non-deterministically we've already updated buttons in Update() - UpdateButtonsStatus(); - } - rpt_builder.SetCoreData(m_status.buttons); } diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index ae51b04ace..5a54b66b40 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -37,6 +37,8 @@ class Tilt; namespace WiimoteEmu { +struct DesiredWiimoteState; + enum class WiimoteGroup { Buttons, @@ -150,7 +152,8 @@ private: void RefreshConfig(); void StepDynamics(); - void UpdateButtonsStatus(); + void UpdateButtonsStatus(const DesiredWiimoteState& target_state); + DesiredWiimoteState BuildDesiredWiimoteState(); // Returns simulated accelerometer data in m/s^2. Common::Vec3 GetAcceleration( diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index e0c8baf5ab..73b5bd61d0 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -315,6 +315,7 @@ +