2015-10-14 13:05:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "onepad.h"
|
|
|
|
#include "controller.h"
|
2016-09-04 12:10:02 +00:00
|
|
|
#ifdef SDL_BUILD
|
2015-10-14 13:05:02 +00:00
|
|
|
#include <SDL.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class GamePad
|
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
public:
|
|
|
|
GamePad()
|
2017-04-16 12:57:23 +00:00
|
|
|
: m_deadzone(1500)
|
2017-04-14 18:33:33 +00:00
|
|
|
, m_no_error(false)
|
2016-09-04 12:10:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GamePad()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-16 19:39:56 +00:00
|
|
|
GamePad(const GamePad &); // copy constructor
|
|
|
|
GamePad &operator=(const GamePad &); // assignment
|
2016-09-04 12:10:02 +00:00
|
|
|
|
2017-04-11 17:02:31 +00:00
|
|
|
/*
|
|
|
|
* Find every interesting devices and create right structure for them(depend on backend)
|
|
|
|
*/
|
2017-04-10 16:19:23 +00:00
|
|
|
static void EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad);
|
2017-04-11 17:02:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update state of every attached devices
|
|
|
|
*/
|
2017-04-16 12:57:23 +00:00
|
|
|
virtual void UpdateGamePadState() = 0;
|
2015-10-14 13:05:02 +00:00
|
|
|
|
2017-04-11 17:02:31 +00:00
|
|
|
/*
|
|
|
|
* Causes devices to rumble
|
|
|
|
* Rumble will differ according to type which is either 0(small motor) or 1(big motor)
|
|
|
|
*/
|
2017-04-26 18:12:46 +00:00
|
|
|
virtual void Rumble(unsigned type, unsigned pad) {}
|
2017-04-11 17:02:31 +00:00
|
|
|
/*
|
|
|
|
* Safely dispatch to the Rumble method above
|
|
|
|
*/
|
2017-04-14 18:14:42 +00:00
|
|
|
static void DoRumble(unsigned type, unsigned pad);
|
2015-10-14 13:05:02 +00:00
|
|
|
|
2017-04-11 17:02:31 +00:00
|
|
|
/*
|
|
|
|
* Used for GUI checkbox to give feedback to the user
|
|
|
|
*/
|
2016-09-04 12:10:02 +00:00
|
|
|
virtual bool TestForce(float strength = 0.6) { return false; }
|
|
|
|
|
2017-04-16 12:57:23 +00:00
|
|
|
virtual const char *GetName() = 0;
|
|
|
|
|
|
|
|
virtual int GetInput(gamePadValues input) = 0;
|
2016-09-04 12:10:02 +00:00
|
|
|
|
2017-04-26 18:12:46 +00:00
|
|
|
int GetDeadzone()
|
2016-09-04 12:10:02 +00:00
|
|
|
{
|
2017-04-16 12:57:23 +00:00
|
|
|
return m_deadzone;
|
2016-09-04 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-16 15:41:05 +00:00
|
|
|
virtual size_t GetUniqueIdentifier() = 0;
|
|
|
|
|
|
|
|
static size_t index_to_uid(int index);
|
|
|
|
static int uid_to_index(size_t uid);
|
|
|
|
|
2017-04-14 18:33:33 +00:00
|
|
|
bool IsProperlyInitialized()
|
|
|
|
{
|
|
|
|
return m_no_error;
|
|
|
|
}
|
|
|
|
|
2016-09-04 12:10:02 +00:00
|
|
|
protected:
|
2017-04-16 12:57:23 +00:00
|
|
|
int m_deadzone;
|
2017-04-14 18:33:33 +00:00
|
|
|
bool m_no_error;
|
2015-10-14 13:05:02 +00:00
|
|
|
};
|
|
|
|
|
2017-04-10 16:19:23 +00:00
|
|
|
extern std::vector<std::unique_ptr<GamePad>> s_vgamePad;
|