summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2024-01-11 06:02:49 +0100
committerAdmiral H. Curtiss <pikachu025@gmail.com>2024-01-11 06:02:49 +0100
commitbe7f4ab2447fe06c8a0845c8400557dec27df8a3 (patch)
tree543d80d25dc342dd8552ebb5f590e2d07e268049 /Source/Core
parent115ad825813d76e3ac8bd8aaab0d110c3fe378ad (diff)
Core: Pass sensor bar state into the Wiimote input calculation functions instead of having it access a global.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/HW/WiimoteCommon/WiimoteHid.h9
-rw-r--r--Source/Core/Core/HW/WiimoteEmu/Camera.cpp5
-rw-r--r--Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp24
-rw-r--r--Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h5
-rw-r--r--Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp3
-rw-r--r--Source/Core/Core/HW/WiimoteReal/WiimoteReal.h3
-rw-r--r--Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp6
7 files changed, 37 insertions, 18 deletions
diff --git a/Source/Core/Core/HW/WiimoteCommon/WiimoteHid.h b/Source/Core/Core/HW/WiimoteCommon/WiimoteHid.h
index 0b3b5d37d6..dd284ab625 100644
--- a/Source/Core/Core/HW/WiimoteCommon/WiimoteHid.h
+++ b/Source/Core/Core/HW/WiimoteCommon/WiimoteHid.h
@@ -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); }
diff --git a/Source/Core/Core/HW/WiimoteEmu/Camera.cpp b/Source/Core/Core/HW/WiimoteEmu/Camera.cpp
index fb79f12702..593c7bc87f 100644
--- a/Source/Core/Core/HW/WiimoteEmu/Camera.cpp
+++ b/Source/Core/Core/HW/WiimoteEmu/Camera.cpp
@@ -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:
diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
index 59433f8798..1baccc4e81 100644
--- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
+++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
@@ -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)
diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
index fcfad80fa7..f6cfab90d7 100644
--- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
+++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
@@ -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;
diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
index abd90979f7..213873b61c 100644
--- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
+++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
@@ -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.
}
diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h
index eccf7bb22d..aa59202daa 100644
--- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h
+++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h
@@ -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;
diff --git a/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp b/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp
index 18d24c9feb..b92123796b 100644
--- a/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp
+++ b/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp
@@ -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;