SDL Input : Changed the keymap codes to 32 bits values because the GDK keyboard syms are 16bit (as opposed to 8bits for SDL) + we still have to store the device number. Configuration changes are needed.
This commit is contained in:
parent
63fba2be26
commit
7cf772ea6c
|
@ -4,38 +4,39 @@
|
|||
#
|
||||
# Key configuration (all numbers are in hexadecimal!)
|
||||
#
|
||||
# Keys values are in the format YXXX where Y is the device number. 0 means
|
||||
# keyborad and XXX is the SDL define for the desired key (read SDL_keysym.h).
|
||||
# Keys values are in the format YYYYXXXX where YYYY is the device number.
|
||||
# 0 means keyboard and XXXX is the SDL define for the desired key
|
||||
# (read SDL_keysym.h).
|
||||
#
|
||||
# If Y is greater than 0, it means joystick number Y-1 and it uses the
|
||||
# following format for XXX:
|
||||
# If YYYY is greater than 0, it means joystick number YYYY-1 and it uses the
|
||||
# following format for XXXX:
|
||||
#
|
||||
# - if XXX < 20, XXX is the axis number multiplied by 2. An even number means
|
||||
# - if XXXX < 20, XXXX is the axis number multiplied by 2. An even number means
|
||||
# movement to the negative side (on the X axis, it means left). An odd
|
||||
# number means movement to the positive side (on the X axis, it mean
|
||||
# right). For the Y axis, negative means up and positive means down.
|
||||
# X axis is usally axis number 0 and Y is axis number 1.
|
||||
# - if 20 >= XXX > 30, then XXX is the HAT number multiplied by 4 plus the
|
||||
# - if 20 >= XXXX > 30, then XXXX is the HAT number multiplied by 4 plus the
|
||||
# direction: 0 for up, 1 for down, 2 for right and 3 for left. Example:
|
||||
# 0021 is HAT 0 down, 0026 is HAT 1 right.
|
||||
# - if 80 >= XXX > 100, XXX is the joystick button number (XXX-080).
|
||||
# - if 80 >= XXXX > 100, XXXX is the joystick button number (XXXX-0080).
|
||||
#
|
||||
# Default key configuration is (value in parenthesis):
|
||||
#
|
||||
# Left Left Arrow (0114)
|
||||
# Right Right Arrow (0113)
|
||||
# Up Up Arrow (0111)
|
||||
# Down Down Arrow (0112)
|
||||
# A Z (007a)
|
||||
# B X (0078)
|
||||
# L A (0061)
|
||||
# R S (0073)
|
||||
# Start ENTER (000d)
|
||||
# Select BACKSPACE (0008)
|
||||
# Speed up SPACE (0020)
|
||||
# Capture F12 (0125)
|
||||
# Auto A Q (0071)
|
||||
# Auto B W (0077)
|
||||
# Left Left Arrow (00000114)
|
||||
# Right Right Arrow (00000113)
|
||||
# Up Up Arrow (00000111)
|
||||
# Down Down Arrow (00000112)
|
||||
# A Z (0000007a)
|
||||
# B X (00000078)
|
||||
# L A (00000061)
|
||||
# R S (00000073)
|
||||
# Start ENTER (0000000d)
|
||||
# Select BACKSPACE (00000008)
|
||||
# Speed up SPACE (00000020)
|
||||
# Capture F12 (00000125)
|
||||
# Auto A Q (00000071)
|
||||
# Auto B W (00000077)
|
||||
#
|
||||
Joy0_Left=0114
|
||||
Joy0_Right=0113
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
#define SDLBUTTONS_NUM 14
|
||||
|
||||
static void sdlUpdateKey(int key, bool down);
|
||||
static void sdlUpdateKey(uint32_t key, bool down);
|
||||
static void sdlUpdateJoyButton(int which, int button, bool pressed);
|
||||
static void sdlUpdateJoyHat(int which, int hat, int value);
|
||||
static void sdlUpdateJoyAxis(int which, int axis, int value);
|
||||
static bool sdlCheckJoyKey(int key);
|
||||
|
||||
bool sdlButtons[4][SDLBUTTONS_NUM] = {
|
||||
static bool sdlButtons[4][SDLBUTTONS_NUM] = {
|
||||
{ false, false, false, false, false, false,
|
||||
false, false, false, false, false, false,
|
||||
false, false
|
||||
|
@ -44,17 +44,17 @@ bool sdlButtons[4][SDLBUTTONS_NUM] = {
|
|||
}
|
||||
};
|
||||
|
||||
bool sdlMotionButtons[4] = { false, false, false, false };
|
||||
static bool sdlMotionButtons[4] = { false, false, false, false };
|
||||
|
||||
int sdlNumDevices = 0;
|
||||
SDL_Joystick **sdlDevices = NULL;
|
||||
static int sdlNumDevices = 0;
|
||||
static SDL_Joystick **sdlDevices = NULL;
|
||||
|
||||
int sdlDefaultJoypad = 0;
|
||||
static int sdlDefaultJoypad = 0;
|
||||
|
||||
int autoFire = 0;
|
||||
bool autoFireToggle = false;
|
||||
static int autoFire = 0;
|
||||
static bool autoFireToggle = false;
|
||||
|
||||
uint16_t joypad[4][SDLBUTTONS_NUM] = {
|
||||
static uint32_t joypad[4][SDLBUTTONS_NUM] = {
|
||||
{ SDLK_LEFT, SDLK_RIGHT,
|
||||
SDLK_UP, SDLK_DOWN,
|
||||
SDLK_z, SDLK_x,
|
||||
|
@ -68,7 +68,7 @@ uint16_t joypad[4][SDLBUTTONS_NUM] = {
|
|||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
uint16_t defaultJoypad[SDLBUTTONS_NUM] = {
|
||||
static uint32_t defaultJoypad[SDLBUTTONS_NUM] = {
|
||||
SDLK_LEFT, SDLK_RIGHT,
|
||||
SDLK_UP, SDLK_DOWN,
|
||||
SDLK_z, SDLK_x,
|
||||
|
@ -78,21 +78,21 @@ uint16_t defaultJoypad[SDLBUTTONS_NUM] = {
|
|||
SDLK_q, SDLK_w
|
||||
};
|
||||
|
||||
uint16_t motion[4] = {
|
||||
static uint32_t motion[4] = {
|
||||
SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2
|
||||
};
|
||||
|
||||
uint16_t defaultMotion[4] = {
|
||||
static uint32_t defaultMotion[4] = {
|
||||
SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2
|
||||
};
|
||||
|
||||
int sensorX = 2047;
|
||||
int sensorY = 2047;
|
||||
static int sensorX = 2047;
|
||||
static int sensorY = 2047;
|
||||
|
||||
static uint16_t sdlGetHatCode(const SDL_Event &event)
|
||||
static uint32_t sdlGetHatCode(const SDL_Event &event)
|
||||
{
|
||||
return (
|
||||
((event.jhat.which + 1) << 12) |
|
||||
((event.jhat.which + 1) << 16) |
|
||||
(event.jhat.hat << 2) |
|
||||
(
|
||||
event.jhat.value & SDL_HAT_UP ? 0 :
|
||||
|
@ -103,18 +103,18 @@ static uint16_t sdlGetHatCode(const SDL_Event &event)
|
|||
);
|
||||
}
|
||||
|
||||
static uint16_t sdlGetButtonCode(const SDL_Event &event)
|
||||
static uint32_t sdlGetButtonCode(const SDL_Event &event)
|
||||
{
|
||||
return (
|
||||
((event.jbutton.which + 1) << 12) |
|
||||
((event.jbutton.which + 1) << 16) |
|
||||
(event.jbutton.button + 0x80)
|
||||
);
|
||||
}
|
||||
|
||||
static uint16_t sdlGetAxisCode(const SDL_Event &event)
|
||||
static uint32_t sdlGetAxisCode(const SDL_Event &event)
|
||||
{
|
||||
return (
|
||||
((event.jaxis.which + 1) << 12) |
|
||||
((event.jaxis.which + 1) << 16) |
|
||||
(event.jaxis.axis << 1) |
|
||||
(
|
||||
event.jaxis.value > 16384 ? 1 :
|
||||
|
@ -123,7 +123,7 @@ static uint16_t sdlGetAxisCode(const SDL_Event &event)
|
|||
);
|
||||
}
|
||||
|
||||
uint16_t inputGetEventCode(const SDL_Event &event)
|
||||
uint32_t inputGetEventCode(const SDL_Event &event)
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
|
@ -147,12 +147,12 @@ uint16_t inputGetEventCode(const SDL_Event &event)
|
|||
}
|
||||
}
|
||||
|
||||
void inputSetKeymap(int joy, EKey key, uint16_t code)
|
||||
void inputSetKeymap(int joy, EKey key, uint32_t code)
|
||||
{
|
||||
joypad[joy][key] = code;
|
||||
}
|
||||
|
||||
void inputSetMotionKeymap(EKey key, uint16_t code)
|
||||
void inputSetMotionKeymap(EKey key, uint32_t code)
|
||||
{
|
||||
motion[key] = code;
|
||||
}
|
||||
|
@ -191,19 +191,19 @@ bool inputToggleAutoFire(EKey key)
|
|||
}
|
||||
}
|
||||
|
||||
static void sdlUpdateKey(int key, bool down)
|
||||
static void sdlUpdateKey(uint32_t key, bool down)
|
||||
{
|
||||
int i;
|
||||
for(int j = 0; j < 4; j++) {
|
||||
for(i = 0 ; i < SDLBUTTONS_NUM; i++) {
|
||||
if((joypad[j][i] & 0xf000) == 0) {
|
||||
if((joypad[j][i] & 0xffff0000) == 0) {
|
||||
if(key == joypad[j][i])
|
||||
sdlButtons[j][i] = down;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i = 0 ; i < 4; i++) {
|
||||
if((motion[i] & 0xf000) == 0) {
|
||||
if((motion[i] & 0xffff0000) == 0) {
|
||||
if(key == motion[i])
|
||||
sdlMotionButtons[i] = down;
|
||||
}
|
||||
|
@ -217,8 +217,8 @@ static void sdlUpdateJoyButton(int which,
|
|||
int i;
|
||||
for(int j = 0; j < 4; j++) {
|
||||
for(i = 0; i < SDLBUTTONS_NUM; i++) {
|
||||
int dev = (joypad[j][i] >> 12);
|
||||
int b = joypad[j][i] & 0xfff;
|
||||
int dev = (joypad[j][i] >> 16);
|
||||
int b = joypad[j][i] & 0xffff;
|
||||
if(dev) {
|
||||
dev--;
|
||||
|
||||
|
@ -229,8 +229,8 @@ static void sdlUpdateJoyButton(int which,
|
|||
}
|
||||
}
|
||||
for(i = 0; i < 4; i++) {
|
||||
int dev = (motion[i] >> 12);
|
||||
int b = motion[i] & 0xfff;
|
||||
int dev = (motion[i] >> 16);
|
||||
int b = motion[i] & 0xffff;
|
||||
if(dev) {
|
||||
dev--;
|
||||
|
||||
|
@ -248,8 +248,8 @@ static void sdlUpdateJoyHat(int which,
|
|||
int i;
|
||||
for(int j = 0; j < 4; j++) {
|
||||
for(i = 0; i < SDLBUTTONS_NUM; i++) {
|
||||
int dev = (joypad[j][i] >> 12);
|
||||
int a = joypad[j][i] & 0xfff;
|
||||
int dev = (joypad[j][i] >> 16);
|
||||
int a = joypad[j][i] & 0xffff;
|
||||
if(dev) {
|
||||
dev--;
|
||||
|
||||
|
@ -276,8 +276,8 @@ static void sdlUpdateJoyHat(int which,
|
|||
}
|
||||
}
|
||||
for(i = 0; i < 4; i++) {
|
||||
int dev = (motion[i] >> 12);
|
||||
int a = motion[i] & 0xfff;
|
||||
int dev = (motion[i] >> 16);
|
||||
int a = motion[i] & 0xffff;
|
||||
if(dev) {
|
||||
dev--;
|
||||
|
||||
|
@ -311,8 +311,8 @@ static void sdlUpdateJoyAxis(int which,
|
|||
int i;
|
||||
for(int j = 0; j < 4; j++) {
|
||||
for(i = 0; i < SDLBUTTONS_NUM; i++) {
|
||||
int dev = (joypad[j][i] >> 12);
|
||||
int a = joypad[j][i] & 0xfff;
|
||||
int dev = (joypad[j][i] >> 16);
|
||||
int a = joypad[j][i] & 0xffff;
|
||||
if(dev) {
|
||||
dev--;
|
||||
|
||||
|
@ -323,8 +323,8 @@ static void sdlUpdateJoyAxis(int which,
|
|||
}
|
||||
}
|
||||
for(i = 0; i < 4; i++) {
|
||||
int dev = (motion[i] >> 12);
|
||||
int a = motion[i] & 0xfff;
|
||||
int dev = (motion[i] >> 16);
|
||||
int a = motion[i] & 0xffff;
|
||||
if(dev) {
|
||||
dev--;
|
||||
|
||||
|
@ -337,8 +337,8 @@ static void sdlUpdateJoyAxis(int which,
|
|||
|
||||
static bool sdlCheckJoyKey(int key)
|
||||
{
|
||||
int dev = (key >> 12) - 1;
|
||||
int what = key & 0xfff;
|
||||
int dev = (key >> 16) - 1;
|
||||
int what = key & 0xffff;
|
||||
|
||||
if(what >= 128) {
|
||||
// joystick button
|
||||
|
@ -376,7 +376,7 @@ void inputInitJoysticks()
|
|||
|
||||
for(int j = 0; j < 4; j++) {
|
||||
for(i = 0; i < SDLBUTTONS_NUM; i++) {
|
||||
int dev = joypad[j][i] >> 12;
|
||||
int dev = joypad[j][i] >> 16;
|
||||
if(dev) {
|
||||
dev--;
|
||||
bool ok = false;
|
||||
|
@ -401,7 +401,7 @@ void inputInitJoysticks()
|
|||
}
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
int dev = motion[i] >> 12;
|
||||
int dev = motion[i] >> 16;
|
||||
if(dev) {
|
||||
dev--;
|
||||
bool ok = false;
|
||||
|
|
|
@ -49,14 +49,14 @@ void inputInitJoysticks();
|
|||
* @param key Emulated joypad button
|
||||
* @param code Code defining an actual joypad / keyboard button
|
||||
*/
|
||||
void inputSetKeymap(int joy, EKey key, uint16_t code);
|
||||
void inputSetKeymap(int joy, EKey key, uint32_t code);
|
||||
|
||||
/**
|
||||
* Define which keys control motion detection emulation
|
||||
* @param key Emulated joypad button
|
||||
* @param code Code defining an actual joypad / keyboard button
|
||||
*/
|
||||
void inputSetMotionKeymap(EKey key, uint16_t code);
|
||||
void inputSetMotionKeymap(EKey key, uint32_t code);
|
||||
|
||||
/**
|
||||
* Toggle Auto fire for the specified button. Only A, B, R, L are supported.
|
||||
|
@ -76,7 +76,7 @@ void inputProcessSDLEvent(const SDL_Event &event);
|
|||
* @param SDL_Event An event that has just occured
|
||||
* @return Keymap code
|
||||
*/
|
||||
uint16_t inputGetEventCode(const SDL_Event &event);
|
||||
uint32_t inputGetEventCode(const SDL_Event &event);
|
||||
|
||||
/**
|
||||
* Read the state of an emulated joypad
|
||||
|
|
Loading…
Reference in New Issue