Skip to content

Commit

Permalink
Commit before reversion... messy.
Browse files Browse the repository at this point in the history
  • Loading branch information
XerTheSquirrel committed Dec 24, 2023
1 parent e0def8f commit 909ba14
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 133 deletions.
62 changes: 43 additions & 19 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ const struct input_bind_map input_config_bind_map[RARCH_BIND_LIST_END_NULL] = {
DECLARE_META_BIND(2, overlay_next, RARCH_OVERLAY_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_OVERLAY_NEXT),

DECLARE_META_BIND(2, osk_toggle, RARCH_OSK, MENU_ENUM_LABEL_VALUE_INPUT_META_OSK),

/* Extra defined keys. */
#if 0
/* Deprecated */
DECLARE_META_BIND(2, send_debug_info, RARCH_SEND_DEBUG_INFO, MENU_ENUM_LABEL_VALUE_INPUT_META_SEND_DEBUG_INFO),
Expand Down Expand Up @@ -5669,6 +5671,34 @@ bool config_replace(bool config_replace_save_on_exit, char *path)
return task_push_start_dummy_core(&content_info);
}

#define KEYSTRING_BUTTON_BUF_SIZE 8
typedef char rarch_key_strings_array[RARCH_MAX_TOTAL_BUTTON][KEYSTRING_BUTTON_BUF_SIZE];

static rarch_key_strings_array* rarch_static_key_strings(void)
{
static bool didInit;
static char key_strings[RARCH_MAX_TOTAL_BUTTON][KEYSTRING_BUTTON_BUF_SIZE] = {
"b", "y", "select", "start",
"up", "down", "left", "right",
"a", "x", "l", "r", "l2", "r2",
"l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" };
int i;

/* Need to initialize all of the extra keys? */
if (!didInit)
{
/* Do not initialize again. */
didInit = true;

/* Setup massive number of extra buttons. */
for (i = RARCH_FIRST_ID_EXTRA_BUTTON; i < RARCH_LAST_ID_EXTRA_BUTTON; i++)
snprintf(key_strings[i], KEYSTRING_BUTTON_BUF_SIZE - 1,
"ext%d", i - RARCH_FIRST_ID_EXTRA_BUTTON);
}

return &key_strings;
}

/**
* input_remapping_load_file:
* @data : Path to config file.
Expand All @@ -5683,11 +5713,10 @@ bool input_remapping_load_file(void *data, const char *path)
config_file_t *conf = (config_file_t*)data;
settings_t *settings = config_st;
runloop_state_t *runloop_st = runloop_state_get_ptr();
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][8] = {
"b", "y", "select", "start",
"up", "down", "left", "right",
"a", "x", "l", "r", "l2", "r2",
"l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" };
rarch_key_strings_array* key_strings;

/* Get all the key strings. */
key_strings = rarch_static_key_strings();

if ( !conf
|| string_is_empty(path))
Expand Down Expand Up @@ -5716,11 +5745,11 @@ bool input_remapping_load_file(void *data, const char *path)
_len = strlcpy(s3, prefix, sizeof(s3));
strlcpy(s3 + _len, "_stk", sizeof(s3) - _len);

