Skip to content

Commit

Permalink
InputConfig: Clean up controller management
Browse files Browse the repository at this point in the history
  • Loading branch information
lioncash committed Nov 19, 2015
1 parent 59b54a7 commit b997569
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 171 deletions.
26 changes: 11 additions & 15 deletions Source/Core/Core/HW/GCKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,22 @@ InputConfig* GetConfig()

void Shutdown()
{
std::vector<ControllerEmu*>::const_iterator
i = s_config.controllers.begin(),
e = s_config.controllers.end();
for ( ; i!=e; ++i )
delete *i;
s_config.controllers.clear();
s_config.ClearControllers();

g_controller_interface.Shutdown();
}

// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd)
{
if (s_config.controllers.empty())
if (s_config.ControllersNeedToBeCreated())
{
for (unsigned int i = 0; i < 4; ++i)
s_config.controllers.push_back(new GCKeyboard(i));
s_config.CreateController<GCKeyboard>(i);
}

g_controller_interface.Initialize(hwnd);

// load the saved controller config
// Load the saved controller config
s_config.LoadConfig(true);
}

Expand All @@ -50,13 +46,13 @@ void LoadConfig()
s_config.LoadConfig(true);
}

void GetStatus(u8 _port, KeyboardStatus* _pKeyboardStatus)
void GetStatus(u8 port, KeyboardStatus* keyboard_status)
{
memset(_pKeyboardStatus, 0, sizeof(*_pKeyboardStatus));
_pKeyboardStatus->err = PAD_ERR_NONE;
memset(keyboard_status, 0, sizeof(*keyboard_status));
keyboard_status->err = PAD_ERR_NONE;

// get input
((GCKeyboard*)s_config.controllers[_port])->GetInput(_pKeyboardStatus);
// Get input
static_cast<GCKeyboard*>(s_config.GetController(port))->GetInput(keyboard_status);
}

}
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/GCKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ void LoadConfig();

InputConfig* GetConfig();

void GetStatus(u8 _port, KeyboardStatus* _pKeyboardStatus);
void GetStatus(u8 port, KeyboardStatus* keyboard_status);

}
43 changes: 19 additions & 24 deletions Source/Core/Core/HW/GCPad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@ InputConfig* GetConfig()

void Shutdown()
{
std::vector<ControllerEmu*>::const_iterator
i = s_config.controllers.begin(),
e = s_config.controllers.end();
for ( ; i!=e; ++i )
delete *i;
s_config.controllers.clear();
s_config.ClearControllers();

g_controller_interface.Shutdown();
}

// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd)
{
// add 4 gcpads
if (s_config.controllers.empty())
if (s_config.ControllersNeedToBeCreated())
{
for (unsigned int i = 0; i < 4; ++i)
s_config.controllers.push_back(new GCPad(i));
s_config.CreateController<GCPad>(i);
}

g_controller_interface.Initialize(hwnd);

// load the saved controller config
// Load the saved controller config
s_config.LoadConfig(true);
}

Expand All @@ -53,31 +48,31 @@ void LoadConfig()
}


void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus)
void GetStatus(u8 pad_num, GCPadStatus* pad_status)
{
memset(_pPADStatus, 0, sizeof(*_pPADStatus));
_pPADStatus->err = PAD_ERR_NONE;
memset(pad_status, 0, sizeof(*pad_status));
pad_status->err = PAD_ERR_NONE;

// if we are on the next input cycle, update output and input
static int _last_numPAD = 4;
if (_numPAD <= _last_numPAD)
// If we are on the next input cycle, update output and input
static int last_pad_num = 4;
if (pad_num <= last_pad_num)
{
g_controller_interface.UpdateInput();
}
_last_numPAD = _numPAD;
last_pad_num = pad_num;

// get input
((GCPad*)s_config.controllers[_numPAD])->GetInput(_pPADStatus);
// Get input
static_cast<GCPad*>(s_config.GetController(pad_num))->GetInput(pad_status);
}

