Move input_keys_pressed from input_common.c to runloop.c

This commit is contained in:
twinaphex 2014-10-05 02:45:38 +02:00
parent c50352ebb9
commit 2df2346301
3 changed files with 77 additions and 82 deletions

View File

@ -1619,83 +1619,3 @@ void input_pop_analog_dpad(struct retro_keybind *binds)
for (i = RETRO_DEVICE_ID_JOYPAD_UP; i <= RETRO_DEVICE_ID_JOYPAD_RIGHT; i++)
binds[i].joyaxis = binds[i].orig_joyaxis;
}
#if !defined(IS_JOYCONFIG) && !defined(IS_RETROLAUNCH)
static void check_block_hotkey(bool enable_hotkey)
{
bool use_hotkey_enable;
static const struct retro_keybind *bind =
&g_settings.input.binds[0][RARCH_ENABLE_HOTKEY];
/* Don't block the check to RARCH_ENABLE_HOTKEY
* unless we're really supposed to. */
driver.block_hotkey = driver.block_input;
// If we haven't bound anything to this, always allow hotkeys.
use_hotkey_enable = bind->key != RETROK_UNKNOWN ||
bind->joykey != NO_BTN ||
bind->joyaxis != AXIS_NONE;
driver.block_hotkey = driver.block_input ||
(use_hotkey_enable && !enable_hotkey);
/* If we hold ENABLE_HOTKEY button, block all libretro input to allow
* hotkeys to be bound to same keys as RetroPad. */
driver.block_libretro_input = use_hotkey_enable && enable_hotkey;
}
/* Returns a 64-bit mask of all pressed keys, starting
* from bind ID 0 (RARCH_DEVICE_ID_JOYPAD_B) up until
* last bind ID (RARCH_BIND_LIST_END).
*
* TODO: In case RARCH_BIND_LIST_END starts exceeding 64,
* and you need a bitmask of more than 64 entries, don't
* use this function.
*/
retro_input_t input_keys_pressed(void)
{
static const struct retro_keybind *binds[] = { g_settings.input.binds[0] };
retro_input_t ret = 0;
int i, key;
check_block_hotkey(driver.input->key_pressed(driver.input_data,
RARCH_ENABLE_HOTKEY));
input_push_analog_dpad((struct retro_keybind*)binds[0],
(g_settings.input.analog_dpad_mode[0] == ANALOG_DPAD_NONE) ?
ANALOG_DPAD_LSTICK : g_settings.input.analog_dpad_mode[0]);
for (i = 0; i < MAX_PLAYERS; i++)
input_push_analog_dpad(g_settings.input.autoconf_binds[i],
g_settings.input.analog_dpad_mode[i]);
for (key = 0; key < RARCH_BIND_LIST_END; key++)
{
bool state = false;
if (
(!driver.block_libretro_input && (key < RARCH_FIRST_META_KEY)) ||
!driver.block_hotkey)
state = driver.input->key_pressed(driver.input_data, key);
#ifdef HAVE_OVERLAY
state = state || (driver.overlay_state.buttons & (1ULL << key));
#endif
#ifdef HAVE_COMMAND
if (driver.command)
state = state || rarch_cmd_get(driver.command, key);
#endif
if (state)
ret |= (1ULL << key);
}
input_pop_analog_dpad((struct retro_keybind*)binds[0]);
for (i = 0; i < MAX_PLAYERS; i++)
input_pop_analog_dpad(g_settings.input.autoconf_binds[i]);
return ret;
}
#endif

View File

@ -209,8 +209,6 @@ void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode);
void input_pop_analog_dpad(struct retro_keybind *binds);
retro_input_t input_keys_pressed(void);
#ifdef __cplusplus
}
#endif

View File

@ -620,6 +620,83 @@ static void limit_frame_time(void)
g_extern.frame_limit.last_frame_time = rarch_get_time_usec();
}
static void check_block_hotkey(bool enable_hotkey)
{
bool use_hotkey_enable;
static const struct retro_keybind *bind =
&g_settings.input.binds[0][RARCH_ENABLE_HOTKEY];
/* Don't block the check to RARCH_ENABLE_HOTKEY
* unless we're really supposed to. */
driver.block_hotkey = driver.block_input;
// If we haven't bound anything to this, always allow hotkeys.
use_hotkey_enable = bind->key != RETROK_UNKNOWN ||
bind->joykey != NO_BTN ||
bind->joyaxis != AXIS_NONE;
driver.block_hotkey = driver.block_input ||
(use_hotkey_enable && !enable_hotkey);
/* If we hold ENABLE_HOTKEY button, block all libretro input to allow
* hotkeys to be bound to same keys as RetroPad. */
driver.block_libretro_input = use_hotkey_enable && enable_hotkey;
}
/* We query all known keys per frame. Returns a 64-bit mask
* of all pressed keys.
*
* TODO: In case RARCH_BIND_LIST_END starts exceeding 64,
* and you need a bitmask of more than 64 entries, reimplement
* it to use something like rarch_bits_t.
*/
static inline retro_input_t input_keys_pressed(void)
{
static const struct retro_keybind *binds[] = { g_settings.input.binds[0] };
retro_input_t ret = 0;
int i, key;
check_block_hotkey(driver.input->key_pressed(driver.input_data,
RARCH_ENABLE_HOTKEY));
input_push_analog_dpad((struct retro_keybind*)binds[0],
(g_settings.input.analog_dpad_mode[0] == ANALOG_DPAD_NONE) ?
ANALOG_DPAD_LSTICK : g_settings.input.analog_dpad_mode[0]);
for (i = 0; i < MAX_PLAYERS; i++)
input_push_analog_dpad(g_settings.input.autoconf_binds[i],
g_settings.input.analog_dpad_mode[i]);
for (key = 0; key < RARCH_BIND_LIST_END; key++)
{
bool state = false;
if (
(!driver.block_libretro_input && (key < RARCH_FIRST_META_KEY)) ||
!driver.block_hotkey)
state = driver.input->key_pressed(driver.input_data, key);
#ifdef HAVE_OVERLAY
state = state || (driver.overlay_state.buttons & (1ULL << key));
#endif
#ifdef HAVE_COMMAND
if (driver.command)
state = state || rarch_cmd_get(driver.command, key);
#endif
if (state)
ret |= (1ULL << key);
}
input_pop_analog_dpad((struct retro_keybind*)binds[0]);
for (i = 0; i < MAX_PLAYERS; i++)
input_pop_analog_dpad(g_settings.input.autoconf_binds[i]);
return ret;
}
/*
* RetroArch's main iteration loop.
*