Improve the SDL/XInput hackery of my last commit. Fixes the device refresh button crash.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5628 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak 2010-06-06 06:28:18 +00:00
parent 08636392b6
commit 0af55bd85b
2 changed files with 20 additions and 18 deletions

View file

@ -18,11 +18,11 @@ namespace ciface
namespace SDL
{
// just a struct with an int that is set to ZERO by default
struct ZeroedInt{ZeroedInt():value(0){}unsigned int value;};
void Init( std::vector<ControllerInterface::Device*>& devices )
{
// just a struct with an int that is set to ZERO by default
// this is used to number the joysticks
// multiple joysticks with the same name shall get unique ids starting at 0
std::map<std::string, ZeroedInt> name_counts;
@ -55,22 +55,23 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
// to not use SDL for an XInput device
// too many people on the forums pick the SDL device and ask:
// "why don't my 360 gamepad triggers/rumble work correctly"
#ifdef _WIN32
// checking the name is probably good (and hacky) enough
// but i'll double check with the num of buttons/axes
if (
("Controller (Xbox 360 Wireless Receiver for Windows)" == GetName())
&& (10 == SDL_JoystickNumButtons(joystick))
&& (5 == SDL_JoystickNumAxes(joystick))
&& (1 == SDL_JoystickNumHats(joystick))
&& (0 == SDL_JoystickNumBalls(joystick))
)
{
// this device won't be used
return;
}
#ifdef _WIN32
// checking the name is probably good (and hacky) enough
// but i'll double check with the num of buttons/axes
std::string lcasename = GetName();
std::transform(lcasename.begin(), lcasename.end(), lcasename.begin(), tolower);
#endif
if ((std::string::npos != lcasename.find("xbox 360"))
&& (10 == SDL_JoystickNumButtons(joystick))
&& (5 == SDL_JoystickNumAxes(joystick))
&& (1 == SDL_JoystickNumHats(joystick))
&& (0 == SDL_JoystickNumBalls(joystick))
)
{
// this device won't be used
return;
}
#endif
// get buttons
for ( int i = 0; i < SDL_JoystickNumButtons( m_joystick ); ++i )

View file

@ -600,7 +600,8 @@ void GamepadPage::RefreshDevices( wxCommandEvent& event )
g_plugin->controls_crit.Enter(); // enter
// refresh devices
g_plugin->controller_interface.DeInit();
// TODO: remove hackery of not deinting SDL
g_plugin->controller_interface.DeInit(true);
g_plugin->controller_interface.Init();
// update all control references