Skip to content

Commit

Permalink
onepad: fallback on 2nd gamepad for the 2nd player
Browse files Browse the repository at this point in the history
Close #2039
  • Loading branch information
gregory38 committed Aug 10, 2017
1 parent 0d0a54f commit d6c27c1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
15 changes: 9 additions & 6 deletions plugins/onepad/GamePad.cpp
Expand Up @@ -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);
}
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion plugins/onepad/GamePad.h
Expand Up @@ -59,7 +59,7 @@ class GamePad
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()
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/onepad/Linux/GamepadConfiguration.cpp
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion plugins/onepad/Linux/linux.cpp
Expand Up @@ -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;

Expand Down

0 comments on commit d6c27c1

Please sign in to comment.