remap-redux part2:

- remapping analogs to buttons works 100%
- remapping analogs to other analogs still messed up for some reason
- need to reset input of the original axis in input_driver.c still
This commit is contained in:
radius 2018-04-08 00:44:05 -05:00
parent f662d9f65f
commit 0ed9f05571
3 changed files with 58 additions and 7 deletions

View File

@ -1121,7 +1121,8 @@ void input_keys_pressed(void *data, retro_bits_t* p_new_state)
void input_get_state_for_port(void *data, unsigned port, retro_bits_t* p_new_state) void input_get_state_for_port(void *data, unsigned port, retro_bits_t* p_new_state)
{ {
unsigned i; unsigned i, j;
int16_t val;
rarch_joypad_info_t joypad_info; rarch_joypad_info_t joypad_info;
settings_t *settings = (settings_t*)data; settings_t *settings = (settings_t*)data;
BIT256_CLEAR_ALL_PTR(p_new_state); BIT256_CLEAR_ALL_PTR(p_new_state);
@ -1140,6 +1141,35 @@ void input_get_state_for_port(void *data, unsigned port, retro_bits_t* p_new_sta
if (bit_pressed) if (bit_pressed)
BIT256_SET_PTR(p_new_state, i); BIT256_SET_PTR(p_new_state, i);
} }
/* left-stick x */
val = input_joypad_analog(input_driver_get_joypad_driver(), joypad_info, port, 0, 0, libretro_input_binds[port]);
if (val >= 0)
p_new_state->analogs[0] = val;
else
p_new_state->analogs[1] = val;
/* left-stick y */
val = input_joypad_analog(input_driver_get_joypad_driver(), joypad_info, port, 0, 1, libretro_input_binds[port]);
if (val >= 0)
p_new_state->analogs[2] = val;
else
p_new_state->analogs[3] = val;
/* right-stick x */
val = input_joypad_analog(input_driver_get_joypad_driver(), joypad_info, port, 1, 0, libretro_input_binds[port]);
if (val >= 0)
p_new_state->analogs[4] = val;
else
p_new_state->analogs[5] = val;
/* right-stick y */
val = input_joypad_analog(input_driver_get_joypad_driver(), joypad_info, port, 1, 1, libretro_input_binds[port]);
if (val >= 0)
p_new_state->analogs[6] = val;
else
p_new_state->analogs[7] = val;
} }
void *input_driver_get_data(void) void *input_driver_get_data(void)

View File

@ -51,7 +51,7 @@
struct input_mapper struct input_mapper
{ {
/* Left X, Left Y, Right X, Right Y */ /* Left X, Left Y, Right X, Right Y */
int16_t analog[4]; int16_t analog[MAX_USERS][8];
/* the whole keyboard state */ /* the whole keyboard state */
uint32_t keys[RETROK_LAST / 32 + 1]; uint32_t keys[RETROK_LAST / 32 + 1];
/* This is a bitmask of (1 << key_bind_id). */ /* This is a bitmask of (1 << key_bind_id). */
@ -83,13 +83,14 @@ bool input_mapper_button_pressed(input_mapper_t *handle, unsigned port, unsigned
void input_mapper_poll(input_mapper_t *handle) void input_mapper_poll(input_mapper_t *handle)
{ {
int i, j; int i, j, k;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
retro_bits_t current_input; retro_bits_t current_input;
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; unsigned device = 0;
unsigned current_button_value; unsigned current_button_value;
unsigned remap_button; int16_t current_axis_value;
unsigned remap_button, remap_axis;
bool key_event[RARCH_CUSTOM_BIND_LIST_END]; bool key_event[RARCH_CUSTOM_BIND_LIST_END];
#ifdef HAVE_MENU #ifdef HAVE_MENU
bool menu_is_alive = menu_driver_is_alive(); bool menu_is_alive = menu_driver_is_alive();
@ -157,15 +158,29 @@ void input_mapper_poll(input_mapper_t *handle)
remap_button != RARCH_UNMAPPED) remap_button != RARCH_UNMAPPED)
BIT256_SET(handle->buttons[i], remap_button); BIT256_SET(handle->buttons[i], remap_button);
} }
#if 0 #if 1
/* --CURRENTLY NOT IMPLEMENTED-- /* --CURRENTLY NOT IMPLEMENTED--
this loop should iterate on all users and all analog stick axes and if the axes are this loop should iterate on all users and all analog stick axes and if the axes are
moved and is assigned to a button it should set the bit on the mapper input bitmap. moved and is assigned to a button it should set the bit on the mapper input bitmap.
Once implemented we should make sure to clear the original analog Once implemented we should make sure to clear the original analog
stick input in input_state in input_driver.c */ stick input in input_state in input_driver.c */
for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_CUSTOM_BIND_LIST_END; j++) for (j = 0; j < 8; j++)
{ } {
handle->analog[i][j] = 0;
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)
BIT256_SET(handle->buttons[i], remap_axis);
else
handle->analog[i][remap_axis - RARCH_FIRST_CUSTOM_BIND] = current_axis_value;
}
}
#endif #endif
} }
} }
@ -188,6 +203,10 @@ void input_mapper_state(
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:
if (handle->analog[port][idx == 0 ? id : id / 2] != 0)
*ret = handle->analog[port][idx == 0 ? id : id / 2];
break;
case RETRO_DEVICE_KEYBOARD: case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST) if (id < RETROK_LAST)
{ {

View File

@ -153,6 +153,8 @@ static INLINE bool bits_any_set(uint32_t* ptr, uint32_t count)
typedef struct typedef struct
{ {
uint32_t data[8]; uint32_t data[8];
uint16_t analogs[8];
} retro_bits_t; } retro_bits_t;
#endif #endif