2015-10-14 13:05:02 +00:00
|
|
|
#include "GamePad.h"
|
2016-09-04 12:10:02 +00:00
|
|
|
#ifdef SDL_BUILD
|
2015-10-14 13:05:02 +00:00
|
|
|
#include "SDL/joystick.h"
|
|
|
|
#endif
|
|
|
|
|
2017-04-10 16:19:23 +00:00
|
|
|
std::vector<std::unique_ptr<GamePad>> s_vgamePad;
|
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
bool GamePadIdWithinBounds(int GamePadId)
|
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
return ((GamePadId >= 0) && (GamePadId < (int)s_vgamePad.size()));
|
2015-10-14 13:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
**/
|
2017-04-10 16:19:23 +00:00
|
|
|
void GamePad::EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad)
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
#ifdef SDL_BUILD
|
|
|
|
JoystickInfo::EnumerateJoysticks(vgamePad);
|
2015-10-14 13:05:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-11-10 07:12:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Safely dispatch to the Rumble method above
|
|
|
|
**/
|
2017-04-14 18:14:42 +00:00
|
|
|
void GamePad::DoRumble(unsigned type, unsigned pad)
|
2015-11-10 07:12:20 +00:00
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
u32 id = conf->get_joyid(pad);
|
|
|
|
if (GamePadIdWithinBounds(id)) {
|
2017-04-10 16:19:23 +00:00
|
|
|
s_vgamePad[id]->Rumble(type, pad);
|
2016-09-04 12:10:02 +00:00
|
|
|
}
|
2015-11-10 07:12:20 +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;
|
|
|
|
}
|