Rearranged EmuWiimote & nJoy. Wow they can share one pad at the same time, and they also can be enabled/disabled separately.

So as long as the game supports, you can toggle controller input between them on the fly.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4691 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
ayuanx 2009-12-14 02:23:14 +00:00
parent 2d10a47c2b
commit 6f1efd4873
20 changed files with 271 additions and 208 deletions

View File

@ -100,6 +100,7 @@ struct CONTROLLER_MAPPING // GC PAD MAPPING
std::string SRadius, SDiagonal, SRadiusC, SDiagonalC; std::string SRadius, SDiagonal, SRadiusC, SDiagonalC;
bool bRadiusOnOff, bSquareToCircle, bRadiusOnOffC, bSquareToCircleC; bool bRadiusOnOff, bSquareToCircle, bRadiusOnOffC, bSquareToCircleC;
bool rumble; bool rumble;
bool enable;
int eventnum; // Linux Event Number, Can't be found dynamically yet int eventnum; // Linux Event Number, Can't be found dynamically yet
}; };
@ -231,8 +232,6 @@ struct CONTROLLER_MAPPING_NEW // GC PAD MAPPING
std::string SDiagonal; std::string SDiagonal;
bool bSquareToCircle; bool bSquareToCircle;
bool bCircle2Square; bool bCircle2Square;
bool bRollInvert;
bool bPitchInvert;
}; };

View File

@ -288,9 +288,15 @@ void Config::Load(bool ChangePad)
sprintf(SectionName, "Wiimote%i", i + 1); sprintf(SectionName, "Wiimote%i", i + 1);
iniFile.Get(SectionName, "NoTriggerFilter", &bNoTriggerFilter, false); iniFile.Get(SectionName, "NoTriggerFilter", &bNoTriggerFilter, false);
iniFile.Get(SectionName, "TiltType", &Tilt.Type, Tilt.OFF); iniFile.Get(SectionName, "TiltType", &Tilt.Type, Tilt.KEYBOARD);
iniFile.Get(SectionName, "TiltRollRange", &Tilt.Range.Roll, 0); iniFile.Get(SectionName, "TiltRollSwing", &Tilt.Range.RollSwing, false);
iniFile.Get(SectionName, "TiltPitchRange", &Tilt.Range.Pitch, 0); iniFile.Get(SectionName, "TiltRollDegree", &Tilt.Range.RollDegree, 60);
Tilt.Range.Roll = (Tilt.Range.RollSwing) ? 0 : Tilt.Range.RollDegree;
iniFile.Get(SectionName, "TiltRollInvert", &Tilt.RollInvert, false);
iniFile.Get(SectionName, "TiltPitchSwing", &Tilt.Range.PitchSwing, false);
iniFile.Get(SectionName, "TiltPitchDegree", &Tilt.Range.PitchDegree, 60);
Tilt.Range.Pitch = (Tilt.Range.PitchSwing) ? 0 : Tilt.Range.PitchDegree;
iniFile.Get(SectionName, "TiltPitchInvert", &Tilt.PitchInvert, false);
// Wiimote // Wiimote
for (int x = 0; x < WM_CONTROLS; x++) for (int x = 0; x < WM_CONTROLS; x++)
@ -342,9 +348,7 @@ void Config::Load(bool ChangePad)
iniFile.Get(joySectionName.c_str(), "Diagonal", &WiiMoteEmu::PadMapping[i].SDiagonal, "100%"); iniFile.Get(joySectionName.c_str(), "Diagonal", &WiiMoteEmu::PadMapping[i].SDiagonal, "100%");
iniFile.Get(joySectionName.c_str(), "Circle2Square", &WiiMoteEmu::PadMapping[i].bCircle2Square, false); iniFile.Get(joySectionName.c_str(), "Circle2Square", &WiiMoteEmu::PadMapping[i].bCircle2Square, false);
iniFile.Get(joySectionName.c_str(), "Rumble", &WiiMoteEmu::PadMapping[i].Rumble, true); iniFile.Get(joySectionName.c_str(), "Rumble", &WiiMoteEmu::PadMapping[i].Rumble, true);
iniFile.Get(joySectionName.c_str(), "RumbleStrength", &WiiMoteEmu::PadMapping[i].RumbleStrength, 10); iniFile.Get(joySectionName.c_str(), "RumbleStrength", &WiiMoteEmu::PadMapping[i].RumbleStrength, 9);
iniFile.Get(joySectionName.c_str(), "RollInvert", &WiiMoteEmu::PadMapping[i].bRollInvert, false);
iniFile.Get(joySectionName.c_str(), "PitchInvert", &WiiMoteEmu::PadMapping[i].bPitchInvert, false);
iniFile.Get(joySectionName.c_str(), "TriggerType", &WiiMoteEmu::PadMapping[i].triggertype, 0); iniFile.Get(joySectionName.c_str(), "TriggerType", &WiiMoteEmu::PadMapping[i].triggertype, 0);
} }
// Load the IR cursor settings if it's avaliable for the GameId, if not load the default settings // Load the IR cursor settings if it's avaliable for the GameId, if not load the default settings
@ -371,7 +375,7 @@ void Config::Save(int Slot)
{ {
IniFile iniFile; IniFile iniFile;
iniFile.Load(FULL_CONFIG_DIR "Wiimote.ini"); iniFile.Load(FULL_CONFIG_DIR "Wiimote.ini");
iniFile.Set("Settings", "InputActive", bInputActive); // iniFile.Set("Settings", "InputActive", bInputActive);
iniFile.Set("Settings", "Sideways", bSideways); iniFile.Set("Settings", "Sideways", bSideways);
iniFile.Set("Settings", "Upright", bUpright); iniFile.Set("Settings", "Upright", bUpright);
iniFile.Set("Settings", "MotionPlusConnected", bMotionPlusConnected); iniFile.Set("Settings", "MotionPlusConnected", bMotionPlusConnected);
@ -395,9 +399,12 @@ void Config::Save(int Slot)
iniFile.Set(SectionName, "NoTriggerFilter", bNoTriggerFilter); iniFile.Set(SectionName, "NoTriggerFilter", bNoTriggerFilter);
iniFile.Set(SectionName, "TiltType", Tilt.Type);; iniFile.Set(SectionName, "TiltType", Tilt.Type);;
iniFile.Set(SectionName, "TiltRollRange", Tilt.Range.Roll); iniFile.Set(SectionName, "TiltRollDegree", Tilt.Range.RollDegree);
iniFile.Set(SectionName, "TiltPitchRange", Tilt.Range.Pitch); iniFile.Set(SectionName, "TiltRollSwing", Tilt.Range.RollSwing);
iniFile.Set(SectionName, "TiltRollInvert", Tilt.RollInvert);
iniFile.Set(SectionName, "TiltPitchDegree", Tilt.Range.PitchDegree);
iniFile.Set(SectionName, "TiltPitchSwing", Tilt.Range.PitchSwing);
iniFile.Set(SectionName, "TiltPitchInvert", Tilt.PitchInvert);
// Wiimote // Wiimote
for (int x = 0; x < WM_CONTROLS; x++) for (int x = 0; x < WM_CONTROLS; x++)
iniFile.Set(SectionName, wmControlNames[x], WiiMoteEmu::PadMapping[i].Wm.keyForControls[x]); iniFile.Set(SectionName, wmControlNames[x], WiiMoteEmu::PadMapping[i].Wm.keyForControls[x]);
@ -446,8 +453,6 @@ void Config::Save(int Slot)
iniFile.Set(joySectionName.c_str(), "Circle2Square", WiiMoteEmu::PadMapping[i].bCircle2Square); iniFile.Set(joySectionName.c_str(), "Circle2Square", WiiMoteEmu::PadMapping[i].bCircle2Square);
iniFile.Set(joySectionName.c_str(), "Rumble", WiiMoteEmu::PadMapping[i].Rumble); iniFile.Set(joySectionName.c_str(), "Rumble", WiiMoteEmu::PadMapping[i].Rumble);
iniFile.Set(joySectionName.c_str(), "RumbleStrength", WiiMoteEmu::PadMapping[i].RumbleStrength); iniFile.Set(joySectionName.c_str(), "RumbleStrength", WiiMoteEmu::PadMapping[i].RumbleStrength);
iniFile.Set(joySectionName.c_str(), "RollInvert", WiiMoteEmu::PadMapping[i].bRollInvert);
iniFile.Set(joySectionName.c_str(), "PitchInvert", WiiMoteEmu::PadMapping[i].bPitchInvert);
iniFile.Set(joySectionName.c_str(), "TriggerType", WiiMoteEmu::PadMapping[i].triggertype); iniFile.Set(joySectionName.c_str(), "TriggerType", WiiMoteEmu::PadMapping[i].triggertype);
} }

View File

@ -44,10 +44,13 @@ struct Config
struct TiltRange struct TiltRange
{ {
int RollDegree;
bool RollSwing;
int Roll; int Roll;
int PitchDegree;
bool PitchSwing;
int Pitch; int Pitch;
}; };
struct PadTilt struct PadTilt
{ {
enum ETiltType enum ETiltType
@ -59,6 +62,8 @@ struct Config
TRIGGER TRIGGER
}; };
int Type; int Type;
bool RollInvert;
bool PitchInvert;
TiltRange Range; TiltRange Range;
}; };
struct PadNunchuck struct PadNunchuck

