mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
remap-redux part2: better wraparound, skip analogs, add RARCH_UNMAPPED
This commit is contained in:
parent
23331aa484
commit
5efba1c257
@ -35,6 +35,8 @@ RETRO_BEGIN_DECLS
|
||||
#define RARCH_FIRST_MISC_CUSTOM_BIND RARCH_LIGHTGUN_BIND_LIST_END
|
||||
#define RARCH_FIRST_META_KEY RARCH_CUSTOM_BIND_LIST_END
|
||||
|
||||
#define RARCH_UNMAPPED 1024
|
||||
|
||||
/* RetroArch specific bind IDs. */
|
||||
enum
|
||||
{
|
||||
|
@ -666,13 +666,6 @@ int16_t input_state(unsigned port, unsigned device,
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
if (idx < 2 && id < 2)
|
||||
{
|
||||
unsigned new_id = RARCH_FIRST_CUSTOM_BIND + (idx * 2 + id);
|
||||
|
||||
new_id = settings->uints.input_remap_ids[port][new_id];
|
||||
idx = (new_id & 2) >> 1;
|
||||
id = new_id & 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,10 @@ void input_mapper_poll(input_mapper_t *handle)
|
||||
{
|
||||
int i, j;
|
||||
settings_t *settings = config_get_ptr();
|
||||
retro_bits_t current_input;
|
||||
unsigned device = settings->uints.input_libretro_device[handle->port];
|
||||
unsigned current_button_value;
|
||||
unsigned remap_button;
|
||||
bool key_event[RARCH_CUSTOM_BIND_LIST_END];
|
||||
#ifdef HAVE_MENU
|
||||
bool menu_is_alive = menu_driver_is_alive();
|
||||
@ -141,18 +144,66 @@ void input_mapper_poll(input_mapper_t *handle)
|
||||
}
|
||||
if (device == RETRO_DEVICE_JOYPAD)
|
||||
{
|
||||
retro_bits_t current_input;
|
||||
input_keys_pressed(settings, ¤t_input);
|
||||
BIT256_CLEAR_ALL(handle->buttons);
|
||||
for (i = 0; i < MAX_USERS; i++)
|
||||
{
|
||||
for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++)
|
||||
/* this loop iterates on all users and all buttons, and checks if a pressed button
|
||||
is assigned to any other button than the default one, then it sets the bit on the
|
||||
mapper input bitmap, later on the original input is cleared in input_state */
|
||||
|
||||
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++)
|
||||
{
|
||||
int aux = BIT256_GET(current_input, j);
|
||||
int remap = settings->uints.input_remap_ids[i][j];
|
||||
if (aux == 1 && j != remap)
|
||||
BIT256_SET(handle->buttons, remap);
|
||||
current_button_value = BIT256_GET(current_input, j);
|
||||
remap_button = settings->uints.input_remap_ids[i][j];
|
||||
if (current_button_value == 1 && j != remap_button &&
|
||||
remap_button != RARCH_UNMAPPED)
|
||||
BIT256_SET(handle->buttons, remap_button);
|
||||
}
|
||||
#if 0
|
||||
/* --CURRENTLY NOT IMPLEMENTED--
|
||||
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.
|
||||
Once implemented we should make sure to clear the original analog
|
||||
stick input in input_state in input_driver.c */
|
||||
|
||||
for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_CUSTOM_BIND_LIST_END; j++)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (device == RETRO_DEVICE_ANALOG)
|
||||
{
|
||||
input_keys_pressed(settings, ¤t_input);
|
||||
BIT256_CLEAR_ALL(handle->buttons);
|
||||
for (i = 0; i < MAX_USERS; i++)
|
||||
{
|
||||
/* this loop iterates on all users and all buttons, and checks if a pressed button
|
||||
is assigned to any other button than the default one, then it sets the bit on the
|
||||
mapper input bitmap, later on the original input is cleared in input_state */
|
||||
|
||||
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++)
|
||||
{
|
||||
current_button_value = BIT256_GET(current_input, j);
|
||||
remap_button = settings->uints.input_remap_ids[i][j];
|
||||
if (current_button_value == 1 && j != remap_button &&
|
||||
remap_button != RARCH_UNMAPPED)
|
||||
BIT256_SET(handle->buttons, remap_button);
|
||||
}
|
||||
#if 0
|
||||
/* --CURRENTLY NOT IMPLEMENTED--
|
||||
this loop should iterate on all users and all analog stick axes and if the axes are
|
||||
moved and is assigned to a button or another stick, it should set the bit on the
|
||||
mapper input bitmap. Once implemented we should make sure to clear the original analog
|
||||
stick input in input_state in input_driver.c */
|
||||
|
||||
for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_CUSTOM_BIND_LIST_END; j++)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,18 +73,21 @@ bool input_remapping_load_file(void *data, const char *path)
|
||||
|
||||
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 4; j++)
|
||||
{
|
||||
int key_remap = -1;
|
||||
int btn_remap = -1;
|
||||
|
||||
fill_pathname_join_delim(key_ident[j], s1,
|
||||
key_strings[j], '_', sizeof(key_ident[j]));
|
||||
fill_pathname_join_delim(keymapper_ident[j], s2,
|
||||
key_strings[j], '_', sizeof(key_ident[j]));
|
||||
|
||||
if (config_get_int(conf, key_ident[j], &key_remap)
|
||||
&& key_remap < RARCH_FIRST_CUSTOM_BIND)
|
||||
settings->uints.input_remap_ids[i][j] = key_remap;
|
||||
if (config_get_int(conf, key_ident[j], &btn_remap)
|
||||
&& (btn_remap < RARCH_FIRST_CUSTOM_BIND && btn_remap != -1))
|
||||
settings->uints.input_remap_ids[i][j] = btn_remap;
|
||||
else if (config_get_int(conf, key_ident[j], &btn_remap)
|
||||
&& (btn_remap == -1))
|
||||
settings->uints.input_remap_ids[i][j] = RARCH_UNMAPPED;
|
||||
|
||||
key_remap = -1;
|
||||
int key_remap = -1;
|
||||
|
||||
if (config_get_int(conf, keymapper_ident[j], &key_remap))
|
||||
settings->uints.input_keymapper_ids[i][j] = key_remap;
|
||||
@ -96,7 +99,7 @@ bool input_remapping_load_file(void *data, const char *path)
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
int key_remap = -1;
|
||||
int btn_remap = -1;
|
||||
|
||||
snprintf(key_ident[RARCH_FIRST_CUSTOM_BIND + j],
|
||||
sizeof(key_ident[RARCH_FIRST_CUSTOM_BIND + j]),
|
||||
@ -105,9 +108,9 @@ bool input_remapping_load_file(void *data, const char *path)
|
||||
key_strings[RARCH_FIRST_CUSTOM_BIND + j]);
|
||||
|
||||
if (config_get_int(conf, key_ident[RARCH_FIRST_CUSTOM_BIND + j],
|
||||
&key_remap) && (key_remap < 4))
|
||||
&btn_remap) && (btn_remap < 4))
|
||||
settings->uints.input_remap_ids[i][RARCH_FIRST_CUSTOM_BIND + j] =
|
||||
key_remap;
|
||||
btn_remap;
|
||||
}
|
||||
|
||||
snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1);
|
||||
@ -189,8 +192,10 @@ bool input_remapping_save_file(const char *path)
|
||||
/* only save values that have been modified */
|
||||
if(j < RARCH_FIRST_CUSTOM_BIND)
|
||||
{
|
||||
if(settings->uints.input_remap_ids[i][j] != j)
|
||||
if(settings->uints.input_remap_ids[i][j] != j && settings->uints.input_remap_ids[i][j] != RARCH_UNMAPPED)
|
||||
config_set_int(conf, key_ident[j], settings->uints.input_remap_ids[i][j]);
|
||||
else if (settings->uints.input_remap_ids[i][j] != j && settings->uints.input_remap_ids[i][j] == RARCH_UNMAPPED)
|
||||
config_set_int(conf, key_ident[j], -1);
|
||||
else
|
||||
config_unset(conf,key_ident[j]);
|
||||
|
||||
|
@ -562,6 +562,9 @@ static void menu_action_setting_disp_set_label_input_desc(
|
||||
remap_idx =
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx];
|
||||
|
||||
if (remap_idx == RARCH_UNMAPPED)
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED;
|
||||
|
||||
if (!system)
|
||||
return;
|
||||
|
||||
|
@ -103,14 +103,22 @@ static int action_left_input_desc(unsigned type, const char *label,
|
||||
user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
|
||||
btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
|
||||
|
||||
if (settings->uints.input_remap_ids[user_idx][btn_idx] == RARCH_UNMAPPED)
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_CUSTOM_BIND_LIST_END - 1;
|
||||
|
||||
if (settings->uints.input_remap_ids[user_idx][btn_idx] > 0)
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx]--;
|
||||
else if (settings->uints.input_remap_ids[user_idx][btn_idx] == 0)
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED;
|
||||
else
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_FIRST_CUSTOM_BIND;
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_CUSTOM_BIND_LIST_END - 1;
|
||||
|
||||
/* skip the not used button (unless they are at the end by calling the right desc function recursively */
|
||||
remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
|
||||
if (string_is_empty(system->input_desc_btn[user_idx][remap_idx]) && remap_idx < RARCH_FIRST_CUSTOM_BIND)
|
||||
|
||||
/* skip the not used buttons (unless they are at the end by calling the right desc function recursively
|
||||
also skip all the axes until analog remapping is implemented */
|
||||
if ((string_is_empty(system->input_desc_btn[user_idx][remap_idx]) && remap_idx < RARCH_CUSTOM_BIND_LIST_END) ||
|
||||
(remap_idx >= RARCH_FIRST_CUSTOM_BIND && remap_idx < RARCH_CUSTOM_BIND_LIST_END))
|
||||
action_left_input_desc(type, label, wraparound);
|
||||
|
||||
return 0;
|
||||
|
@ -155,20 +155,25 @@ int action_right_input_desc(unsigned type, const char *label,
|
||||
user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
|
||||
btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
|
||||
|
||||
if (settings->uints.input_remap_ids[user_idx][btn_idx] < RARCH_FIRST_CUSTOM_BIND)
|
||||
if (settings->uints.input_remap_ids[user_idx][btn_idx] < RARCH_CUSTOM_BIND_LIST_END - 1)
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx]++;
|
||||
else if (settings->uints.input_remap_ids[user_idx][btn_idx] == RARCH_CUSTOM_BIND_LIST_END - 1)
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED;
|
||||
else
|
||||
settings->uints.input_remap_ids[user_idx][btn_idx] = 0;
|
||||
|
||||
/* skip the not used button (unless they are at the end by calling the right desc function recursively */
|
||||
remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
|
||||
if (string_is_empty(system->input_desc_btn[user_idx][remap_idx]) && remap_idx < RARCH_FIRST_CUSTOM_BIND)
|
||||
|
||||
/* skip the not used buttons (unless they are at the end by calling the right desc function recursively
|
||||
also skip all the axes until analog remapping is implemented */
|
||||
if ((string_is_empty(system->input_desc_btn[user_idx][remap_idx]) && remap_idx < RARCH_CUSTOM_BIND_LIST_END) ||
|
||||
(remap_idx >= RARCH_FIRST_CUSTOM_BIND && remap_idx < RARCH_CUSTOM_BIND_LIST_END))
|
||||
action_right_input_desc(type, label, wraparound);
|
||||
|
||||
#if 0
|
||||
int i = 0;
|
||||
RARCH_LOG("[remap-debug] new descriptor for %d: %s\n", remap_idx, system->input_desc_btn[user_idx][remap_idx]);
|
||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||
//RARCH_LOG("[remap-debug] new descriptor for %d: %s\n", remap_idx, system->input_desc_btn[user_idx][remap_idx]);
|
||||
for (i = 0; i < RARCH_ANALOG_BIND_LIST_END; i++)
|
||||
RARCH_LOG("[remap-debug]: user %d button %d new id %d\n", user_idx, i, settings->uints.input_remap_ids[user_idx][i]);
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user