void Rumble(u8 _numPAD, const ControlState strength)
void Rumble(const u8 pad_num, const ControlState strength)
{
((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(strength);
static_cast<GCPad*>(s_config.GetController(pad_num))->SetOutput(strength);
}

bool GetMicButton(u8 pad)
bool GetMicButton(const u8 pad_num)
{
return ((GCPad*)s_config.controllers[pad])->GetMicButton();
return static_cast<GCPad*>(s_config.GetController(pad_num))->GetMicButton();
}

}
6 changes: 3 additions & 3 deletions Source/Core/Core/HW/GCPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void LoadConfig();

InputConfig* GetConfig();

void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus);
void Rumble(u8 _numPAD, const ControlState strength);
void GetStatus(u8 pad_num, GCPadStatus* pad_status);
void Rumble(u8 pad_num, ControlState strength);

bool GetMicButton(u8 pad);
bool GetMicButton(u8 pad_num);
}
110 changes: 31 additions & 79 deletions Source/Core/Core/HW/Wiimote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,28 @@ InputConfig* GetConfig()

void Shutdown()
{
for (const ControllerEmu* i : s_config.controllers)
{
delete i;
}
s_config.controllers.clear();
s_config.ClearControllers();

WiimoteReal::Stop();

g_controller_interface.Shutdown();
}

// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd, bool wait)
{
// add 4 Wiimotes
if (s_config.controllers.empty())
if (s_config.ControllersNeedToBeCreated())
{
for (unsigned int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i)
s_config.controllers.push_back(new WiimoteEmu::Wiimote(i));
s_config.CreateController<WiimoteEmu::Wiimote>(i);
}

g_controller_interface.Initialize(hwnd);

s_config.LoadConfig(false);

WiimoteReal::Initialize(wait);

// reload Wiimotes with our settings
// Reload Wiimotes with our settings
if (Movie::IsMovieActive())
Movie::ChangeWiiPads();
}
Expand All @@ -72,104 +68,60 @@ void Pause()
}


// __________________________________________________________________________________________________
// Function: ControlChannel
// Purpose: An L2CAP packet is passed from the Core to the Wiimote,
// on the HID CONTROL channel.
//
// Inputs: _number [Description needed]
// _channelID [Description needed]
// _pData [Description needed]
// _Size [Description needed]
//
// Output: none
//
void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
// 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 (WIIMOTE_SRC_HYBRID & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->ControlChannel(_channelID, _pData, _Size);
if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[number])
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->ControlChannel(channel_id, data, size);
}

// __________________________________________________________________________________________________
// Function: InterruptChannel
// Purpose: An L2CAP packet is passed from the Core to the Wiimote,
// on the HID INTERRUPT channel.
//
// Inputs: _number [Description needed]
// _channelID [Description needed]
// _pData [Description needed]
// _Size [Description needed]
//
// Output: none
//
void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _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 (WIIMOTE_SRC_HYBRID & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->InterruptChannel(_channelID, _pData, _Size);
if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[number])
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->InterruptChannel(channel_id, data, size);
}

// __________________________________________________________________________________________________
// Function: Update
// Purpose: This function is called periodically by the Core. // TODO: Explain why.
// input: _number: [Description needed]
// output: none
//
void Update(int _number, bool _connected)
// This function is called periodically by the Core to update Wiimote state.
void Update(int number, bool connected)
{
if (_connected)
if (connected)
{
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->Update();
if (WIIMOTE_SRC_EMU & g_wiimote_sources[number])
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->Update();
else
WiimoteReal::Update(_number);
WiimoteReal::Update(number);
}
else
{
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->ConnectOnInput();
if (WIIMOTE_SRC_REAL & g_wiimote_sources[_number])
WiimoteReal::ConnectOnInput(_number);
if (WIIMOTE_SRC_EMU & g_wiimote_sources[number])
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(number))->ConnectOnInput();

if (WIIMOTE_SRC_REAL & g_wiimote_sources[number])
WiimoteReal::ConnectOnInput(number);
}
}

