2013-11-05 12:49:23 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-11-24 05:32:19 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "SDL/SDL.h"
|
|
|
|
#include "SDL/SDL_joystick.h"
|
|
|
|
#include "SDL/SDL_thread.h"
|
|
|
|
#else
|
2013-11-05 12:49:23 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_joystick.h"
|
|
|
|
#include "SDL_thread.h"
|
2013-11-24 05:32:19 +00:00
|
|
|
#endif
|
2013-11-05 12:49:23 +00:00
|
|
|
|
|
|
|
#include "input/input_state.h"
|
|
|
|
#include "input/keycodes.h"
|
|
|
|
#include "net/resolve.h"
|
|
|
|
#include "base/NativeApp.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
int SDLJoystickThreadWrapper(void *SDLJoy);
|
|
|
|
}
|
|
|
|
|
|
|
|
class SDLJoystick{
|
|
|
|
friend int ::SDLJoystickThreadWrapper(void *);
|
|
|
|
public:
|
|
|
|
SDLJoystick(bool init_SDL = false);
|
|
|
|
~SDLJoystick();
|
|
|
|
|
|
|
|
void startEventLoop();
|
|
|
|
void ProcessInput(SDL_Event &event);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void runLoop();
|
|
|
|
void fillMapping()
|
|
|
|
{
|
|
|
|
//TODO: C++11 aggregate initialization
|
|
|
|
//would remove runtime overhead completely
|
2015-12-21 22:48:22 +00:00
|
|
|
|
|
|
|
// Mapping on Windows
|
2013-11-05 12:49:23 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
SDLJoyButtonMap[0] = NKCODE_BUTTON_2;
|
|
|
|
SDLJoyButtonMap[1] = NKCODE_BUTTON_3;
|
|
|
|
SDLJoyButtonMap[2] = NKCODE_BUTTON_4;
|
|
|
|
SDLJoyButtonMap[3] = NKCODE_BUTTON_1;
|
|
|
|
SDLJoyButtonMap[4] = NKCODE_BUTTON_7;
|
|
|
|
SDLJoyButtonMap[5] = NKCODE_BUTTON_8;
|
|
|
|
SDLJoyButtonMap[6] = NKCODE_BUTTON_9;
|
|
|
|
SDLJoyButtonMap[7] = NKCODE_BUTTON_10;
|
|
|
|
SDLJoyButtonMap[8] = NKCODE_BUTTON_11;
|
|
|
|
SDLJoyButtonMap[9] = NKCODE_BUTTON_12;
|
|
|
|
SDLJoyButtonMap[10] = NKCODE_BUTTON_5;
|
|
|
|
SDLJoyButtonMap[11] = NKCODE_BUTTON_6;
|
|
|
|
SDLJoyButtonMap[12] = NKCODE_BUTTON_7;
|
|
|
|
SDLJoyButtonMap[13] = NKCODE_BUTTON_8;
|
|
|
|
SDLJoyButtonMap[14] = NKCODE_BUTTON_9;
|
|
|
|
|
|
|
|
SDLJoyAxisMap[0] = JOYSTICK_AXIS_X;
|
|
|
|
SDLJoyAxisMap[1] = JOYSTICK_AXIS_Y;
|
|
|
|
SDLJoyAxisMap[2] = JOYSTICK_AXIS_Z;
|
|
|
|
SDLJoyAxisMap[3] = JOYSTICK_AXIS_RZ;
|
|
|
|
SDLJoyAxisMap[4] = JOYSTICK_AXIS_LTRIGGER;
|
|
|
|
SDLJoyAxisMap[5] = JOYSTICK_AXIS_RTRIGGER;
|
2015-12-21 22:48:22 +00:00
|
|
|
// Mapping on MacOSX to match X360 controller
|
|
|
|
#elif __APPLE__
|
2013-11-05 12:49:23 +00:00
|
|
|
SDLJoyButtonMap[0] = NKCODE_DPAD_UP;
|
|
|
|
SDLJoyButtonMap[1] = NKCODE_DPAD_DOWN;
|
|
|
|
SDLJoyButtonMap[2] = NKCODE_DPAD_LEFT;
|
|
|
|
SDLJoyButtonMap[3] = NKCODE_DPAD_RIGHT;
|
|
|
|
SDLJoyButtonMap[4] = NKCODE_BUTTON_10;
|
|
|
|
SDLJoyButtonMap[5] = NKCODE_BUTTON_9;
|
|
|
|
SDLJoyButtonMap[6] = NKCODE_BUTTON_5;
|
|
|
|
SDLJoyButtonMap[7] = NKCODE_BUTTON_6;
|
|
|
|
SDLJoyButtonMap[8] = NKCODE_BUTTON_7;
|
|
|
|
SDLJoyButtonMap[9] = NKCODE_BUTTON_8;
|
|
|
|
SDLJoyButtonMap[10] = NKCODE_BUTTON_SELECT;
|
|
|
|
SDLJoyButtonMap[11] = NKCODE_BUTTON_2;
|
|
|
|
SDLJoyButtonMap[12] = NKCODE_BUTTON_3;
|
|
|
|
SDLJoyButtonMap[13] = NKCODE_BUTTON_4;
|
|
|
|
SDLJoyButtonMap[14] = NKCODE_BUTTON_1;
|
2014-04-05 14:16:21 +00:00
|
|
|
SDLJoyButtonMap[15] = NKCODE_BUTTON_11;
|
2015-12-21 22:03:14 +00:00
|
|
|
SDLJoyButtonMap[16] = NKCODE_BUTTON_12;
|
2013-11-05 12:49:23 +00:00
|
|
|
|
|
|
|
SDLJoyAxisMap[0] = JOYSTICK_AXIS_X;
|
|
|
|
SDLJoyAxisMap[1] = JOYSTICK_AXIS_Y;
|
|
|
|
SDLJoyAxisMap[2] = JOYSTICK_AXIS_Z;
|
|
|
|
SDLJoyAxisMap[3] = JOYSTICK_AXIS_RZ;
|
|
|
|
SDLJoyAxisMap[4] = JOYSTICK_AXIS_LTRIGGER;
|
|
|
|
SDLJoyAxisMap[5] = JOYSTICK_AXIS_RTRIGGER;
|
2015-12-21 22:48:22 +00:00
|
|
|
// Mapping on Linux/Android/Other to match X360 and wii-u pro controller
|
|
|
|
#else
|
2015-12-21 23:27:33 +00:00
|
|
|
SDLJoyButtonMap[0] = NKCODE_BUTTON_1;
|
|
|
|
SDLJoyButtonMap[1] = NKCODE_BUTTON_2;
|
|
|
|
SDLJoyButtonMap[2] = NKCODE_BUTTON_3;
|
|
|
|
SDLJoyButtonMap[3] = NKCODE_BUTTON_4;
|
|
|
|
SDLJoyButtonMap[4] = NKCODE_BUTTON_5;
|
|
|
|
SDLJoyButtonMap[5] = NKCODE_BUTTON_6;
|
|
|
|
SDLJoyButtonMap[6] = NKCODE_BUTTON_7;
|
|
|
|
SDLJoyButtonMap[7] = NKCODE_BUTTON_8;
|
|
|
|
SDLJoyButtonMap[8] = NKCODE_BUTTON_9;
|
|
|
|
SDLJoyButtonMap[9] = NKCODE_BUTTON_10;
|
|
|
|
SDLJoyButtonMap[10] = NKCODE_BUTTON_11;
|
|
|
|
SDLJoyButtonMap[11] = NKCODE_BUTTON_12;
|
|
|
|
SDLJoyButtonMap[12] = NKCODE_BUTTON_13;
|
|
|
|
SDLJoyButtonMap[13] = NKCODE_DPAD_UP;
|
|
|
|
SDLJoyButtonMap[14] = NKCODE_DPAD_DOWN;
|
|
|
|
SDLJoyButtonMap[15] = NKCODE_DPAD_LEFT;
|
|
|
|
SDLJoyButtonMap[16] = NKCODE_DPAD_RIGHT;
|
2015-12-21 22:48:22 +00:00
|
|
|
|
2015-12-21 23:27:33 +00:00
|
|
|
SDLJoyAxisMap[0] = JOYSTICK_AXIS_X;
|
|
|
|
SDLJoyAxisMap[1] = JOYSTICK_AXIS_Y;
|
|
|
|
SDLJoyAxisMap[2] = JOYSTICK_AXIS_Z;
|
|
|
|
SDLJoyAxisMap[3] = JOYSTICK_AXIS_RZ;
|
|
|
|
SDLJoyAxisMap[4] = JOYSTICK_AXIS_LTRIGGER;
|
|
|
|
SDLJoyAxisMap[5] = JOYSTICK_AXIS_RTRIGGER;
|
2015-12-21 22:48:22 +00:00
|
|
|
|
2013-11-05 12:49:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
std::map<int, int> SDLJoyButtonMap;
|
|
|
|
std::map<int, int> SDLJoyAxisMap;
|
|
|
|
|
2014-05-30 21:50:03 +00:00
|
|
|
std::vector<SDL_Joystick *> joys;
|
2013-11-24 05:32:19 +00:00
|
|
|
SDL_Thread *thread ;
|
|
|
|
bool running ;
|
2013-11-05 12:49:23 +00:00
|
|
|
|
2015-06-23 14:13:23 +00:00
|
|
|
int getDeviceIndex(int instanceId);
|
2013-11-05 12:49:23 +00:00
|
|
|
};
|