Skip to content
Permalink
Browse files

Merge pull request #7871 from jordan-woyak/wm-real-cleanup

WiimoteReal: Improve state changes and code cleanups.
  • Loading branch information...
JMC47 committed Mar 25, 2019
2 parents 8bad3f9 + 49218c3 commit e636b3e7120a9f6e8899425ec668e1f1f8e40b17
@@ -6,6 +6,7 @@

#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"

#include "Core/ConfigManager.h"
@@ -137,21 +138,29 @@ void Pause()
// An L2CAP packet is passed from the Core to the Wiimote on the HID CONTROL channel.
void ControlChannel(int number, u16 channel_id, const void* data, u32 size)
{
if (g_wiimote_sources[number])
if (WIIMOTE_SRC_EMU == g_wiimote_sources[number])
{
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))
->ControlChannel(channel_id, data, size);
}
else
{
WiimoteReal::ControlChannel(number, channel_id, data, size);
}
}

// An L2CAP packet is passed from the Core to the Wiimote on the HID INTERRUPT channel.
void InterruptChannel(int number, u16 channel_id, const void* data, u32 size)
{
if (g_wiimote_sources[number])
if (WIIMOTE_SRC_EMU == g_wiimote_sources[number])
{
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))
->InterruptChannel(channel_id, data, size);
}
else
{
WiimoteReal::InterruptChannel(number, channel_id, data, size);
}
}

bool ButtonPressed(int number)
@@ -215,6 +224,26 @@ unsigned int GetAttached()
void DoState(PointerWrap& p)
{
for (int i = 0; i < MAX_BBMOTES; ++i)
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->DoState(p);
{
auto state_wiimote_source = u8(g_wiimote_sources[i]);
p.Do(state_wiimote_source);

if (WIIMOTE_SRC_EMU == state_wiimote_source)
{
// Sync complete state of emulated wiimotes.
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->DoState(p);
}

if (p.GetMode() == PointerWrap::MODE_READ)
{
// If using a real wiimote or the save-state source does not match the current source,
// then force a reconnection on load.
if (WIIMOTE_SRC_REAL == g_wiimote_sources[i] || state_wiimote_source != g_wiimote_sources[i])
{
Connect(i, false);
Connect(i, true);
}
}
}
}
} // namespace Wiimote
@@ -4,6 +4,9 @@

#pragma once

#include <array>
#include <atomic>

#include "Common/Common.h"
#include "Common/CommonTypes.h"

@@ -45,7 +48,7 @@ enum
WIIMOTE_SRC_REAL = 2,
};

extern unsigned int g_wiimote_sources[MAX_BBMOTES];
extern std::array<std::atomic<u32>, MAX_BBMOTES> g_wiimote_sources;

namespace Wiimote
{
@@ -590,24 +590,11 @@ void Wiimote::DoState(PointerWrap& p)
p.Do(m_shake_step);

p.DoMarker("Wiimote");

if (p.GetMode() == PointerWrap::MODE_READ)
RealState();
}

ExtensionNumber Wiimote::GetActiveExtensionNumber() const
{
return m_active_extension;
}

void Wiimote::RealState()
{
using namespace WiimoteReal;

if (g_wiimotes[m_index])
{
g_wiimotes[m_index]->SetChannel(m_reporting_channel);
}
}

} // namespace WiimoteEmu
@@ -20,6 +20,7 @@
#include "Core/Config/WiimoteInputSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/Wiimote.h"
#include "Core/Movie.h"
#include "Core/NetPlayClient.h"

@@ -30,7 +31,6 @@
#include "Core/HW/WiimoteEmu/Extension/Guitar.h"
#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h"
#include "Core/HW/WiimoteEmu/Extension/Turntable.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"

#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/Control/Output.h"
@@ -503,14 +503,6 @@ void Wiimote::ControlChannel(const u16 channel_id, const void* data, u32 size)

m_reporting_channel = channel_id;

// FYI: ControlChannel is piped through WiimoteEmu before WiimoteReal just so we can sync the
// channel on state load. This is ugly.
if (WIIMOTE_SRC_REAL == g_wiimote_sources[m_index])
{
WiimoteReal::ControlChannel(m_index, channel_id, data, size);
return;
}

const auto& hidp = *reinterpret_cast<const HIDPacket*>(data);

DEBUG_LOG(WIIMOTE, "Emu ControlChannel (page: %i, type: 0x%02x, param: 0x%02x)", m_index,
@@ -559,14 +551,6 @@ void Wiimote::InterruptChannel(const u16 channel_id, const void* data, u32 size)

m_reporting_channel = channel_id;

// FYI: InterruptChannel is piped through WiimoteEmu before WiimoteReal just so we can sync the
// channel on state load. This is ugly.
if (WIIMOTE_SRC_REAL == g_wiimote_sources[m_index])
{
WiimoteReal::InterruptChannel(m_index, channel_id, data, size);
return;
}

const auto& hidp = *reinterpret_cast<const HIDPacket*>(data);

switch (hidp.type)
@@ -35,12 +35,6 @@ class Output;
class Tilt;
} // namespace ControllerEmu

// Needed for friendship:
namespace WiimoteReal
{
class Wiimote;
} // namespace WiimoteReal

namespace WiimoteEmu
{
enum class WiimoteGroup
@@ -87,8 +81,6 @@ void UpdateCalibrationDataChecksum(T& data, int cksum_bytes)

class Wiimote : public ControllerEmu::EmulatedController
{
friend class WiimoteReal::Wiimote;

public:
enum : u8
{
@@ -173,8 +165,6 @@ class Wiimote : public ControllerEmu::EmulatedController
void SendDataReport();
bool ProcessReadDataRequest();

void RealState();

void SetRumble(bool on);

void CallbackInterruptChannel(const u8* data, u32 size);
@@ -284,7 +284,7 @@ - (void)l2capChannelData:(IOBluetoothL2CAPChannel*)l2capChannel

for (int i = 0; i < MAX_WIIMOTES; i++)
{
wm = static_cast<WiimoteReal::WiimoteDarwin*>(WiimoteReal::g_wiimotes[i]);
wm = static_cast<WiimoteReal::WiimoteDarwin*>(WiimoteReal::g_wiimotes[i].get());
if (!wm)
continue;
if ([device isEqual:wm->m_btd])
@@ -325,7 +325,7 @@ - (void)l2capChannelClosed:(IOBluetoothL2CAPChannel*)l2capChannel

for (int i = 0; i < MAX_WIIMOTES; i++)
{
wm = static_cast<WiimoteReal::WiimoteDarwin*>(WiimoteReal::g_wiimotes[i]);
wm = static_cast<WiimoteReal::WiimoteDarwin*>(WiimoteReal::g_wiimotes[i].get());
if (!wm)
continue;
if ([device isEqual:wm->m_btd])

0 comments on commit e636b3e

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