Re-worked multiple reall wiimotes... Now it looks a lot better! :P

Fixes a crash when the slot selected to use Real WiiMote is greater than the number of Reall WiiMotes connected...

For example: We have 1 Real WiiMote connected, and the user selects the 4th WiiMote as Real WiiMote...

Also Let's you choose between Inactive and Emulated when the game is running... But you must disconnect and connect the wiimote for the emulated to start working (Via Menu -> Tools -> Connect)

I'm trying to figure out a way of allowing change to Real WiiMote while the game is running... It can be done when the game is paused, but I can't find a way of detecting if the game is paused =\

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4771 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
fgfemperor 2010-01-01 16:50:11 +00:00
parent 746b9eeaab
commit 492e44dcb1
7 changed files with 187 additions and 97 deletions

View File

@ -271,8 +271,6 @@ void Config::Load()
iniFile.Get("Real", "AccNunNeutralY", &iAccNunNeutralY, 0);
iniFile.Get("Real", "AccNunNeutralZ", &iAccNunNeutralZ, 0);
g_Config.bNumberEmuWiimotes = g_Config.bNumberRealWiimotes = 0;
for (int i = 0; i < MAX_WIIMOTES; i++)
{
// Slot specific settings
@ -281,10 +279,6 @@ void Config::Load()
// General
iniFile.Get(SectionName, "Source", &WiiMoteEmu::WiiMapping[i].Source, (i == 0) ? 1 : 0);
if (WiiMoteEmu::WiiMapping[i].Source == 1)
g_Config.bNumberEmuWiimotes++;
else if (WiiMoteEmu::WiiMapping[i].Source == 2)
g_Config.bNumberRealWiimotes++;
iniFile.Get(SectionName, "Sideways", &WiiMoteEmu::WiiMapping[i].bSideways, false);
iniFile.Get(SectionName, "Upright", &WiiMoteEmu::WiiMapping[i].bUpright, false);

View File

@ -29,6 +29,7 @@ BEGIN_EVENT_TABLE(WiimoteBasicConfigDialog,wxDialog)
EVT_CLOSE(WiimoteBasicConfigDialog::OnClose)
EVT_BUTTON(ID_OK, WiimoteBasicConfigDialog::ButtonClick)
EVT_BUTTON(ID_CANCEL, WiimoteBasicConfigDialog::ButtonClick)
EVT_BUTTON(ID_REFRESH_REAL, WiimoteBasicConfigDialog::ButtonClick)
EVT_BUTTON(ID_BUTTONMAPPING, WiimoteBasicConfigDialog::ButtonClick)
EVT_BUTTON(ID_BUTTONRECORDING, WiimoteBasicConfigDialog::ButtonClick)
EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, WiimoteBasicConfigDialog::NotebookPageChanged)
@ -62,7 +63,7 @@ WiimoteBasicConfigDialog::WiimoteBasicConfigDialog(wxWindow *parent, wxWindowID
m_bEnableUseRealWiimote = true;
// Initialize the Real WiiMotes here, so we get a count of how many were found and set everything properly
if (!g_RealWiiMoteInitialized && g_Config.bConnectRealWiimote)
if (!g_RealWiiMoteInitialized)
WiiMoteReal::Initialize();
CreateGUIControls();
@ -75,10 +76,6 @@ void WiimoteBasicConfigDialog::OnClose(wxCloseEvent& event)
UpdateGUI();
g_FrameOpen = false;
EndModal(wxID_CLOSE);
// Shutdown Real WiiMotes so everything is set properly before the game starts
if (g_RealWiiMoteInitialized && !g_EmulatorRunning)
WiiMoteReal::Shutdown();
}
void WiimoteBasicConfigDialog::ButtonClick(wxCommandEvent& event)
@ -86,6 +83,7 @@ void WiimoteBasicConfigDialog::ButtonClick(wxCommandEvent& event)
switch(event.GetId())
{
case ID_OK:
WiiMoteReal::Allocate();
g_Config.Save();
Close();
break;
@ -109,6 +107,9 @@ void WiimoteBasicConfigDialog::ButtonClick(wxCommandEvent& event)
m_RecordingConfigFrame->Destroy();
m_RecordingConfigFrame = NULL;
break;
case ID_REFRESH_REAL:
DoRefreshReal();
break;
}
}
@ -147,7 +148,10 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
m_Extension[i] = new wxChoice(m_Controller[i], IDC_EXTCONNECTED, wxDefaultPosition, wxDefaultSize, arrayStringFor_extension, 0, wxDefaultValidator);
m_ConnectRealWiimote[i] = new wxCheckBox(m_Controller[i], IDC_CONNECT_REAL, wxT("Connect Real Wiimote"));
m_ConnectRealWiimote[i]->SetToolTip(wxT("Connected to the real wiimote. This can not be changed during gameplay."));
m_ConnectRealWiimote[i]->SetToolTip(wxT("Connected to the Real WiiMote(s). This can not be changed during gameplay."));
m_FoundWiimote[i] = new wxStaticText(m_Controller[i], ID_FOUND_REAL, wxT("Found 0 WiiMotes"));
m_RefreshRealWiiMote[i] = new wxButton(m_Controller[i], ID_REFRESH_REAL, wxT("Refresh Real WiiMotes"));
m_RefreshRealWiiMote[i]->SetToolTip(wxT("Reconnect to all Real WiiMotes. This is useful if you recently connected another one."));
//IR Pointer
m_TextScreenWidth[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Width: 000"));
@ -183,6 +187,8 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
m_SizeReal[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("Real Wiimote"));
m_SizeReal[i]->Add(m_ConnectRealWiimote[i], 0, wxEXPAND | wxALL, 5);
m_SizeReal[i]->Add(m_FoundWiimote[i], 0, wxEXPAND | wxALL, 5);
m_SizeReal[i]->Add(m_RefreshRealWiiMote[i], 0, wxEXPAND | wxALL, 5);
m_SizerIRPointerWidth[i] = new wxBoxSizer(wxHORIZONTAL);
m_SizerIRPointerWidth[i]->Add(m_TextScreenLeft[i], 0, wxEXPAND | (wxTOP), 3);
@ -273,7 +279,10 @@ void WiimoteBasicConfigDialog::DoConnectReal()
if(g_Config.bConnectRealWiimote)
{
if (!g_RealWiiMoteInitialized)
{
WiiMoteReal::Initialize();
UpdateGUI();
}
}
else
{
@ -284,9 +293,22 @@ void WiimoteBasicConfigDialog::DoConnectReal()
}
}
void WiimoteBasicConfigDialog::DoRefreshReal()
{
if(!g_Config.bConnectRealWiimote || g_EmulatorRunning)
return;
if (g_RealWiiMoteInitialized)
WiiMoteReal::Shutdown();
if (!g_RealWiiMoteInitialized)
{
WiiMoteReal::Initialize();
UpdateGUI();;
}
}
void WiimoteBasicConfigDialog::DoUseReal()
{
if (!g_RealWiiMotePresent || !g_Config.bConnectRealWiimote)
if (!g_RealWiiMotePresent)
return;
// Clear any eventual events in the Wiimote queue
@ -353,27 +375,28 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
switch (event.GetId())
{
case IDC_CONNECT_REAL:
g_Config.bConnectRealWiimote = m_ConnectRealWiimote[m_Page]->IsChecked();
DoConnectReal();
if(!g_EmulatorRunning)
{
g_Config.bConnectRealWiimote = m_ConnectRealWiimote[m_Page]->IsChecked();
DoConnectReal();
}
break;
case IDC_INPUT_SOURCE:
WiiMoteEmu::WiiMapping[m_Page].Source = m_InputSource[m_Page]->GetSelection();
if (WiiMoteEmu::WiiMapping[m_Page].Source == 2)
if (m_InputSource[m_Page]->GetSelection() == 2)
{
int current_real = 0;
for (int i = 0; i < MAX_WIIMOTES; i++)
if (WiiMoteEmu::WiiMapping[i].Source == 2)
current_real++;
if (current_real > WiiMoteReal::g_NumberOfWiiMotes)
if(!g_EmulatorRunning)
{
PanicAlert("You've already assigned all your %i Real WiiMote(s) connected!", WiiMoteReal::g_NumberOfWiiMotes);
WiiMoteEmu::WiiMapping[m_Page].Source = 0;
WiiMoteEmu::WiiMapping[m_Page].Source = 2;
DoUseReal();
}
else
{
DoUseReal();
PanicAlert("You can't change to Real WiiMote when a game is running!");
WiiMoteEmu::WiiMapping[m_Page].Source = 0;
}
}
else
WiiMoteEmu::WiiMapping[m_Page].Source = m_InputSource[m_Page]->GetSelection();
break;
case IDC_SIDEWAYSWIIMOTE:
WiiMoteEmu::WiiMapping[m_Page].bSideways = m_SidewaysWiimote[m_Page]->IsChecked();
@ -431,6 +454,13 @@ void WiimoteBasicConfigDialog::UpdateGUI()
could possibly be simplified to one option. */
m_ConnectRealWiimote[m_Page]->SetValue(g_Config.bConnectRealWiimote);
m_ConnectRealWiimote[m_Page]->Enable(!g_EmulatorRunning);
m_RefreshRealWiiMote[m_Page]->Enable(!g_EmulatorRunning && g_Config.bConnectRealWiimote);
wxString Found;
if(g_Config.bConnectRealWiimote)
Found.Printf(wxT("Connected to %i Real WiiMote(s)"), WiiMoteReal::g_NumberOfWiiMotes);
else
Found.Printf(wxT("Not connected to Real WiiMotes"));
m_FoundWiimote[m_Page]->SetLabel(Found);
m_InputSource[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].Source);
if (WiiMoteEmu::WiiMapping[m_Page].Source == 2)

View File

@ -65,7 +65,8 @@ class WiimoteBasicConfigDialog : public wxDialog
wxButton *m_OK,
*m_Cancel,
*m_ButtonMapping,
*m_Recording;
*m_Recording,
*m_RefreshRealWiiMote[MAX_WIIMOTES];
wxChoice *m_InputSource[MAX_WIIMOTES],
*m_Extension[MAX_WIIMOTES];
@ -87,7 +88,8 @@ class WiimoteBasicConfigDialog : public wxDialog
*m_TextScreenHeight[MAX_WIIMOTES],
*m_TextScreenLeft[MAX_WIIMOTES],
*m_TextScreenTop[MAX_WIIMOTES],
*m_TextAR[MAX_WIIMOTES];
*m_TextAR[MAX_WIIMOTES],
*m_FoundWiimote[MAX_WIIMOTES];
wxBoxSizer *m_MainSizer,
*m_SizeBasicGeneral[MAX_WIIMOTES],
@ -128,6 +130,8 @@ class WiimoteBasicConfigDialog : public wxDialog
// Real
IDC_CONNECT_REAL,
ID_FOUND_REAL,
ID_REFRESH_REAL,
IDS_WIDTH,
IDS_HEIGHT,
@ -142,6 +146,7 @@ class WiimoteBasicConfigDialog : public wxDialog
void IRCursorChanged(wxScrollEvent& event);
void DoConnectReal(); // Real
void DoRefreshReal();
void DoUseReal();
void DoExtensionConnectedDisconnected(int Extension = -1); // Emulated

View File

@ -54,6 +54,7 @@ bool g_FrameOpen = false;
bool g_SearchDeviceDone = false;
bool g_RealWiiMotePresent = false;
bool g_RealWiiMoteInitialized = false;
bool g_RealWiiMoteAllocated = false;
bool g_EmulatedWiiMoteInitialized = false;
// Settings
@ -236,7 +237,11 @@ void Initialize(void *init)
Wiimote connected or not. It takes no time for Wiiuse to check for
connected Wiimotes. */
#if HAVE_WIIUSE
if (g_Config.bConnectRealWiimote) WiiMoteReal::Initialize();
//if (g_Config.bConnectRealWiimote) WiiMoteReal::Initialize();
if(!g_RealWiiMoteInitialized)
WiiMoteReal::Initialize();
if(!g_RealWiiMoteAllocated)
WiiMoteReal::Allocate();
#endif
}