for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
for (j = 0; j < RARCH_MAX_TOTAL_BUTTON + 8; j++)
{
const char *key_string = key_strings[j];
const char *key_string = (*key_strings)[j];

if (j < RARCH_FIRST_CUSTOM_BIND)
if (j < RARCH_FIRST_CUSTOM_BIND || j >= RARCH_FIRST_ID_EXTRA_BUTTON)
{
int btn_remap = -1;
int key_remap = -1;
Expand Down Expand Up @@ -5814,19 +5843,14 @@ bool input_remapping_save_file(const char *path)
bool ret;
unsigned i, j;
char remap_file_dir[PATH_MAX_LENGTH];
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][8] =
{
"b", "y", "select", "start",
"up", "down", "left", "right",
"a", "x", "l", "r",
"l2", "r2", "l3", "r3",
"l_x+", "l_x-", "l_y+", "l_y-",
"r_x+", "r_x-", "r_y+", "r_y-"
};
config_file_t *conf = NULL;
runloop_state_t *runloop_st = runloop_state_get_ptr();
settings_t *settings = config_st;
unsigned max_users = settings->uints.input_max_users;
rarch_key_strings_array* key_strings;

/* Get all the key strings. */
key_strings = rarch_static_key_strings();

if (string_is_empty(path))
return false;
Expand Down Expand Up @@ -5887,11 +5911,11 @@ bool input_remapping_save_file(const char *path)
_len = strlcpy(s3, prefix, sizeof(s3));
strlcpy(s3 + _len, "_stk", sizeof(s3) - _len);

for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++)
for (j = 0; j < RARCH_MAX_TOTAL_BUTTON; j++)
{
char btn_ident[128];
char key_ident[128];
const char *key_string = key_strings[j];
const char *key_string = (*key_strings)[j];
unsigned remap_id = settings->uints.input_remap_ids[i][j];
unsigned keymap_id = settings->uints.input_keymapper_ids[i][j];

Expand Down
4 changes: 2 additions & 2 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ typedef struct settings
unsigned input_analog_dpad_mode[MAX_USERS];

unsigned input_remap_ports[MAX_USERS];
unsigned input_remap_ids[MAX_USERS][RARCH_CUSTOM_BIND_LIST_END];
unsigned input_keymapper_ids[MAX_USERS][RARCH_CUSTOM_BIND_LIST_END];
unsigned input_remap_ids[MAX_USERS][RARCH_MAX_TOTAL_BUTTON];
unsigned input_keymapper_ids[MAX_USERS][RARCH_MAX_TOTAL_BUTTON];
unsigned input_remap_port_map[MAX_USERS][MAX_USERS + 1];

unsigned led_map[MAX_LEDS];
Expand Down
22 changes: 19 additions & 3 deletions input/input_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,26 @@
#define RARCH_FIRST_MISC_CUSTOM_BIND RARCH_LIGHTGUN_BIND_LIST_END
#define RARCH_FIRST_META_KEY RARCH_CUSTOM_BIND_LIST_END

#define RARCH_MAX_EXTRA_BUTTON (RETRO_DEVICE_ID_JOYPAD_MASK - RETRO_DEVICE_ID_JOYPAD_MAX_BUTTONS)
#define RARCH_EXTRA_BUTTON_ID(id) (RETRO_DEVICE_ID_JOYPAD_MAX_BUTTONS + (id))
/** The number of extra buttons to define, this is virtualized. */
#define RARCH_MAX_EXTRA_BUTTON 128

#define RARCH_EXTRA_BUTTON_ID_END (RARCH_FIRST_META_KEY + RARCH_MAX_EXTRA_BUTTON)
/** The base for extra buttons. */
#define RARCH_BASE_EXTRA_BUTTON 24

/** The total number of button binds which are possible. */
#define RARCH_MAX_TOTAL_BUTTON (RARCH_BASE_EXTRA_BUTTON + RARCH_MAX_EXTRA_BUTTON)

/** An extra button at the given index. */
#define RARCH_ID_EXTRA_BUTTON(id) (RARCH_BASE_EXTRA_BUTTON + (id))

/** The first starting extra button. */
#define RARCH_FIRST_ID_EXTRA_BUTTON RARCH_ID_EXTRA_BUTTON(0)

/** The last ending extra button. */
#define RARCH_LAST_ID_EXTRA_BUTTON RARCH_ID_EXTRA_BUTTON(RARCH_MAX_EXTRA_BUTTON)

/** Is this an extra button bind? */
#define RARCH_IS_EXTRA_BUTTON_BIND(id) (((id) >= RARCH_FIRST_EXTRA_BUTTON_BIND) ? 1 : 0)

#define RARCH_UNMAPPED 1024

Expand Down
114 changes: 62 additions & 52 deletions menu/cbs/menu_cbs_left.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,61 +135,71 @@ static int action_left_cheat(unsigned type, const char *label,
}
#endif

static int action_left_input_desc(unsigned type, const char *label,
bool wraparound)
int action_bidirectional_input_desc(unsigned type, const char *label, bool wraparound, int direction)
{
unsigned btn_idx;
unsigned user_idx;
unsigned remap_idx;
unsigned bind_idx;
unsigned mapped_port;
settings_t *settings = config_get_ptr();
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
if (!settings || !sys_info)
return 0;

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;
mapped_port = settings->uints.input_remap_ports[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;

remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
for (bind_idx = 0; bind_idx < RARCH_ANALOG_BIND_LIST_END; bind_idx++)
{
if (input_config_bind_order[bind_idx] == remap_idx)
break;
}

if (bind_idx > 0)
{
if (bind_idx > RARCH_ANALOG_BIND_LIST_END)
settings->uints.input_remap_ids[user_idx][btn_idx]--;
else
{
bind_idx--;
bind_idx = input_config_bind_order[bind_idx];
settings->uints.input_remap_ids[user_idx][btn_idx] = bind_idx;
}
}
else if (bind_idx == 0)
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED;
else
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_CUSTOM_BIND_LIST_END - 1;

remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];

/* 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 (remap_idx != RARCH_UNMAPPED)
{
if ((string_is_empty(sys_info->input_desc_btn[mapped_port][remap_idx]) && remap_idx < RARCH_CUSTOM_BIND_LIST_END) /*||
unsigned btn_idx;
unsigned user_idx;
unsigned remap_idx;
unsigned bind_idx;
unsigned mapped_port;
settings_t *settings = config_get_ptr();
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;

if (!settings || !sys_info)
return 0;

/* TODO: Implement this in a much nicer way! */

#if 0
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;
mapped_port = settings->uints.input_remap_ports[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;

remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
for (bind_idx = 0; bind_idx < RARCH_ANALOG_BIND_LIST_END; bind_idx++)
{
if (input_config_bind_order[bind_idx] == remap_idx)
break;
}

if (bind_idx > 0)
{
if (bind_idx > RARCH_ANALOG_BIND_LIST_END)
settings->uints.input_remap_ids[user_idx][btn_idx]--;
else
{
bind_idx--;
bind_idx = input_config_bind_order[bind_idx];
settings->uints.input_remap_ids[user_idx][btn_idx] = bind_idx;
}
}
else if (bind_idx == 0)
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED;
else
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_CUSTOM_BIND_LIST_END - 1;

remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];

/* 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 (remap_idx != RARCH_UNMAPPED)
{
if ((string_is_empty(sys_info->input_desc_btn[mapped_port][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);
}
action_bidirectional_input_desc(type, label, wraparound, direction);
}
#endif

return 0;
return 0;
}

static int action_left_input_desc(unsigned type, const char *label,
bool wraparound)
{
return action_bidirectional_input_desc(type, label, wraparound, -1);
}

static int action_left_input_desc_kbd(unsigned type, const char *label,
Expand Down
53 changes: 2 additions & 51 deletions menu/cbs/menu_cbs_right.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,60 +171,11 @@ static int action_right_input_desc_kbd(unsigned type, const char *label,
return 0;
}

/* TODO/FIXME: incomplete, lacks error checking */
static int action_right_input_desc(unsigned type, const char *label,
bool wraparound)
{
settings_t *settings = config_get_ptr();
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
if (settings && sys_info)
{
unsigned bind_idx;
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
unsigned mapped_port = settings->uints.input_remap_ports[user_idx];
unsigned remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
for (bind_idx = 0; bind_idx < RARCH_ANALOG_BIND_LIST_END; bind_idx++)
{
if (input_config_bind_order[bind_idx] == remap_idx)
break;
}

if (bind_idx < RARCH_CUSTOM_BIND_LIST_END - 1)
{
if (bind_idx > RARCH_ANALOG_BIND_LIST_END)
settings->uints.input_remap_ids[user_idx][btn_idx]++;
else
{
if (bind_idx < RARCH_ANALOG_BIND_LIST_END - 1)
{
bind_idx++;
bind_idx = input_config_bind_order[bind_idx];
}
else if (bind_idx == RARCH_ANALOG_BIND_LIST_END - 1)
bind_idx = RARCH_UNMAPPED;
else
bind_idx = input_config_bind_order[0];
settings->uints.input_remap_ids[user_idx][btn_idx] = bind_idx;
}
}
else if (bind_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] = input_config_bind_order[0];

remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];

/* 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 (remap_idx != RARCH_UNMAPPED)
{
if ((string_is_empty(sys_info->input_desc_btn[mapped_port][remap_idx]) && remap_idx < RARCH_CUSTOM_BIND_LIST_END))
action_right_input_desc(type, label, wraparound);
}
}

return 0;
/* The left and right actions are very similar. */
return action_bidirectional_input_desc(type, label, wraparound, 1);
}

static int action_right_scroll(unsigned type, const char *label,
Expand Down
14 changes: 14 additions & 0 deletions menu/menu_cbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ void cb_generic_download(retro_task_t *task,
void *task_data,
void *user_data, const char *err);

/**
* Bidirectional input descriptor navigation.
*
* @param type
* @param label
* @param wraparound
* @param direction
* @return Always zero?
*/
int action_bidirectional_input_desc(unsigned type,
const char *label,
bool wraparound,
int direction);

RETRO_END_DECLS

#endif
2 changes: 1 addition & 1 deletion menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -5470,7 +5470,7 @@ static int menu_displaylist_parse_input_description_list(
btn_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;

if ( (user_idx >= MAX_USERS)
|| (btn_idx >= RARCH_CUSTOM_BIND_LIST_END))
|| (btn_idx >= RARCH_MAX_TOTAL_BUTTON))
return 0;

mapped_port = settings->uints.input_remap_ports[user_idx];
Expand Down
2 changes: 1 addition & 1 deletion retroarch_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ typedef struct rarch_system_info
disk_control_interface_t disk_control; /* ptr alignment */
struct retro_system_info info; /* ptr alignment */
rarch_memory_map_t mmaps; /* ptr alignment */
const char *input_desc_btn[MAX_USERS][RARCH_EXTRA_BUTTON_ID_END];
const char *input_desc_btn[MAX_USERS][RARCH_MAX_TOTAL_BUTTON];
struct
{
struct retro_subsystem_info *data;
Expand Down
Loading

0 comments on commit 909ba14

Please sign in to comment.