mirror of
https://github.com/libretro/RetroArch.git
synced 2024-10-10 08:04:37 +00:00
Create runloop_poll
This commit is contained in:
parent
335c9ec958
commit
4b807b482f
@ -45,7 +45,13 @@
|
|||||||
static void emscripten_mainloop(void)
|
static void emscripten_mainloop(void)
|
||||||
{
|
{
|
||||||
unsigned sleep_ms = 0;
|
unsigned sleep_ms = 0;
|
||||||
int ret = runloop_iterate(&sleep_ms);
|
event_cmd_state_t cmd;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
runloop_poll(&cmd);
|
||||||
|
|
||||||
|
ret = runloop_iterate(&cmd, &sleep_ms);
|
||||||
|
|
||||||
if (ret == 1 && sleep_ms > 0)
|
if (ret == 1 && sleep_ms > 0)
|
||||||
retro_sleep(sleep_ms);
|
retro_sleep(sleep_ms);
|
||||||
task_queue_ctl(TASK_QUEUE_CTL_CHECK, NULL);
|
task_queue_ctl(TASK_QUEUE_CTL_CHECK, NULL);
|
||||||
|
@ -378,7 +378,12 @@ static void android_app_entry(void *data)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
unsigned sleep_ms = 0;
|
unsigned sleep_ms = 0;
|
||||||
int ret = runloop_iterate(&sleep_ms);
|
event_cmd_state_t cmd;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
runloop_poll(&cmd);
|
||||||
|
|
||||||
|
ret = runloop_iterate(&cmd, &sleep_ms);
|
||||||
|
|
||||||
if (ret == 1 && sleep_ms > 0)
|
if (ret == 1 && sleep_ms > 0)
|
||||||
retro_sleep(sleep_ms);
|
retro_sleep(sleep_ms);
|
||||||
|
@ -124,7 +124,12 @@ int rarch_main(int argc, char *argv[], void *data)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
unsigned sleep_ms = 0;
|
unsigned sleep_ms = 0;
|
||||||
int ret = runloop_iterate(&sleep_ms);
|
event_cmd_state_t cmd;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
runloop_poll(&cmd);
|
||||||
|
|
||||||
|
ret = runloop_iterate(&cmd, &sleep_ms);
|
||||||
|
|
||||||
if (ret == 1 && sleep_ms > 0)
|
if (ret == 1 && sleep_ms > 0)
|
||||||
retro_sleep(sleep_ms);
|
retro_sleep(sleep_ms);
|
||||||
|
@ -96,6 +96,12 @@ enum analog_dpad_mode
|
|||||||
ANALOG_DPAD_LAST
|
ANALOG_DPAD_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct retro_input
|
||||||
|
{
|
||||||
|
unsigned type;
|
||||||
|
uint64_t state;
|
||||||
|
} retro_input_t;
|
||||||
|
|
||||||
/* Specialized _MOUSE that targets the full screen regardless of viewport.
|
/* Specialized _MOUSE that targets the full screen regardless of viewport.
|
||||||
*/
|
*/
|
||||||
#define RARCH_DEVICE_MOUSE_SCREEN (RETRO_DEVICE_MOUSE | 0x10000)
|
#define RARCH_DEVICE_MOUSE_SCREEN (RETRO_DEVICE_MOUSE | 0x10000)
|
||||||
|
@ -29,12 +29,6 @@
|
|||||||
|
|
||||||
RETRO_BEGIN_DECLS
|
RETRO_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct retro_input
|
|
||||||
{
|
|
||||||
unsigned type;
|
|
||||||
uint64_t state;
|
|
||||||
} retro_input_t;
|
|
||||||
|
|
||||||
enum input_device_type
|
enum input_device_type
|
||||||
{
|
{
|
||||||
INPUT_DEVICE_TYPE_NONE = 0,
|
INPUT_DEVICE_TYPE_NONE = 0,
|
||||||
|
45
runloop.c
45
runloop.c
@ -99,11 +99,6 @@
|
|||||||
cmd->state[1], cmd->state[2]))
|
cmd->state[1], cmd->state[2]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct event_cmd_state
|
|
||||||
{
|
|
||||||
retro_input_t state[3];
|
|
||||||
} event_cmd_state_t;
|
|
||||||
|
|
||||||
static rarch_system_info_t runloop_system;
|
static rarch_system_info_t runloop_system;
|
||||||
static struct retro_frame_time_callback runloop_frame_time;
|
static struct retro_frame_time_callback runloop_frame_time;
|
||||||
static retro_keyboard_event_t runloop_key_event = NULL;
|
static retro_keyboard_event_t runloop_key_event = NULL;
|
||||||
@ -1167,6 +1162,16 @@ static int runloop_iterate_menu(enum menu_action action, unsigned *sleep_ms)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void runloop_poll(event_cmd_state_t *cmd)
|
||||||
|
{
|
||||||
|
static retro_input_t last_input = {0};
|
||||||
|
cmd->state[1] = last_input;
|
||||||
|
cmd->state[0] = input_keys_pressed();
|
||||||
|
cmd->state[2].state = cmd->state[0].state
|
||||||
|
& ~cmd->state[1].state;
|
||||||
|
last_input = cmd->state[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* runloop_iterate:
|
* runloop_iterate:
|
||||||
*
|
*
|
||||||
@ -1176,21 +1181,14 @@ static int runloop_iterate_menu(enum menu_action action, unsigned *sleep_ms)
|
|||||||
* button input in order to wake up the loop,
|
* button input in order to wake up the loop,
|
||||||
* -1 if we forcibly quit out of the RetroArch iteration loop.
|
* -1 if we forcibly quit out of the RetroArch iteration loop.
|
||||||
**/
|
**/
|
||||||
int runloop_iterate(unsigned *sleep_ms)
|
int runloop_iterate(event_cmd_state_t *cmd, unsigned *sleep_ms)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
event_cmd_state_t cmd;
|
|
||||||
retro_time_t current, target, to_sleep_ms;
|
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_minimum_time = 0.0;
|
||||||
static retro_time_t frame_limit_last_time = 0.0;
|
static retro_time_t frame_limit_last_time = 0.0;
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
cmd.state[1] = last_input;
|
|
||||||
cmd.state[0] = input_keys_pressed();
|
|
||||||
last_input = cmd.state[0];
|
|
||||||
|
|
||||||
runloop_ctl(RUNLOOP_CTL_UNSET_FRAME_TIME_LAST, NULL);
|
runloop_ctl(RUNLOOP_CTL_UNSET_FRAME_TIME_LAST, NULL);
|
||||||
|
|
||||||
if (runloop_ctl(RUNLOOP_CTL_SHOULD_SET_FRAME_LIMIT, NULL))
|
if (runloop_ctl(RUNLOOP_CTL_SHOULD_SET_FRAME_LIMIT, NULL))
|
||||||
@ -1211,14 +1209,14 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
if (input_driver_is_flushing_input())
|
if (input_driver_is_flushing_input())
|
||||||
{
|
{
|
||||||
input_driver_unset_flushing_input();
|
input_driver_unset_flushing_input();
|
||||||
if (cmd.state[0].state)
|
if (cmd->state[0].state)
|
||||||
{
|
{
|
||||||
cmd.state[0].state = 0;
|
cmd->state[0].state = 0;
|
||||||
|
|
||||||
/* If core was paused before entering menu, evoke
|
/* If core was paused before entering menu, evoke
|
||||||
* pause toggle to wake it up. */
|
* pause toggle to wake it up. */
|
||||||
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
|
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
|
||||||
BIT64_SET(cmd.state[0].state, RARCH_PAUSE_TOGGLE);
|
BIT64_SET(cmd->state[0].state, RARCH_PAUSE_TOGGLE);
|
||||||
input_driver_set_flushing_input();
|
input_driver_set_flushing_input();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1249,12 +1247,11 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
runloop_frame_time.callback(delta);
|
runloop_frame_time.callback(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.state[2].state = cmd.state[0].state & ~cmd.state[1].state; /* trigger */
|
|
||||||
|
|
||||||
if (runloop_cmd_triggered(cmd_ptr, RARCH_OVERLAY_NEXT))
|
if (runloop_cmd_triggered(cmd, RARCH_OVERLAY_NEXT))
|
||||||
command_event(CMD_EVENT_OVERLAY_NEXT, NULL);
|
command_event(CMD_EVENT_OVERLAY_NEXT, NULL);
|
||||||
|
|
||||||
if (runloop_cmd_triggered(cmd_ptr, RARCH_FULLSCREEN_TOGGLE_KEY))
|
if (runloop_cmd_triggered(cmd, RARCH_FULLSCREEN_TOGGLE_KEY))
|
||||||
{
|
{
|
||||||
bool fullscreen_toggled = !runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL);
|
bool fullscreen_toggled = !runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL);
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
@ -1266,11 +1263,11 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
command_event(CMD_EVENT_FULLSCREEN_TOGGLE, NULL);
|
command_event(CMD_EVENT_FULLSCREEN_TOGGLE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runloop_cmd_triggered(cmd_ptr, RARCH_GRAB_MOUSE_TOGGLE))
|
if (runloop_cmd_triggered(cmd, RARCH_GRAB_MOUSE_TOGGLE))
|
||||||
command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL);
|
command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL);
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
if (runloop_cmd_menu_press(cmd_ptr) ||
|
if (runloop_cmd_menu_press(cmd) ||
|
||||||
rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
|
rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
|
||||||
{
|
{
|
||||||
if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL))
|
if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL))
|
||||||
@ -1292,7 +1289,7 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (runloop_iterate_time_to_exit(
|
if (runloop_iterate_time_to_exit(
|
||||||
runloop_cmd_press(cmd_ptr, RARCH_QUIT_KEY)) != 1)
|
runloop_cmd_press(cmd, RARCH_QUIT_KEY)) != 1)
|
||||||
{
|
{
|
||||||
frame_limit_last_time = 0.0;
|
frame_limit_last_time = 0.0;
|
||||||
command_event(CMD_EVENT_QUIT, NULL);
|
command_event(CMD_EVENT_QUIT, NULL);
|
||||||
@ -1306,7 +1303,7 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
|
|
||||||
core_poll();
|
core_poll();
|
||||||
ret = runloop_iterate_menu((enum menu_action)
|
ret = runloop_iterate_menu((enum menu_action)
|
||||||
menu_event(cmd.state[0], cmd.state[2]),
|
menu_event(cmd->state[0], cmd->state[2]),
|
||||||
sleep_ms);
|
sleep_ms);
|
||||||
|
|
||||||
#ifdef HAVE_NETWORKING
|
#ifdef HAVE_NETWORKING
|
||||||
@ -1321,7 +1318,7 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!runloop_check_state(&cmd))
|
if (!runloop_check_state(cmd))
|
||||||
{
|
{
|
||||||
/* RetroArch has been paused. */
|
/* RetroArch has been paused. */
|
||||||
core_poll();
|
core_poll();
|
||||||
|
@ -203,8 +203,15 @@ typedef struct runloop_ctx_msg_info
|
|||||||
bool flush;
|
bool flush;
|
||||||
} runloop_ctx_msg_info_t;
|
} runloop_ctx_msg_info_t;
|
||||||
|
|
||||||
|
typedef struct event_cmd_state
|
||||||
|
{
|
||||||
|
retro_input_t state[3];
|
||||||
|
} event_cmd_state_t;
|
||||||
|
|
||||||
global_t *global_get_ptr(void);
|
global_t *global_get_ptr(void);
|
||||||
|
|
||||||
|
void runloop_poll(event_cmd_state_t *cmd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* runloop_iterate:
|
* runloop_iterate:
|
||||||
*
|
*
|
||||||
@ -216,7 +223,7 @@ global_t *global_get_ptr(void);
|
|||||||
* Returns -1 if we forcibly quit out of the
|
* Returns -1 if we forcibly quit out of the
|
||||||
* RetroArch iteration loop.
|
* RetroArch iteration loop.
|
||||||
**/
|
**/
|
||||||
int runloop_iterate(unsigned *sleep_ms);
|
int runloop_iterate(event_cmd_state_t *cmd, unsigned *sleep_ms);
|
||||||
|
|
||||||
void runloop_msg_queue_push(const char *msg, unsigned prio,
|
void runloop_msg_queue_push(const char *msg, unsigned prio,
|
||||||
unsigned duration, bool flush);
|
unsigned duration, bool flush);
|
||||||
|
@ -232,11 +232,15 @@ static char** waiting_argv;
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
event_cmd_state_t cmd;
|
||||||
unsigned sleep_ms = 0;
|
unsigned sleep_ms = 0;
|
||||||
const ui_application_t *application = ui_companion_driver_get_application_ptr();
|
const ui_application_t *application = ui_companion_driver_get_application_ptr();
|
||||||
if (application)
|
if (application)
|
||||||
application->process_events();
|
application->process_events();
|
||||||
ret = runloop_iterate(&sleep_ms);
|
|
||||||
|
runloop_poll(&cmd);
|
||||||
|
|
||||||
|
ret = runloop_iterate(&cmd, &sleep_ms);
|
||||||
if (ret == 1 && sleep_ms > 0)
|
if (ret == 1 && sleep_ms > 0)
|
||||||
retro_sleep(sleep_ms);
|
retro_sleep(sleep_ms);
|
||||||
task_queue_ctl(TASK_QUEUE_CTL_CHECK, NULL);
|
task_queue_ctl(TASK_QUEUE_CTL_CHECK, NULL);
|
||||||
|
@ -84,8 +84,13 @@ static void ui_companion_cocoatouch_event_command(
|
|||||||
static void rarch_draw_observer(CFRunLoopObserverRef observer,
|
static void rarch_draw_observer(CFRunLoopObserverRef observer,
|
||||||
CFRunLoopActivity activity, void *info)
|
CFRunLoopActivity activity, void *info)
|
||||||
{
|
{
|
||||||
|
event_cmd_state_t cmd;
|
||||||
unsigned sleep_ms = 0;
|
unsigned sleep_ms = 0;
|
||||||
int ret = runloop_iterate(&sleep_ms);
|
int ret = 0;
|
||||||
|
|
||||||
|
runloop_poll(&cmd);
|
||||||
|
|
||||||
|
ret = runloop_iterate(&cmd, &sleep_ms);
|
||||||
|
|
||||||
if (ret == 1 && !ui_companion_is_on_foreground() && sleep_ms > 0)
|
if (ret == 1 && !ui_companion_is_on_foreground() && sleep_ms > 0)
|
||||||
retro_sleep(sleep_ms);
|
retro_sleep(sleep_ms);
|
||||||
|
Loading…
Reference in New Issue
Block a user