2015-10-14 13:05:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "onepad.h"
|
|
|
|
#include "controller.h"
|
|
|
|
#ifdef SDL_BUILD
|
|
|
|
#include <SDL.h>
|
|
|
|
#define HAT_UP SDL_HAT_UP
|
|
|
|
#define HAT_DOWN SDL_HAT_DOWN
|
|
|
|
#define HAT_RIGHT SDL_HAT_RIGHT
|
|
|
|
#define HAT_LEFT SDL_HAT_LEFT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class GamePad
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GamePad() : devname(""), _id(-1), numbuttons(0), numaxes(0), numhats(0),
|
|
|
|
deadzone(1500), pad(-1) {
|
|
|
|
vbuttonstate.clear();
|
|
|
|
vaxisstate.clear();
|
|
|
|
vhatstate.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GamePad()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GamePad(const GamePad&); // copy constructor
|
|
|
|
GamePad& operator=(const GamePad&); // assignment
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find every interesting devices and create right structure for them(depend on backend)
|
|
|
|
**/
|
|
|
|
static void EnumerateGamePads(vector<GamePad*>& vgamePad);
|
|
|
|
static void UpdateReleaseState();
|
|
|
|
/**
|
|
|
|
* Update state of every attached devices
|
|
|
|
**/
|
|
|
|
static void UpdateGamePadState();
|
|
|
|
|
2015-10-17 16:57:28 +00:00
|
|
|
/**
|
2015-10-14 13:05:02 +00:00
|
|
|
* Causes devices to rumble
|
|
|
|
* Rumble will differ according to type which is either 0(small motor) or 1(big motor)
|
|
|
|
**/
|
2015-10-14 14:06:31 +00:00
|
|
|
virtual void Rumble(int type,int pad){return;}
|
2015-11-10 07:12:20 +00:00
|
|
|
/**
|
|
|
|
* Safely dispatch to the Rumble method above
|
|
|
|
**/
|
|
|
|
static void DoRumble(int type, int pad);
|
2015-10-14 13:05:02 +00:00
|
|
|
|
|
|
|
virtual bool Init(int id){return false;} // opens a handle and gets information
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for GUI checkbox to give feedback to the user
|
|
|
|
**/
|
2015-10-17 16:57:28 +00:00
|
|
|
virtual bool TestForce(float strength = 0.6){return false;}
|
2015-10-14 13:05:02 +00:00
|
|
|
|
|
|
|
virtual bool PollButtons(u32 &pkey){return false;}
|
|
|
|
virtual bool PollAxes(u32 &pkey){return false;}
|
|
|
|
virtual bool PollHats(u32 &pkey){return false;}
|
|
|
|
|
|
|
|
virtual int GetHat(int key_to_axis)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetButton(int key_to_button)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
const string& GetName()
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
return devname;
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
int GetPAD()
|
|
|
|
{
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetNumButtons()
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
return numbuttons;
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
int GetNumAxes()
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
return numaxes;
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
int GetNumHats()
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
return numhats;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetDeadzone()
|
|
|
|
{
|
|
|
|
return deadzone;
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
virtual void SaveState() {}
|
2015-10-14 13:05:02 +00:00
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
int GetButtonState(int i)
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
return vbuttonstate[i];
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
int GetAxisState(int i)
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
return vaxisstate[i];
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
int GetHatState(int i)
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
//PAD_LOG("Getting POV State of %d.\n", i);
|
|
|
|
return vhatstate[i];
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
void SetButtonState(int i, int state)
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
vbuttonstate[i] = state;
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
void SetAxisState(int i, int value)
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
vaxisstate[i] = value;
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:37:37 +00:00
|
|
|
void SetHatState(int i, int value)
|
2015-10-14 13:05:02 +00:00
|
|
|
{
|
|
|
|
//PAD_LOG("We should set %d to %d.\n", i, value);
|
|
|
|
vhatstate[i] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetAxisFromKey(int pad, int index){return 0;}
|
|
|
|
// These fields need to be inherited by child classes
|
|
|
|
protected:
|
|
|
|
string devname; // pretty device name
|
|
|
|
int _id;
|
|
|
|
int numbuttons, numaxes, numhats;
|
|
|
|
int deadzone;
|
|
|
|
int pad;
|
|
|
|
vector<int> vbuttonstate, vaxisstate, vhatstate;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern vector<GamePad*> s_vgamePad;
|
|
|
|
extern bool GamePadIdWithinBounds(int joyid);
|