mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 00:32:49 +00:00
Create rarch_timer functions and have menu_dialog.c use them
This commit is contained in:
parent
2f352ed1b7
commit
f6ec61b15c
@ -35,6 +35,7 @@
|
||||
|
||||
#include "../../tasks/tasks_internal.h"
|
||||
#include "../../input/input_config.h"
|
||||
#include "../../performance_counters.h"
|
||||
|
||||
static bool menu_dialog_pending_push = false;
|
||||
static bool menu_dialog_active = false;
|
||||
@ -54,31 +55,20 @@ int menu_dialog_iterate(char *s, size_t len, const char *label)
|
||||
{
|
||||
case MENU_DIALOG_WELCOME:
|
||||
{
|
||||
static int64_t timeout_end;
|
||||
int64_t timeout;
|
||||
static bool timer_begin = false;
|
||||
static bool timer_end = false;
|
||||
int64_t current = cpu_features_get_time_usec();
|
||||
static rarch_timer_t timer;
|
||||
|
||||
if (!timer_begin)
|
||||
{
|
||||
timeout_end = cpu_features_get_time_usec() +
|
||||
3 /* seconds */ * 1000000;
|
||||
timer_begin = true;
|
||||
timer_end = false;
|
||||
}
|
||||
if (!rarch_timer_is_running(&timer))
|
||||
rarch_timer_begin(&timer, 3);
|
||||
|
||||
timeout = (timeout_end - current) / 1000000;
|
||||
rarch_timer_tick(&timer);
|
||||
|
||||
menu_hash_get_help_enum(
|
||||
MENU_ENUM_LABEL_WELCOME_TO_RETROARCH,
|
||||
s, len);
|
||||
|
||||
if (!timer_end && timeout <= 0)
|
||||
if (rarch_timer_has_expired(&timer))
|
||||
{
|
||||
timer_end = true;
|
||||
timer_begin = false;
|
||||
timeout_end = 0;
|
||||
rarch_timer_end(&timer);
|
||||
do_exit = true;
|
||||
}
|
||||
}
|
||||
|
@ -147,3 +147,45 @@ void performance_counter_stop(struct retro_perf_counter *perf)
|
||||
|
||||
perf->total += cpu_features_get_perf_counter() - perf->start;
|
||||
}
|
||||
|
||||
void rarch_timer_tick(rarch_timer_t *timer)
|
||||
{
|
||||
if (!timer)
|
||||
return;
|
||||
timer->current = cpu_features_get_time_usec();
|
||||
timer->timeout = (timer->timeout_end - timer->current) / 1000000;
|
||||
}
|
||||
|
||||
bool rarch_timer_is_running(rarch_timer_t *timer)
|
||||
{
|
||||
if (!timer)
|
||||
return false;
|
||||
return timer->timer_begin;
|
||||
}
|
||||
|
||||
bool rarch_timer_has_expired(rarch_timer_t *timer)
|
||||
{
|
||||
if (!timer)
|
||||
return true;
|
||||
if (!timer->timer_end && timer->timeout <= 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void rarch_timer_end(rarch_timer_t *timer)
|
||||
{
|
||||
if (!timer)
|
||||
return;
|
||||
timer->timer_end = true;
|
||||
timer->timer_begin = false;
|
||||
timer->timeout_end = 0;
|
||||
}
|
||||
|
||||
void rarch_timer_begin(rarch_timer_t *timer, uint64_t sec)
|
||||
{
|
||||
if (!timer)
|
||||
return;
|
||||
timer->timeout_end = cpu_features_get_time_usec() + sec * 1000000;
|
||||
timer->timer_begin = true;
|
||||
timer->timer_end = false;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define _PERFORMANCE_COUNTERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <boolean.h>
|
||||
|
||||
#include <retro_common_api.h>
|
||||
#include <libretro.h>
|
||||
@ -28,6 +29,15 @@ RETRO_BEGIN_DECLS
|
||||
#define MAX_COUNTERS 64
|
||||
#endif
|
||||
|
||||
typedef struct rarch_timer
|
||||
{
|
||||
int64_t current;
|
||||
int64_t timeout;
|
||||
int64_t timeout_end;
|
||||
bool timer_begin;
|
||||
bool timer_end;
|
||||
} rarch_timer_t;
|
||||
|
||||
struct retro_perf_counter **retro_get_perf_counter_rarch(void);
|
||||
|
||||
struct retro_perf_counter **retro_get_perf_counter_libretro(void);
|
||||
@ -62,6 +72,16 @@ void performance_counter_start(struct retro_perf_counter *perf);
|
||||
**/
|
||||
void performance_counter_stop(struct retro_perf_counter *perf);
|
||||
|
||||
void rarch_timer_tick(rarch_timer_t *timer);
|
||||
|
||||
bool rarch_timer_is_running(rarch_timer_t *timer);
|
||||
|
||||
bool rarch_timer_has_expired(rarch_timer_t *timer);
|
||||
|
||||
void rarch_timer_begin(rarch_timer_t *timer, uint64_t ms);
|
||||
|
||||
void rarch_timer_end(rarch_timer_t *timer);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user