From 3dff69864413270f13d037e781fc6c6b2cdac8f6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 25 Jun 2016 09:04:00 +0200 Subject: [PATCH] Turn retro_input_t into struct --- input/input_driver.c | 8 +++--- input/input_driver.h | 5 +++- menu/menu_input.c | 64 ++++++++++++++++++++++---------------------- runloop.c | 30 ++++++++++----------- 4 files changed, 55 insertions(+), 52 deletions(-) diff --git a/input/input_driver.c b/input/input_driver.c index cb0aba6d9b..8a17b8b641 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -253,7 +253,7 @@ float input_sensor_get_input(unsigned port, unsigned id) static retro_input_t input_driver_keys_pressed(void) { unsigned key; - retro_input_t ret = 0; + retro_input_t ret = {0}; for (key = 0; key < RARCH_BIND_LIST_END; key++) { @@ -287,7 +287,7 @@ static retro_input_t input_driver_keys_pressed(void) #endif if (state) - ret |= (UINT64_C(1) << key); + ret.state |= (UINT64_C(1) << key); } return ret; } @@ -580,14 +580,14 @@ retro_input_t input_keys_pressed(void) { unsigned i, key; const struct retro_keybind *binds[MAX_USERS]; - retro_input_t ret = 0; + retro_input_t ret = {0}; settings_t *settings = config_get_ptr(); for (i = 0; i < MAX_USERS; i++) binds[i] = settings->input.binds[i]; if (!current_input || !current_input_data) - return 0; + return ret; input_driver_turbo_btns.count++; diff --git a/input/input_driver.h b/input/input_driver.h index 413327142a..dd5f0cf547 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -36,7 +36,10 @@ RETRO_BEGIN_DECLS -typedef uint64_t retro_input_t; +typedef struct retro_input +{ + uint64_t state; +} retro_input_t; enum input_device_type { diff --git a/menu/menu_input.c b/menu/menu_input.c index 610ce9d390..127f535c60 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -1199,31 +1199,31 @@ static unsigned menu_input_frame_build(retro_input_t trigger_input) settings_t *settings = config_get_ptr(); unsigned ret = MENU_ACTION_NOOP; - if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) + if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) ret = MENU_ACTION_UP; - else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) + else if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) ret = MENU_ACTION_DOWN; - else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT)) + else if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT)) ret = MENU_ACTION_LEFT; - else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT)) + else if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT)) ret = MENU_ACTION_RIGHT; - else if (trigger_input & (UINT64_C(1) << settings->menu_scroll_up_btn)) + else if (trigger_input.state & (UINT64_C(1) << settings->menu_scroll_up_btn)) ret = MENU_ACTION_SCROLL_UP; - else if (trigger_input & (UINT64_C(1) << settings->menu_scroll_down_btn)) + else if (trigger_input.state & (UINT64_C(1) << settings->menu_scroll_down_btn)) ret = MENU_ACTION_SCROLL_DOWN; - else if (trigger_input & (UINT64_C(1) << settings->menu_cancel_btn)) + else if (trigger_input.state & (UINT64_C(1) << settings->menu_cancel_btn)) ret = MENU_ACTION_CANCEL; - else if (trigger_input & (UINT64_C(1) << settings->menu_ok_btn)) + else if (trigger_input.state & (UINT64_C(1) << settings->menu_ok_btn)) ret = MENU_ACTION_OK; - else if (trigger_input & (UINT64_C(1) << settings->menu_search_btn)) + else if (trigger_input.state & (UINT64_C(1) << settings->menu_search_btn)) ret = MENU_ACTION_SEARCH; - else if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y)) + else if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y)) ret = MENU_ACTION_SCAN; - else if (trigger_input & (UINT64_C(1) << settings->menu_default_btn)) + else if (trigger_input.state & (UINT64_C(1) << settings->menu_default_btn)) ret = MENU_ACTION_START; - else if (trigger_input & (UINT64_C(1) << settings->menu_info_btn)) + else if (trigger_input.state & (UINT64_C(1) << settings->menu_info_btn)) ret = MENU_ACTION_INFO; - else if (trigger_input & (UINT64_C(1) << RARCH_MENU_TOGGLE)) + else if (trigger_input.state & (UINT64_C(1) << RARCH_MENU_TOGGLE)) ret = MENU_ACTION_TOGGLE; return menu_input_frame_pointer(&ret); @@ -1252,7 +1252,7 @@ unsigned menu_input_frame_retropad(retro_input_t input, /* don't run anything first frame, only capture held inputs * for old_input_state. */ - if (input) + if (input.state) { if (!first_held) { @@ -1263,19 +1263,19 @@ unsigned menu_input_frame_retropad(retro_input_t input, if (menu_input->delay.count >= menu_input->delay.timer) { - retro_input_t input_repeat = 0; - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_UP); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_DOWN); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_LEFT); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_RIGHT); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_B); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_A); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_L); - BIT32_SET(input_repeat, RETRO_DEVICE_ID_JOYPAD_R); + retro_input_t input_repeat = {0}; + BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_UP); + BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_DOWN); + BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_LEFT); + BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_RIGHT); + BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_B); + BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_A); + BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_L); + BIT32_SET(input_repeat.state, RETRO_DEVICE_ID_JOYPAD_R); - set_scroll = true; - first_held = false; - trigger_input |= input & input_repeat; + set_scroll = true; + first_held = false; + trigger_input.state |= input.state & input_repeat.state; menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SCROLL_ACCEL, &new_scroll_accel); @@ -1308,7 +1308,7 @@ unsigned menu_input_frame_retropad(retro_input_t input, static unsigned ti_char = 64; static bool ti_next = false; - if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) + if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN)) { if (ti_char > 32) ti_char--; @@ -1318,7 +1318,7 @@ unsigned menu_input_frame_retropad(retro_input_t input, ti_next = false; } - if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) + if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP)) { if (ti_char < 125) ti_char++; @@ -1328,13 +1328,13 @@ unsigned menu_input_frame_retropad(retro_input_t input, ti_next = false; } - if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A)) + if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A)) { ti_char = 64; ti_next = true; } - if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B)) + if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B)) { input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD); ti_char = 64; @@ -1342,10 +1342,10 @@ unsigned menu_input_frame_retropad(retro_input_t input, } /* send return key to close keyboard input window */ - if (trigger_input & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START)) + if (trigger_input.state & (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START)) input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD); - trigger_input = 0; + trigger_input.state = 0; } return menu_input_frame_build(trigger_input); diff --git a/runloop.c b/runloop.c index 53342ad812..7b85bf4044 100644 --- a/runloop.c +++ b/runloop.c @@ -77,12 +77,12 @@ #define DEFAULT_EXT "" #endif -#define runloop_cmd_triggered(cmd, id) BIT64_GET(cmd->state[2], id) +#define runloop_cmd_triggered(cmd, id) BIT64_GET(cmd->state[2].state, id) -#define runloop_cmd_press(cmd, id) BIT64_GET(cmd->state[0], id) -#define runloop_cmd_pressed(cmd, id) BIT64_GET(cmd->state[1], id) +#define runloop_cmd_press(cmd, id) BIT64_GET(cmd->state[0].state, id) +#define runloop_cmd_pressed(cmd, id) BIT64_GET(cmd->state[1].state, id) #ifdef HAVE_MENU -#define runloop_cmd_menu_press(cmd) (BIT64_GET(cmd->state[2], RARCH_MENU_TOGGLE) || \ +#define runloop_cmd_menu_press(cmd) (BIT64_GET(cmd->state[2].state, RARCH_MENU_TOGGLE) || \ runloop_cmd_get_state_menu_toggle_button_combo( \ settings, cmd->state[0], \ cmd->state[1], cmd->state[2])) @@ -317,19 +317,19 @@ static bool runloop_cmd_get_state_menu_toggle_button_combo( case 0: return false; case 1: - if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_DOWN)) + if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_DOWN)) return false; - if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_Y)) + if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_Y)) return false; - if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_L)) + if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_L)) return false; - if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_R)) + if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_R)) return false; break; case 2: - if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_L3)) + if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_L3)) return false; - if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_R3)) + if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_R3)) return false; break; } @@ -1300,10 +1300,10 @@ int runloop_iterate(unsigned *sleep_ms) unsigned i; event_cmd_state_t cmd; retro_time_t current, target, to_sleep_ms; + static retro_input_t last_input = {0}; event_cmd_state_t *cmd_ptr = &cmd; static retro_time_t frame_limit_minimum_time = 0.0; static retro_time_t frame_limit_last_time = 0.0; - static retro_input_t last_input = 0; settings_t *settings = config_get_ptr(); cmd.state[1] = last_input; @@ -1330,14 +1330,14 @@ int runloop_iterate(unsigned *sleep_ms) if (input_driver_is_flushing_input()) { input_driver_unset_flushing_input(); - if (cmd.state[0]) + if (cmd.state[0].state) { - cmd.state[0] = 0; + cmd.state[0].state = 0; /* If core was paused before entering menu, evoke * pause toggle to wake it up. */ if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL)) - BIT64_SET(cmd.state[0], RARCH_PAUSE_TOGGLE); + BIT64_SET(cmd.state[0].state, RARCH_PAUSE_TOGGLE); input_driver_set_flushing_input(); } } @@ -1368,7 +1368,7 @@ int runloop_iterate(unsigned *sleep_ms) runloop_frame_time.callback(delta); } - cmd.state[2] = cmd.state[0] & ~cmd.state[1]; /* trigger */ + cmd.state[2].state = cmd.state[0].state & ~cmd.state[1].state; /* trigger */ if (runloop_cmd_triggered(cmd_ptr, RARCH_OVERLAY_NEXT)) command_event(CMD_EVENT_OVERLAY_NEXT, NULL);