Fixed crash: when you try to change pad in config dialog

Fixed issue: XInput trigger source cannot be selected
Added proper close of SDL_Joystick

But still nJoy and Wiimote cannot share the same gamepad. It needs to be figured out how to do it with SDL.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4686 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
ayuanx 2009-12-13 04:31:38 +00:00
parent d476048359
commit 5f47aa7bb1
6 changed files with 37 additions and 40 deletions

View File

@ -281,7 +281,7 @@ void Config::Load(bool ChangePad)
iniFile.Get("Real", "AccNunNeutralY", &iAccNunNeutralY, 0); iniFile.Get("Real", "AccNunNeutralY", &iAccNunNeutralY, 0);
iniFile.Get("Real", "AccNunNeutralZ", &iAccNunNeutralZ, 0); iniFile.Get("Real", "AccNunNeutralZ", &iAccNunNeutralZ, 0);
for (int i = 0; i < 1; i++) for (int i = 0; i < 1; i++) // Only got 1 wiimote yet
{ {
// Slot specific settings // Slot specific settings
char SectionName[32]; char SectionName[32];
@ -387,7 +387,7 @@ void Config::Save(int Slot)
iniFile.Set("Real", "AccNunNeutralY", iAccNunNeutralY); iniFile.Set("Real", "AccNunNeutralY", iAccNunNeutralY);
iniFile.Set("Real", "AccNunNeutralZ", iAccNunNeutralZ); iniFile.Set("Real", "AccNunNeutralZ", iAccNunNeutralZ);
for (int i = 0; i < 1; i++) for (int i = 0; i < 1; i++) // Only got 1 wiimote yet
{ {
// Slot specific settings // Slot specific settings
char SectionName[32]; char SectionName[32];

View File

@ -31,7 +31,7 @@
void WiimotePadConfigDialog::DoChangeJoystick() void WiimotePadConfigDialog::DoChangeJoystick()
{ {
// Close the current pad, unless it's used by another slot // Close the current pad, unless it's used by another slot
//if (PadMapping[notebookpage].enabled) PadClose(notebookpage); //if (PadMapping[Page].enabled) PadClose(Page);
// Before changing the pad we save potential changes to the current pad // Before changing the pad we save potential changes to the current pad
DoSave(true); DoSave(true);
@ -42,7 +42,7 @@ void WiimotePadConfigDialog::DoChangeJoystick()
UpdateGUI(Page); // Update the GUI UpdateGUI(Page); // Update the GUI
// Open the new pad // Open the new pad
if (WiiMoteEmu::PadMapping[Page].enabled) PadOpen(Page); //if (WiiMoteEmu::PadMapping[Page].enabled) PadOpen(Page);
} }
void WiimotePadConfigDialog::PadOpen(int Open) // Open for slot 1, 2, 3 or 4 void WiimotePadConfigDialog::PadOpen(int Open) // Open for slot 1, 2, 3 or 4
{ {
@ -306,15 +306,15 @@ void WiimotePadConfigDialog::SetButtonText(int id, const char text[128], int _Pa
else controller = _Page; else controller = _Page;
if (IDB_ANALOG_LEFT_X <= id && id <= IDB_TRIGGER_R) if (IDB_ANALOG_LEFT_X <= id && id <= IDB_TRIGGER_R)
m_Button_Analog[id - IDB_ANALOG_LEFT_X][controller]->SetLabel(wxString::FromAscii(text)); m_Button_Analog[id - IDB_ANALOG_LEFT_X][controller]->SetLabel(wxString::FromAscii(text));
else if (IDB_WM_A <= id && id <= IDB_WM_SHAKE) else if (IDB_WM_A <= id && id <= IDB_WM_SHAKE)
m_Button_Wiimote[id - IDB_WM_A][controller]->SetLabel(wxString::FromAscii(text)); m_Button_Wiimote[id - IDB_WM_A][controller]->SetLabel(wxString::FromAscii(text));
else if (IDB_NC_Z <= id && id <= IDB_NC_SHAKE) else if (IDB_NC_Z <= id && id <= IDB_NC_SHAKE)
m_Button_NunChuck[id - IDB_NC_Z][controller]->SetLabel(wxString::FromAscii(text)); m_Button_NunChuck[id - IDB_NC_Z][controller]->SetLabel(wxString::FromAscii(text));
else if (IDB_CC_A <= id && id <= IDB_CC_RD) else if (IDB_CC_A <= id && id <= IDB_CC_RD)
m_Button_Classic[id - IDB_CC_A][controller]->SetLabel(wxString::FromAscii(text)); m_Button_Classic[id - IDB_CC_A][controller]->SetLabel(wxString::FromAscii(text));
else if (IDB_GH3_GREEN <= id && id <= IDB_GH3_STRUM_DOWN) else if (IDB_GH3_GREEN <= id && id <= IDB_GH3_STRUM_DOWN)
m_Button_GH3[id - IDB_GH3_GREEN][controller]->SetLabel(wxString::FromAscii(text)); m_Button_GH3[id - IDB_GH3_GREEN][controller]->SetLabel(wxString::FromAscii(text));
//DEBUG_LOG(WIIMOTE, "SetButtonText: %s", text); //DEBUG_LOG(WIIMOTE, "SetButtonText: %s", text);
} }
@ -364,9 +364,10 @@ void WiimotePadConfigDialog::GetButtons(wxCommandEvent& event)
if (m_ButtonMappingTimer->IsRunning()) if (m_ButtonMappingTimer->IsRunning())
return; return;
OldLabel = ((wxButton *)event.GetEventObject())->GetLabel(); wxButton* pButton = (wxButton *)event.GetEventObject();
SetButtonText(event.GetId(), "<Move Axis>"); OldLabel = pButton->GetLabel();
DoGetButtons(event.GetId()); pButton->SetLabel(wxT("<Move Axis>"));
DoGetButtons(pButton->GetId());
} }
void WiimotePadConfigDialog::DoGetButtons(int _GetId) void WiimotePadConfigDialog::DoGetButtons(int _GetId)
@ -425,20 +426,19 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
// 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
DEBUG_LOG(WIIMOTE, "Timer Started for Pad:%i _GetId:%i" DEBUG_LOG(WIIMOTE, "Timer Started: Pad:%i _GetId:%i "
"Allowed input is Axis:%i LeftRight:%i XInput:%i Button:%i Hat:%i\n", "Allowed input is Axis:%i LeftRight:%i XInput:%i Button:%i Hat:%i",
WiiMoteEmu::PadMapping[Controller].ID, _GetId, WiiMoteEmu::PadMapping[Controller].ID, _GetId,
Axis, LeftRight, XInput, Button, Hat); Axis, LeftRight, XInput, Button, Hat);
} }
// Check for buttons // Check for buttons
// If there is a timer but we should not create a new one // If there is a timer we should not create a new one
else if (WiiMoteEmu::NumGoodPads >0) else if (WiiMoteEmu::NumGoodPads >0)
{ {
InputCommon::GetButton( InputCommon::GetButton(
WiiMoteEmu::joyinfo[PadID].joy, PadID, WiiMoteEmu::joyinfo[PadID].NumButtons, WiiMoteEmu::joyinfo[PadID].NumAxes, WiiMoteEmu::joyinfo[PadID].NumHats, WiiMoteEmu::joyinfo[PadID].joy, PadID, WiiMoteEmu::joyinfo[PadID].NumButtons, WiiMoteEmu::joyinfo[PadID].NumAxes, WiiMoteEmu::joyinfo[PadID].NumHats,
g_Pressed, value, type, pressed, Succeed, Stop, g_Pressed, value, type, pressed, Succeed, Stop,
@ -450,7 +450,6 @@ void WiimotePadConfigDialog::DoGetButtons(int _GetId)
// Count each time // Count each time
GetButtonWaitingTimer++; GetButtonWaitingTimer++;
// This is run every second // This is run every second
if(GetButtonWaitingTimer % TimesPerSecond == 0) if(GetButtonWaitingTimer % TimesPerSecond == 0)
{ {

View File

@ -120,7 +120,7 @@ WiimotePadConfigDialog::WiimotePadConfigDialog(wxWindow *parent, wxWindowID id,
// Start the permanent timer // Start the permanent timer
const int TimesPerSecond = 10; const int TimesPerSecond = 10;
m_UpdatePadTimer->Start( floor((double)(1000 / TimesPerSecond)) ); m_UpdatePadTimer->Start(1000 / TimesPerSecond);
#endif #endif
ControlsCreated = false; ControlsCreated = false;
@ -254,7 +254,7 @@ void WiimotePadConfigDialog::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++) for(int i = 0; i < 1; i++) // Only got 1 wiimote yet
SaveButtonMapping(i, true); SaveButtonMapping(i, true);
// Save the settings for the current pad // Save the settings for the current pad
g_Config.Save(Slot); g_Config.Save(Slot);
@ -264,7 +264,7 @@ void WiimotePadConfigDialog::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++) for(int i = 0; i < 1; i++) // Only got 1 wiimote yet
SaveButtonMapping(i); SaveButtonMapping(i);
g_Config.Save(Slot); g_Config.Save(Slot);
} }
@ -975,6 +975,7 @@ void WiimotePadConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
case IDC_RUMBLE_STRENGTH: case IDC_RUMBLE_STRENGTH:
case IDC_TILT_INVERT_ROLL: case IDC_TILT_INVERT_ROLL:
case IDC_TILT_INVERT_PITCH: case IDC_TILT_INVERT_PITCH:
case IDC_TRIGGER_TYPE:
SaveButtonMappingAll(Page); SaveButtonMappingAll(Page);
break; break;
} }

View File

@ -202,10 +202,6 @@ class WiimotePadConfigDialog : public wxDialog
ID_CONTROLLERPAGE3, ID_CONTROLLERPAGE3,
ID_CONTROLLERPAGE4, ID_CONTROLLERPAGE4,
ID_ANALOG_LEFT_X, ID_ANALOG_LEFT_Y,
ID_ANALOG_RIGHT_X, ID_ANALOG_RIGHT_Y,
ID_TRIGGER_L, ID_TRIGGER_R,
// Gamepad <It's important that the internal ordering of these are unchanged> // Gamepad <It's important that the internal ordering of these are unchanged>
IDB_ANALOG_LEFT_X, IDB_ANALOG_LEFT_Y, IDB_ANALOG_LEFT_X, IDB_ANALOG_LEFT_Y,
IDB_ANALOG_RIGHT_X, IDB_ANALOG_RIGHT_Y, IDB_ANALOG_RIGHT_X, IDB_ANALOG_RIGHT_Y,
@ -280,8 +276,8 @@ class WiimotePadConfigDialog : public wxDialog
// Gamepad configuration // Gamepad configuration
void SetButtonText(int id, const char text[128], int _Page = -1); void SetButtonText(int id, const char text[128], int _Page = -1);
void SetButtonTextAll(int id, char text[128]); void SetButtonTextAll(int id, char text[128]);
void GetButtons(wxCommandEvent& event); void GetButtons(wxCommandEvent& btn_event);
void DoGetButtons(int); void DoGetButtons(int id);
void SaveButtonMapping(int controller, bool DontChangeId = false, int FromSlot = -1); void SaveButtonMapping(int controller, bool DontChangeId = false, int FromSlot = -1);
void SaveButtonMappingAll(int Slot); void SaveButtonMappingAll(int Slot);
void SaveKeyboardMapping(int Controller, int Id, int Key); void SaveKeyboardMapping(int Controller, int Id, int Key);

View File

@ -39,7 +39,7 @@ extern SWiimoteInitialize g_WiimoteInitialize;
namespace WiiMoteEmu namespace WiiMoteEmu
{ {
extern void PAD_Rumble(u8 _numPAD, unsigned int _uType); extern void PAD_RumbleClose();
/* Bit shift conversions */ /* Bit shift conversions */
u32 convert24bit(const u8* src) { u32 convert24bit(const u8* src) {
@ -508,19 +508,18 @@ void Shutdown(void)
ResetVariables(); ResetVariables();
PAD_RumbleClose();
/* Close all devices carefully. We must check that we are not accessing any /* Close all devices carefully. We must check that we are not accessing any
undefined vector elements or any bad devices */ undefined vector elements or any bad devices */
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 (SDL_WasInit(0) && joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo.at(PadMapping[i].ID).Good) if (PadState[i].joy && joyinfo.at(PadMapping[i].ID).Good)
{ {
INFO_LOG(WIIMOTE, "ShutDown: %i", PadState[i].joy); INFO_LOG(WIIMOTE, "ShutDown: %i", PadState[i].joy);
PAD_Rumble(i, false); if(SDL_JoystickOpened(PadMapping[i].ID))
/* SDL_JoystickClose() crashes for some reason so I avoid this SDL_JoystickClose(PadState[i].joy);
for now, SDL_Quit() should close the pads to I think */ PadState[i].joy = NULL;
//if(SDL_JoystickOpened(PadMapping[i].ID)) SDL_JoystickClose(PadState[i].joy);
//PadState[i].joy = NULL;
} }
} }
@ -530,7 +529,8 @@ void Shutdown(void)
NumGoodPads = 0; NumGoodPads = 0;
// Finally close SDL // Finally close SDL
if (SDL_WasInit(0)) SDL_Quit(); if (SDL_WasInit(0))
SDL_Quit();
} }
/* This function produce Wiimote Input, i.e. reports from the Wiimote in /* This function produce Wiimote Input, i.e. reports from the Wiimote in

View File

@ -204,7 +204,7 @@ void Initialize(void *init)
Called from: The Dolphin Core, PADConfigDialognJoy::OnClose() */ Called from: The Dolphin Core, PADConfigDialognJoy::OnClose() */
void Shutdown() void Shutdown()
{ {
INFO_LOG(PAD, "Shutdown: %i\n", SDL_WasInit(0)); INFO_LOG(PAD, "Shutdown: %i", SDL_WasInit(0));
// Always change this variable // Always change this variable
g_EmulatorRunning = false; g_EmulatorRunning = false;
@ -220,8 +220,8 @@ void Shutdown()
vector elements or any bad devices */ vector elements or any bad devices */
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
if (joyinfo.size() > (u32)PadMapping[i].ID) if (SDL_WasInit(0) && joyinfo.size() > (u32)PadMapping[i].ID)
if (joyinfo.at(PadMapping[i].ID).Good) if (PadState[i].joy && joyinfo.at(PadMapping[i].ID).Good)
if(SDL_JoystickOpened(PadMapping[i].ID)) if(SDL_JoystickOpened(PadMapping[i].ID))
{ {
SDL_JoystickClose(PadState[i].joy); SDL_JoystickClose(PadState[i].joy);
@ -235,7 +235,8 @@ void Shutdown()
NumGoodPads = 0; NumGoodPads = 0;
// Finally close SDL // Finally close SDL
SDL_Quit(); if (SDL_WasInit(0))
SDL_Quit();
// Remove the pointer to the initialize data // Remove the pointer to the initialize data
g_PADInitialize = NULL; g_PADInitialize = NULL;