Fix RETRO_DEVICE_ANALOG for keyboard binds.

This commit is contained in:
Themaister 2013-11-09 01:01:18 +01:00
parent 9b34000434
commit b20f8670b0
5 changed files with 79 additions and 8 deletions

View File

@ -197,6 +197,24 @@ static bool dinput_is_pressed(struct dinput_input *di, const struct retro_keybin
return dinput_keyboard_pressed(di, bind->key) || input_joypad_pressed(di->joypad, port, binds, id);
}
static int16_t dinput_pressed_analog(struct dinput_input *di,
const struct retro_keybind *binds,
unsigned index, unsigned id)
{
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
const struct retro_keybind *bind_minus = &binds[id_minus];
const struct retro_keybind *bind_plus = &binds[id_plus];
if (!bind_minus->valid || !bind_plus->valid)
return 0;
int16_t pressed_minus = dinput_keyboard_pressed(di, bind_minus->key) ? -0x7fff : 0;
int16_t pressed_plus = dinput_keyboard_pressed(di, bind_plus->key) ? 0x7fff : 0;
return pressed_plus + pressed_minus;
}
static bool dinput_key_pressed(void *data, int key)
{
return dinput_is_pressed((struct dinput_input*)data, g_settings.input.binds[0], 0, key);
@ -294,6 +312,8 @@ static int16_t dinput_input_state(void *data,
unsigned device, unsigned index, unsigned id)
{
struct dinput_input *di = (struct dinput_input*)data;
int16_t ret;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
@ -303,7 +323,10 @@ static int16_t dinput_input_state(void *data,
return dinput_keyboard_pressed(di, id);
case RETRO_DEVICE_ANALOG:
return input_joypad_analog(di->joypad, port, index, id, g_settings.input.binds[port]);
ret = input_joypad_analog(di->joypad, port, index, id, g_settings.input.binds[port]);
if (!ret)
dinput_pressed_analog(di, binds[port], index, id);
return ret;
case RETRO_DEVICE_MOUSE:
return dinput_mouse_state(di, id);

View File

@ -254,6 +254,20 @@ static bool linuxraw_is_pressed(linuxraw_input_t *linuxraw, const struct retro_k
return false;
}
static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw,
const struct retro_keybind *binds, unsigned index, unsigned id)
{
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
int16_t pressed_minus = linuxraw_is_pressed(linuxraw,
binds, id_minus) ? -0x7fff : 0;
int16_t pressed_plus = linuxraw_is_pressed(linuxraw,
binds, id_plus) ? 0x7fff : 0;
return pressed_plus + pressed_minus;
}
static bool linuxraw_bind_button_pressed(void *data, int key)
{
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
@ -264,6 +278,7 @@ static bool linuxraw_bind_button_pressed(void *data, int key)
static int16_t linuxraw_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id)
{
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
int16_t ret;
switch (device)
{
@ -272,7 +287,10 @@ static int16_t linuxraw_input_state(void *data, const struct retro_keybind **bin
input_joypad_pressed(linuxraw->joypad, port, binds[port], id);
case RETRO_DEVICE_ANALOG:
return input_joypad_analog(linuxraw->joypad, port, index, id, binds[port]);
ret = input_joypad_analog(linuxraw->joypad, port, index, id, binds[port]);
if (!ret)
ret = linuxraw_analog_pressed(linuxraw, binds[port], index, id);
return ret;
default:
return 0;

View File

@ -67,6 +67,18 @@ static bool sdl_is_pressed(sdl_input_t *sdl, unsigned port_num, const struct ret
return input_joypad_pressed(sdl->joypad, port_num, binds, key);
}
static int16_t sdl_analog_pressed(sdl_input_t *sdl, const struct retro_keybind *binds,
unsigned index, unsigned id)
{
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
int16_t pressed_minus = sdl_key_pressed(binds[id_minus].key) ? -0x7fff : 0;
int16_t pressed_plus = sdl_key_pressed(binds[id_plus].key) ? 0x7fff : 0;
return pressed_plus + pressed_minus;
}
static bool sdl_bind_button_pressed(void *data, int key)
{
const struct retro_keybind *binds = g_settings.input.binds[0];
@ -89,7 +101,10 @@ static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct retro_keyb
static int16_t sdl_analog_device_state(sdl_input_t *sdl, const struct retro_keybind **binds,
unsigned port_num, unsigned index, unsigned id)
{
return input_joypad_analog(sdl->joypad, port_num, index, id, binds[port_num]);
int16_t ret = input_joypad_analog(sdl->joypad, port_num, index, id, binds[port_num]);
if (!ret)
ret = sdl_analog_pressed(sdl, binds[port_num], index, id);
return ret;
}
static int16_t sdl_keyboard_device_state(sdl_input_t *sdl, unsigned id)

View File

@ -85,6 +85,17 @@ static bool x_is_pressed(x11_input_t *x11, const struct retro_keybind *binds, un
return false;
}
static int16_t x_pressed_analog(x11_input_t *x11, const struct retro_keybind *binds, unsigned index, unsigned id)
{
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
int16_t pressed_minus = x_is_pressed(x11, binds, id_minus) ? -0x7fff : 0;
int16_t pressed_plus = x_is_pressed(x11, binds, id_plus) ? 0x7fff : 0;
return pressed_plus + pressed_minus;
}
static bool x_bind_button_pressed(void *data, int key)
{
x11_input_t *x11 = (x11_input_t*)data;
@ -171,6 +182,7 @@ static int16_t x_lightgun_state(x11_input_t *x11, unsigned id)
static int16_t x_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id)
{
x11_input_t *x11 = (x11_input_t*)data;
int16_t ret;
switch (device)
{
@ -182,7 +194,10 @@ static int16_t x_input_state(void *data, const struct retro_keybind **binds, uns
return x_key_pressed(x11, id);
case RETRO_DEVICE_ANALOG:
return input_joypad_analog(x11->joypad, port, index, id, binds[port]);
ret = input_joypad_analog(x11->joypad, port, index, id, binds[port]);
if (!ret)
ret = x_pressed_analog(x11, binds[port], index, id);
return ret;
case RETRO_DEVICE_MOUSE:
return x_mouse_state(x11, id);

View File

@ -168,10 +168,10 @@ static void update_input(void)
if (pointer_pressed)
fprintf(stderr, "Pointer: (%6d, %6d).\n", pointer_x, pointer_y);
dir_x += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 2000;
dir_y += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 2000;
//dir_x += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 2000;
//dir_y += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 2000;
dir_x += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 5000;
dir_y += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 5000;
dir_x += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 5000;
dir_y += input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 5000;
x_coord = (x_coord + dir_x) & 31;
y_coord = (y_coord + dir_y) & 31;