Debork input some more ...

This commit is contained in:
Themaister 2012-01-30 01:45:18 +01:00
parent 5b0a948797
commit 08686bcd06
3 changed files with 32 additions and 53 deletions

View File

@ -70,19 +70,12 @@ static int16_t input_ext_input_state(void *data, const struct snes_keybind **sne
else
player = (port == SNES_PORT_1) ? 1 : 2;
const struct snes_keybind *ssnes_bind = NULL;
for (unsigned i = 0; g_settings.input.binds[player - 1][i].id != -1; i++)
if (id < SSNES_BIND_LIST_END)
{
if (g_settings.input.binds[player - 1][i].id == (int)id)
{
ssnes_bind = &g_settings.input.binds[player - 1][i];
break;
}
}
const struct snes_keybind *ssnes_bind = &snes_keybinds[player - 1][id];
if (!ssnes_bind->valid)
return 0;
if (ssnes_bind)
{
struct ssnes_keybind bind = {0};
bind.key = ssnes_bind->key;
bind.joykey = ssnes_bind->joykey;
@ -98,18 +91,12 @@ static bool input_ext_key_pressed(void *data, int key)
{
input_ext_t *ext = (input_ext_t*)data;
const struct snes_keybind *ssnes_bind = NULL;
for (unsigned i = 0; g_settings.input.binds[0][i].id != -1; i++)
if (key >= 0 && key < SSNES_BIND_LIST_END)
{
if (g_settings.input.binds[0][i].id == key)
{
ssnes_bind = &g_settings.input.binds[0][i];
break;
}
}
const struct snes_keybind *ssnes_bind = &g_settings.input.binds[0][key];
if (!ssnes_bind->valid)
return false;
if (ssnes_bind)
{
struct ssnes_keybind bind = {0};
bind.key = ssnes_bind->key;
bind.joykey = ssnes_bind->joykey;

View File

@ -268,28 +268,27 @@ static bool sdl_is_pressed(sdl_input_t *sdl, unsigned port_num, const struct sne
static bool sdl_bind_button_pressed(void *data, int key)
{
// Only let player 1 use special binds called from main loop.
const struct snes_keybind *binds = g_settings.input.binds[0];
for (unsigned i = 0; binds[i].id != -1; i++)
if (key >= 0 && key < SSNES_BIND_LIST_END)
{
if (binds[i].id == key)
return sdl_is_pressed((sdl_input_t*)data, 0, &binds[i]);
const struct snes_keybind *bind = &binds[key];
return sdl_is_pressed((sdl_input_t*)data, 0, bind);
}
return false;
else
return false;
}
static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct snes_keybind **binds,
unsigned port_num, int id)
static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct snes_keybind **binds_,
unsigned port_num, unsigned id)
{
const struct snes_keybind *snes_keybinds = binds[port_num];
for (unsigned i = 0; snes_keybinds[i].id != -1; i++)
const struct snes_keybind *binds = binds_[port_num];
if (id < SSNES_BIND_LIST_END)
{
if (snes_keybinds[i].id == id)
return sdl_is_pressed(sdl, port_num, &snes_keybinds[i]) ? 1 : 0;
const struct snes_keybind *bind = &binds[id];
return bind->valid ? (sdl_is_pressed(sdl, port_num, bind) ? 1 : 0) : 0;
}
return 0;
else
return 0;
}
static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id)

View File

@ -169,42 +169,35 @@ static bool x_key_pressed(x11_input_t *x11, int key)
static bool x_is_pressed(x11_input_t *x11, const struct snes_keybind *binds, unsigned id)
{
for (int i = 0; binds[i].id != -1; i++)
if (id < SSNES_BIND_LIST_END)
{
if (binds[i].id == (int)id)
return x_key_pressed(x11, binds[i].key);
const struct snes_keybind *bind = &binds[id];
return bind->valid && x_key_pressed(x11, binds[id].key);
}
return false;
else
return false;
}
static bool x_bind_button_pressed(void *data, int key)
{
x11_input_t *x11 = (x11_input_t*)data;
bool pressed = x_is_pressed(x11, g_settings.input.binds[0], key);
if (!pressed)
return input_sdl.key_pressed(x11->sdl, key);
return pressed;
return x_is_pressed(x11, g_settings.input.binds[0], key) ||
input_sdl.key_pressed(x11->sdl, key);
}
static int16_t x_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id)
{
x11_input_t *x11 = (x11_input_t*)data;
bool pressed = false;
switch (device)
{
case SNES_DEVICE_JOYPAD:
pressed = x_is_pressed(x11, binds[(port == SNES_PORT_1) ? 0 : 1], id);
if (!pressed)
pressed = input_sdl.input_state(x11->sdl, binds, port, device, index, id);
return pressed;
return x_is_pressed(x11, binds[(port == SNES_PORT_1) ? 0 : 1], id) ||
input_sdl.input_state(x11->sdl, binds, port, device, index, id);
case SNES_DEVICE_MULTITAP:
pressed = x_is_pressed(x11, binds[(port == SNES_PORT_2) ? 1 + index : 0], id);
if (!pressed)
pressed = input_sdl.input_state(x11->sdl, binds, port, device, index, id);
return pressed;
return x_is_pressed(x11, binds[(port == SNES_PORT_2) ? 1 + index : 0], id) ||
input_sdl.input_state(x11->sdl, binds, port, device, index, id);
default:
return 0;