wiimote code cleaning
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1079 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
e19f01c33b
commit
fafbbdfee5
|
@ -1672,9 +1672,9 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandDisconnect(u8* _Input)
|
||||||
{
|
{
|
||||||
OneShotMessage = false;
|
OneShotMessage = false;
|
||||||
PanicAlert("IPC CommandDisconnect: WiiMote emulation is out of sync.\n"
|
PanicAlert("IPC CommandDisconnect: WiiMote emulation is out of sync.\n"
|
||||||
"This message will be shot one time only, because dolphin\n"
|
"This message will be shot one time only, because dolphin does\n"
|
||||||
"executes the disconnect at all and some times you can play\n"
|
"not executes the disconnect at all and some times you can play\n"
|
||||||
"anyway. It is strongly recommed to save and/or restart the"
|
"anyway. It is strongly recommed to save and/or restart the\n"
|
||||||
"emulation.");
|
"emulation.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,27 @@ namespace WiiMoteReal
|
||||||
{
|
{
|
||||||
#define MAX_WIIMOTES 1
|
#define MAX_WIIMOTES 1
|
||||||
|
|
||||||
|
//******************************************************************************
|
||||||
|
// Forwording
|
||||||
|
//******************************************************************************
|
||||||
|
|
||||||
|
class CWiiMote;
|
||||||
|
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg);
|
||||||
|
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
// Variable declarations
|
// Variable declarations
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
|
|
||||||
|
wiimote_t** g_WiiMotesFromWiiUse = NULL;
|
||||||
|
Common::Thread* g_pReadThread = NULL;
|
||||||
|
int g_NumberOfWiiMotes;
|
||||||
|
CWiiMote* g_WiiMotes[MAX_WIIMOTES];
|
||||||
|
bool g_Shutdown = false;
|
||||||
|
|
||||||
|
//******************************************************************************
|
||||||
|
// Prolly this class should be in its own file
|
||||||
|
//******************************************************************************
|
||||||
|
|
||||||
wiimote_t** m_WiiMotesFromWiiUse = NULL;
|
|
||||||
Common::Thread* g_pReadThread = NULL;
|
|
||||||
Common::CriticalSection* g_pCriticalSection = NULL;
|
|
||||||
bool g_Shutdown = false;
|
|
||||||
|
|
||||||
class CWiiMote
|
class CWiiMote
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -51,7 +63,10 @@ namespace WiiMoteReal
|
||||||
, m_pWiiMote(_pWiimote)
|
, m_pWiiMote(_pWiimote)
|
||||||
, m_LastReportValid(false)
|
, m_LastReportValid(false)
|
||||||
, m_channelID(0)
|
, m_channelID(0)
|
||||||
|
, m_pCriticalSection(NULL)
|
||||||
{
|
{
|
||||||
|
m_pCriticalSection = new Common::CriticalSection();
|
||||||
|
|
||||||
wiiuse_set_leds(m_pWiiMote, WIIMOTE_LED_4);
|
wiiuse_set_leds(m_pWiiMote, WIIMOTE_LED_4);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -61,26 +76,28 @@ namespace WiiMoteReal
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~CWiiMote()
|
virtual ~CWiiMote()
|
||||||
{};
|
{
|
||||||
|
delete m_pCriticalSection;
|
||||||
|
};
|
||||||
|
|
||||||
// send raw HID data from the core to wiimote
|
// send raw HID data from the core to wiimote
|
||||||
void SendData(u16 _channelID, const u8* _pData, u32 _Size)
|
void SendData(u16 _channelID, const u8* _pData, u32 _Size)
|
||||||
{
|
{
|
||||||
m_channelID = _channelID;
|
m_channelID = _channelID;
|
||||||
|
|
||||||
g_pCriticalSection->Enter();
|
m_pCriticalSection->Enter();
|
||||||
{
|
{
|
||||||
SEvent WriteEvent;
|
SEvent WriteEvent;
|
||||||
memcpy(WriteEvent.m_PayLoad, _pData+1, _Size-1);
|
memcpy(WriteEvent.m_PayLoad, _pData+1, _Size-1);
|
||||||
m_EventWriteQueue.push(WriteEvent);
|
m_EventWriteQueue.push(WriteEvent);
|
||||||
}
|
}
|
||||||
g_pCriticalSection->Leave();
|
m_pCriticalSection->Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
// read data from wiimote (but don't send it to the core, just filter and queue)
|
// read data from wiimote (but don't send it to the core, just filter and queue)
|
||||||
void ReadData()
|
void ReadData()
|
||||||
{
|
{
|
||||||
g_pCriticalSection->Enter();
|
m_pCriticalSection->Enter();
|
||||||
|
|
||||||
if (!m_EventWriteQueue.empty())
|
if (!m_EventWriteQueue.empty())
|
||||||
{
|
{
|
||||||
|
@ -89,7 +106,7 @@ namespace WiiMoteReal
|
||||||
m_EventWriteQueue.pop();
|
m_EventWriteQueue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pCriticalSection->Leave();
|
m_pCriticalSection->Leave();
|
||||||
|
|
||||||
if (wiiuse_io_read(m_pWiiMote))
|
if (wiiuse_io_read(m_pWiiMote))
|
||||||
{
|
{
|
||||||
|
@ -98,7 +115,7 @@ namespace WiiMoteReal
|
||||||
// check if we have a channel (connection) if so save the data...
|
// check if we have a channel (connection) if so save the data...
|
||||||
if (m_channelID > 0)
|
if (m_channelID > 0)
|
||||||
{
|
{
|
||||||
g_pCriticalSection->Enter();
|
m_pCriticalSection->Enter();
|
||||||
|
|
||||||
// filter out reports
|
// filter out reports
|
||||||
if (pBuffer[0] >= 0x30)
|
if (pBuffer[0] >= 0x30)
|
||||||
|
@ -113,7 +130,7 @@ namespace WiiMoteReal
|
||||||
m_EventReadQueue.push(ImportantEvent);
|
m_EventReadQueue.push(ImportantEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pCriticalSection->Leave();
|
m_pCriticalSection->Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -121,7 +138,7 @@ namespace WiiMoteReal
|
||||||
// send queued data to the core
|
// send queued data to the core
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
g_pCriticalSection->Enter();
|
m_pCriticalSection->Enter();
|
||||||
|
|
||||||
if (m_EventReadQueue.empty())
|
if (m_EventReadQueue.empty())
|
||||||
{
|
{
|
||||||
|
@ -134,7 +151,7 @@ namespace WiiMoteReal
|
||||||
m_EventReadQueue.pop();
|
m_EventReadQueue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pCriticalSection->Leave();
|
m_pCriticalSection->Leave();
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -153,6 +170,7 @@ namespace WiiMoteReal
|
||||||
u16 m_channelID;
|
u16 m_channelID;
|
||||||
wiimote_t* m_pWiiMote;
|
wiimote_t* m_pWiiMote;
|
||||||
|
|
||||||
|
Common::CriticalSection* m_pCriticalSection;
|
||||||
CEventQueue m_EventReadQueue;
|
CEventQueue m_EventReadQueue;
|
||||||
CEventQueue m_EventWriteQueue;
|
CEventQueue m_EventWriteQueue;
|
||||||
bool m_LastReportValid;
|
bool m_LastReportValid;
|
||||||
|
@ -179,11 +197,6 @@ namespace WiiMoteReal
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int g_NumberOfWiiMotes;
|
|
||||||
CWiiMote* g_WiiMotes[MAX_WIIMOTES];
|
|
||||||
|
|
||||||
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg);
|
|
||||||
|
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
// Function Definitions
|
// Function Definitions
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
|
@ -191,18 +204,17 @@ namespace WiiMoteReal
|
||||||
int Initialize()
|
int Initialize()
|
||||||
{
|
{
|
||||||
memset(g_WiiMotes, 0, sizeof(CWiiMote*) * MAX_WIIMOTES);
|
memset(g_WiiMotes, 0, sizeof(CWiiMote*) * MAX_WIIMOTES);
|
||||||
m_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
|
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
|
||||||
g_NumberOfWiiMotes= wiiuse_find(m_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
|
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
|
||||||
|
|
||||||
for (int i=0; i<g_NumberOfWiiMotes; i++)
|
for (int i=0; i<g_NumberOfWiiMotes; i++)
|
||||||
{
|
{
|
||||||
g_WiiMotes[i] = new CWiiMote(i+1, m_WiiMotesFromWiiUse[i]);
|
g_WiiMotes[i] = new CWiiMote(i+1, g_WiiMotesFromWiiUse[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_NumberOfWiiMotes == 0)
|
if (g_NumberOfWiiMotes == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
g_pCriticalSection = new Common::CriticalSection();
|
|
||||||
g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL);
|
g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -225,8 +237,8 @@ namespace WiiMoteReal
|
||||||
|
|
||||||
delete g_pReadThread;
|
delete g_pReadThread;
|
||||||
g_pReadThread = NULL;
|
g_pReadThread = NULL;
|
||||||
delete g_pCriticalSection;
|
|
||||||
g_pCriticalSection = NULL;
|
wiiuse_cleanup(g_WiiMotesFromWiiUse, g_NumberOfWiiMotes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
|
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
|
||||||
|
|
Loading…
Reference in New Issue