WiimoteEmu: Update button status from DesiredWiimoteState.
This commit is contained in:
parent
52424fe327
commit
a39f82cb1f
|
@ -279,6 +279,7 @@ add_library(core
|
||||||
HW/WiimoteCommon/WiimoteReport.h
|
HW/WiimoteCommon/WiimoteReport.h
|
||||||
HW/WiimoteEmu/Camera.cpp
|
HW/WiimoteEmu/Camera.cpp
|
||||||
HW/WiimoteEmu/Camera.h
|
HW/WiimoteEmu/Camera.h
|
||||||
|
HW/WiimoteEmu/DesiredWiimoteState.h
|
||||||
HW/WiimoteEmu/Dynamics.cpp
|
HW/WiimoteEmu/Dynamics.cpp
|
||||||
HW/WiimoteEmu/Dynamics.h
|
HW/WiimoteEmu/Dynamics.h
|
||||||
HW/WiimoteEmu/EmuSubroutines.cpp
|
HW/WiimoteEmu/EmuSubroutines.cpp
|
||||||
|
|
|
@ -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
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "Core/HW/WiimoteCommon/WiimoteConstants.h"
|
#include "Core/HW/WiimoteCommon/WiimoteConstants.h"
|
||||||
#include "Core/HW/WiimoteCommon/WiimoteHid.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/Classic.h"
|
||||||
#include "Core/HW/WiimoteEmu/Extension/DrawsomeTablet.h"
|
#include "Core/HW/WiimoteEmu/Extension/DrawsomeTablet.h"
|
||||||
#include "Core/HW/WiimoteEmu/Extension/Drums.h"
|
#include "Core/HW/WiimoteEmu/Extension/Drums.h"
|
||||||
|
@ -427,20 +428,13 @@ bool Wiimote::ProcessExtensionPortEvent()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update buttons in status struct from user input.
|
void Wiimote::UpdateButtonsStatus(const DesiredWiimoteState& target_state)
|
||||||
void Wiimote::UpdateButtonsStatus()
|
|
||||||
{
|
{
|
||||||
m_status.buttons.hex = 0;
|
m_status.buttons.hex = target_state.buttons.hex & ButtonData::BUTTON_MASK;
|
||||||
|
|
||||||
m_buttons->GetState(&m_status.buttons.hex, button_bitmasks);
|
|
||||||
m_dpad->GetState(&m_status.buttons.hex, IsSideways() ? dpad_sideways_bitmasks : dpad_bitmasks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called every ::Wiimote::UPDATE_FREQ (200hz)
|
DesiredWiimoteState Wiimote::BuildDesiredWiimoteState()
|
||||||
void Wiimote::Update()
|
|
||||||
{
|
{
|
||||||
const auto lock = GetStateLock();
|
|
||||||
|
|
||||||
// Hotkey / settings modifier
|
// Hotkey / settings modifier
|
||||||
// Data is later accessed in IsSideways and IsUpright
|
// Data is later accessed in IsSideways and IsUpright
|
||||||
m_hotkeys->UpdateState();
|
m_hotkeys->UpdateState();
|
||||||
|
@ -448,12 +442,26 @@ void Wiimote::Update()
|
||||||
// Update our motion simulations.
|
// Update our motion simulations.
|
||||||
StepDynamics();
|
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.
|
// Update buttons in the status struct which is sent in 99% of input reports.
|
||||||
// FYI: Movies only sync button updates in data reports.
|
UpdateButtonsStatus(target_state);
|
||||||
if (!Core::WantsDeterminism())
|
|
||||||
{
|
|
||||||
UpdateButtonsStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a new extension is requested in the GUI the change will happen here.
|
// If a new extension is requested in the GUI the change will happen here.
|
||||||
HandleExtensionSwap();
|
HandleExtensionSwap();
|
||||||
|
@ -518,12 +526,6 @@ void Wiimote::SendDataReport()
|
||||||
// Core buttons:
|
// Core buttons:
|
||||||
if (rpt_builder.HasCore())
|
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);
|
rpt_builder.SetCoreData(m_status.buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ class Tilt;
|
||||||
|
|
||||||
namespace WiimoteEmu
|
namespace WiimoteEmu
|
||||||
{
|
{
|
||||||
|
struct DesiredWiimoteState;
|
||||||
|
|
||||||
enum class WiimoteGroup
|
enum class WiimoteGroup
|
||||||
{
|
{
|
||||||
Buttons,
|
Buttons,
|
||||||
|
@ -150,7 +152,8 @@ private:
|
||||||
void RefreshConfig();
|
void RefreshConfig();
|
||||||
|
|
||||||
void StepDynamics();
|
void StepDynamics();
|
||||||
void UpdateButtonsStatus();
|
void UpdateButtonsStatus(const DesiredWiimoteState& target_state);
|
||||||
|
DesiredWiimoteState BuildDesiredWiimoteState();
|
||||||
|
|
||||||
// Returns simulated accelerometer data in m/s^2.
|
// Returns simulated accelerometer data in m/s^2.
|
||||||
Common::Vec3 GetAcceleration(
|
Common::Vec3 GetAcceleration(
|
||||||
|
|
|
@ -315,6 +315,7 @@
|
||||||
<ClInclude Include="Core\HW\WiimoteCommon\WiimoteReport.h" />
|
<ClInclude Include="Core\HW\WiimoteCommon\WiimoteReport.h" />
|
||||||
<ClInclude Include="Core\HW\WiimoteEmu\Camera.h" />
|
<ClInclude Include="Core\HW\WiimoteEmu\Camera.h" />
|
||||||
<ClInclude Include="Core\HW\WiimoteEmu\Dynamics.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\Encryption.h" />
|
||||||
<ClInclude Include="Core\HW\WiimoteEmu\Extension\Classic.h" />
|
<ClInclude Include="Core\HW\WiimoteEmu\Extension\Classic.h" />
|
||||||
<ClInclude Include="Core\HW\WiimoteEmu\Extension\DrawsomeTablet.h" />
|
<ClInclude Include="Core\HW\WiimoteEmu\Extension\DrawsomeTablet.h" />
|
||||||
|
|
Loading…
Reference in New Issue