Merge pull request #5867 from hiddenasbestos/more_devices

Don't limit available input devices to user count.
This commit is contained in:
Twinaphex 2017-12-06 01:43:52 +01:00 committed by GitHub
commit d881931254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 29 deletions

View File

@ -26,6 +26,8 @@ RETRO_BEGIN_DECLS
#define MAX_USERS 16
#define MAX_INPUT_DEVICES 16
#define RARCH_FIRST_CUSTOM_BIND 16
#define RARCH_FIRST_LIGHTGUN_BIND RARCH_ANALOG_BIND_LIST_END
#define RARCH_FIRST_MISC_CUSTOM_BIND RARCH_LIGHTGUN_BIND_LIST_END

View File

@ -233,7 +233,7 @@ static const uint8_t buttons[] = {
static uint16_t input_config_vid[MAX_USERS];
static uint16_t input_config_pid[MAX_USERS];
char input_device_names[MAX_USERS][64];
char input_device_names[MAX_INPUT_DEVICES][64];
struct retro_keybind input_config_binds[MAX_USERS][RARCH_BIND_LIST_END];
struct retro_keybind input_autoconf_binds[MAX_USERS][RARCH_BIND_LIST_END];
const struct retro_keybind *libretro_input_binds[MAX_USERS];
@ -2691,6 +2691,18 @@ void input_config_get_bind_string(char *buf, const struct retro_keybind *bind,
strlcat(buf, "---", size);
}
unsigned input_config_get_device_count()
{
unsigned num_devices;
for ( num_devices = 0; num_devices < MAX_INPUT_DEVICES; ++num_devices )
{
const char *device_name = input_config_get_device_name(num_devices);
if ( string_is_empty(device_name) )
break;
}
return num_devices;
}
const char *input_config_get_device_name(unsigned port)
{
if (string_is_empty(input_device_names[port]))
@ -2701,14 +2713,19 @@ const char *input_config_get_device_name(unsigned port)
void input_config_set_device_name(unsigned port, const char *name)
{
if (!string_is_empty(name))
{
strlcpy(input_device_names[port],
name,
sizeof(input_device_names[port]));
input_autoconfigure_joypad_reindex_devices();
}
}
void input_config_clear_device_name(unsigned port)
{
input_device_names[port][0] = '\0';
input_autoconfigure_joypad_reindex_devices();
}
unsigned *input_config_get_device_ptr(unsigned port)

View File

@ -761,6 +761,8 @@ void input_config_set_device_name(unsigned port, const char *name);
void input_config_clear_device_name(unsigned port);
unsigned input_config_get_device_count();
unsigned *input_config_get_device_ptr(unsigned port);
unsigned input_config_get_device(unsigned port);

View File

@ -1305,7 +1305,7 @@ static int setting_action_left_bind_device(void *data, bool wraparound)
{
unsigned index_offset;
unsigned *p = NULL;
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
unsigned max_devices = input_config_get_device_count();
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
@ -1316,8 +1316,8 @@ static int setting_action_left_bind_device(void *data, bool wraparound)
p = &settings->uints.input_joypad_map[index_offset];
if ((*p) >= max_users)
*p = max_users - 1;
if ((*p) >= max_devices)
*p = max_devices - 1;
else if ((*p) > 0)
(*p)--;
@ -1328,7 +1328,7 @@ static int setting_action_right_bind_device(void *data, bool wraparound)
{
unsigned index_offset;
unsigned *p = NULL;
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
unsigned max_devices = input_config_get_device_count();
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
@ -1339,7 +1339,7 @@ static int setting_action_right_bind_device(void *data, bool wraparound)
p = &settings->uints.input_joypad_map[index_offset];
if (*p < max_users)
if (*p < max_devices)
(*p)++;
return 0;
@ -1497,7 +1497,7 @@ static void get_string_representation_bind_device(void * data, char *s,
size_t len)
{
unsigned index_offset, map = 0;
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
unsigned max_devices = input_config_get_device_count();
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
@ -1507,21 +1507,37 @@ static void get_string_representation_bind_device(void * data, char *s,
index_offset = setting->index_offset;
map = settings->uints.input_joypad_map[index_offset];
if (map < max_users)
if (map < max_devices)
{
const char *device_name = input_config_get_device_name(map);
if (!string_is_empty(device_name))
snprintf(s, len,
"%s (#%u)",
device_name,
input_autoconfigure_get_device_name_index(map));
{
unsigned idx = input_autoconfigure_get_device_name_index(map);
/*if idx is non-zero, it's part of a set*/
if ( idx > 0 )
{
snprintf(s, len,
"%s (#%u)",
device_name,
idx);
}
else
{
snprintf(s, len,
"%s",
device_name);
}
}
else
{
snprintf(s, len,
"%s (%s #%u)",
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT),
map);
}
}
else
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISABLED), len);

View File

@ -96,7 +96,7 @@ struct autoconfig_params
};
static bool input_autoconfigured[MAX_USERS];
static unsigned input_device_name_index[MAX_USERS];
static unsigned input_device_name_index[MAX_INPUT_DEVICES];
static bool input_autoconfigure_swap_override;
bool input_autoconfigure_get_swap_override(void)
@ -106,24 +106,38 @@ bool input_autoconfigure_get_swap_override(void)
/* Adds an index for devices with the same name,
* so they can be identified in the GUI. */
static void input_autoconfigure_joypad_reindex_devices(autoconfig_params_t *params)
void input_autoconfigure_joypad_reindex_devices()
{
unsigned i;
unsigned i, j, k;
for(i = 0; i < params->max_users; i++)
for(i = 0; i < MAX_INPUT_DEVICES; i++)
input_device_name_index[i] = 0;
for(i = 0; i < params->max_users; i++)
for(i = 0; i < MAX_INPUT_DEVICES; i++)
{
unsigned j;
const char *tmp = input_config_get_device_name(i);
int k = 1;
if ( !tmp || input_device_name_index[i] )
continue;
for(j = 0; j < params->max_users; j++)
k = 2; /*Additional devices start at two*/
for(j = i+1; j < MAX_INPUT_DEVICES; j++)
{
if(string_is_equal(tmp, input_config_get_device_name(j))
&& input_device_name_index[i] == 0)
const char *other = input_config_get_device_name(j);
if (!other)
continue;
/*another device with the same name found, for the first time*/
if(string_is_equal(tmp, other) &&
input_device_name_index[j]==0 )
{
/*Mark the first device of the set*/
input_device_name_index[i] = 1;
/*count this additional device, from two up*/
input_device_name_index[j] = k++;
}
}
}
}
@ -190,7 +204,7 @@ static void input_autoconfigure_joypad_add(config_file_t *conf,
char msg[128], display_name[128], device_type[128];
/* This will be the case if input driver is reinitialized.
* No reason to spam autoconfigure messages every time. */
bool block_osd_spam =
bool block_osd_spam =
input_autoconfigured[params->idx]
&& !string_is_empty(params->name);
@ -228,7 +242,7 @@ static void input_autoconfigure_joypad_add(config_file_t *conf,
bool tmp = false;
snprintf(msg, sizeof(msg), "%s %s #%u.",
(string_is_empty(display_name) &&
!string_is_empty(params->name))
!string_is_empty(params->name))
? params->name : (!string_is_empty(display_name) ? display_name : "N/A"),
msg_hash_to_str(MSG_DEVICE_CONFIGURED_IN_PORT),
params->idx);
@ -250,7 +264,7 @@ static void input_autoconfigure_joypad_add(config_file_t *conf,
}
input_autoconfigure_joypad_reindex_devices(params);
input_autoconfigure_joypad_reindex_devices();
}
static int input_autoconfigure_joypad_from_conf(
@ -393,7 +407,7 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
BOOL bResult = TRUE;
BOOL success = FALSE;
GUID guidDeviceInterface = {0};
PSP_DEVICE_INTERFACE_DETAIL_DATA
PSP_DEVICE_INTERFACE_DETAIL_DATA
pInterfaceDetailData = NULL;
ULONG requiredLength = 0;
LPTSTR lpDevicePath = NULL;
@ -845,7 +859,7 @@ bool input_autoconfigure_disconnect(unsigned i, const char *ident)
state->idx = i;
snprintf(msg, sizeof(msg), "%s #%u (%s).",
snprintf(msg, sizeof(msg), "%s #%u (%s).",
msg_hash_to_str(MSG_DEVICE_DISCONNECTED_FROM_PORT),
i, ident);
@ -942,10 +956,10 @@ bool input_autoconfigure_connect(
{
input_autoconf_binds[state->idx][i].joykey = NO_BTN;
input_autoconf_binds[state->idx][i].joyaxis = AXIS_NONE;
if (
if (
!string_is_empty(input_autoconf_binds[state->idx][i].joykey_label))
free(input_autoconf_binds[state->idx][i].joykey_label);
if (
if (
!string_is_empty(input_autoconf_binds[state->idx][i].joyaxis_label))
free(input_autoconf_binds[state->idx][i].joyaxis_label);
input_autoconf_binds[state->idx][i].joykey_label = NULL;

View File

@ -245,6 +245,8 @@ bool input_autoconfigure_disconnect(unsigned i, const char *ident);
bool input_autoconfigure_get_swap_override(void);
void input_autoconfigure_joypad_reindex_devices(void);
void task_push_get_powerstate(void);
enum frontend_powerstate get_last_powerstate(int *percent);