Skip to content
Permalink
Browse files

WiimoteEmu: Fix a config change callback causing a crash on exit.

  • Loading branch information...
jordan-woyak committed Mar 9, 2019
1 parent f6b856d commit 224e678cf8e8800cb6c709f7d144b82098b5583b
@@ -11,6 +11,8 @@
#include "Common/ChunkFile.h"
#include "Common/MathUtil.h"
#include "Common/Matrix.h"

#include "Core/Config/SYSCONFSettings.h"
#include "Core/HW/WiimoteCommon/WiimoteReport.h"

namespace WiimoteEmu
@@ -51,7 +53,7 @@ int CameraLogic::BusWrite(u8 slave_addr, u8 addr, int count, const u8* data_in)
return RawWrite(&reg_data, addr, count, data_in);
}

void CameraLogic::Update(const Common::Matrix44& transform, bool sensor_bar_on_top)
void CameraLogic::Update(const Common::Matrix44& transform)
{
using Common::Matrix33;
using Common::Matrix44;
@@ -81,6 +83,9 @@ void CameraLogic::Update(const Common::Matrix44& transform, bool sensor_bar_on_t
// Values are optimized for default settings in "Super Mario Galaxy 2"
// This seems to be acceptable for a good number of games.
constexpr float SENSOR_BAR_LED_SEPARATION = 0.2f;

// Emulate a sensor bar height that matches the config.
const bool sensor_bar_on_top = Config::Get(Config::SYSCONF_SENSOR_BAR_POSITION) != 0;
const float sensor_bar_height = sensor_bar_on_top ? 0.11 : -0.11;

const std::array<Vec3, NUM_POINTS> leds{
@@ -71,7 +71,7 @@ class CameraLogic : public I2CSlave

void Reset();
void DoState(PointerWrap& p);
void Update(const Common::Matrix44& transform, bool sensor_bar_on_top);
void Update(const Common::Matrix44& transform);
void SetEnabled(bool is_enabled);

static constexpr u8 I2C_ADDR = 0x58;
@@ -243,13 +243,6 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
m_hotkeys->AddInput(_trans("Sideways Hold"), false);
m_hotkeys->AddInput(_trans("Upright Hold"), false);

auto config_change_callback = [this] {
m_sensor_bar_on_top = Config::Get(Config::SYSCONF_SENSOR_BAR_POSITION) != 0;
};
Config::AddConfigChangedCallback(config_change_callback);

config_change_callback();

Reset();
}

@@ -439,7 +432,7 @@ void Wiimote::SendDataReport()
// IR Camera:
if (rpt_builder.HasIR())
{
m_camera_logic.Update(GetTransformation(), m_sensor_bar_on_top);
m_camera_logic.Update(GetTransformation());

// The real wiimote reads camera data from the i2c bus starting at offset 0x37:
const u8 camera_data_offset =
@@ -268,9 +268,6 @@ class Wiimote : public ControllerEmu::EmulatedController

bool m_speaker_mute;

// This is just for the IR Camera to compensate for the sensor bar position.
bool m_sensor_bar_on_top;

WiimoteCommon::InputReportStatus m_status;

ExtensionNumber m_active_extension;

0 comments on commit 224e678

Please sign in to comment.
You can’t perform that action at this time.