WiimoteEmu: Update button status from DesiredWiimoteState.

This commit is contained in:
Admiral H. Curtiss 2022-09-17 13:54:17 +02:00
parent 52424fe327
commit a39f82cb1f
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
5 changed files with 43 additions and 22 deletions

View File

@ -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

View File

@ -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

View File

@ -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,13 +442,27 @@ void Wiimote::Update()
// Update our motion simulations.
StepDynamics();
// 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();
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.
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);
}

View File

@ -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(

View File

@ -315,6 +315,7 @@
<ClInclude Include="Core\HW\WiimoteCommon\WiimoteReport.h" />
<ClInclude Include="Core\HW\WiimoteEmu\Camera.h" />
<ClInclude Include="Core\HW\WiimoteEmu\Dynamics.h" />
<ClInclude Include="Core\HW\WiimoteEmu\DesiredWiimoteState.h" />
<ClInclude Include="Core\HW\WiimoteEmu\Encryption.h" />
<ClInclude Include="Core\HW\WiimoteEmu\Extension\Classic.h" />
<ClInclude Include="Core\HW\WiimoteEmu\Extension\DrawsomeTablet.h" />