Core: Pass sensor bar state into the Wiimote input calculation functions instead of having it access a global.
This commit is contained in:
parent
115ad82581
commit
be7f4ab244
|
@ -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); }
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.
|
||||
target_state->camera_points = CameraLogic::GetCameraPoints(
|
||||
GetTotalTransformation(),
|
||||
Common::Vec2(m_fov_x_setting.GetValue(), m_fov_y_setting.GetValue()) / 360 *
|
||||
float(MathUtil::TAU));
|
||||
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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue