pcsx2/plugins/onepad/GamePad.cpp

61 lines
1.4 KiB
C++
Raw Normal View History

#include "GamePad.h"
2016-09-04 12:10:02 +00:00
#ifdef SDL_BUILD
#include "SDL/joystick.h"
#endif
std::vector<std::unique_ptr<GamePad>> s_vgamePad;
bool GamePadIdWithinBounds(int GamePadId)
{
2016-09-04 12:10:02 +00:00
return ((GamePadId >= 0) && (GamePadId < (int)s_vgamePad.size()));
}
/**
* Following static methods are just forwarders to their backend
* This is where link between agnostic and specific code is done
**/
/**
* Find every interesting devices and create right structure for them(depend on backend)
**/
void GamePad::EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad)
{
2016-09-04 12:10:02 +00:00
#ifdef SDL_BUILD
JoystickInfo::EnumerateJoysticks(vgamePad);
#endif
}
/**
* Safely dispatch to the Rumble method above
**/
void GamePad::DoRumble(unsigned type, unsigned pad)
{
2016-09-04 12:10:02 +00:00
u32 id = conf->get_joyid(pad);
if (GamePadIdWithinBounds(id)) {
s_vgamePad[id]->Rumble(type, pad);
2016-09-04 12:10:02 +00:00
}
}
2017-04-16 15:41:05 +00:00
size_t GamePad::index_to_uid(int index)
{
if ((index >= 0) && (index < (int)s_vgamePad.size()))
return s_vgamePad[index]->GetUniqueIdentifier();
else
return 0;
}
int GamePad::uid_to_index(size_t uid)
{
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;
return -1;
}