Rewrite autoconf_binds and move it to task_autodetect.c - take

it out of the settings struct
This commit is contained in:
twinaphex 2017-04-25 16:33:30 +02:00
parent 359af5d5ab
commit 6ace8ce66a
9 changed files with 68 additions and 50 deletions

View File

@ -1166,16 +1166,6 @@ static void config_set_defaults(void)
sizeof(retro_keybinds_rest));
input_remapping_set_defaults();
for (i = 0; i < MAX_USERS; i++)
{
for (j = 0; j < RARCH_BIND_LIST_END; j++)
{
settings->input.autoconf_binds[i][j].joykey = NO_BTN;
settings->input.autoconf_binds[i][j].joyaxis = AXIS_NONE;
}
}
input_autoconfigure_reset();
/* Verify that binds are in proper order. */

View File

@ -279,7 +279,6 @@ typedef struct settings
unsigned remap_ids[MAX_USERS][RARCH_BIND_LIST_END];
struct retro_keybind binds[MAX_USERS][RARCH_BIND_LIST_END];
struct retro_keybind autoconf_binds[MAX_USERS][RARCH_BIND_LIST_END];
unsigned max_users;

View File

@ -125,7 +125,7 @@ static PyObject *py_read_input(PyObject *self, PyObject *args)
return NULL;
joypad_info.joy_idx = settings->input.joypad_map[user - 1];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
if (!input_driver_is_libretro_input_blocked())
res = current_input->input_state(current_input_data, joypad_info,
@ -154,7 +154,7 @@ static PyObject *py_read_analog(PyObject *self, PyObject *args)
return NULL;
joypad_info.joy_idx = settings->input.joypad_map[user - 1];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
res = current_input->input_state(current_input_data,
joypad_info, py_binds,
@ -400,7 +400,7 @@ float py_state_get(py_state_t *handle, const char *id,
for (i = 0; i < MAX_USERS; i++)
{
struct retro_keybind *general_binds = settings->input.binds[i];
struct retro_keybind *auto_binds = settings->input.autoconf_binds[i];
struct retro_keybind *auto_binds = input_autoconfigure_get_binds(i);
enum analog_dpad_mode dpad_mode = settings->input.analog_dpad_mode[i];
if (dpad_mode == ANALOG_DPAD_NONE)
@ -415,7 +415,7 @@ float py_state_get(py_state_t *handle, const char *id,
for (i = 0; i < MAX_USERS; i++)
{
struct retro_keybind *general_binds = settings->input.binds[i];
struct retro_keybind *auto_binds = settings->input.autoconf_binds[i];
struct retro_keybind *auto_binds = input_autoconfigure_get_binds(i);
input_pop_analog_dpad(general_binds);
input_pop_analog_dpad(auto_binds);
}

View File

@ -1250,7 +1250,7 @@ static bool android_input_key_pressed(void *data, int key)
return true;
joypad_info.joy_idx = 0;
joypad_info.auto_binds = settings->input.autoconf_binds[0];
joypad_info.auto_binds = input_autoconfigure_get_binds(0);
joypad_info.axis_threshold = settings->input.axis_threshold;
if (settings->input.binds[0][key].valid &&
@ -1366,8 +1366,11 @@ static int16_t android_input_state(void *data,
(android->pointer[idx].x != -0x8000) &&
(android->pointer[idx].y != -0x8000);
case RARCH_DEVICE_ID_POINTER_BACK:
if(settings->input.autoconf_binds[0][RARCH_MENU_TOGGLE].joykey == 0)
{
const struct retro_keybind *keyptr = input_autoconfigure_get_specific_bind(0, RARCH_MENU_TOGGLE);
if (keyptr->joykey == 0)
return android_keyboard_input_pressed(AKEYCODE_BACK);
}
}
break;
case RARCH_DEVICE_POINTER_SCREEN:
@ -1382,8 +1385,11 @@ static int16_t android_input_state(void *data,
(android->pointer[idx].full_x != -0x8000) &&
(android->pointer[idx].full_y != -0x8000);
case RARCH_DEVICE_ID_POINTER_BACK:
if(settings->input.autoconf_binds[0][RARCH_MENU_TOGGLE].joykey == 0)
return android_keyboard_input_pressed(AKEYCODE_BACK);
{
const struct retro_keybind *keyptr = input_autoconfigure_get_specific_bind(0, RARCH_MENU_TOGGLE);
if (keyptr->joykey == 0)
return android_keyboard_input_pressed(AKEYCODE_BACK);
}
}
break;
}

View File

@ -35,6 +35,7 @@
#include "../msg_hash.h"
#include "../configuration.h"
#include "../file_path_special.h"
#include "../tasks/tasks_internal.h"
#include "../verbosity.h"
/* Input config. */
@ -524,13 +525,10 @@ bool input_config_get_bind_idx(unsigned port, unsigned *joy_idx_real)
const struct retro_keybind *input_config_get_bind_auto(unsigned port, unsigned id)
{
settings_t *settings = config_get_ptr();
unsigned joy_idx = 0;
if (settings)
joy_idx = settings->input.joypad_map[port];
unsigned joy_idx = settings->input.joypad_map[port];
if (joy_idx < MAX_USERS)
return &settings->input.autoconf_binds[joy_idx][id];
return input_autoconfigure_get_specific_bind(joy_idx, id);
return NULL;
}

View File

@ -39,6 +39,7 @@
#include "../movie.h"
#include "../list_special.h"
#include "../verbosity.h"
#include "../tasks/tasks_internal.h"
#include "../command.h"
static const input_driver_t *input_drivers[] = {
@ -291,7 +292,7 @@ void input_poll(void)
if (libretro_input_binds[i][RARCH_TURBO_ENABLE].valid)
{
joypad_info.joy_idx = settings->input.joypad_map[i];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
input_driver_turbo_btns.frame_enable[i] = current_input->input_state(
current_input_data, joypad_info, libretro_input_binds,
@ -385,7 +386,7 @@ int16_t input_state(unsigned port, unsigned device,
joypad_info.axis_threshold = settings->input.axis_threshold;
joypad_info.joy_idx = settings->input.joypad_map[port];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
res = current_input->input_state(
current_input_data, joypad_info, libretro_input_binds, port, device, idx, id);
@ -486,7 +487,7 @@ void state_tracker_update_input(uint16_t *input1, uint16_t *input2)
for (i = 0; i < max_users; i++)
{
struct retro_keybind *general_binds = settings->input.binds[i];
struct retro_keybind *auto_binds = settings->input.autoconf_binds[i];
struct retro_keybind *auto_binds = input_autoconfigure_get_binds(i);
enum analog_dpad_mode dpad_mode = (enum analog_dpad_mode)settings->input.analog_dpad_mode[i];
binds[i] = settings->input.binds[i];
@ -509,7 +510,7 @@ void state_tracker_update_input(uint16_t *input1, uint16_t *input2)
if (binds[0][id].valid)
{
joypad_info.joy_idx = settings->input.joypad_map[0];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
*input1 |= (current_input->input_state(current_input_data, joypad_info,
binds,
0, RETRO_DEVICE_JOYPAD, 0, id) ? 1 : 0) << i;
@ -517,7 +518,7 @@ void state_tracker_update_input(uint16_t *input1, uint16_t *input2)
if (binds[1][id].valid)
{
joypad_info.joy_idx = settings->input.joypad_map[1];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
*input2 |= (current_input->input_state(current_input_data, joypad_info,
binds,
1, RETRO_DEVICE_JOYPAD, 0, id) ? 1 : 0) << i;
@ -528,7 +529,7 @@ void state_tracker_update_input(uint16_t *input1, uint16_t *input2)
for (i = 0; i < max_users; i++)
{
struct retro_keybind *general_binds = settings->input.binds[i];
struct retro_keybind *auto_binds = settings->input.autoconf_binds[i];
struct retro_keybind *auto_binds = input_autoconfigure_get_binds(i);
input_pop_analog_dpad(general_binds);
input_pop_analog_dpad(auto_binds);
@ -560,7 +561,7 @@ static INLINE bool input_menu_keys_pressed_internal(
? current_input->get_sec_joypad_driver(current_input_data) : NULL;
joypad_info.joy_idx = settings->input.joypad_map[port];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
joypad_info.axis_threshold = settings->input.axis_threshold;
if (sec && input_joypad_pressed(sec,
@ -691,7 +692,7 @@ uint64_t input_menu_keys_pressed(
for (i = 0; i < max_users; i++)
{
struct retro_keybind *auto_binds = settings->input.autoconf_binds[i];
struct retro_keybind *auto_binds = input_autoconfigure_get_binds(i);
input_push_analog_dpad(auto_binds, ANALOG_DPAD_LSTICK);
}
@ -708,7 +709,7 @@ uint64_t input_menu_keys_pressed(
input_driver_block_hotkey = true;
binds_norm = &settings->input.binds[0][RARCH_ENABLE_HOTKEY];
binds_auto = &settings->input.autoconf_binds[0][RARCH_ENABLE_HOTKEY];
binds_auto = input_autoconfigure_get_specific_bind(0, RARCH_ENABLE_HOTKEY);
for (i = 0; i < max_users; i++)
binds[i] = settings->input.binds[i];
@ -716,7 +717,7 @@ uint64_t input_menu_keys_pressed(
if (check_input_driver_block_hotkey(binds_norm, binds_auto))
{
joypad_info.joy_idx = settings->input.joypad_map[0];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
if (settings->input.binds[0][RARCH_ENABLE_HOTKEY].valid
&& current_input->input_state(current_input_data, joypad_info,
@ -750,7 +751,7 @@ uint64_t input_menu_keys_pressed(
for (i = 0; i < max_users; i++)
{
struct retro_keybind *auto_binds = settings->input.autoconf_binds[i];
struct retro_keybind *auto_binds = input_autoconfigure_get_binds(i);
input_pop_analog_dpad(auto_binds);
}
@ -836,7 +837,7 @@ static INLINE bool input_keys_pressed_internal(
bool bind_valid = binds[i].valid;
joypad_info.joy_idx = settings->input.joypad_map[0];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
joypad_info.axis_threshold = settings->input.axis_threshold;
if (bind_valid && current_input->input_state(current_input_data,
@ -904,10 +905,10 @@ uint64_t input_keys_pressed(
uint64_t ret = 0;
settings_t *settings = config_get_ptr();
const struct retro_keybind *binds = settings->input.binds[0];
const struct retro_keybind *binds_auto = &settings->input.autoconf_binds[0][RARCH_ENABLE_HOTKEY];
const struct retro_keybind *binds_auto = input_autoconfigure_get_specific_bind(0, RARCH_ENABLE_HOTKEY);
const struct retro_keybind *binds_norm = &binds[RARCH_ENABLE_HOTKEY];
const struct retro_keybind *focus_binds_auto = &settings->input.autoconf_binds[0][RARCH_GAME_FOCUS_TOGGLE];
const struct retro_keybind *focus_binds_auto = input_autoconfigure_get_specific_bind(0, RARCH_GAME_FOCUS_TOGGLE);
const struct retro_keybind *focus_normal = &binds[RARCH_GAME_FOCUS_TOGGLE];
bool enable_hotkey_valid = settings && settings->input.binds[0][RARCH_ENABLE_HOTKEY].valid;
bool game_focus_toggle_valid = false;
@ -926,7 +927,7 @@ uint64_t input_keys_pressed(
if (check_input_driver_block_hotkey(binds_norm, binds_auto))
{
joypad_info.joy_idx = settings->input.joypad_map[0];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
if ( enable_hotkey_valid
&& current_input->input_state(
current_input_data, joypad_info, &binds, 0,
@ -944,7 +945,7 @@ uint64_t input_keys_pressed(
focus_normal, focus_binds_auto) && game_focus_toggle_valid)
{
joypad_info.joy_idx = settings->input.joypad_map[0];
joypad_info.auto_binds = settings->input.autoconf_binds[joypad_info.joy_idx];
joypad_info.auto_binds = input_autoconfigure_get_binds(joypad_info.joy_idx);
if (current_input->input_state(current_input_data, joypad_info, &binds, 0,
RETRO_DEVICE_JOYPAD, 0, RARCH_GAME_FOCUS_TOGGLE))
input_driver_block_hotkey = false;

View File

@ -1141,7 +1141,7 @@ int runloop_iterate(unsigned *sleep_ms)
for (i = 0; i < settings->input.max_users; i++)
{
struct retro_keybind *general_binds = settings->input.binds[i];
struct retro_keybind *auto_binds = settings->input.autoconf_binds[i];
struct retro_keybind *auto_binds = input_autoconfigure_get_binds(i);
enum analog_dpad_mode dpad_mode = (enum analog_dpad_mode)settings->input.analog_dpad_mode[i];
if (dpad_mode == ANALOG_DPAD_NONE)
@ -1164,7 +1164,7 @@ int runloop_iterate(unsigned *sleep_ms)
for (i = 0; i < settings->input.max_users; i++)
{
struct retro_keybind *general_binds = settings->input.binds[i];
struct retro_keybind *auto_binds = settings->input.autoconf_binds[i];
struct retro_keybind *auto_binds = input_autoconfigure_get_binds(i);
enum analog_dpad_mode dpad_mode = (enum analog_dpad_mode)settings->input.analog_dpad_mode[i];
if (dpad_mode == ANALOG_DPAD_NONE)

View File

@ -51,6 +51,7 @@ typedef struct autoconfig_params
} autoconfig_params_t;
static bool input_autoconfigured[MAX_USERS];
static struct retro_keybind input_autoconf_binds[MAX_USERS][RARCH_BIND_LIST_END];
/* Adds an index for devices with the same name,
* so they can be identified in the GUI. */
@ -162,7 +163,7 @@ static void input_autoconfigure_joypad_add(config_file_t *conf,
input_autoconfigured[params->idx] = true;
input_autoconfigure_joypad_conf(conf,
settings->input.autoconf_binds[params->idx]);
input_autoconf_binds[params->idx]);
if (memcmp(device_type, "remote", 6) == 0)
{
@ -399,11 +400,29 @@ error:
return false;
}
const struct retro_keybind *input_autoconfigure_get_specific_bind(unsigned i, unsigned j)
{
return &input_autoconf_binds[i][j];
}
struct retro_keybind *input_autoconfigure_get_binds(unsigned i)
{
return input_autoconf_binds[i];
}
void input_autoconfigure_reset(void)
{
unsigned i;
unsigned i, j;
for (i = 0; i < MAX_USERS; i++)
{
for (j = 0; j < RARCH_BIND_LIST_END; j++)
{
input_autoconf_binds[i][j].joykey = NO_BTN;
input_autoconf_binds[i][j].joyaxis = AXIS_NONE;
}
input_autoconfigured[i] = 0;
}
}
bool input_is_autoconfigured(unsigned i)
@ -455,10 +474,10 @@ bool input_autoconfigure_connect(
for (i = 0; i < RARCH_BIND_LIST_END; i++)
{
settings->input.autoconf_binds[state->idx][i].joykey = NO_BTN;
settings->input.autoconf_binds[state->idx][i].joyaxis = AXIS_NONE;
settings->input.autoconf_binds[state->idx][i].joykey_label[0] = '\0';
settings->input.autoconf_binds[state->idx][i].joyaxis_label[0] = '\0';
input_autoconf_binds[state->idx][i].joykey = NO_BTN;
input_autoconf_binds[state->idx][i].joyaxis = AXIS_NONE;
input_autoconf_binds[state->idx][i].joykey_label[0] = '\0';
input_autoconf_binds[state->idx][i].joyaxis_label[0] = '\0';
}
input_autoconfigured[state->idx] = false;

View File

@ -219,10 +219,15 @@ void *savefile_ptr_get(void);
void path_init_savefile_new(void);
void input_autoconfigure_reset(void);
bool input_is_autoconfigured(unsigned i);
const struct retro_keybind *
input_autoconfigure_get_specific_bind(unsigned i, unsigned j);
struct retro_keybind *input_autoconfigure_get_binds(unsigned i);
void input_autoconfigure_reset(void);
bool input_autoconfigure_connect(
const char *name,
const char *display_name,