onepad: fallback on 2nd gamepad for the 2nd player

Close #2039
This commit is contained in:
Gregory Hainaut 2017-08-09 21:23:06 +02:00
parent 0d0a54f095
commit d6c27c190d
4 changed files with 12 additions and 9 deletions

View File

@ -25,7 +25,7 @@ void GamePad::EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad)
**/
void GamePad::DoRumble(unsigned type, unsigned pad)
{
int index = uid_to_index(g_conf.get_joy_uid(pad));
int index = uid_to_index(pad);
if (index >= 0)
s_vgamePad[index]->Rumble(type, pad);
}
@ -38,17 +38,20 @@ size_t GamePad::index_to_uid(int index)
return 0;
}
int GamePad::uid_to_index(size_t uid)
int GamePad::uid_to_index(int pad)
{
size_t uid = g_conf.get_joy_uid(pad);
for (int i = 0; i < (int)s_vgamePad.size(); ++i) {
if (s_vgamePad[i]->GetUniqueIdentifier() == uid)
return i;
}
// Current uid wasn't found maybe the pad was unplugged
// Fallback to the first pad which more friendly than nothing
if (!s_vgamePad.empty())
return 0;
// Current uid wasn't found maybe the pad was unplugged. Or
// user didn't select it. Fallback to 1st pad for
// 1st player. And 2nd pad for 2nd player.
if ((int)s_vgamePad.size() > pad)
return pad;
return -1;
}

View File

@ -59,7 +59,7 @@ public:
virtual size_t GetUniqueIdentifier() = 0;
static size_t index_to_uid(int index);
static int uid_to_index(size_t uid);
static int uid_to_index(int pad);
bool IsProperlyInitialized()
{

View File

@ -244,7 +244,7 @@ void GamepadConfiguration::repopulate()
tmp = g_conf.get_sensibility();
m_sl_joystick_sensibility->SetValue(tmp);
u32 joyid = GamePad::uid_to_index(g_conf.get_joy_uid(m_pad_id));
u32 joyid = GamePad::uid_to_index(m_pad_id);
if (joyid < m_joy_map->GetCount() && !m_joy_map->IsEmpty())
m_joy_map->SetSelection(joyid);

View File

@ -80,7 +80,7 @@ void _PADclose()
void PollForJoystickInput(int cpad)
{
int index = GamePad::uid_to_index(g_conf.get_joy_uid(cpad));
int index = GamePad::uid_to_index(cpad);
if (index < 0)
return;