// __________________________________________________________________________________________________
// Function: GetAttached
// Purpose: Get mask of attached pads (eg: controller 1 & 4 -> 0x9)
// input: none
// output: The number of attached pads
//
// Get a mask of attached the pads (eg: controller 1 & 4 -> 0x9)
unsigned int GetAttached()
{
unsigned int attached = 0;
for (unsigned int i=0; i<MAX_BBMOTES; ++i)
for (unsigned int i = 0; i < MAX_BBMOTES; ++i)
if (g_wiimote_sources[i])
attached |= (1 << i);
return attached;
}

// ___________________________________________________________________________
// Function: DoState
// Purpose: Saves/load state
// input/output: ptr: [Description Needed]
// input: mode [Description needed]
//
// Save/Load state
void DoState(PointerWrap& p)
{
// TODO:

for (unsigned int i=0; i<MAX_BBMOTES; ++i)
((WiimoteEmu::Wiimote*)s_config.controllers[i])->DoState(p);
for (int i = 0; i < MAX_BBMOTES; ++i)
static_cast<WiimoteEmu::Wiimote*>(s_config.GetController(i))->DoState(p);
}

// ___________________________________________________________________________
// Function: EmuStateChange
// Purpose: Notifies the plugin of a change in emulation state
// input: newState - The new state for the Wiimote to change to.
// output: none
//
// Notifies the plugin of a change in emulation state
void EmuStateChange(EMUSTATE_CHANGE newState)
{
// TODO
WiimoteReal::StateChange(newState);
}

Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/HW/WiimoteReal/IONix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <bluetooth/hci_lib.h>
#include <bluetooth/l2cap.h>

#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"

namespace WiimoteReal
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/HW/WiimoteReal/IOWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Common/StringUtil.h"
#include "Common/Thread.h"

#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"

//#define AUTHENTICATE_WIIMOTES
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/WiimoteReal/IOdarwin.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#define BLUETOOTH_VERSION_USE_CURRENT

#include "Common/Common.h"
#include "Common/Logging/Log.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"

@interface SearchBT: NSObject {
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include "Common/Timer.h"
#include "Core/ConfigManager.h"
#include "Core/Host.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "InputCommon/InputConfig.h"

#include "SFML/Network.hpp"

Expand Down Expand Up @@ -153,7 +155,7 @@ void Wiimote::InterruptChannel(const u16 channel, const void* const _data, const

auto const data = static_cast<const u8*>(_data);
Report rpt(data, data + size);
WiimoteEmu::Wiimote *const wm = (WiimoteEmu::Wiimote*)::Wiimote::GetConfig()->controllers[m_index];
WiimoteEmu::Wiimote* const wm = static_cast<WiimoteEmu::Wiimote*>(::Wiimote::GetConfig()->GetController(m_index));

// Convert output DATA packets to SET_REPORT packets.
// Nintendo Wiimotes work without this translation, but 3rd
Expand Down Expand Up @@ -382,7 +384,7 @@ void Wiimote::EmuStop()

void Wiimote::EmuResume()
{
WiimoteEmu::Wiimote *const wm = (WiimoteEmu::Wiimote*)::Wiimote::GetConfig()->controllers[m_index];
WiimoteEmu::Wiimote* const wm = static_cast<WiimoteEmu::Wiimote*>(::Wiimote::GetConfig()->GetController(m_index));

m_last_input_report.clear();

Expand Down
3 changes: 0 additions & 3 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include "Common/NonCopyable.h"
#include "Common/Timer.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/WiimoteRealBase.h"
#include "InputCommon/InputConfig.h"

class PointerWrap;

Expand All @@ -29,7 +27,6 @@ namespace WiimoteReal

class Wiimote : NonCopyable
{
friend class WiimoteEmu::Wiimote;
public:
virtual ~Wiimote() {}
// This needs to be called in derived destructors!
Expand Down

0 comments on commit b997569

Please sign in to comment.