mirror of
https://github.com/libretro/RetroArch
synced 2025-04-16 08:43:10 +00:00
(menu_input_bind_dialog.c) Use timer code
This commit is contained in:
parent
ab2ee3c690
commit
74e224abf0
@ -26,6 +26,7 @@
|
|||||||
#include "../../input/input_config.h"
|
#include "../../input/input_config.h"
|
||||||
|
|
||||||
#include "../../configuration.h"
|
#include "../../configuration.h"
|
||||||
|
#include "../../performance_counters.h"
|
||||||
|
|
||||||
#define MENU_MAX_BUTTONS 219
|
#define MENU_MAX_BUTTONS 219
|
||||||
#define MENU_MAX_AXES 32
|
#define MENU_MAX_AXES 32
|
||||||
@ -51,7 +52,8 @@ struct menu_bind_state
|
|||||||
{
|
{
|
||||||
struct retro_keybind *target;
|
struct retro_keybind *target;
|
||||||
/* For keyboard binding. */
|
/* For keyboard binding. */
|
||||||
int64_t timeout_end;
|
|
||||||
|
rarch_timer_t timer;
|
||||||
unsigned begin;
|
unsigned begin;
|
||||||
unsigned last;
|
unsigned last;
|
||||||
unsigned user;
|
unsigned user;
|
||||||
@ -61,7 +63,7 @@ struct menu_bind_state
|
|||||||
};
|
};
|
||||||
|
|
||||||
static unsigned menu_bind_port = 0;
|
static unsigned menu_bind_port = 0;
|
||||||
static struct menu_bind_state menu_input_binds;
|
static struct menu_bind_state menu_input_binds = {0};
|
||||||
|
|
||||||
static bool menu_input_key_bind_custom_bind_keyboard_cb(
|
static bool menu_input_key_bind_custom_bind_keyboard_cb(
|
||||||
void *data, unsigned code)
|
void *data, unsigned code)
|
||||||
@ -71,8 +73,8 @@ static bool menu_input_key_bind_custom_bind_keyboard_cb(
|
|||||||
menu_input_binds.target->key = (enum retro_key)code;
|
menu_input_binds.target->key = (enum retro_key)code;
|
||||||
menu_input_binds.begin++;
|
menu_input_binds.begin++;
|
||||||
menu_input_binds.target++;
|
menu_input_binds.target++;
|
||||||
menu_input_binds.timeout_end = cpu_features_get_time_usec() +
|
|
||||||
settings->input.bind_timeout * 1000000;
|
rarch_timer_begin_new_time(&menu_input_binds.timer, settings->input.bind_timeout);
|
||||||
|
|
||||||
return (menu_input_binds.begin <= menu_input_binds.last);
|
return (menu_input_binds.begin <= menu_input_binds.last);
|
||||||
}
|
}
|
||||||
@ -251,8 +253,7 @@ bool menu_input_key_bind_set_mode(
|
|||||||
menu_input_key_bind_poll_bind_state(
|
menu_input_key_bind_poll_bind_state(
|
||||||
&menu_input_binds, menu_bind_port, false);
|
&menu_input_binds, menu_bind_port, false);
|
||||||
|
|
||||||
menu_input_binds.timeout_end = cpu_features_get_time_usec() +
|
rarch_timer_begin_new_time(&menu_input_binds.timer, settings->input.bind_timeout);
|
||||||
settings->input.bind_timeout * 1000000;
|
|
||||||
|
|
||||||
keys.userdata = menu;
|
keys.userdata = menu;
|
||||||
keys.cb = menu_input_key_bind_custom_bind_keyboard_cb;
|
keys.cb = menu_input_key_bind_custom_bind_keyboard_cb;
|
||||||
@ -376,21 +377,19 @@ bool menu_input_key_bind_iterate(menu_input_ctx_bind_t *bind)
|
|||||||
struct menu_bind_state binds;
|
struct menu_bind_state binds;
|
||||||
bool timed_out = false;
|
bool timed_out = false;
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
int64_t current = cpu_features_get_time_usec();
|
|
||||||
int timeout =
|
rarch_timer_tick(&menu_input_binds.timer);
|
||||||
(menu_input_binds.timeout_end - current) / 1000000;
|
|
||||||
|
|
||||||
if (!bind)
|
if (!bind)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (timeout <= 0)
|
if (rarch_timer_has_expired(&menu_input_binds.timer))
|
||||||
{
|
{
|
||||||
input_driver_keyboard_mapping_set_block(false);
|
input_driver_keyboard_mapping_set_block(false);
|
||||||
|
|
||||||
menu_input_binds.begin++;
|
menu_input_binds.begin++;
|
||||||
menu_input_binds.target++;
|
menu_input_binds.target++;
|
||||||
menu_input_binds.timeout_end = cpu_features_get_time_usec() +
|
rarch_timer_begin_new_time(&menu_input_binds.timer, settings->input.bind_timeout);
|
||||||
settings->input.bind_timeout * 1000000;
|
|
||||||
timed_out = true;
|
timed_out = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +397,7 @@ bool menu_input_key_bind_iterate(menu_input_ctx_bind_t *bind)
|
|||||||
"[%s]\npress keyboard or joypad\n(timeout %d %s)",
|
"[%s]\npress keyboard or joypad\n(timeout %d %s)",
|
||||||
input_config_bind_map_get_desc(
|
input_config_bind_map_get_desc(
|
||||||
menu_input_binds.begin - MENU_SETTINGS_BIND_BEGIN),
|
menu_input_binds.begin - MENU_SETTINGS_BIND_BEGIN),
|
||||||
timeout,
|
rarch_timer_get_timeout(&menu_input_binds.timer),
|
||||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SECONDS));
|
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SECONDS));
|
||||||
|
|
||||||
/* binds.begin is updated in keyboard_press callback. */
|
/* binds.begin is updated in keyboard_press callback. */
|
||||||
@ -436,8 +435,7 @@ bool menu_input_key_bind_iterate(menu_input_ctx_bind_t *bind)
|
|||||||
}
|
}
|
||||||
|
|
||||||
binds.target++;
|
binds.target++;
|
||||||
binds.timeout_end = cpu_features_get_time_usec() +
|
rarch_timer_begin_new_time(&binds.timer, settings->input.bind_timeout);
|
||||||
settings->input.bind_timeout * 1000000;
|
|
||||||
}
|
}
|
||||||
menu_input_binds = binds;
|
menu_input_binds = binds;
|
||||||
|
|
||||||
|
@ -156,6 +156,13 @@ void rarch_timer_tick(rarch_timer_t *timer)
|
|||||||
timer->timeout = (timer->timeout_end - timer->current) / 1000000;
|
timer->timeout = (timer->timeout_end - timer->current) / 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rarch_timer_get_timeout(rarch_timer_t *timer)
|
||||||
|
{
|
||||||
|
if (!timer)
|
||||||
|
return 0;
|
||||||
|
return timer->timeout;
|
||||||
|
}
|
||||||
|
|
||||||
bool rarch_timer_is_running(rarch_timer_t *timer)
|
bool rarch_timer_is_running(rarch_timer_t *timer)
|
||||||
{
|
{
|
||||||
if (!timer)
|
if (!timer)
|
||||||
@ -179,11 +186,18 @@ void rarch_timer_end(rarch_timer_t *timer)
|
|||||||
timer->timeout_end = 0;
|
timer->timeout_end = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rarch_timer_begin(rarch_timer_t *timer, uint64_t sec)
|
void rarch_timer_begin_new_time(rarch_timer_t *timer, uint64_t sec)
|
||||||
{
|
{
|
||||||
if (!timer)
|
if (!timer)
|
||||||
return;
|
return;
|
||||||
timer->timeout_end = cpu_features_get_time_usec() + sec * 1000000;
|
timer->timeout_end = cpu_features_get_time_usec() + sec * 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rarch_timer_begin(rarch_timer_t *timer, uint64_t sec)
|
||||||
|
{
|
||||||
|
if (!timer)
|
||||||
|
return;
|
||||||
|
rarch_timer_begin_new_time(timer, sec);
|
||||||
timer->timer_begin = true;
|
timer->timer_begin = true;
|
||||||
timer->timer_end = false;
|
timer->timer_end = false;
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,12 @@ bool rarch_timer_has_expired(rarch_timer_t *timer);
|
|||||||
|
|
||||||
void rarch_timer_begin(rarch_timer_t *timer, uint64_t ms);
|
void rarch_timer_begin(rarch_timer_t *timer, uint64_t ms);
|
||||||
|
|
||||||
|
void rarch_timer_begin_new_time(rarch_timer_t *timer, uint64_t sec);
|
||||||
|
|
||||||
void rarch_timer_end(rarch_timer_t *timer);
|
void rarch_timer_end(rarch_timer_t *timer);
|
||||||
|
|
||||||
|
int rarch_timer_get_timeout(rarch_timer_t *timer);
|
||||||
|
|
||||||
RETRO_END_DECLS
|
RETRO_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user