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
|
|
|
|
|
2016-09-04 12:10:02 +00:00
|
|
|
vector<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)
|
|
|
|
**/
|
2016-09-04 12:10:02 +00:00
|
|
|
void GamePad::EnumerateGamePads(vector<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
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
void GamePad::UpdateReleaseState()
|
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
#ifdef SDL_BUILD
|
|
|
|
JoystickInfo::UpdateReleaseState();
|
2015-10-14 13:05:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-11-10 07:12:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Safely dispatch to the Rumble method above
|
|
|
|
**/
|
|
|
|
void GamePad::DoRumble(int type, int pad)
|
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
u32 id = conf->get_joyid(pad);
|
|
|
|
if (GamePadIdWithinBounds(id)) {
|
|
|
|
GamePad *gamePad = s_vgamePad[id];
|
|
|
|
if (gamePad)
|
|
|
|
gamePad->Rumble(type, pad);
|
|
|
|
}
|
2015-11-10 07:12:20 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
/**
|
|
|
|
* Update state of every attached devices
|
|
|
|
**/
|
|
|
|
void GamePad::UpdateGamePadState()
|
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
#ifdef SDL_BUILD
|
2016-10-16 19:39:56 +00:00
|
|
|
SDL_JoystickUpdate(); // No need to make yet another function call for that
|
2015-10-14 13:05:02 +00:00
|
|
|
#endif
|
|
|
|
}
|