2012-07-20 01:08:29 +00:00
|
|
|
#ifndef _INPUTMANAGER_H_
|
|
|
|
#define _INPUTMANAGER_H_
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
#include <SDL.h>
|
2012-07-20 01:08:29 +00:00
|
|
|
#include <vector>
|
2012-07-22 21:15:55 +00:00
|
|
|
#include <map>
|
2013-04-08 16:52:40 +00:00
|
|
|
#include <string>
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
class InputConfig;
|
|
|
|
class Window;
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-05-24 11:44:40 +00:00
|
|
|
struct InputDevice
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
unsigned long vendor;
|
|
|
|
unsigned long product;
|
|
|
|
|
|
|
|
InputDevice(const std::string & deviceName, unsigned long vendorId, unsigned long productId);
|
|
|
|
bool operator==(const InputDevice & b) const;
|
|
|
|
};
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
//you should only ever instantiate one of these, by the way
|
|
|
|
class InputManager
|
|
|
|
{
|
2013-05-24 11:44:40 +00:00
|
|
|
static const int DEADZONE = 23000;
|
|
|
|
|
|
|
|
Window* mWindow;
|
|
|
|
|
|
|
|
//non-InputManager classes shouldn't use this, as you can easily miss the keyboard
|
|
|
|
InputConfig* getInputConfigByDevice(int device);
|
|
|
|
|
|
|
|
void loadDefaultConfig();
|
|
|
|
|
|
|
|
int mNumJoysticks;
|
|
|
|
int mNumPlayers;
|
|
|
|
SDL_Joystick** mJoysticks;
|
|
|
|
InputConfig** mInputConfigs;
|
|
|
|
InputConfig* mKeyboardInputConfig;
|
|
|
|
std::map<int, int>* mPrevAxisValues;
|
|
|
|
|
|
|
|
std::vector<InputDevice> inputDevices;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Retrieve joysticks/ HID devices from system.
|
|
|
|
\return Returns a list of InputDevices that can be compared to the current /inputDevices to check if the configuration has changed.
|
|
|
|
\note This currently reads the content of the /dev/input on linux, searches for "js**" names and stores those. On Windows it uses GetRawInputDeviceInfo to find devices of type RIM_TYPEHID and stores those.
|
|
|
|
*/
|
|
|
|
std::vector<InputDevice> getInputDevices() const;
|
|
|
|
|
|
|
|
static const int POLLING_INTERVAL = 5000;
|
|
|
|
SDL_TimerID devicePollingTimer;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Called when devicePollingTimer runs out. Sends a SDL_UserEvent with type SDL_USEREVENT_POLLDEVICES to the event queue.
|
|
|
|
*/
|
|
|
|
static Uint32 devicePollingCallback(Uint32 interval, void * param);
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
public:
|
2013-05-24 11:44:40 +00:00
|
|
|
static const int SDL_USEREVENT_POLLDEVICES = SDL_USEREVENT + 100; //This event is issued when the input devices should be rescanned.
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
InputManager(Window* window);
|
|
|
|
~InputManager();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
void loadConfig();
|
2013-04-11 22:27:27 +00:00
|
|
|
void writeConfig();
|
2013-04-08 16:52:40 +00:00
|
|
|
static std::string getConfigPath();
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
void init();
|
|
|
|
void deinit();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
void setNumPlayers(int num);
|
|
|
|
int getNumPlayers();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
int getNumJoysticks();
|
2013-04-13 23:10:23 +00:00
|
|
|
int getButtonCountByDevice(int id);
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 16:52:40 +00:00
|
|
|
bool parseEvent(const SDL_Event& ev);
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
InputConfig* getInputConfigByPlayer(int player);
|
2013-06-30 01:37:18 +00:00
|
|
|
|
|
|
|
void startPolling();
|
|
|
|
void stopPolling();
|
2013-04-08 14:41:25 +00:00
|
|
|
};
|
2012-07-20 01:08:29 +00:00
|
|
|
|
|
|
|
#endif
|