View File

@ -64,6 +64,7 @@ struct SRecordingAll
extern bool g_SearchDeviceDone;
extern bool g_RealWiiMotePresent;
extern bool g_RealWiiMoteInitialized;
extern bool g_RealWiiMoteAllocated;
extern bool g_EmulatedWiiMoteInitialized;
// Settings

View File

@ -283,21 +283,26 @@ void FlashLights(bool Connect)
{
if (Connect)
wiiuse_rumble(WiiMoteReal::g_WiiMotesFromWiiUse[i], 1);
wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1 | WIIMOTE_LED_2 | WIIMOTE_LED_3 | WIIMOTE_LED_4);
}
SLEEP(100);
#ifndef WIN32
usleep(200000);
#else
Sleep(200);
#endif
for (int i = 0; i < g_NumberOfWiiMotes; i++)
{
if (Connect)
if (Connect) {
wiiuse_rumble(WiiMoteReal::g_WiiMotesFromWiiUse[i], 0);
// We are not connecting, so turn off all the LEDs
wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1 | WIIMOTE_LED_2 | WIIMOTE_LED_3 | WIIMOTE_LED_4);
}
else
wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[i], WIIMOTE_LED_NONE);
}
}
int Initialize() // None of this code is intelligible, oh well...
int Initialize()
{
// Return if already initialized
if (g_RealWiiMoteInitialized)
@ -309,31 +314,24 @@ int Initialize() // None of this code is intelligible, oh well...
g_WiimoteInUse[i] = false;
g_RealWiiMotePresent = false;
g_RealWiiMoteAllocated = false;
if (!g_Config.bConnectRealWiimote)
return 0;
// Call Wiiuse.dll
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
if (g_NumberOfWiiMotes > 0)
g_RealWiiMotePresent = true;
DEBUG_LOG(WIIMOTE, "Found No of Wiimotes: %i", g_NumberOfWiiMotes);
DEBUG_LOG(WIIMOTE, "Using %i Real Wiimote(s) and %i Emu Wiimote(s)", g_Config.bNumberRealWiimotes, g_Config.bNumberEmuWiimotes);
// We want to use more Real WiiMotes than we really have, so we disable some...
if (g_Config.bNumberRealWiimotes > g_NumberOfWiiMotes)
if(g_Config.bConnectRealWiimote)
{
int tmp = 0;
for(int i = 0; i < MAX_WIIMOTES; i++)
{
if (WiiMoteEmu::WiiMapping[i].Source == 2)
tmp++;
if (tmp > g_NumberOfWiiMotes)
WiiMoteEmu::WiiMapping[i].Source = 0;
}
// Call Wiiuse.dll
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
DEBUG_LOG(WIIMOTE, "Found No of Wiimotes: %i", g_NumberOfWiiMotes);
if (g_NumberOfWiiMotes > 0)
g_RealWiiMotePresent = true;
else
return 0;
}
else
{
g_NumberOfWiiMotes = 0;
return 0;
}
for (int i = 0; i < g_NumberOfWiiMotes; i++)
{
@ -362,42 +360,10 @@ int Initialize() // None of this code is intelligible, oh well...
if (!g_EmulatorRunning && g_RealWiiMotePresent)
FlashLights(true);
// Create Wiimote classes
for (int i = 0; i < g_NumberOfWiiMotes; i++)
{
if (WiiMoteEmu::WiiMapping[i].Source == 2)
{
g_WiimoteInUse[i] = true;
switch (i)
{
case 0:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1);
break;
case 1:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_2);
break;
case 2:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_3);
break;
case 3:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_4);
break;
default:
PanicAlert("Trying to create real wiimote %i WTF", i);
break;
}
g_WiiMotes[i] = new CWiiMote(i, g_WiiMotesFromWiiUse[i]);
}
}
// Create a new thread and start listening for Wiimote data
if (g_NumberOfWiiMotes > 0)
g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL);
// If we are not using any emulated wiimotes we can run the thread temporary until the data has beeen copied
if (g_Config.bNumberEmuWiimotes == 0)
g_RunTemporary = true;
/* Allocate memory and copy the Wiimote eeprom accelerometer neutral values
to g_Eeprom. Unlike with and extension we have to do this here, because
this data is only read once when the Wiimote is connected. Also, we
@ -421,6 +387,85 @@ int Initialize() // None of this code is intelligible, oh well...
return g_NumberOfWiiMotes;
}
// Allocate each Real WiiMote found to a WiiMote slot with Source set to "WiiMote Real"
void Allocate()
{
if(!g_RealWiiMoteInitialized)
Initialize();
// Clear the wiimote classes
memset(g_WiiMotes, 0, sizeof(CWiiMote*) * MAX_WIIMOTES);
for (int i = 0; i < MAX_WIIMOTES; i++)
g_WiimoteInUse[i] = false;
g_Config.bNumberEmuWiimotes = g_Config.bNumberRealWiimotes = 0;
// Create Wiimote classes, one for each Real WiiMote found
int current_number = 0;
for (int i = 0; i < g_NumberOfWiiMotes; i++)
{
// Let's find out the slot this Real WiiMote will be using... We need this because the user can set any of the 4 WiiMotes as Real, Emulated or Inactive...
for (; current_number < MAX_WIIMOTES; current_number++)
{
// Just to be sure we won't be overlapping any WiiMote...
if (g_WiimoteInUse[current_number] == true)
continue;
if (WiiMoteEmu::WiiMapping[current_number].Source == 1)
g_Config.bNumberEmuWiimotes++;
// Found a WiiMote (slot) that wants to be real :P
else if (WiiMoteEmu::WiiMapping[current_number].Source == 2) {
g_Config.bNumberRealWiimotes++;
break;
}
}
// If we found a valid slot for this WiiMote...
if(current_number < MAX_WIIMOTES)
{
g_WiiMotes[current_number] = new CWiiMote(current_number, g_WiiMotesFromWiiUse[i]);
g_WiimoteInUse[current_number] = true;
switch (current_number)
{
case 0:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_1);
break;
case 1:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_2);
break;
case 2:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_3);
break;
case 3:
wiiuse_set_leds(g_WiiMotesFromWiiUse[i], WIIMOTE_LED_4);
break;
default:
PanicAlert("Trying to create real wiimote %i WTF", current_number);
break;
}
DEBUG_LOG(WIIMOTE, "Real WiiMote allocated as WiiMote #%i", current_number);
}
}
// If there are more slots marked as "Real WiiMote" than the number of Real WiiMotes connected, disable them!
for(current_number++; current_number < MAX_WIIMOTES; current_number++)
{
if (WiiMoteEmu::WiiMapping[current_number].Source == 1)
g_Config.bNumberEmuWiimotes++;
else if (WiiMoteEmu::WiiMapping[current_number].Source == 2)
WiiMoteEmu::WiiMapping[current_number].Source = 0;
}
DEBUG_LOG(WIIMOTE, "Using %i Real Wiimote(s) and %i Emu Wiimote(s)", g_Config.bNumberRealWiimotes, g_Config.bNumberEmuWiimotes);
// If we are not using any emulated wiimotes we can run the thread temporary until the data has beeen copied
if (g_Config.bNumberEmuWiimotes == 0)
g_RunTemporary = true;
g_RealWiiMoteAllocated = true;
}
void DoState(PointerWrap &p)
{
//TODO: Implement
@ -439,7 +484,7 @@ void Shutdown(void)
}
// Delete the wiimotes
for (int i = 0; i < g_NumberOfWiiMotes; i++)
for (int i = 0; i < MAX_WIIMOTES; i++)
{
delete g_WiiMotes[i];
g_WiiMotes[i] = NULL;
@ -487,15 +532,24 @@ THREAD_RETURN ReadWiimote_ThreadFunc(void* arg)
{
// We need g_ThreadGoing to do a manual WaitForSingleObject() from the configuration window
g_ThreadGoing = true;
// There is at least one Real Wiimote in use
if (g_Config.bNumberRealWiimotes > 0 && !g_RunTemporary)
{
for (int i = 0; i < MAX_WIIMOTES; i++)
if (g_WiimoteInUse[i] == true)
g_WiiMotes[i]->ReadData();
}
/*if(g_RealWiiMoteAllocated)
{*/
// There is at least one Real Wiimote in use
if (g_Config.bNumberRealWiimotes > 0 && !g_RunTemporary)
{
for (int i = 0; i < MAX_WIIMOTES; i++)
if (g_WiimoteInUse[i])
g_WiiMotes[i]->ReadData();
}
else
ReadWiimote();
/*}
else
ReadWiimote();
#ifndef WIN32
usleep(1000000);
#else
Sleep(1000);
#endif*/
g_ThreadGoing = false;
}
return 0;

View File

@ -27,6 +27,7 @@ namespace WiiMoteReal
{
int Initialize();
void Allocate();
void DoState(PointerWrap &p);
void Shutdown(void);
void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size);