View File

@ -27,8 +27,8 @@
BEGIN_EVENT_TABLE(WiimoteBasicConfigDialog,wxDialog) BEGIN_EVENT_TABLE(WiimoteBasicConfigDialog,wxDialog)
EVT_CLOSE(WiimoteBasicConfigDialog::OnClose) EVT_CLOSE(WiimoteBasicConfigDialog::OnClose)
EVT_BUTTON(ID_CLOSE, WiimoteBasicConfigDialog::ButtonClick) EVT_BUTTON(ID_OK, WiimoteBasicConfigDialog::ButtonClick)
EVT_BUTTON(ID_APPLY, WiimoteBasicConfigDialog::ButtonClick) EVT_BUTTON(ID_CANCEL, WiimoteBasicConfigDialog::ButtonClick)
EVT_BUTTON(ID_BUTTONMAPPING, WiimoteBasicConfigDialog::ButtonClick) EVT_BUTTON(ID_BUTTONMAPPING, WiimoteBasicConfigDialog::ButtonClick)
EVT_BUTTON(ID_BUTTONRECORDING, WiimoteBasicConfigDialog::ButtonClick) EVT_BUTTON(ID_BUTTONRECORDING, WiimoteBasicConfigDialog::ButtonClick)
EVT_CHECKBOX(IDC_INPUT_ACTIVE, WiimoteBasicConfigDialog::GeneralSettingsChanged) EVT_CHECKBOX(IDC_INPUT_ACTIVE, WiimoteBasicConfigDialog::GeneralSettingsChanged)
@ -61,7 +61,7 @@ WiimoteBasicConfigDialog::WiimoteBasicConfigDialog(wxWindow *parent, wxWindowID
ControlsCreated = false; ControlsCreated = false;
m_bEnableUseRealWiimote = true; m_bEnableUseRealWiimote = true;
Page = 0; Page = 0;
g_Config.Load(); //g_Config.Load();
CreateGUIControls(); CreateGUIControls();
UpdateGUI(); UpdateGUI();
} }
@ -69,7 +69,6 @@ WiimoteBasicConfigDialog::WiimoteBasicConfigDialog(wxWindow *parent, wxWindowID
void WiimoteBasicConfigDialog::OnClose(wxCloseEvent& event) void WiimoteBasicConfigDialog::OnClose(wxCloseEvent& event)
{ {
g_FrameOpen = false; g_FrameOpen = false;
g_Config.Save();
EndModal(wxID_CLOSE); EndModal(wxID_CLOSE);
} }
@ -89,7 +88,9 @@ void WiimoteBasicConfigDialog::ButtonClick(wxCommandEvent& event)
{ {
switch(event.GetId()) switch(event.GetId())
{ {
case ID_CLOSE: case ID_OK:
g_Config.Save();
/*
// Wait for the Wiimote thread to stop, then close and shutdown // Wait for the Wiimote thread to stop, then close and shutdown
if(!g_EmulatorRunning) if(!g_EmulatorRunning)
{ {
@ -101,9 +102,12 @@ void WiimoteBasicConfigDialog::ButtonClick(wxCommandEvent& event)
{ {
Close(); Close();
} }
*/
Close();
break; break;
case ID_APPLY: case ID_CANCEL:
g_Config.Save(); g_Config.Load();
Close();
break; break;
case ID_BUTTONMAPPING: case ID_BUTTONMAPPING:
m_PadConfigFrame = new WiimotePadConfigDialog(this); m_PadConfigFrame = new WiimotePadConfigDialog(this);
@ -172,7 +176,7 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
// Basic Settings // Basic Settings
m_InputActive[i] = new wxCheckBox(m_Controller[i], IDC_INPUT_ACTIVE, wxT("Wiimote Input Active")); m_InputActive[i] = new wxCheckBox(m_Controller[i], IDC_INPUT_ACTIVE, wxT("Wiimote Input Active"));
m_InputActive[i]->SetValue(true); m_InputActive[i]->SetValue(g_Config.bInputActive);
m_InputActive[i]->SetToolTip(wxString::Format(wxT("Decide if Wiimote button events shall be sent to game"), i)); m_InputActive[i]->SetToolTip(wxString::Format(wxT("Decide if Wiimote button events shall be sent to game"), i));
// Emulated Wiimote // Emulated Wiimote
@ -274,52 +278,55 @@ void WiimoteBasicConfigDialog::CreateGUIControls()
m_ButtonMapping = new wxButton(this, ID_BUTTONMAPPING, wxT("Button Mapping")); m_ButtonMapping = new wxButton(this, ID_BUTTONMAPPING, wxT("Button Mapping"));
m_Recording = new wxButton(this, ID_BUTTONRECORDING, wxT("Recording")); m_Recording = new wxButton(this, ID_BUTTONRECORDING, wxT("Recording"));
m_Apply = new wxButton(this, ID_APPLY, wxT("Apply")); m_OK = new wxButton(this, ID_OK, wxT("OK"));
m_Close = new wxButton(this, ID_CLOSE, wxT("Close")); m_OK->SetToolTip(wxT("Save changes and close"));
m_Cancel = new wxButton(this, ID_CANCEL, wxT("Cancel"));
m_Cancel->SetToolTip(wxT("Discard changes and close"));
wxBoxSizer* sButtons = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* sButtons = new wxBoxSizer(wxHORIZONTAL);
sButtons->Add(m_ButtonMapping, 0, (wxALL), 0); sButtons->Add(m_ButtonMapping, 0, (wxALL), 0);
sButtons->Add(m_Recording, 0, (wxALL), 0); sButtons->Add(m_Recording, 0, (wxALL), 0);
sButtons->AddStretchSpacer(); sButtons->AddStretchSpacer();
sButtons->Add(m_Apply, 0, (wxALL), 0); sButtons->Add(m_OK, 0, (wxALL), 0);
sButtons->Add(m_Close, 0, (wxLEFT), 5); sButtons->Add(m_Cancel, 0, (wxLEFT), 5);
m_MainSizer = new wxBoxSizer(wxVERTICAL); m_MainSizer = new wxBoxSizer(wxVERTICAL);
m_MainSizer->Add(m_Notebook, 1, wxEXPAND | wxALL, 5); m_MainSizer->Add(m_Notebook, 1, wxEXPAND | wxALL, 5);
m_MainSizer->Add(sButtons, 0, wxEXPAND | (wxLEFT | wxRIGHT | wxDOWN), 5); m_MainSizer->Add(sButtons, 0, wxEXPAND | (wxLEFT | wxRIGHT | wxDOWN), 5);
this->SetSizer(m_MainSizer); SetSizer(m_MainSizer);
this->Layout(); Layout();
Fit(); Fit();
// Center the window if there is room for it // Center the window if there is room for it
#ifdef _WIN32 #ifdef _WIN32
if (GetSystemMetrics(SM_CYFULLSCREEN) > 600) if (GetSystemMetrics(SM_CYFULLSCREEN) > 600)
Center(); Center();
#endif #endif
ControlsCreated = true; ControlsCreated = true;
} }
void WiimoteBasicConfigDialog::DoConnectReal() void WiimoteBasicConfigDialog::DoConnectReal()
{ {
g_Config.bConnectRealWiimote = m_ConnectRealWiimote[Page]->IsChecked();
if(g_Config.bConnectRealWiimote) if(g_Config.bConnectRealWiimote)
{ {
if (!g_RealWiiMoteInitialized) WiiMoteReal::Initialize(); if (!g_RealWiiMoteInitialized)
WiiMoteReal::Initialize();
} }
else else
{ {
DEBUG_LOG(WIIMOTE, "Post Message: %i", g_RealWiiMoteInitialized); DEBUG_LOG(WIIMOTE, "Post Message: %i", g_RealWiiMoteInitialized);
if (g_RealWiiMoteInitialized) if (g_RealWiiMoteInitialized)
{
WiiMoteReal::Shutdown(); WiiMoteReal::Shutdown();
}
} }
} }
void WiimoteBasicConfigDialog::DoUseReal() void WiimoteBasicConfigDialog::DoUseReal()
{ {
if (!g_Config.bUseRealWiimote)
return;
// Clear any eventual events in the Wiimote queue // Clear any eventual events in the Wiimote queue
WiiMoteReal::ClearEvents(); WiiMoteReal::ClearEvents();
@ -370,14 +377,14 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
switch (event.GetId()) switch (event.GetId())
{ {
case IDC_CONNECT_REAL: case IDC_CONNECT_REAL:
g_Config.bConnectRealWiimote = m_ConnectRealWiimote[Page]->IsChecked();
DoConnectReal(); DoConnectReal();
break; break;
case IDC_USE_REAL: case IDC_USE_REAL:
// Enable the Wiimote thread // Enable the Wiimote thread
g_Config.bUseRealWiimote = m_UseRealWiimote[Page]->IsChecked(); g_Config.bUseRealWiimote = m_UseRealWiimote[Page]->IsChecked();
if (g_Config.bUseRealWiimote) DoUseReal(); DoUseReal();
break; break;
case IDC_INPUT_ACTIVE: case IDC_INPUT_ACTIVE:
g_Config.bInputActive = m_InputActive[Page]->IsChecked(); g_Config.bInputActive = m_InputActive[Page]->IsChecked();
break; break;
@ -387,7 +394,6 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
case IDC_UPRIGHTWIIMOTE: case IDC_UPRIGHTWIIMOTE:
g_Config.bUpright = m_UprightWiimote[Page]->IsChecked(); g_Config.bUpright = m_UprightWiimote[Page]->IsChecked();
break; break;
case IDC_MOTIONPLUSCONNECTED: case IDC_MOTIONPLUSCONNECTED:
g_Config.bMotionPlusConnected = m_WiiMotionPlusConnected[Page]->IsChecked(); g_Config.bMotionPlusConnected = m_WiiMotionPlusConnected[Page]->IsChecked();
break; break;
@ -409,7 +415,6 @@ void WiimoteBasicConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
DoExtensionConnectedDisconnected(); DoExtensionConnectedDisconnected();
break; break;
} }
g_Config.Save();
UpdateGUI(); UpdateGUI();
} }
@ -430,7 +435,6 @@ void WiimoteBasicConfigDialog::IRCursorChanged(wxScrollEvent& event)
g_Config.iIRTop = m_SliderTop[Page]->GetValue(); g_Config.iIRTop = m_SliderTop[Page]->GetValue();
break; break;
} }
UpdateGUI(); UpdateGUI();
} }

