From 150941aad2414e181601e645a2270ec7fb793dad Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 3 Nov 2014 16:37:19 +1100 Subject: [PATCH] Maintain a flag that indicates if the gamepad device name is 'useful' (on windows we might get a dummy name, identical for all gamepads). Only add a number to the gamepad if the device has a useless default name. --- lib/irrlicht/include/IEventReceiver.h | 8 ++++++++ .../source/Irrlicht/CIrrDeviceLinux.cpp | 1 + lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp | 1 + .../source/Irrlicht/CIrrDeviceWin32.cpp | 4 +++- .../source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm | 1 + src/input/device_manager.cpp | 18 +++++++++++------- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/irrlicht/include/IEventReceiver.h b/lib/irrlicht/include/IEventReceiver.h index 3ca8b16ab..ee47d091b 100644 --- a/lib/irrlicht/include/IEventReceiver.h +++ b/lib/irrlicht/include/IEventReceiver.h @@ -481,6 +481,14 @@ struct SJoystickInfo //! The presence or absence of a hat cannot be determined. POV_HAT_UNKNOWN } PovHat; + + //! Set if the name of the joystick is useful: + /** On windows the default name is useless, since it's always the same + * indepentent of what joystick is connected ("Microsoft PC-joystick driver"). + * We will try to get a better name from the registry, but if this should + * fail this flag is set and used by STK. */ + bool HasNonDefaultName; + }; // struct SJoystickInfo diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp index 09a15b162..b04e92436 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp @@ -2038,6 +2038,7 @@ bool CIrrDeviceLinux::activateJoysticks(core::array & joystickInf ActiveJoysticks.push_back(info); + returnInfo.HasNonDefaultName = true; returnInfo.Joystick = joystick; returnInfo.PovHat = SJoystickInfo::POV_HAT_UNKNOWN; returnInfo.Axes = info.axes; diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp index 68e07e2a4..2ecf07c12 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceSDL.cpp @@ -557,6 +557,7 @@ bool CIrrDeviceSDL::activateJoysticks(core::array & joystickInfo) SJoystickInfo info; info.Joystick = joystick; + info.HasNonDefaultName = true; info.Axes = SDL_JoystickNumAxes(Joysticks[joystick]); info.Buttons = SDL_JoystickNumButtons(Joysticks[joystick]); info.Name = SDL_JoystickName(joystick); diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWin32.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceWin32.cpp index 09b05d148..264ea3b8d 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWin32.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWin32.cpp @@ -368,7 +368,8 @@ void setJoystickName(int index, const JOYCAPS &caps, SJoystickInfo *joystick) { // As a default use the name given in the joystick structure // - though that is always the same name, independent of joystick :( - joystick->Name = caps.szPname; + joystick->Name = caps.szPname; + joystick->HasNonDefaultName = true; core::stringc key = core::stringc(REGSTR_PATH_JOYCONFIG)+"\\"+caps.szRegKey + "\\"+REGSTR_KEY_JOYCURR; @@ -412,6 +413,7 @@ void setJoystickName(int index, const JOYCAPS &caps, SJoystickInfo *joystick) regresult = RegQueryValueExA(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, (LPBYTE)name, ®size ); joystick->Name = name; + joystick->HasNonDefaultName = false; } // if name } // if SUCCESS RegCloseKey(hKey); diff --git a/lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm b/lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm index b418baecb..4729618d8 100644 --- a/lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm +++ b/lib/irrlicht/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm @@ -1709,6 +1709,7 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array & joystickIn SJoystickInfo returnInfo; returnInfo.Joystick = jindex; + returnInfo..HasNonDefaultName = true; returnInfo.Axes = info.axes; //returnInfo.Hats = info.hats; returnInfo.Buttons = info.buttons; diff --git a/src/input/device_manager.cpp b/src/input/device_manager.cpp index 527496208..bc2ce78a7 100644 --- a/src/input/device_manager.cpp +++ b/src/input/device_manager.cpp @@ -101,13 +101,17 @@ bool DeviceManager::initialize() // Some linux systems report a disk accelerometer as a gamepad, skip that if (name.find("LIS3LV02DL") != -1) continue; -#ifdef WIN32 - // On Windows, unless we use DirectInput, all gamepads are given the - // same name ('microsoft pc-joystick driver'). This makes configuration - // totally useless, so append an ID to the name. We can't test for the - // name, since the name is even translated. - name = name + " " + StringUtils::toString(id).c_str(); -#endif + if(!m_irrlicht_gamepads[id].HasNonDefaultName) + { + // On Windows all gamepads are given the same name ('microsoft + // pc-joystick driver') - unless we add DirectInput or so as + // dependency. We can't test for the name, since the name is even + // translated. Irrlicht now tries to get a better name from the + // registry, but in case this should fail we still have all + // gamepads with the same name shown in the GUI. This makes + // configuration totally useless, so append an ID to the name. + name = name + " " + StringUtils::toString(id).c_str(); + } if (UserConfigParams::logMisc()) {