Skip to content

Commit

Permalink
WiimoteEmu: Update button status from DesiredWiimoteState.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss committed Oct 2, 2022
1 parent 52424fe commit a39f82c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
1 change: 1 addition & 0 deletions Source/Core/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.h
Original file line number Diff line number Diff line change
@@ -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
44 changes: 23 additions & 21 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -427,33 +428,40 @@ 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();

// 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();
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 4 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Tilt;

namespace WiimoteEmu
{
struct DesiredWiimoteState;

enum class WiimoteGroup
{
Buttons,
Expand Down Expand Up @@ -150,7 +152,8 @@ class Wiimote : public ControllerEmu::EmulatedController, public WiimoteCommon::
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(
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinLib.props
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down

0 comments on commit a39f82c

Please sign in to comment.