View File

@ -63,8 +63,8 @@ class WiimoteBasicConfigDialog : public wxDialog
wxNotebook *m_Notebook; wxNotebook *m_Notebook;
wxPanel *m_Controller[4]; wxPanel *m_Controller[4];
wxButton *m_Close, wxButton *m_OK,
*m_Apply, *m_Cancel,
*m_ButtonMapping, *m_ButtonMapping,
*m_Recording; *m_Recording;
@ -108,8 +108,8 @@ class WiimoteBasicConfigDialog : public wxDialog
enum enum
{ {
ID_CLOSE = 1000, ID_OK = 1000,
ID_APPLY, ID_CANCEL,
ID_BUTTONMAPPING, ID_BUTTONMAPPING,
ID_BUTTONRECORDING, ID_BUTTONRECORDING,
IDTM_SHUTDOWN, IDTM_SHUTDOWN,

View File

@ -130,8 +130,6 @@ void WiimotePadConfigDialog::UpdateGUIButtonMapping(int controller)
m_CheckC2S[controller]->SetValue(WiiMoteEmu::PadMapping[controller].bCircle2Square); m_CheckC2S[controller]->SetValue(WiiMoteEmu::PadMapping[controller].bCircle2Square);
m_CheckRumble[controller]->SetValue(WiiMoteEmu::PadMapping[controller].Rumble); m_CheckRumble[controller]->SetValue(WiiMoteEmu::PadMapping[controller].Rumble);
m_RumbleStrength[controller]->SetSelection(WiiMoteEmu::PadMapping[controller].RumbleStrength); m_RumbleStrength[controller]->SetSelection(WiiMoteEmu::PadMapping[controller].RumbleStrength);
m_TiltInvertRoll[controller]->SetValue(WiiMoteEmu::PadMapping[controller].bRollInvert);
m_TiltInvertPitch[controller]->SetValue(WiiMoteEmu::PadMapping[controller].bPitchInvert);
m_TriggerType[controller]->SetSelection(WiiMoteEmu::PadMapping[controller].triggertype); m_TriggerType[controller]->SetSelection(WiiMoteEmu::PadMapping[controller].triggertype);
for (int i = 0; i < AN_CONTROLS; i++) for (int i = 0; i < AN_CONTROLS; i++)
@ -231,8 +229,6 @@ void WiimotePadConfigDialog::SaveButtonMapping(int controller, bool DontChangeId
WiiMoteEmu::PadMapping[controller].bCircle2Square = m_CheckC2S[FromSlot]->IsChecked(); WiiMoteEmu::PadMapping[controller].bCircle2Square = m_CheckC2S[FromSlot]->IsChecked();
WiiMoteEmu::PadMapping[controller].Rumble = m_CheckRumble[FromSlot]->IsChecked(); WiiMoteEmu::PadMapping[controller].Rumble = m_CheckRumble[FromSlot]->IsChecked();
WiiMoteEmu::PadMapping[controller].RumbleStrength = m_RumbleStrength[FromSlot]->GetSelection(); WiiMoteEmu::PadMapping[controller].RumbleStrength = m_RumbleStrength[FromSlot]->GetSelection();
WiiMoteEmu::PadMapping[controller].bRollInvert = m_TiltInvertRoll[FromSlot]->IsChecked();
WiiMoteEmu::PadMapping[controller].bPitchInvert = m_TiltInvertPitch[FromSlot]->IsChecked();
WiiMoteEmu::PadMapping[controller].triggertype = m_TriggerType[FromSlot]->GetSelection(); WiiMoteEmu::PadMapping[controller].triggertype = m_TriggerType[FromSlot]->GetSelection();
for (int i = 0; i < AN_CONTROLS; i++) for (int i = 0; i < AN_CONTROLS; i++)

View File

@ -46,10 +46,12 @@ BEGIN_EVENT_TABLE(WiimotePadConfigDialog,wxDialog)
EVT_COMBOBOX(IDC_STICK_DIAGONAL, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_COMBOBOX(IDC_STICK_DIAGONAL, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(IDC_STICK_C2S, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_CHECKBOX(IDC_STICK_C2S, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_COMBOBOX(IDC_TILT_INPUT, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_COMBOBOX(IDC_TILT_INPUT, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_COMBOBOX(IDC_TILT_RANGE_ROLL, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_COMBOBOX(IDC_TILT_ROLL, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_COMBOBOX(IDC_TILT_RANGE_PITCH, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_CHECKBOX(IDC_TILT_ROLL_SWING, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(IDC_TILT_INVERT_ROLL, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_COMBOBOX(IDC_TILT_PITCH, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(IDC_TILT_INVERT_PITCH, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_CHECKBOX(IDC_TILT_PITCH_SWING, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(IDC_TILT_ROLL_INVERT, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_CHECKBOX(IDC_TILT_PITCH_INVERT, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_COMBOBOX(IDC_TRIGGER_TYPE, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_COMBOBOX(IDC_TRIGGER_TYPE, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_COMBOBOX(IDC_NUNCHUCK_STICK, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_COMBOBOX(IDC_NUNCHUCK_STICK, WiimotePadConfigDialog::GeneralSettingsChanged)
EVT_COMBOBOX(IDC_CC_LEFT_STICK, WiimotePadConfigDialog::GeneralSettingsChanged) EVT_COMBOBOX(IDC_CC_LEFT_STICK, WiimotePadConfigDialog::GeneralSettingsChanged)
@ -127,7 +129,7 @@ WiimotePadConfigDialog::WiimotePadConfigDialog(wxWindow *parent, wxWindowID id,
Page = 0; Page = 0;
ClickedButton = NULL; ClickedButton = NULL;
g_Config.Load(); //g_Config.Load();
CreatePadGUIControls(); CreatePadGUIControls();
SetBackgroundColour(m_Notebook->GetBackgroundColour()); SetBackgroundColour(m_Notebook->GetBackgroundColour());
@ -229,6 +231,7 @@ void WiimotePadConfigDialog::OnClose(wxCloseEvent& event)
m_UpdatePadTimer->Stop(); m_UpdatePadTimer->Stop();
if (m_ButtonMappingTimer) if (m_ButtonMappingTimer)
m_ButtonMappingTimer->Stop(); m_ButtonMappingTimer->Stop();
SaveButtonMappingAll(Page); SaveButtonMappingAll(Page);
EndModal(wxID_CLOSE); EndModal(wxID_CLOSE);
} }
@ -378,11 +381,9 @@ void WiimotePadConfigDialog::CreatePadGUIControls()
// The range is in degrees and are set at even 5 degrees values // The range is in degrees and are set at even 5 degrees values
wxArrayString StrTiltRangeRoll, StrTiltRangePitch; wxArrayString StrTiltRangeRoll, StrTiltRangePitch;
StrTiltRangeRoll.Add(wxString::Format(wxT("Free Swing"))); for (int i = 1; i <= 36; i++)
for (int i = 1; i < 37; i++)
StrTiltRangeRoll.Add(wxString::Format(wxT("%i"), i*5)); StrTiltRangeRoll.Add(wxString::Format(wxT("%i"), i*5));
StrTiltRangePitch.Add(wxString::Format(wxT("Free Swing"))); for (int i = 1; i <= 36; i++)
for (int i = 1; i < 37; i++)
StrTiltRangePitch.Add(wxString::Format(wxT("%i"), i*5)); StrTiltRangePitch.Add(wxString::Format(wxT("%i"), i*5));
// The Trigger type list // The Trigger type list
@ -566,36 +567,43 @@ void WiimotePadConfigDialog::CreatePadGUIControls()
m_gJoyPad[i]->AddStretchSpacer(); m_gJoyPad[i]->AddStretchSpacer();
// Tilt Wiimote // Tilt Wiimote
m_TiltComboInput[i] = new wxComboBox(m_Controller[i], IDC_TILT_INPUT, StrTilt[0], wxDefaultPosition, wxSize(100, -1), StrTilt, wxCB_READONLY); m_TiltComboInput[i] = new wxComboBox(m_Controller[i], IDC_TILT_INPUT, StrTilt[0], wxDefaultPosition, wxSize(80, -1), StrTilt, wxCB_READONLY);
m_TiltComboInput[i]->SetSelection(g_Config.Tilt.Type); m_TiltComboInput[i]->SetSelection(g_Config.Tilt.Type);
m_TiltComboInput[i]->SetToolTip(wxT("Control tilting by an analog gamepad stick, an analog trigger or the keyboard.")); m_TiltComboInput[i]->SetToolTip(wxT("Control tilting by keyboard or analog stick or trigger"));
m_TiltTextRoll[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Roll L/R")); m_TiltTextRoll[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Roll L/R"));
m_TiltTextPitch[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Pitch U/D")); m_TiltTextPitch[i] = new wxStaticText(m_Controller[i], wxID_ANY, wxT("Pitch U/D"));
m_TiltComboRangeRoll[i] = new wxComboBox(m_Controller[i], IDC_TILT_RANGE_ROLL, StrTiltRangeRoll[0], wxDefaultPosition, wxSize(75, -1), StrTiltRangeRoll, wxCB_READONLY); m_TiltComboRangeRoll[i] = new wxComboBox(m_Controller[i], IDC_TILT_ROLL, StrTiltRangeRoll[0], wxDefaultPosition, wxSize(40, -1), StrTiltRangeRoll, wxCB_READONLY);
m_TiltComboRangeRoll[i]->SetValue(wxString::Format(wxT("%i"), g_Config.Tilt.Range.Roll)); m_TiltComboRangeRoll[i]->SetValue(wxString::Format(wxT("%i"), g_Config.Tilt.Range.Roll));
m_TiltComboRangeRoll[i]->SetToolTip(wxT("The maximum roll in degrees.")); m_TiltComboRangeRoll[i]->SetToolTip(wxT("The maximum Left/Righ Roll in degrees"));
m_TiltComboRangePitch[i] = new wxComboBox(m_Controller[i], IDC_TILT_RANGE_PITCH, StrTiltRangePitch[0], wxDefaultPosition, wxSize(75, -1), StrTiltRangePitch, wxCB_READONLY); m_TiltComboRangePitch[i] = new wxComboBox(m_Controller[i], IDC_TILT_PITCH, StrTiltRangePitch[0], wxDefaultPosition, wxSize(40, -1), StrTiltRangePitch, wxCB_READONLY);
m_TiltComboRangePitch[i]->SetValue(wxString::Format(wxT("%i"), g_Config.Tilt.Range.Pitch)); m_TiltComboRangePitch[i]->SetValue(wxString::Format(wxT("%i"), g_Config.Tilt.Range.Pitch));
m_TiltComboRangePitch[i]->SetToolTip(wxT("The maximum pitch in degrees.")); m_TiltComboRangePitch[i]->SetToolTip(wxT("The maximum Up/Down Pitch in degrees"));
m_TiltRollSwing[i] = new wxCheckBox(m_Controller[i], IDC_TILT_ROLL_SWING, wxT("Swing"));
m_TiltInvertRoll[i] = new wxCheckBox(m_Controller[i], IDC_TILT_INVERT_ROLL, wxT("Invert")); m_TiltRollSwing[i]->SetToolTip(wxT("Emulate Left/Right Swing instead of Left/Right Roll"));
m_TiltInvertPitch[i] = new wxCheckBox(m_Controller[i], IDC_TILT_INVERT_PITCH, wxT("Invert")); m_TiltPitchSwing[i] = new wxCheckBox(m_Controller[i], IDC_TILT_PITCH_SWING, wxT("Swing"));
m_TiltPitchSwing[i]->SetToolTip(wxT("Emulate Up/Down Swing instead of Up/Down Pitch"));
m_TiltRollInvert[i] = new wxCheckBox(m_Controller[i], IDC_TILT_ROLL_INVERT, wxT("Invert"));
m_TiltRollInvert[i]->SetToolTip(wxT("Invert Left/Right direction"));
m_TiltPitchInvert[i] = new wxCheckBox(m_Controller[i], IDC_TILT_PITCH_INVERT, wxT("Invert"));
m_TiltPitchInvert[i]->SetToolTip(wxT("Invert Up/Down direction"));
// Sizers // Sizers
m_sGridTilt[i] = new wxGridBagSizer(0, 0); m_sGridTilt[i] = new wxGridBagSizer(0, 0);
m_sGridTilt[i]->Add(m_TiltTextRoll[i], wxGBPosition(0, 0), wxGBSpan(1, 1), (wxTOP), 4); m_sGridTilt[i]->Add(m_TiltTextRoll[i], wxGBPosition(0, 0), wxGBSpan(1, 1), (wxTOP), 4);
m_sGridTilt[i]->Add(m_TiltComboRangeRoll[i], wxGBPosition(0, 1), wxGBSpan(1, 1), (wxLEFT), 2); m_sGridTilt[i]->Add(m_TiltRollInvert[i], wxGBPosition(1, 0), wxGBSpan(1, 1), (wxTOP), 4);
m_sGridTilt[i]->Add(m_TiltInvertRoll[i], wxGBPosition(0, 2), wxGBSpan(1, 1), (wxLEFT | wxTOP), 4); m_sGridTilt[i]->Add(m_TiltComboRangeRoll[i], wxGBPosition(0, 1), wxGBSpan(1, 1), (wxLEFT | wxRIGHT), 4);
m_sGridTilt[i]->Add(m_TiltTextPitch[i], wxGBPosition(1, 0), wxGBSpan(1, 1), (wxTOP), 4); m_sGridTilt[i]->Add(m_TiltRollSwing[i], wxGBPosition(1, 1), wxGBSpan(1, 1), (wxTOP | wxLEFT | wxRIGHT), 4);
m_sGridTilt[i]->Add(m_TiltComboRangePitch[i], wxGBPosition(1, 1), wxGBSpan(1, 1), (wxLEFT | wxTOP), 2); m_sGridTilt[i]->Add(m_TiltTextPitch[i], wxGBPosition(0, 2), wxGBSpan(1, 1), (wxLEFT | wxTOP), 4);
m_sGridTilt[i]->Add(m_TiltInvertPitch[i], wxGBPosition(1, 2), wxGBSpan(1, 1), (wxLEFT | wxTOP), 4); m_sGridTilt[i]->Add(m_TiltPitchInvert[i], wxGBPosition(1, 2), wxGBSpan(1, 1), (wxLEFT | wxTOP), 4);
m_sGridTilt[i]->Add(m_TiltComboRangePitch[i], wxGBPosition(0, 3), wxGBSpan(1, 1), (wxLEFT), 4);
m_sGridTilt[i]->Add(m_TiltPitchSwing[i], wxGBPosition(1, 3), wxGBSpan(1, 1), (wxLEFT | wxTOP), 4);
m_gTilt[i] = new wxStaticBoxSizer (wxVERTICAL, m_Controller[i], wxT("Tilt and Swing")); m_gTilt[i] = new wxStaticBoxSizer (wxVERTICAL, m_Controller[i], wxT("Tilt and Swing"));
m_gTilt[i]->AddStretchSpacer(); m_gTilt[i]->AddStretchSpacer();
m_gTilt[i]->Add(m_TiltComboInput[i], 0, wxEXPAND | (wxLEFT | wxRIGHT | wxDOWN), 5); m_gTilt[i]->Add(m_TiltComboInput[i], 0, wxEXPAND | (wxLEFT | wxRIGHT | wxDOWN), 5);
m_gTilt[i]->Add(m_sGridTilt[i], 0, wxEXPAND | (wxLEFT | wxRIGHT), 5); m_gTilt[i]->Add(m_sGridTilt[i], 0, wxEXPAND | (wxLEFT), 5);
m_gTilt[i]->AddStretchSpacer(); m_gTilt[i]->AddStretchSpacer();
// Row 1 Sizers: Connected pads, tilt // Row 1 Sizers: Connected pads, tilt
@ -933,23 +941,25 @@ void WiimotePadConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
case IDC_TILT_INPUT: case IDC_TILT_INPUT:
g_Config.Tilt.Type = m_TiltComboInput[Page]->GetSelection(); g_Config.Tilt.Type = m_TiltComboInput[Page]->GetSelection();
break; break;
case IDC_TILT_RANGE_ROLL: case IDC_TILT_ROLL:
if (m_TiltComboRangeRoll[Page]->GetSelection() == 0) case IDC_TILT_ROLL_SWING:
g_Config.Tilt.Range.Roll = 0; m_TiltComboRangeRoll[Page]->GetValue().ToLong(&TmpValue);
else g_Config.Tilt.Range.RollDegree = TmpValue;
{ g_Config.Tilt.Range.RollSwing = m_TiltRollSwing[Page]->IsChecked();
m_TiltComboRangeRoll[Page]->GetValue().ToLong(&TmpValue); g_Config.Tilt.Range.Roll = (g_Config.Tilt.Range.RollSwing) ? 0 : g_Config.Tilt.Range.RollDegree;
g_Config.Tilt.Range.Roll = TmpValue;
}
break; break;
case IDC_TILT_RANGE_PITCH: case IDC_TILT_PITCH:
if (m_TiltComboRangePitch[Page]->GetSelection() == 0) case IDC_TILT_PITCH_SWING:
g_Config.Tilt.Range.Pitch = 0; m_TiltComboRangePitch[Page]->GetValue().ToLong(&TmpValue);
else g_Config.Tilt.Range.PitchDegree = TmpValue;
{ g_Config.Tilt.Range.PitchSwing = m_TiltPitchSwing[Page]->IsChecked();
m_TiltComboRangePitch[Page]->GetValue().ToLong(&TmpValue); g_Config.Tilt.Range.Pitch = (g_Config.Tilt.Range.PitchSwing) ? 0 : g_Config.Tilt.Range.PitchDegree;
g_Config.Tilt.Range.Pitch = TmpValue; break;
} case IDC_TILT_ROLL_INVERT:
g_Config.Tilt.RollInvert = m_TiltRollInvert[Page]->IsChecked();
break;
case IDC_TILT_PITCH_INVERT:
g_Config.Tilt.PitchInvert = m_TiltPitchInvert[Page]->IsChecked();
break; break;
case IDC_NUNCHUCK_STICK: case IDC_NUNCHUCK_STICK:
g_Config.Nunchuck.Type = m_NunchuckComboStick[Page]->GetSelection(); g_Config.Nunchuck.Type = m_NunchuckComboStick[Page]->GetSelection();
@ -973,8 +983,6 @@ void WiimotePadConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
case IDC_STICK_C2S: case IDC_STICK_C2S:
case IDC_RUMBLE: case IDC_RUMBLE:
case IDC_RUMBLE_STRENGTH: case IDC_RUMBLE_STRENGTH:
case IDC_TILT_INVERT_ROLL:
case IDC_TILT_INVERT_PITCH:
case IDC_TRIGGER_TYPE: case IDC_TRIGGER_TYPE:
SaveButtonMappingAll(Page); SaveButtonMappingAll(Page);
break; break;
@ -1003,6 +1011,8 @@ void WiimotePadConfigDialog::UpdateGUI(int Slot)
m_Notebook->FindItem(IDC_RUMBLE)->Enable(PadEnabled); m_Notebook->FindItem(IDC_RUMBLE)->Enable(PadEnabled);
m_Notebook->FindItem(IDC_RUMBLE_STRENGTH)->Enable(PadEnabled); m_Notebook->FindItem(IDC_RUMBLE_STRENGTH)->Enable(PadEnabled);
m_Notebook->FindItem(IDC_TRIGGER_TYPE)->Enable(PadEnabled); m_Notebook->FindItem(IDC_TRIGGER_TYPE)->Enable(PadEnabled);
m_Notebook->FindItem(IDC_TILT_ROLL)->Enable(!g_Config.Tilt.Range.RollSwing);
m_Notebook->FindItem(IDC_TILT_PITCH)->Enable(!g_Config.Tilt.Range.PitchSwing);
for(int i = IDB_ANALOG_LEFT_X; i <= IDB_TRIGGER_R; i++) for(int i = IDB_ANALOG_LEFT_X; i <= IDB_TRIGGER_R; i++)
m_Notebook->FindItem(i)->Enable(PadEnabled); m_Notebook->FindItem(i)->Enable(PadEnabled);
#endif #endif

View File

@ -95,8 +95,10 @@ class WiimotePadConfigDialog : public wxDialog
wxCheckBox *m_CheckC2S[4], wxCheckBox *m_CheckC2S[4],
*m_CheckRumble[4], *m_CheckRumble[4],
*m_TiltInvertRoll[4], *m_TiltRollSwing[4],
*m_TiltInvertPitch[4]; *m_TiltPitchSwing[4],
*m_TiltRollInvert[4],
*m_TiltPitchInvert[4];
wxButton *m_Close, *m_Apply, *ClickedButton, wxButton *m_Close, *m_Apply, *ClickedButton,
*m_Button_Analog[AN_CONTROLS][4], *m_Button_Analog[AN_CONTROLS][4],
@ -256,8 +258,9 @@ class WiimotePadConfigDialog : public wxDialog
IDC_DEAD_ZONE_LEFT, IDC_DEAD_ZONE_RIGHT, IDC_DEAD_ZONE_LEFT, IDC_DEAD_ZONE_RIGHT,
IDC_STICK_DIAGONAL, IDC_STICK_C2S, IDC_STICK_DIAGONAL, IDC_STICK_C2S,
IDC_TILT_INPUT, IDC_TILT_INPUT,
IDC_TILT_RANGE_ROLL, IDC_TILT_RANGE_PITCH, IDC_TILT_ROLL, IDC_TILT_ROLL_SWING,
IDC_TILT_INVERT_ROLL, IDC_TILT_INVERT_PITCH, IDC_TILT_PITCH, IDC_TILT_PITCH_SWING,
IDC_TILT_ROLL_INVERT, IDC_TILT_PITCH_INVERT,
IDC_TRIGGER_TYPE, IDC_TRIGGER_TYPE,
IDC_NUNCHUCK_STICK, IDC_NUNCHUCK_STICK,
IDC_CC_LEFT_STICK, IDC_CC_RIGHT_STICK, IDC_CC_TRIGGERS, IDC_CC_LEFT_STICK, IDC_CC_RIGHT_STICK, IDC_CC_TRIGGERS,

View File

@ -39,8 +39,6 @@ extern SWiimoteInitialize g_WiimoteInitialize;
namespace WiiMoteEmu namespace WiiMoteEmu
{ {
extern void PAD_RumbleClose();
/* Bit shift conversions */ /* Bit shift conversions */
u32 convert24bit(const u8* src) { u32 convert24bit(const u8* src) {
return (src[0] << 16) | (src[1] << 8) | src[2]; return (src[0] << 16) | (src[1] << 8) | src[2];
@ -424,11 +422,12 @@ void UpdateExtRegisterBlocks()
UpdateEeprom(); UpdateEeprom();
} }
// Start emulation
/* Write initial values to Eeprom and registers. */
void Initialize() void Initialize()
{ {
if (g_EmulatedWiiMoteInitialized) return; INFO_LOG(WIIMOTE, "Initialize");
//if (g_EmulatedWiiMoteInitialized) return;
// Reset variables // Reset variables
ResetVariables(); ResetVariables();
@ -442,10 +441,10 @@ void Initialize()
/* Populate joyinfo for all attached devices and do g_Config.Load() if the /* 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 configuration window is not already open, if it's already open we
continue with the settings we have */ continue with the settings we have */
if(!g_FrameOpen) //if(!g_FrameOpen)
{ Search_Devices(joyinfo, NumPads, NumGoodPads);
Search_Devices(joyinfo, NumPads, NumGoodPads);
} g_Config.Load();
// Copy extension id and calibration to its register, g_Config.Load() is needed before this // Copy extension id and calibration to its register, g_Config.Load() is needed before this
UpdateExtRegisterBlocks(); UpdateExtRegisterBlocks();
@ -502,32 +501,13 @@ void DoState(PointerWrap &p)
/* This is not needed if we call FreeLibrary() when we stop a game, but if it's /* This is not needed if we call FreeLibrary() when we stop a game, but if it's
not called we need to reset these variables. */ not called we need to reset these variables. */
void Shutdown(void) void Shutdown()
{ {
INFO_LOG(WIIMOTE, "ShutDown"); INFO_LOG(WIIMOTE, "ShutDown");
ResetVariables(); ResetVariables();
// Close joypads
PAD_RumbleClose(); Close_Devices();
/* Close all devices carefully. We must check that we are not accessing any
undefined vector elements or any bad devices */
for (int i = 0; i < 1; i++)
{
if (SDL_WasInit(0) && joyinfo.size() > (u32)PadMapping[i].ID)
if (PadState[i].joy && joyinfo.at(PadMapping[i].ID).Good)
{
INFO_LOG(WIIMOTE, "ShutDown: %i", PadState[i].joy);
if(SDL_JoystickOpened(PadMapping[i].ID))
SDL_JoystickClose(PadState[i].joy);
PadState[i].joy = NULL;
}
}
// Clear the physical device info
joyinfo.clear();
NumPads = 0;
NumGoodPads = 0;
// Finally close SDL // Finally close SDL
if (SDL_WasInit(0)) if (SDL_WasInit(0))
SDL_Quit(); SDL_Quit();

View File

@ -37,7 +37,7 @@ void GetMousePos(float& x, float& y);
// General functions // General functions
void Initialize(); void Initialize();
void DoState(PointerWrap &p); void DoState(PointerWrap &p);
void Shutdown(void); void Shutdown();
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size); void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size);
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) ; void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) ;
void Update(); void Update();
@ -52,6 +52,7 @@ void UpdateEeprom();
void UpdateExtRegisterBlocks(); void UpdateExtRegisterBlocks();
// Gamepad // Gamepad
void Close_Devices();
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads); bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads);
void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONTROLLER_MAPPING_NEW _PadMapping, int controller, int NumButtons); void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONTROLLER_MAPPING_NEW _PadMapping, int controller, int NumButtons);
void PadStateAdjustments(int &Lx, int &Ly, int &Rx, int &Ry, int &Tl, int &Tr); void PadStateAdjustments(int &Lx, int &Ly, int &Rx, int &Ry, int &Tl, int &Tr);

View File

@ -40,25 +40,50 @@ extern SWiimoteInitialize g_WiimoteInitialize;
namespace WiiMoteEmu namespace WiiMoteEmu
{ {
extern void PAD_RumbleClose();
// Close joypads
void Close_Devices()
{
PAD_RumbleClose();
/* Close all devices carefully. We must check that we are not accessing any
undefined vector elements or any bad devices */
for (int i = 0; i < 1; i++)
{
if (SDL_WasInit(0) && joyinfo.size() > (u32)PadMapping[i].ID)
if (PadState[i].joy && joyinfo.at(PadMapping[i].ID).Good)
{
INFO_LOG(WIIMOTE, "ShutDown: %i", PadState[i].joy);
if(SDL_JoystickOpened(PadMapping[i].ID))
{
SDL_JoystickClose(PadState[i].joy);
PadState[i].joy = NULL;
}
}
}
// Clear the physical device info
joyinfo.clear();
NumPads = 0;
NumGoodPads = 0;
}
// Fill joyinfo with the current connected devices // Fill joyinfo with the current connected devices
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads) bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
{ {
// Close opened pad first
Close_Devices();
bool WasGotten = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads); bool WasGotten = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
// Warn the user if no gamepads are detected // Warn the user if no gamepads are detected
if (_NumGoodPads == 0 && g_EmulatorRunning) if (_NumGoodPads == 0)
{ return false;
//PanicAlert("nJoy: No Gamepad Detected");
//return false;
}
// Load PadMapping[] etc
g_Config.Load();
// Update the PadState[].joy handle // Update the PadState[].joy handle
for (int i = 0; i < 1; i++) for (int i = 0; i < 1; i++)
{ {
if (PadMapping[i].enabled && joyinfo.size() > (u32)PadMapping[i].ID) if (joyinfo.size() > (u32)PadMapping[i].ID)
if(joyinfo.at(PadMapping[i].ID).Good) if(joyinfo.at(PadMapping[i].ID).Good)
PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID); PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID);
} }

View File

@ -514,7 +514,7 @@ void TiltWiimoteGamepad(int &Roll, int &Pitch)
Tl = Tl / 2; Tl = Tl / 2;
Tr = Tr / 2; Tr = Tr / 2;
// Invert // Invert
if (PadMapping[Page].bPitchInvert) { Tl = -Tl; Tr = -Tr; } if (g_Config.Tilt.PitchInvert) { Tl = -Tl; Tr = -Tr; }
// The final value // The final value
Pitch = (float)PitchRange * ((float)(Tl - Tr) / 128.0f); Pitch = (float)PitchRange * ((float)(Tl - Tr) / 128.0f);
} }
@ -528,8 +528,8 @@ void TiltWiimoteGamepad(int &Roll, int &Pitch)
Lx = Lx - 0x80; Lx = Lx - 0x80;
Ly = Ly - 0x80; Ly = Ly - 0x80;
// Invert // Invert
if (PadMapping[Page].bRollInvert) Lx = -Lx; // else Tr = -Tr; if (g_Config.Tilt.RollInvert) Lx = -Lx; // else Tr = -Tr;
if (PadMapping[Page].bPitchInvert) Ly = -Ly; // else Tr = -Tr; if (g_Config.Tilt.PitchInvert) Ly = -Ly; // else Tr = -Tr;
// Produce the final value // Produce the final value
Roll = (RollRange) ? (float)RollRange * ((float)Lx / 128.0f) : Lx; Roll = (RollRange) ? (float)RollRange * ((float)Lx / 128.0f) : Lx;
Pitch = (PitchRange) ? (float)PitchRange * ((float)Ly / 128.0f) : Ly; Pitch = (PitchRange) ? (float)PitchRange * ((float)Ly / 128.0f) : Ly;
@ -541,8 +541,8 @@ void TiltWiimoteGamepad(int &Roll, int &Pitch)
Rx = Rx - 0x80; Rx = Rx - 0x80;
Ry = Ry - 0x80; Ry = Ry - 0x80;
// Invert // Invert
if (PadMapping[Page].bRollInvert) Rx = -Rx; // else Tr = -Tr; if (g_Config.Tilt.RollInvert) Rx = -Rx; // else Tr = -Tr;
if (PadMapping[Page].bPitchInvert) Ry = -Ry; // else Tr = -Tr; if (g_Config.Tilt.PitchInvert) Ry = -Ry; // else Tr = -Tr;
// Produce the final value // Produce the final value
Roll = (RollRange) ? (float)RollRange * ((float)Rx / 128.0f) : Rx; Roll = (RollRange) ? (float)RollRange * ((float)Rx / 128.0f) : Rx;
Pitch = (PitchRange) ? (float)PitchRange * ((float)Ry / 128.0f) : Ry; Pitch = (PitchRange) ? (float)PitchRange * ((float)Ry / 128.0f) : Ry;

View File

@ -185,9 +185,13 @@ void DllDebugger(HWND _hParent, bool Show) {}
void DllConfig(HWND _hParent) void DllConfig(HWND _hParent)
{ {
#if defined(HAVE_WX) && HAVE_WX // We do a pad search before creating the dialog
WiiMoteEmu::Search_Devices(WiiMoteEmu::joyinfo, WiiMoteEmu::NumPads, WiiMoteEmu::NumGoodPads);
DoInitialize(); // Load settings
g_Config.Load();
#if defined(HAVE_WX) && HAVE_WX
if (!m_BasicConfigFrame) if (!m_BasicConfigFrame)
m_BasicConfigFrame = new WiimoteBasicConfigDialog(GetParentedWxWindow(_hParent)); m_BasicConfigFrame = new WiimoteBasicConfigDialog(GetParentedWxWindow(_hParent));
@ -202,6 +206,7 @@ void DllConfig(HWND _hParent)
#endif #endif
} }
// Start emulation
void Initialize(void *init) void Initialize(void *init)
{ {
// Declarations // Declarations

View File

@ -127,6 +127,7 @@ void Config::Save(int Slot)
// Save the physical device ID // Save the physical device ID
file.Set(SectionName.c_str(), "joy_id", PadMapping[i].ID); file.Set(SectionName.c_str(), "joy_id", PadMapping[i].ID);
file.Set(SectionName.c_str(), "enable", PadMapping[i].enable);
// =================== // ===================
// ================================================================== // ==================================================================
@ -190,7 +191,8 @@ void Config::Save(int Slot)
void Config::Load(bool ChangePad, bool ChangeSaveByID) void Config::Load(bool ChangePad, bool ChangeSaveByID)
{ {
// If there are no good pads don't load // If there are no good pads don't load
if (NumGoodPads == 0) return; if (NumGoodPads == 0)
return;
// Load file // Load file
IniFile file; IniFile file;
@ -219,6 +221,7 @@ void Config::Load(bool ChangePad, bool ChangeSaveByID)
if (!ChangePad) if (!ChangePad)
{ {
file.Get(SectionName.c_str(), "joy_id", &PadMapping[i].ID, 0); file.Get(SectionName.c_str(), "joy_id", &PadMapping[i].ID, 0);
file.Get(SectionName.c_str(), "enable", &PadMapping[i].enable, false);
} }
// ================================================================== // ==================================================================

View File

@ -58,6 +58,7 @@ BEGIN_EVENT_TABLE(PADConfigDialognJoy,wxDialog)
// Change gamepad // Change gamepad
EVT_COMBOBOX(IDC_JOYNAME, PADConfigDialognJoy::ChangeSettings) EVT_COMBOBOX(IDC_JOYNAME, PADConfigDialognJoy::ChangeSettings)
EVT_CHECKBOX(IDC_ENABLE, PADConfigDialognJoy::ChangeSettings)
// Other settings // Other settings
EVT_CHECKBOX(IDC_SAVEBYID, PADConfigDialognJoy::ChangeSettings) EVT_CHECKBOX(IDC_SAVEBYID, PADConfigDialognJoy::ChangeSettings)
@ -130,8 +131,8 @@ PADConfigDialognJoy::PADConfigDialognJoy(wxWindow *parent, wxWindowID id, const
GetButtonWaitingID = 0; GetButtonWaitingTimer = 0; GetButtonWaitingID = 0; GetButtonWaitingTimer = 0;
// Start the constant timer // Start the constant timer
int TimesPerSecond = 30; int TimesPerSecond = 10;
m_ConstantTimer->Start( floor((double)(1000 / TimesPerSecond)) ); m_ConstantTimer->Start(1000 / TimesPerSecond);
#endif #endif
// wxEVT_KEY_DOWN is blocked for enter, tab and the directional keys // wxEVT_KEY_DOWN is blocked for enter, tab and the directional keys
@ -157,13 +158,15 @@ void PADConfigDialognJoy::OnKeyDown(wxKeyEvent& event)
void PADConfigDialognJoy::OnClose(wxCloseEvent& event) void PADConfigDialognJoy::OnClose(wxCloseEvent& event)
{ {
// Allow wxWidgets to close the window // Allow wxWidgets to close the window
event.Skip(); //event.Skip();
// Stop the timer // Stop the timer
m_ConstantTimer->Stop(); m_ConstantTimer->Stop();
// Close pads, unless we are running a game // Close pads, unless we are running a game
if (!g_EmulatorRunning) Shutdown(); //if (!g_EmulatorRunning) Shutdown();
EndModal(wxID_CLOSE);
} }
// Call about dialog // Call about dialog
@ -252,7 +255,8 @@ void PADConfigDialognJoy::DoSave(bool ChangePad, int Slot)
if (ChangePad) if (ChangePad)
{ {
// Since we are selecting the pad to save to by the Id we can't update it when we change the pad // Since we are selecting the pad to save to by the Id we can't update it when we change the pad
for(int i = 0; i < 4; i++) SaveButtonMapping(i, true); for(int i = 0; i < 4; i++)
SaveButtonMapping(i, true);
g_Config.Save(Slot); g_Config.Save(Slot);
// Now we can update the ID // Now we can update the ID
@ -261,7 +265,9 @@ void PADConfigDialognJoy::DoSave(bool ChangePad, int Slot)
else else
{ {
// Update PadMapping[] from the GUI controls // Update PadMapping[] from the GUI controls
for(int i = 0; i < 4; i++) SaveButtonMapping(i); for(int i = 0; i < 4; i++)
SaveButtonMapping(i);
g_Config.Save(Slot); g_Config.Save(Slot);
} }
@ -301,13 +307,15 @@ void PADConfigDialognJoy::DoChangeJoystick()
void PADConfigDialognJoy::NotebookPageChanged(wxNotebookEvent& event) void PADConfigDialognJoy::NotebookPageChanged(wxNotebookEvent& event)
{ {
// Save current settings now, don't wait for OK // Save current settings now, don't wait for OK
if (ControlsCreated && !g_Config.bSaveByID) DoSave(false, notebookpage); if (ControlsCreated && !g_Config.bSaveByID)
DoSave(false, notebookpage);
// Update the global variable // Update the global variable
notebookpage = event.GetSelection(); notebookpage = event.GetSelection();
// Update GUI // Update GUI
if (ControlsCreated) UpdateGUI(notebookpage); if (ControlsCreated)
UpdateGUI(notebookpage);
} }
// Replace the harder to understand -1 with "" for the sake of user friendliness // Replace the harder to understand -1 with "" for the sake of user friendliness
@ -362,7 +370,8 @@ void PADConfigDialognJoy::UpdateGUIAll(int Slot)
{ {
if (Slot == -1) if (Slot == -1)
{ {
for (int i = 0; i < 4; i++) UpdateGUI(i); for (int i = 0; i < 4; i++)
UpdateGUI(i);
} }
else else
{ {
@ -387,11 +396,8 @@ void PADConfigDialognJoy::ChangeSettings( wxCommandEvent& event )
case IDC_SHOWADVANCED: case IDC_SHOWADVANCED:
g_Config.bShowAdvanced = m_CBShowAdvanced[notebookpage]->IsChecked(); g_Config.bShowAdvanced = m_CBShowAdvanced[notebookpage]->IsChecked();
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{
UpdateGUI(i);
m_CBShowAdvanced[i]->SetValue(g_Config.bShowAdvanced); m_CBShowAdvanced[i]->SetValue(g_Config.bShowAdvanced);
m_sMainRight[i]->Show(g_Config.bShowAdvanced); UpdateGUI(notebookpage);
}
// Resize the window without the need of any weird hack // Resize the window without the need of any weird hack
SetSizerAndFit(m_MainSizer); SetSizerAndFit(m_MainSizer);
break; break;
@ -400,34 +406,30 @@ void PADConfigDialognJoy::ChangeSettings( wxCommandEvent& event )
case IDCB_CHECKFOCUS: case IDCB_CHECKFOCUS:
g_Config.bCheckFocus = m_CBCheckFocus[notebookpage]->IsChecked(); g_Config.bCheckFocus = m_CBCheckFocus[notebookpage]->IsChecked();
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{
m_CBCheckFocus[i]->SetValue(g_Config.bCheckFocus); m_CBCheckFocus[i]->SetValue(g_Config.bCheckFocus);
}
break; break;
case IDCB_FILTER_SETTINGS: case IDCB_FILTER_SETTINGS:
g_Config.bNoTriggerFilter = m_AdvancedMapFilter[notebookpage]->IsChecked(); g_Config.bNoTriggerFilter = m_AdvancedMapFilter[notebookpage]->IsChecked();
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{
m_AdvancedMapFilter[i]->SetValue(g_Config.bNoTriggerFilter); m_AdvancedMapFilter[i]->SetValue(g_Config.bNoTriggerFilter);
}
break; break;
case IDC_CONTROLTYPE: case IDC_CONTROLTYPE:
if(!g_Config.bSaveByID) if(!g_Config.bSaveByID)
{ {
PadMapping[notebookpage].controllertype = m_ControlType[notebookpage]->GetSelection(); PadMapping[notebookpage].controllertype = m_ControlType[notebookpage]->GetSelection();
UpdateGUI(notebookpage); //UpdateGUI(notebookpage);
} }
case IDC_TRIGGERTYPE: case IDC_TRIGGERTYPE:
if(!g_Config.bSaveByID) if(!g_Config.bSaveByID)
{ {
PadMapping[notebookpage].triggertype = m_TriggerType[notebookpage]->GetSelection(); PadMapping[notebookpage].triggertype = m_TriggerType[notebookpage]->GetSelection();
UpdateGUI(notebookpage); //UpdateGUI(notebookpage);
} }
break; break;
case IDC_ENABLERUMBLE: case IDC_ENABLERUMBLE:
PadMapping[notebookpage].rumble = m_Rumble[notebookpage]->IsChecked(); PadMapping[notebookpage].rumble = m_Rumble[notebookpage]->IsChecked();
UpdateGUI(notebookpage); //UpdateGUI(notebookpage);
break; break;
case IDC_RUMBLESTRENGTH: case IDC_RUMBLESTRENGTH:
g_Config.RumbleStrength = m_RStrength[notebookpage]->GetSelection(); g_Config.RumbleStrength = m_RStrength[notebookpage]->GetSelection();
@ -435,11 +437,17 @@ void PADConfigDialognJoy::ChangeSettings( wxCommandEvent& event )
case IDC_JOYNAME: case IDC_JOYNAME:
DoChangeJoystick(); DoChangeJoystick();
break; break;
case IDC_ENABLE:
PadMapping[notebookpage].enable = m_Enable[notebookpage]->IsChecked();
UpdateGUI(notebookpage);
// Resize the window without the need of any weird hack
SetSizerAndFit(m_MainSizer);
break;
} }
// Update all slots that use this device // Update all slots that use this device
if(g_Config.bSaveByID) SaveButtonMappingAll(notebookpage); if(g_Config.bSaveByID) SaveButtonMappingAll(notebookpage);
if(g_Config.bSaveByID) UpdateGUIAll(notebookpage); //if(g_Config.bSaveByID) UpdateGUIAll(notebookpage);
} }
@ -507,7 +515,11 @@ void PADConfigDialognJoy::UpdateGUI(int _notebookpage)
else m_CoBDiagonalC[_notebookpage]->Enable(false); else m_CoBDiagonalC[_notebookpage]->Enable(false);
} }
// Repaint the background m_sKeys[_notebookpage]->Show(PadMapping[_notebookpage].enable);
m_sSettings[_notebookpage]->Show(PadMapping[_notebookpage].enable);
m_sMainRight[_notebookpage]->Show(g_Config.bShowAdvanced && PadMapping[_notebookpage].enable);
// Repaint the background
m_Controller[_notebookpage]->Refresh(); m_Controller[_notebookpage]->Refresh();
} }
@ -525,7 +537,7 @@ void PADConfigDialognJoy::OnPaint(wxPaintEvent &event)
// Populate the config window // Populate the config window
void PADConfigDialognJoy::CreateGUIControls() void PADConfigDialognJoy::CreateGUIControls()
{ {
INFO_LOG(PAD, "CreateGUIControls()\n"); INFO_LOG(PAD, "CreateGUIControls()");
#ifndef _DEBUG #ifndef _DEBUG
SetTitle(wxT("Configure: nJoy Input Plugin")); SetTitle(wxT("Configure: nJoy Input Plugin"));
@ -721,17 +733,18 @@ void PADConfigDialognJoy::CreateGUIControls()
// Populate Controller sizer // Populate Controller sizer
// Groups // Groups
#ifdef _WIN32 #ifdef _WIN32
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(476, 21), arrayStringFor_Joyname, wxCB_READONLY); m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(300, 25), arrayStringFor_Joyname, wxCB_READONLY);
#else #else
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(450, 25), arrayStringFor_Joyname, 0, wxDefaultValidator, wxT("m_Joyname")); m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(300, 25), arrayStringFor_Joyname, 0, wxDefaultValidator, wxT("m_Joyname"));
#endif #endif
m_gJoyname[i] = new wxStaticBoxSizer (wxHORIZONTAL, m_Controller[i], wxT("Controller"));
m_gJoyname[i]->Add(m_Joyname[i], 0, (wxLEFT | wxRIGHT), 5);
m_Joyname[i]->SetToolTip(wxT("Save your settings and configure another joypad")); m_Joyname[i]->SetToolTip(wxT("Save your settings and configure another joypad"));
m_Enable[i] = new wxCheckBox(m_Controller[i], IDC_ENABLE, wxT("Pad Enabled"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_Enable[i]->SetToolTip(wxT("Enable this pad to send input events to game"));
m_gJoyname[i] = new wxStaticBoxSizer (wxHORIZONTAL, m_Controller[i], wxT("Controller"));
m_gJoyname[i]->Add(m_Joyname[i], 0, wxEXPAND | (wxLEFT | wxRIGHT), 5);
m_gJoyname[i]->Add(m_Enable[i], 0, wxEXPAND | (wxLEFT | wxRIGHT), 5);
// General settings // General settings
@ -979,7 +992,14 @@ void PADConfigDialognJoy::CreateGUIControls()
#endif #endif
// Set window size // Set window size
Center(); SetSizer(m_MainSizer);
Layout();
Fit();
// Center the window if there is room for it
#ifdef _WIN32
if (GetSystemMetrics(SM_CYFULLSCREEN) > 600)
Center();
#endif
// All done // All done
ControlsCreated = true; ControlsCreated = true;

View File

@ -99,6 +99,7 @@ class PADConfigDialognJoy : public wxDialog
// --------- // ---------
wxComboBox *m_Joyname[4]; wxComboBox *m_Joyname[4];
wxCheckBox *m_Enable[4];
wxComboBox *m_ControlType[4], *m_TriggerType[4]; wxComboBox *m_ControlType[4], *m_TriggerType[4];
wxComboBox *m_Deadzone[4]; wxComboBox *m_Deadzone[4];
@ -212,7 +213,7 @@ class PADConfigDialognJoy : public wxDialog
ID_KEYSPANEL1, ID_KEYSPANEL2, ID_KEYSPANEL3, ID_KEYSPANEL4, ID_KEYSPANEL1, ID_KEYSPANEL2, ID_KEYSPANEL3, ID_KEYSPANEL4,
IDG_JOYSTICK, IDC_JOYNAME, IDG_JOYSTICK, IDC_JOYNAME, IDC_ENABLE,
IDG_EXTRASETTINGS, IDC_DEADZONE, // Extra settings IDG_EXTRASETTINGS, IDC_DEADZONE, // Extra settings
@ -312,6 +313,7 @@ class PADConfigDialognJoy : public wxDialog
}; };
private: private:
void OnClose(wxCloseEvent& event);
void AboutClick(wxCommandEvent& event); void AboutClick(wxCommandEvent& event);
void OKClick(wxCommandEvent& event); void OKClick(wxCommandEvent& event);
void CancelClick(wxCommandEvent& event); void CancelClick(wxCommandEvent& event);
@ -324,7 +326,6 @@ class PADConfigDialognJoy : public wxDialog
void ChangeSettings(wxCommandEvent& event); void ChangeSettings(wxCommandEvent& event);
void ComboChange(wxCommandEvent& event); void ComboChange(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
void CreateGUIControls(); void CreateGUIControls();
void CreateAdvancedControls(int i); void CreateAdvancedControls(int i);
wxBitmap CreateBitmap(); wxBitmap CreateBitmap();

View File

@ -52,6 +52,7 @@ void PADConfigDialognJoy::UpdateGUIButtonMapping(int controller)
// Update selected gamepad // Update selected gamepad
m_Joyname[controller]->SetSelection(PadMapping[controller].ID); m_Joyname[controller]->SetSelection(PadMapping[controller].ID);
m_Enable[controller]->SetValue(PadMapping[controller].enable);
tmp << PadMapping[controller].buttons[InputCommon::CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear(); tmp << PadMapping[controller].buttons[InputCommon::CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear();
tmp << PadMapping[controller].buttons[InputCommon::CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear(); tmp << PadMapping[controller].buttons[InputCommon::CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear();
@ -336,12 +337,12 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
g_Pressed = 0; g_Pressed = 0;
// Update the text box // Update the text box
sprintf(format, "[%d]", Seconds); sprintf(format, "[ %d ]", Seconds);
SetButtonText(GetId, format); SetButtonText(GetId, format);
// Start the timer // Start the timer
#if wxUSE_TIMER #if wxUSE_TIMER
m_ButtonMappingTimer->Start( floor((double)(1000 / TimesPerSecond)) ); m_ButtonMappingTimer->Start(1000 / TimesPerSecond);
#endif #endif
} }
@ -374,7 +375,7 @@ void PADConfigDialognJoy::DoGetButtons(int GetId)
int TmpTime = Seconds - (GetButtonWaitingTimer / TimesPerSecond); int TmpTime = Seconds - (GetButtonWaitingTimer / TimesPerSecond);
// Update text // Update text
sprintf(format, "[%d]", TmpTime); sprintf(format, "[ %d ]", TmpTime);
SetButtonText(GetId, format); SetButtonText(GetId, format);
} }

View File

@ -81,6 +81,9 @@ void Pad_Use_Rumble(u8 _numPAD)
void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength) void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
{ {
if (!PadMapping[_numPAD].enable)
return;
Pad_Use_Rumble(_numPAD); Pad_Use_Rumble(_numPAD);
int Strenght = 0; int Strenght = 0;

View File

@ -181,7 +181,7 @@ void DllDebugger(HWND _hParent, bool Show) {}
// -------------------------- // --------------------------
void Initialize(void *init) void Initialize(void *init)
{ {
INFO_LOG(PAD, "Initialize: %i\n", SDL_WasInit(0)); INFO_LOG(PAD, "Initialize: %i", SDL_WasInit(0));
g_PADInitialize = (SPADInitialize*)init; g_PADInitialize = (SPADInitialize*)init;
g_EmulatorRunning = true; g_EmulatorRunning = true;
@ -195,6 +195,30 @@ void Initialize(void *init)
// Populate joyinfo for all attached devices // Populate joyinfo for all attached devices
Search_Devices(joyinfo, NumPads, NumGoodPads); Search_Devices(joyinfo, NumPads, NumGoodPads);
g_Config.Load(); // load settings
}
void Close_Devices()
{
PAD_RumbleClose();
/* Close all devices carefully. We must check that we are not accessing any undefined
vector elements or any bad devices */
for (int i = 0; i < 4; i++)
{
if (SDL_WasInit(0) && joyinfo.size() > (u32)PadMapping[i].ID)
if (PadState[i].joy && joyinfo.at(PadMapping[i].ID).Good)
if(SDL_JoystickOpened(PadMapping[i].ID))
{
SDL_JoystickClose(PadState[i].joy);
PadState[i].joy = NULL;
}
}
// Clear the physical device info
joyinfo.clear();
NumPads = 0;
NumGoodPads = 0;
} }
// Shutdown PAD (stop emulation) // Shutdown PAD (stop emulation)
@ -214,25 +238,7 @@ void Shutdown()
DEBUG_QUIT(); DEBUG_QUIT();
#endif #endif
PAD_RumbleClose(); Close_Devices();
/* Close all devices carefully. We must check that we are not accessing any undefined
vector elements or any bad devices */
for (int i = 0; i < 4; i++)
{
if (SDL_WasInit(0) && joyinfo.size() > (u32)PadMapping[i].ID)
if (PadState[i].joy && joyinfo.at(PadMapping[i].ID).Good)
if(SDL_JoystickOpened(PadMapping[i].ID))
{
SDL_JoystickClose(PadState[i].joy);
PadState[i].joy = NULL;
}
}
// Clear the physical device info
joyinfo.clear();
NumPads = 0;
NumGoodPads = 0;
// Finally close SDL // Finally close SDL
if (SDL_WasInit(0)) if (SDL_WasInit(0))
@ -286,7 +292,8 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
{ {
// Check if the pad is avaliable, currently we don't disable pads just because they are // Check if the pad is avaliable, currently we don't disable pads just because they are
// disconnected // disconnected
if (!PadState[_numPAD].joy) return; if (!PadState[_numPAD].joy || !PadMapping[_numPAD].enable)
return;
// Clear pad status // Clear pad status
memset(_pPADStatus, 0, sizeof(SPADStatus)); memset(_pPADStatus, 0, sizeof(SPADStatus));
@ -442,6 +449,9 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// ---------------- // ----------------
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads) bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
{ {
// Close opened devices first
Close_Devices();
bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads); bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
// Warn the user if no gamepads are detected // Warn the user if no gamepads are detected
@ -451,9 +461,6 @@ bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_N
return false; return false;
} }
// Load PadMapping[] etc
g_Config.Load();
// Update the PadState[].joy handle // Update the PadState[].joy handle
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
@ -486,9 +493,3 @@ return true;
return true; return true;
#endif #endif
} }

View File

@ -101,6 +101,7 @@
// Custom Functions // Custom Functions
// ---------------- // ----------------
void Close_Devices();
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads); bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads);
void DEBUG_INIT(); void DEBUG_INIT();
void DEBUG_QUIT(); void DEBUG_QUIT();