Small code cleanup

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4768 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
ayuanx 2010-01-01 03:19:46 +00:00
parent eb16c51d5f
commit 25abd0f944
11 changed files with 33 additions and 71 deletions

View File

@ -280,10 +280,10 @@ void Config::Load()
sprintf(SectionName, "Wiimote%i", i + 1);
// General
iniFile.Get(SectionName, "Source", &WiiMoteEmu::WiiMapping[i].Source, (i) ? 0 : 1);
if(WiiMoteEmu::WiiMapping[i].Source == 1)
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) || (WiiMoteEmu::WiiMapping[i].Source == -1))
else if (WiiMoteEmu::WiiMapping[i].Source == 2)
g_Config.bNumberRealWiimotes++;
iniFile.Get(SectionName, "Sideways", &WiiMoteEmu::WiiMapping[i].bSideways, false);

View File

@ -45,7 +45,6 @@ BEGIN_EVENT_TABLE(WiimoteBasicConfigDialog,wxDialog)
EVT_COMMAND_SCROLL(IDS_TOP, WiimoteBasicConfigDialog::IRCursorChanged)
EVT_TIMER(IDTM_UPDATE_ONCE, WiimoteBasicConfigDialog::UpdateOnce)
EVT_TIMER(IDTM_SHUTDOWN, WiimoteBasicConfigDialog::ShutDown)
END_EVENT_TABLE()
@ -62,6 +61,9 @@ WiimoteBasicConfigDialog::WiimoteBasicConfigDialog(wxWindow *parent, wxWindowID
m_Page = 0;
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)
WiiMoteReal::Initialize();
CreateGUIControls();
UpdateGUI();
@ -79,37 +81,12 @@ void WiimoteBasicConfigDialog::OnClose(wxCloseEvent& event)
WiiMoteReal::Shutdown();
}
/* Timeout the shutdown. In Windows at least the g_pReadThread execution will hang at any attempt to
call a frame function after the main thread has entered WaitForSingleObject() or any other loop.
We must therefore shut down the thread from here and wait for that before we can call ShutDown(). */
void WiimoteBasicConfigDialog::ShutDown(wxTimerEvent& WXUNUSED(event))
{
if (!WiiMoteReal::g_ThreadGoing)
{
m_ShutDownTimer->Stop();
Close();
}
}
void WiimoteBasicConfigDialog::ButtonClick(wxCommandEvent& event)
{
switch(event.GetId())
{
case ID_OK:
g_Config.Save();
/*
// Wait for the Wiimote thread to stop, then close and shutdown
if(!g_EmulatorRunning)
{
WiiMoteReal::g_Shutdown = true;
m_ShutDownTimer->Start(10);
}
// Close directly
else
{
Close();
}
*/
Close();
break;
case ID_CANCEL:
@ -275,10 +252,6 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
#endif
ControlsCreated = 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)
WiiMoteReal::Initialize();
}
// Execute a delayed function
@ -350,7 +323,7 @@ void WiimoteBasicConfigDialog::DoUseReal()
void WiimoteBasicConfigDialog::DoExtensionConnectedDisconnected(int Extension)
{
// There is no need for this if no game is running
if (!g_EmulatorRunning || WiiMoteEmu::WiiMapping[m_Page].Source <= 0)
if (!g_EmulatorRunning || WiiMoteEmu::WiiMapping[m_Page].Source != 1)
return;
u8 DataFrame[8] = {0}; // make a blank report for it
@ -384,25 +357,23 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
DoConnectReal();
break;
case IDC_INPUT_SOURCE:
if (m_InputSource[m_Page]->GetSelection() == 2)
WiiMoteEmu::WiiMapping[m_Page].Source = m_InputSource[m_Page]->GetSelection();
if (WiiMoteEmu::WiiMapping[m_Page].Source == 2)
{
int current_real = 0;
for (int i = 0; i < MAX_WIIMOTES; i++)
if (WiiMoteEmu::WiiMapping[i].Source < 0)
if (WiiMoteEmu::WiiMapping[i].Source == 2)
current_real++;
if (current_real >= WiiMoteReal::g_NumberOfWiiMotes)
if (current_real > WiiMoteReal::g_NumberOfWiiMotes)
{
PanicAlert("You've already assigned all your %i Real WiiMote(s) connected!", WiiMoteReal::g_NumberOfWiiMotes);
m_InputSource[m_Page]->SetSelection(1);
WiiMoteEmu::WiiMapping[m_Page].Source = 0;
}
else
{
WiiMoteEmu::WiiMapping[m_Page].Source = -1;
DoUseReal();
}
}
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();
@ -460,14 +431,9 @@ 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_InputSource[m_Page]->Enable(!g_EmulatorRunning);
if (WiiMoteEmu::WiiMapping[m_Page].Source < 0)
m_InputSource[m_Page]->SetSelection(2);
else
m_InputSource[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].Source);
if (m_InputSource[m_Page]->GetSelection() == 2)
m_InputSource[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].Source);
if (WiiMoteEmu::WiiMapping[m_Page].Source == 2)
{
m_SidewaysWiimote[m_Page]->Enable(false);
m_UprightWiimote[m_Page]->Enable(false);
@ -483,7 +449,6 @@ void WiimoteBasicConfigDialog::UpdateGUI()
m_SidewaysWiimote[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bSideways);
m_UprightWiimote[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bUpright);
m_WiiMotionPlusConnected[m_Page]->SetValue(WiiMoteEmu::WiiMapping[m_Page].bMotionPlusConnected);
m_Extension[m_Page]->SetSelection(WiiMoteEmu::WiiMapping[m_Page].iExtensionConnected);
// Update the Wiimote IR pointer calibration

View File

@ -284,7 +284,7 @@ struct CONTROLLER_MAPPING_WII // WII PAD MAPPING
bool bCircle2Square;
std::string Diagonal;
int Source; // 0: none, 1: emu, -1: real
int Source; // 0: inactive, 1: emu, 2: real
bool bSideways;
bool bUpright;
bool bMotionPlusConnected;

View File

@ -324,10 +324,11 @@ void Initialize()
/* Populate joyinfo for all attached devices and do g_Config.Load() if the
configuration window is not already open, if it's already open we
continue with the settings we have */
if(!g_FrameOpen)
if(!g_SearchDeviceDone)
{
g_Config.Load();
Search_Devices(joyinfo, NumPads, NumGoodPads);
g_SearchDeviceDone = true;
}
// Write default Eeprom data to g_Eeprom[], this may be overwritten by
@ -616,7 +617,7 @@ void Update(int _number)
g_ID = _number;
// Read input or not
if (WiiMapping[g_ID].Source > 0)
if (WiiMapping[g_ID].Source == 1)
{
ReadLinuxKeyboard();

View File

@ -299,7 +299,7 @@ bool IsKey(int Key)
{
int Ret = NULL;
if (WiiMapping[g_ID].Source > 0)
if (WiiMapping[g_ID].Source == 1)
{
int MapKey = WiiMapping[g_ID].Button[Key];

View File

@ -51,6 +51,7 @@ PLUGIN_GLOBALS* globals = NULL;
bool g_EmulatorRunning = false;
u32 g_ISOId = 0;
bool g_FrameOpen = false;
bool g_SearchDeviceDone = false;
bool g_RealWiiMotePresent = false;
bool g_RealWiiMoteInitialized = false;
bool g_EmulatedWiiMoteInitialized = false;
@ -168,12 +169,13 @@ void DllDebugger(HWND _hParent, bool Show) {}
void DllConfig(HWND _hParent)
{
if (!g_EmulatorRunning)
if (!g_SearchDeviceDone)
{
// Load settings
g_Config.Load();
// We do a pad search before creating the dialog
WiiMoteEmu::Search_Devices(WiiMoteEmu::joyinfo, WiiMoteEmu::NumPads, WiiMoteEmu::NumGoodPads);
g_SearchDeviceDone = true;
}
#if defined(HAVE_WX) && HAVE_WX
@ -306,7 +308,7 @@ void Wiimote_InterruptChannel(int _number, u16 _channelID, const void* _pData, u
#endif
// Decice where to send the message
if (WiiMoteEmu::WiiMapping[_number].Source >= 0)
if (WiiMoteEmu::WiiMapping[_number].Source <= 1)
WiiMoteEmu::InterruptChannel(_number, _channelID, _pData, _Size);
#if HAVE_WIIUSE
else if (g_RealWiiMotePresent)
@ -326,7 +328,7 @@ void Wiimote_ControlChannel(int _number, u16 _channelID, const void* _pData, u32
DEBUG_LOG(WIIMOTE, " Data: %s", Temp.c_str());
#endif
if (WiiMoteEmu::WiiMapping[_number].Source >= 0)
if (WiiMoteEmu::WiiMapping[_number].Source <= 1)
WiiMoteEmu::ControlChannel(_number, _channelID, _pData, _Size);
#if HAVE_WIIUSE
else if (g_RealWiiMotePresent)
@ -355,7 +357,7 @@ void Wiimote_Update(int _number)
// This functions will send:
// Emulated Wiimote: Only data reports 0x30-0x37
// Real Wiimote: Both data reports 0x30-0x37 and all other read reports
if (WiiMoteEmu::WiiMapping[_number].Source >= 0)
if (WiiMoteEmu::WiiMapping[_number].Source <= 1)
WiiMoteEmu::Update(_number);
#if HAVE_WIIUSE
else if (g_RealWiiMotePresent)

View File

@ -61,6 +61,7 @@ struct SRecordingAll
extern bool g_EmulatorRunning;
extern u32 g_ISOId;
extern bool g_FrameOpen;
extern bool g_SearchDeviceDone;
extern bool g_RealWiiMotePresent;
extern bool g_RealWiiMoteInitialized;
extern bool g_EmulatedWiiMoteInitialized;

View File

@ -327,7 +327,7 @@ int Initialize() // None of this code is intelligible, oh well...
int tmp = 0;
for(int i = 0; i < MAX_WIIMOTES; i++)
{
if (WiiMoteEmu::WiiMapping[i].Source < 0)
if (WiiMoteEmu::WiiMapping[i].Source == 2)
tmp++;
if (tmp > g_NumberOfWiiMotes)
WiiMoteEmu::WiiMapping[i].Source = 0;
@ -365,8 +365,7 @@ int Initialize() // None of this code is intelligible, oh well...
// Create Wiimote classes
for (int i = 0; i < g_NumberOfWiiMotes; i++)
{
// Why the fuck are there 2 values for "real wiimote"??? NOBODY KNOWS
if ((WiiMoteEmu::WiiMapping[i].Source == -1) || (WiiMoteEmu::WiiMapping[i].Source == 2))
if (WiiMoteEmu::WiiMapping[i].Source == 2)
{
g_WiimoteInUse[i] = true;
switch (i)

View File

@ -168,7 +168,6 @@ void PADConfigDialognJoy::OnClose(wxCloseEvent& event)
// Close pads, unless we are running a game
//if (!g_EmulatorRunning) Shutdown();
g_FrameOpen = false;
EndModal(wxID_CLOSE);
}

View File

@ -48,7 +48,7 @@ std::vector<InputCommon::CONTROLLER_INFO> joyinfo;
InputCommon::CONTROLLER_STATE PadState[4];
InputCommon::CONTROLLER_MAPPING PadMapping[4];
bool g_EmulatorRunning = false;
bool g_FrameOpen = false;
bool g_SearchDeviceDone = false;
int NumPads = 0, NumGoodPads = 0, LastPad = 0;
#ifdef _WIN32
HWND m_hWnd = NULL, m_hConsole = NULL; // Handle to window
@ -155,12 +155,13 @@ void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
// ------------------
void DllConfig(HWND _hParent)
{
if (!g_EmulatorRunning)
if (!g_SearchDeviceDone)
{
g_Config.Load(); // load settings
// Init Joystick + Haptic (force feedback) subsystem on SDL 1.3
// Populate joyinfo for all attached devices
Search_Devices(joyinfo, NumPads, NumGoodPads);
g_SearchDeviceDone = true;
}
#if defined(HAVE_WX) && HAVE_WX
@ -171,15 +172,9 @@ void DllConfig(HWND _hParent)
// Only allow one open at a time
if (!m_ConfigFrame->IsShown())
{
g_FrameOpen = true;
m_ConfigFrame->ShowModal();
}
else
{
g_FrameOpen = false;
m_ConfigFrame->Hide();
}
#endif
}
@ -202,11 +197,12 @@ void Initialize(void *init)
DEBUG_INIT();
#endif
if (!g_FrameOpen)
if (!g_SearchDeviceDone)
{
g_Config.Load(); // load settings
// Populate joyinfo for all attached devices
Search_Devices(joyinfo, NumPads, NumGoodPads);
g_SearchDeviceDone = true;
}
}

View File

@ -95,7 +95,6 @@
#ifdef _WIN32
extern HWND m_hWnd, m_hConsole; // Handle to window
#endif
extern bool g_FrameOpen;
extern int NumPads, NumGoodPads, LastPad; // Number of goods pads
#endif