(input_mapper.c) Small non-functional cleanups

This commit is contained in:
twinaphex 2018-04-08 22:36:48 +02:00
parent 019e2acd92
commit a646fd3e65

View File

@ -58,6 +58,11 @@ struct input_mapper
input_bits_t buttons[MAX_USERS]; input_bits_t buttons[MAX_USERS];
}; };
static bool input_mapper_button_pressed(input_mapper_t *handle, unsigned port, unsigned id)
{
return BIT256_GET(handle->buttons[port], id);
}
input_mapper_t *input_mapper_new(void) input_mapper_t *input_mapper_new(void)
{ {
input_mapper_t* handle = (input_mapper_t*) input_mapper_t* handle = (input_mapper_t*)
@ -76,19 +81,12 @@ void input_mapper_free(input_mapper_t *handle)
free (handle); free (handle);
} }
bool input_mapper_button_pressed(input_mapper_t *handle, unsigned port, unsigned id)
{
return BIT256_GET(handle->buttons[port], id);
}
void input_mapper_poll(input_mapper_t *handle) void input_mapper_poll(input_mapper_t *handle)
{ {
int i, j; int i, j;
input_bits_t current_input; input_bits_t current_input;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
unsigned device = 0;
int16_t current_axis_value;
bool key_event[RARCH_CUSTOM_BIND_LIST_END]; bool key_event[RARCH_CUSTOM_BIND_LIST_END];
#ifdef HAVE_MENU #ifdef HAVE_MENU
@ -100,104 +98,135 @@ void input_mapper_poll(input_mapper_t *handle)
for (i = 0; i < max_users; i++) for (i = 0; i < max_users; i++)
{ {
device = settings->uints.input_libretro_device[i]; unsigned device = settings->uints.input_libretro_device[i];
device &= RETRO_DEVICE_MASK; device &= RETRO_DEVICE_MASK;
/* keyboard to gamepad remapping */ switch (device)
if (device == RETRO_DEVICE_KEYBOARD)
{ {
input_get_state_for_port(settings, i, &current_input); /* keyboard to gamepad remapping */
for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++) case RETRO_DEVICE_KEYBOARD:
{ input_get_state_for_port(settings, i, &current_input);
unsigned current_button_value = BIT256_GET(current_input, j); for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++)
unsigned remap_button = settings->uints.input_keymapper_ids[i][j]; {
unsigned current_button_value = BIT256_GET(current_input, j);
unsigned remap_button =
settings->uints.input_keymapper_ids[i][j];
if (current_button_value == 1 && j != remap_button && if (
remap_button != RETROK_UNKNOWN) (current_button_value == 1) &&
{ (j != remap_button) &&
MAPPER_SET_KEY (handle, (remap_button != RETROK_UNKNOWN)
remap_button); )
input_keyboard_event(true,
remap_button,
0, 0, RETRO_DEVICE_KEYBOARD);
key_event[j] = true;
}
else
{
if (key_event[j] == false &&
remap_button != RETROK_UNKNOWN)
{ {
input_keyboard_event(false, MAPPER_SET_KEY (handle,
remap_button);
input_keyboard_event(true,
remap_button, remap_button,
0, 0, RETRO_DEVICE_KEYBOARD); 0, 0, RETRO_DEVICE_KEYBOARD);
key_event[j] = true;
}
else
{
if ( (key_event[j] == false) &&
(remap_button != RETROK_UNKNOWN)
)
{
input_keyboard_event(false,
remap_button,
0, 0, RETRO_DEVICE_KEYBOARD);
}
} }
} }
} break;
}
/* gamepad remapping */ /* gamepad remapping */
if (device == RETRO_DEVICE_JOYPAD || device == RETRO_DEVICE_ANALOG) case RETRO_DEVICE_JOYPAD:
{ case RETRO_DEVICE_ANALOG:
/* this loop iterates on all users and all buttons, and checks if a pressed button /* this loop iterates on all users and all buttons,
is assigned to any other button than the default one, then it sets the bit on the * and checks if a pressed button is assigned to any
mapper input bitmap, later on the original input is cleared in input_state */ * other button than the default one, then it sets
BIT256_CLEAR_ALL(handle->buttons[i]); * the bit on the mapper input bitmap, later on the
for (j = 0; j < 8; j++) * original input is cleared in input_state */
handle->analog_value[i][j] = 0; BIT256_CLEAR_ALL(handle->buttons[i]);
input_get_state_for_port(settings, i, &current_input); for (j = 0; j < 8; j++)
handle->analog_value[i][j] = 0;
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++) input_get_state_for_port(settings, i, &current_input);
{
unsigned current_button_value = BIT256_GET(current_input, j);
unsigned remap_button = settings->uints.input_remap_ids[i][j];
if (current_button_value == 1 && j != remap_button && for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++)
remap_button != RARCH_UNMAPPED && remap_button < RARCH_FIRST_CUSTOM_BIND)
BIT256_SET(handle->buttons[i], remap_button);
else if (current_button_value == 1 && j != remap_button &&
remap_button != RARCH_UNMAPPED && remap_button >= RARCH_FIRST_CUSTOM_BIND)
{ {
unsigned current_button_value = BIT256_GET(current_input, j);
unsigned remap_button =
settings->uints.input_remap_ids[i][j];
if (
(current_button_value == 1) &&
(j != remap_button) &&
(remap_button != RARCH_UNMAPPED) &&
(remap_button < RARCH_FIRST_CUSTOM_BIND)
)
BIT256_SET(handle->buttons[i], remap_button);
else if (
(current_button_value == 1) &&
(j != remap_button) &&
(remap_button != RARCH_UNMAPPED) &&
(remap_button >= RARCH_FIRST_CUSTOM_BIND)
)
{
int invert = 1; int invert = 1;
if (remap_button % 2 != 0) if (remap_button % 2 != 0)
invert = -1; invert = -1;
handle->analog_value[i][remap_button - RARCH_FIRST_CUSTOM_BIND] = 32767 * invert; handle->analog_value[i][
/* RARCH_LOG("axis %d(%d) remapped to axis %d val %d\n", j, k, remap_button - RARCH_FIRST_CUSTOM_BIND] =
remap_button - RARCH_FIRST_CUSTOM_BIND, current_axis_value); */ 32767 * invert;
}
} }
}
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
{
unsigned remap_axis;
unsigned k = j + RARCH_FIRST_CUSTOM_BIND;
current_axis_value = current_input.analogs[j];
remap_axis = settings->uints.input_remap_ids[i][k];
if (current_axis_value != 0 && k != remap_axis && remap_axis != RARCH_UNMAPPED)
{ {
if (remap_axis < RARCH_FIRST_CUSTOM_BIND) unsigned k = j + RARCH_FIRST_CUSTOM_BIND;
{ int16_t current_axis_value = current_input.analogs[j];
BIT256_SET(handle->buttons[i], remap_axis); unsigned remap_axis =
/* RARCH_LOG("axis %d remapped to button %d val %d\n", j, settings->uints.input_remap_ids[i][k];
remap_axis, current_axis_value); */
}
else
{
int invert = 1;
if ((k % 2 == 0 && remap_axis % 2 != 0) || (k % 2 != 0 && remap_axis % 2 == 0)) if (
invert = -1; (current_axis_value != 0) &&
(k != remap_axis) &&
(remap_axis != RARCH_UNMAPPED)
)
{
if (remap_axis < RARCH_FIRST_CUSTOM_BIND)
{
BIT256_SET(handle->buttons[i], remap_axis);
}
else
{
int invert = 1;
handle->analog_value[i][remap_axis - RARCH_FIRST_CUSTOM_BIND] = current_axis_value * invert; if ( (k % 2 == 0 && remap_axis % 2 != 0) ||
/* RARCH_LOG("axis %d(%d) remapped to axis %d val %d\n", j, k, (k % 2 != 0 && remap_axis % 2 == 0)
remap_axis - RARCH_FIRST_CUSTOM_BIND, current_axis_value); */ )
invert = -1;
handle->analog_value[i][
remap_axis - RARCH_FIRST_CUSTOM_BIND] =
current_axis_value * invert;
#if 0
RARCH_LOG("axis %d(%d) remapped to axis %d val %d\n",
j, k,
remap_axis - RARCH_FIRST_CUSTOM_BIND,
current_axis_value);
#endif
}
} }
} }
break;
} default:
break;
} }
} }
} }
@ -217,30 +246,29 @@ void input_mapper_state(
{ {
case RETRO_DEVICE_JOYPAD: case RETRO_DEVICE_JOYPAD:
if (input_mapper_button_pressed(handle, port, id)) if (input_mapper_button_pressed(handle, port, id))
*ret = 1; *ret = 1;
break; break;
case RETRO_DEVICE_ANALOG: case RETRO_DEVICE_ANALOG:
if (idx < 2 && id < 2) if (idx < 2 && id < 2)
{ {
int val = 0; int val = 0;
unsigned offset = 0 + (idx * 4) + (id * 2); unsigned offset = 0 + (idx * 4) + (id * 2);
int val1 = handle->analog_value[port][offset];
int val2 = handle->analog_value[port][offset+1];
if (handle->analog_value[port][offset]) if (val1)
val = handle->analog_value[port][offset]; val = val1;
else if (handle->analog_value[port][offset+1]) else if (val2)
val = handle->analog_value[port][offset+1]; val = val2;
if ( handle->analog_value[port][offset] || if (val1 || val2)
handle->analog_value[port][offset+1]) *ret |= val;
*ret |= val;
} }
break; break;
case RETRO_DEVICE_KEYBOARD: case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST) if (id < RETROK_LAST)
{
if (MAPPER_GET_KEY(handle, id)) if (MAPPER_GET_KEY(handle, id))
*ret |= 1; *ret |= 1;
}
break; break;
default: default:
break; break;