From 35c485aab057342879a98dce1d6c0298aec7da1c Mon Sep 17 00:00:00 2001 From: Themaister Date: Tue, 7 Jan 2014 17:14:09 +0100 Subject: [PATCH] Reuse bind maps in input_common for overlay. --- input/input_common.c | 9 ++++++ input/input_common.h | 1 + input/overlay.c | 73 +------------------------------------------- 3 files changed, 11 insertions(+), 72 deletions(-) diff --git a/input/input_common.c b/input/input_common.c index d504eace6d..1ca2585a70 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -979,6 +979,15 @@ const char *input_config_get_prefix(unsigned player, bool meta) return NULL; // Don't bother with meta bind for anyone else than first player. } +unsigned input_translate_str_to_bind_id(const char *str) +{ + unsigned i; + for (i = 0; input_config_bind_map[i].valid; i++) + if (!strcmp(str, input_config_bind_map[i].base)) + return i; + return RARCH_BIND_LIST_END; +} + static void parse_hat(struct retro_keybind *bind, const char *str) { if (!isdigit(*str)) diff --git a/input/input_common.h b/input/input_common.h index 8bfa5425b4..e68139b4c1 100644 --- a/input/input_common.h +++ b/input/input_common.h @@ -154,6 +154,7 @@ void input_translate_rk_to_str(enum retro_key key, char *buf, size_t size); extern const char* const input_builtin_autoconfs[]; const char *input_config_get_prefix(unsigned player, bool meta); +unsigned input_translate_str_to_bind_id(const char *str); // Returns RARCH_BIND_LIST_END on not found. void input_config_parse_key(config_file_t *conf, const char *prefix, const char *btn, struct retro_keybind *bind); diff --git a/input/overlay.c b/input/overlay.c index 490b01e7e4..800fb40a56 100644 --- a/input/overlay.c +++ b/input/overlay.c @@ -111,77 +111,6 @@ struct str_to_bind_map unsigned bind; }; -static const struct str_to_bind_map str_to_bind[] = { - { "b", RETRO_DEVICE_ID_JOYPAD_B }, - { "y", RETRO_DEVICE_ID_JOYPAD_Y }, - { "select", RETRO_DEVICE_ID_JOYPAD_SELECT }, - { "start", RETRO_DEVICE_ID_JOYPAD_START }, - { "up", RETRO_DEVICE_ID_JOYPAD_UP }, - { "down", RETRO_DEVICE_ID_JOYPAD_DOWN }, - { "left", RETRO_DEVICE_ID_JOYPAD_LEFT }, - { "right", RETRO_DEVICE_ID_JOYPAD_RIGHT }, - { "a", RETRO_DEVICE_ID_JOYPAD_A }, - { "x", RETRO_DEVICE_ID_JOYPAD_X }, - { "l", RETRO_DEVICE_ID_JOYPAD_L }, - { "r", RETRO_DEVICE_ID_JOYPAD_R }, - { "l2", RETRO_DEVICE_ID_JOYPAD_L2 }, - { "r2", RETRO_DEVICE_ID_JOYPAD_R2 }, - { "l3", RETRO_DEVICE_ID_JOYPAD_L3 }, - { "r3", RETRO_DEVICE_ID_JOYPAD_R3 }, - { "turbo", RARCH_TURBO_ENABLE }, - { "l_x_plus", RARCH_ANALOG_LEFT_X_PLUS }, - { "l_x_minus", RARCH_ANALOG_LEFT_X_MINUS }, - { "l_y_plus", RARCH_ANALOG_LEFT_Y_PLUS }, - { "l_y_minus", RARCH_ANALOG_LEFT_Y_MINUS }, - { "r_x_plus", RARCH_ANALOG_RIGHT_X_PLUS }, - { "r_x_minus", RARCH_ANALOG_RIGHT_X_MINUS }, - { "r_y_plus", RARCH_ANALOG_RIGHT_Y_PLUS }, - { "r_y_minus", RARCH_ANALOG_RIGHT_Y_MINUS }, - { "toggle_fast_forward", RARCH_FAST_FORWARD_KEY }, - { "hold_fast_forward", RARCH_FAST_FORWARD_HOLD_KEY }, - { "load_state", RARCH_LOAD_STATE_KEY }, - { "save_state", RARCH_SAVE_STATE_KEY }, - { "toggle_fullscreen", RARCH_FULLSCREEN_TOGGLE_KEY }, - { "exit_emulator", RARCH_QUIT_KEY }, - { "state_slot_increase", RARCH_STATE_SLOT_PLUS }, - { "state_slot_decrease", RARCH_STATE_SLOT_MINUS }, - { "rewind", RARCH_REWIND }, - { "movie_record_toggle", RARCH_MOVIE_RECORD_TOGGLE }, - { "pause_toggle", RARCH_PAUSE_TOGGLE }, - { "frame_advance", RARCH_FRAMEADVANCE }, - { "reset", RARCH_RESET }, - { "shader_next", RARCH_SHADER_NEXT }, - { "shader_prev", RARCH_SHADER_PREV }, - { "cheat_index_plus", RARCH_CHEAT_INDEX_PLUS }, - { "cheat_index_minus", RARCH_CHEAT_INDEX_MINUS }, - { "cheat_toggle", RARCH_CHEAT_TOGGLE }, - { "screenshot", RARCH_SCREENSHOT }, - { "dsp_config", RARCH_DSP_CONFIG }, - { "audio_mute", RARCH_MUTE }, - { "netplay_flip_players", RARCH_NETPLAY_FLIP }, - { "slowmotion", RARCH_SLOWMOTION }, - { "enable_hotkey", RARCH_ENABLE_HOTKEY }, - { "volume_up", RARCH_VOLUME_UP }, - { "volume_down", RARCH_VOLUME_DOWN }, - { "overlay_next", RARCH_OVERLAY_NEXT }, - { "disk_eject_toggle", RARCH_DISK_EJECT_TOGGLE }, - { "disk_next", RARCH_DISK_NEXT }, - { "grab_mouse_toggle", RARCH_GRAB_MOUSE_TOGGLE }, - { "menu_toggle", RARCH_MENU_TOGGLE }, -}; - -static unsigned input_str_to_bind(const char *str) -{ - unsigned i; - for (i = 0; i < ARRAY_SIZE(str_to_bind); i++) - { - if (!strcmp(str_to_bind[i].str, str)) - return str_to_bind[i].bind; - } - - return RARCH_BIND_LIST_END; -} - static const struct str_to_bind_map str_to_keyboard[] = { { "retrok_backspace", RETROK_BACKSPACE }, { "retrok_tab", RETROK_TAB }, @@ -491,7 +420,7 @@ static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, st for (tmp = strtok_r(key, "|", &save); tmp; tmp = strtok_r(NULL, "|", &save)) { if (strcmp(tmp, "nul") != 0) - desc->key_mask |= UINT64_C(1) << input_str_to_bind(tmp); + desc->key_mask |= UINT64_C(1) << input_translate_str_to_bind_id(tmp); } if (desc->key_mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))