Core: Pass sensor bar state into the Wiimote input calculation functions instead of having it access a global.

This commit is contained in:
Admiral H. Curtiss 2024-01-11 06:02:49 +01:00
parent 115ad82581
commit be7f4ab244
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
7 changed files with 37 additions and 18 deletions

View File

@ -38,8 +38,15 @@ public:
virtual u8 GetWiimoteDeviceIndex() const = 0;
virtual void SetWiimoteDeviceIndex(u8 index) = 0;
enum class SensorBarState : bool
{
Disabled,
Enabled
};
// Called every ~200hz after HID channels are established.
virtual void PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state) = 0;
virtual void PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state,
SensorBarState sensor_bar_state) = 0;
virtual void Update(const WiimoteEmu::DesiredWiimoteState& target_state) = 0;
void SetInterruptCallback(InterruptCallbackType callback) { m_callback = std::move(callback); }

View File

@ -11,7 +11,6 @@
#include "Common/MathUtil.h"
#include "Common/Matrix.h"
#include "Core/HW/WII_IPC.h"
#include "Core/HW/WiimoteCommon/WiimoteReport.h"
namespace WiimoteEmu
@ -111,10 +110,6 @@ void CameraLogic::Update(const std::array<CameraPoint, NUM_POINTS>& camera_point
if (m_reg_data.enable_object_tracking != OBJECT_TRACKING_ENABLE)
return;
// If the sensor bar is off the camera will see no LEDs and return 0xFFs.
if (!IOS::g_gpio_out[IOS::GPIO::SENSOR_BAR])
return;
switch (m_reg_data.mode)
{
case IR_MODE_BASIC:

View File

@ -446,7 +446,8 @@ void Wiimote::UpdateButtonsStatus(const DesiredWiimoteState& target_state)
m_status.buttons.hex = target_state.buttons.hex & ButtonData::BUTTON_MASK;
}
void Wiimote::BuildDesiredWiimoteState(DesiredWiimoteState* target_state)
void Wiimote::BuildDesiredWiimoteState(DesiredWiimoteState* target_state,
SensorBarState sensor_bar_state)
{
// Hotkey / settings modifier
// Data is later accessed in IsSideways and IsUpright
@ -468,10 +469,18 @@ void Wiimote::BuildDesiredWiimoteState(DesiredWiimoteState* target_state)
ConvertAccelData(GetTotalAcceleration(), ACCEL_ZERO_G << 2, ACCEL_ONE_G << 2);
// Calculate IR camera state.
if (sensor_bar_state == SensorBarState::Enabled)
{
target_state->camera_points = CameraLogic::GetCameraPoints(
GetTotalTransformation(),
Common::Vec2(m_fov_x_setting.GetValue(), m_fov_y_setting.GetValue()) / 360 *
float(MathUtil::TAU));
}
else
{
// If the sensor bar is off the camera will see no LEDs and return 0xFFs.
target_state->camera_points = DesiredWiimoteState::DEFAULT_CAMERA;
}
// Calculate MotionPlus state.
if (m_motion_plus_setting.GetValue())
@ -498,10 +507,11 @@ void Wiimote::SetWiimoteDeviceIndex(u8 index)
}
// This is called every ::Wiimote::UPDATE_FREQ (200hz)
void Wiimote::PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state)
void Wiimote::PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state,
SensorBarState sensor_bar_state)
{
const auto lock = GetStateLock();
BuildDesiredWiimoteState(target_state);
BuildDesiredWiimoteState(target_state, sensor_bar_state);
}
void Wiimote::Update(const WiimoteEmu::DesiredWiimoteState& target_state)

View File

@ -156,7 +156,8 @@ public:
u8 GetWiimoteDeviceIndex() const override;
void SetWiimoteDeviceIndex(u8 index) override;
void PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state) override;
void PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state,
SensorBarState sensor_bar_state) override;
void Update(const WiimoteEmu::DesiredWiimoteState& target_state) override;
void EventLinked() override;
void EventUnlinked() override;
@ -187,7 +188,7 @@ private:
void StepDynamics();
void UpdateButtonsStatus(const DesiredWiimoteState& target_state);
void BuildDesiredWiimoteState(DesiredWiimoteState* target_state);
void BuildDesiredWiimoteState(DesiredWiimoteState* target_state, SensorBarState sensor_bar_state);
// Returns simulated accelerometer data in m/s^2.
Common::Vec3 GetAcceleration(Common::Vec3 extra_acceleration) const;

View File

@ -465,7 +465,8 @@ void Wiimote::SetWiimoteDeviceIndex(u8 index)
m_bt_device_index = index;
}
void Wiimote::PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state)
void Wiimote::PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state,
SensorBarState sensor_bar_state)
{
// Nothing to do here on real Wiimotes.
}

View File

@ -67,7 +67,8 @@ public:
u8 GetWiimoteDeviceIndex() const override;
void SetWiimoteDeviceIndex(u8 index) override;
void PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state) override;
void PrepareInput(WiimoteEmu::DesiredWiimoteState* target_state,
SensorBarState sensor_bar_state) override;
void Update(const WiimoteEmu::DesiredWiimoteState& target_state) override;
void EventLinked() override;
void EventUnlinked() override;

View File

@ -18,6 +18,7 @@
#include "Common/StringUtil.h"
#include "Common/Swap.h"
#include "Core/Core.h"
#include "Core/HW/WII_IPC.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteCommon/WiimoteConstants.h"
#include "Core/HW/WiimoteCommon/WiimoteHid.h"
@ -367,7 +368,10 @@ WiimoteDevice::PrepareInput(WiimoteEmu::DesiredWiimoteState* wiimote_state)
const auto* channel = FindChannelWithPSM(L2CAP_PSM_HID_INTR);
if (channel && channel->IsComplete())
{
m_hid_source->PrepareInput(wiimote_state);
m_hid_source->PrepareInput(wiimote_state,
IOS::g_gpio_out[IOS::GPIO::SENSOR_BAR] ?
WiimoteCommon::HIDWiimote::SensorBarState::Enabled :
WiimoteCommon::HIDWiimote::SensorBarState::Disabled);
return NextUpdateInputCall::Update;
}
return NextUpdateInputCall::None;