diff --git a/audio/audio_driver.c b/audio/audio_driver.c index d7d1f82acb..ace584e1f7 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -22,6 +22,7 @@ #include "../driver.h" #include "../general.h" #include "../retroarch.h" +#include "../runloop.h" static const audio_driver_t *audio_drivers[] = { #ifdef HAVE_ALSA diff --git a/camera/camera_driver.c b/camera/camera_driver.c index 0efe084743..08abf8bc05 100644 --- a/camera/camera_driver.c +++ b/camera/camera_driver.c @@ -19,6 +19,7 @@ #include "camera_driver.h" #include "../driver.h" #include "../general.h" +#include "../runloop.h" static const camera_driver_t *camera_drivers[] = { #ifdef HAVE_V4L2 diff --git a/cheats.c b/cheats.c index 2a7935f4c5..07a902f33f 100644 --- a/cheats.c +++ b/cheats.c @@ -16,6 +16,7 @@ #include "cheats.h" #include "general.h" +#include "runloop.h" #include "dynamic.h" #include #include @@ -232,7 +233,6 @@ void cheat_manager_free(cheat_manager_t *handle) void cheat_manager_update(cheat_manager_t *handle, unsigned handle_idx) { - msg_queue_clear(g_runloop.msg_queue); char msg[256]; snprintf(msg, sizeof(msg), "Cheat: #%u [%s]: %s", @@ -240,7 +240,7 @@ void cheat_manager_update(cheat_manager_t *handle, unsigned handle_idx) (handle->cheats[handle_idx].desc) ? (handle->cheats[handle_idx].desc) : (handle->cheats[handle_idx].code) ); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, true); RARCH_LOG("%s\n", msg); } diff --git a/command.c b/command.c index 6662470d12..6c08b013a5 100644 --- a/command.c +++ b/command.c @@ -22,6 +22,7 @@ #endif #include "general.h" +#include "runloop.h" #include "compat/strl.h" #include "compat/posix_string.h" #include @@ -230,10 +231,8 @@ static bool cmd_set_shader(const char *arg) if (type == RARCH_SHADER_NONE) return false; - msg_queue_clear(g_runloop.msg_queue); - snprintf(msg, sizeof(msg), "Shader: \"%s\"", arg); - msg_queue_push(g_runloop.msg_queue, msg, 1, 120); + rarch_main_msg_queue_push(msg, 1, 120, true); RARCH_LOG("Applying shader \"%s\".\n", arg); return driver.video->set_shader(driver.video_data, type, arg); diff --git a/database_info.c b/database_info.c index 1a0abde7dc..08124fe49d 100644 --- a/database_info.c +++ b/database_info.c @@ -20,6 +20,7 @@ #include "file_ops.h" #include "file_extract.h" #include "general.h" +#include "runloop.h" #include #include "file_ext.h" #include @@ -84,8 +85,7 @@ void database_info_write_rdl_free(database_info_rdl_handle_t *dbl) string_list_free(dbl->list); free(dbl); - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, "Scanning of directory finished.\n", 1, 180); + rarch_main_msg_queue_push("Scanning of directory finished.\n", 1, 180, true); } int database_info_write_rdl_iterate(database_info_rdl_handle_t *dbl) @@ -141,8 +141,7 @@ int database_info_write_rdl_iterate(database_info_rdl_handle_t *dbl) snprintf(msg, sizeof(msg), "%zu/%zu: Scanning %s...\n", dbl->list_ptr, dbl->list->size, name); - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, true); crc = crc32_calculate(ret_buf, ret); diff --git a/driver.c b/driver.c index 117d4e03ee..f7f15ebcaa 100644 --- a/driver.c +++ b/driver.c @@ -17,6 +17,7 @@ #include "driver.h" #include "general.h" #include "retroarch.h" +#include "runloop.h" #include "compat/posix_string.h" #include "gfx/video_monitor.h" #include "audio/audio_monitor.h" @@ -281,7 +282,7 @@ bool driver_update_system_av_info(const struct retro_system_av_info *info) if (driver.recording_data) { static const char *msg = "Restarting recording due to driver reinit."; - msg_queue_push(g_runloop.msg_queue, msg, 2, 180); + rarch_main_msg_queue_push(msg, 2, 180, false); RARCH_WARN("%s\n", msg); rarch_main_command(RARCH_CMD_RECORD_DEINIT); rarch_main_command(RARCH_CMD_RECORD_INIT); diff --git a/dynamic.c b/dynamic.c index e2cc0068f9..5fb88b17ac 100644 --- a/dynamic.c +++ b/dynamic.c @@ -31,6 +31,7 @@ #include "libretro_private.h" #include "dynamic_dummy.h" #include "retroarch.h" +#include "runloop.h" #include "input/input_sensor.h" @@ -674,11 +675,7 @@ bool rarch_environment_cb(unsigned cmd, void *data) { const struct retro_message *msg = (const struct retro_message*)data; RARCH_LOG("Environ SET_MESSAGE: %s\n", msg->msg); - if (g_runloop.msg_queue) - { - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, msg->msg, 1, msg->frames); - } + rarch_main_msg_queue_push(msg->msg, 1, msg->frames, true); break; } diff --git a/general.h b/general.h index 749399d0a4..c60d756b7a 100644 --- a/general.h +++ b/general.h @@ -395,71 +395,6 @@ typedef struct rarch_resolution unsigned id; } rarch_resolution_t; -#define AUDIO_BUFFER_FREE_SAMPLES_COUNT (8 * 1024) -#define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024) - -/* All libretro runloop-related globals go here. */ - -struct runloop -{ - /* Lifecycle state checks. */ - bool is_paused; - bool is_idle; - bool is_menu; - bool is_slowmotion; - - struct - { - struct - { - unsigned count; - unsigned max; - struct - { - struct - { - struct - { - bool is_updated; - } label; - - struct - { - bool is_active; - } animation; - - struct - { - bool dirty; - } framebuf; - - struct - { - bool active; - } action; - } menu; - } current; - } video; - - struct - { - retro_time_t minimum_time; - retro_time_t last_time; - } limit; - } frames; - - struct - { - unsigned buffer_free_samples[AUDIO_BUFFER_FREE_SAMPLES_COUNT]; - uint64_t buffer_free_samples_count; - - retro_time_t frame_time_samples[MEASURE_FRAME_TIME_SAMPLES_COUNT]; - uint64_t frame_time_samples_count; - } measure_data; - - msg_queue_t *msg_queue; -}; - /* All run-time- / command line flag-related globals go here. */ struct global @@ -783,7 +718,6 @@ struct global /* Public data structures. */ extern struct settings g_settings; -extern struct runloop g_runloop; extern struct global g_extern; extern struct defaults g_defaults; diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index bb88fda056..ee048f3ff8 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -32,6 +32,7 @@ #include "../../general.h" #include "../../retroarch.h" +#include "../../runloop.h" #include "../video_viewport.h" #include "../video_monitor.h" #include "../font_renderer_driver.h" @@ -1432,7 +1433,7 @@ static bool exynos_gfx_frame(void *data, const void *frame, unsigned width, char buffer[128], buffer_fps[128]; video_monitor_get_fps(buffer, sizeof(buffer), g_settings.fps_show ? buffer_fps : NULL, sizeof(buffer_fps)); - msg_queue_push(g_runloop.msg_queue, buffer_fps, 1, 1); + rarch_main_msg_queue_push(buffer_fps, 1, 1, false); } /* If at this point the dimension parameters are still zero, setup some * diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 79f0cc0bb6..7eaa00074f 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -30,6 +30,7 @@ #include #include "../../general.h" #include "../../retroarch.h" +#include "../../runloop.h" #include #ifdef HAVE_CONFIG_H diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index db262a9b02..b33c150f97 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -21,6 +21,7 @@ #include #include "../../general.h" #include "../../retroarch.h" +#include "../../runloop.h" #include "../../performance.h" #include #include "../video_viewport.h" diff --git a/gfx/drivers_context/androidegl_ctx.c b/gfx/drivers_context/androidegl_ctx.c index 1832980302..c853fda9f8 100644 --- a/gfx/drivers_context/androidegl_ctx.c +++ b/gfx/drivers_context/androidegl_ctx.c @@ -16,6 +16,7 @@ #include "../../driver.h" #include "../../general.h" +#include "../../runloop.h" #include "../video_monitor.h" #include "../gl_common.h" @@ -271,7 +272,7 @@ static void android_gfx_ctx_update_window_title(void *data) video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static bool android_gfx_ctx_set_video_mode(void *data, diff --git a/gfx/drivers_context/bbqnx_ctx.c b/gfx/drivers_context/bbqnx_ctx.c index a3964aa5fc..c83cfc9d55 100644 --- a/gfx/drivers_context/bbqnx_ctx.c +++ b/gfx/drivers_context/bbqnx_ctx.c @@ -16,6 +16,7 @@ #include "../../driver.h" #include "../../general.h" +#include "../../runloop.h" #include "../video_monitor.h" #include "../gl_common.h" @@ -358,7 +359,7 @@ static void gfx_ctx_qnx_update_window_title(void *data) video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static bool gfx_ctx_qnx_set_video_mode(void *data, diff --git a/gfx/drivers_context/d3d_ctx.cpp b/gfx/drivers_context/d3d_ctx.cpp index 1fadd6527f..3b335d2397 100644 --- a/gfx/drivers_context/d3d_ctx.cpp +++ b/gfx/drivers_context/d3d_ctx.cpp @@ -18,6 +18,7 @@ #include "../d3d/d3d.h" #include "win32_common.h" +#include "../../runloop.h" #include "../video_monitor.h" #ifdef _MSC_VER @@ -144,7 +145,7 @@ static void gfx_ctx_d3d_update_title(void *data) stat.dwAvailPhys/(1024.0f*1024.0f), stat.dwTotalPhys/(1024.0f*1024.0f)); strlcat(buffer_fps, mem, sizeof(buffer_fps)); #endif - msg_queue_push(g_runloop.msg_queue, buffer_fps, 1, 1); + rarch_main_msg_queue_push(buffer_fps, 1, 1, false); } } diff --git a/gfx/drivers_context/drm_egl_ctx.c b/gfx/drivers_context/drm_egl_ctx.c index 12f2062515..6f0f8b0b28 100644 --- a/gfx/drivers_context/drm_egl_ctx.c +++ b/gfx/drivers_context/drm_egl_ctx.c @@ -19,6 +19,7 @@ */ #include "../../driver.h" +#include "../../runloop.h" #include "../gl_common.h" #include "../video_monitor.h" #include @@ -268,7 +269,7 @@ static void gfx_ctx_drm_egl_update_window_title(void *data) video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push( buf_fps, 1, 1, false); } static void gfx_ctx_drm_egl_get_video_size(void *data, unsigned *width, unsigned *height) diff --git a/gfx/drivers_context/emscriptenegl_ctx.c b/gfx/drivers_context/emscriptenegl_ctx.c index ad048c0b1e..d7ef02d7fb 100644 --- a/gfx/drivers_context/emscriptenegl_ctx.c +++ b/gfx/drivers_context/emscriptenegl_ctx.c @@ -15,6 +15,7 @@ */ #include "../../driver.h" +#include "../../runloop.h" #include "../video_context_driver.h" #include "../gl_common.h" #include "../video_monitor.h" @@ -92,7 +93,7 @@ static void gfx_ctx_emscripten_update_window_title(void *data) video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static void gfx_ctx_emscripten_get_video_size(void *data, diff --git a/gfx/drivers_context/glx_ctx.c b/gfx/drivers_context/glx_ctx.c index 29b7a16fe7..144a4555c2 100644 --- a/gfx/drivers_context/glx_ctx.c +++ b/gfx/drivers_context/glx_ctx.c @@ -15,6 +15,7 @@ */ #include "../../driver.h" +#include "../../runloop.h" #include "../gl_common.h" #include "../video_monitor.h" #include "x11_common.h" @@ -212,7 +213,7 @@ static void gfx_ctx_glx_update_window_title(void *data) buf_fps, sizeof(buf_fps))) XStoreName(glx->g_dpy, glx->g_win, buf); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static void gfx_ctx_glx_get_video_size(void *data, diff --git a/gfx/drivers_context/mali_fbdev_ctx.c b/gfx/drivers_context/mali_fbdev_ctx.c index e66e9ecbdc..3103f3c7f7 100644 --- a/gfx/drivers_context/mali_fbdev_ctx.c +++ b/gfx/drivers_context/mali_fbdev_ctx.c @@ -15,6 +15,7 @@ #include "../../driver.h" #include "../../general.h" +#include "../../runloop.h" #include "../video_monitor.h" #include "../gl_common.h" @@ -204,7 +205,7 @@ static void gfx_ctx_mali_fbdev_update_window_title(void *data) video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static bool gfx_ctx_mali_fbdev_set_video_mode(void *data, diff --git a/gfx/drivers_context/ps3_ctx.c b/gfx/drivers_context/ps3_ctx.c index f8fdd44dbc..63ffa907eb 100644 --- a/gfx/drivers_context/ps3_ctx.c +++ b/gfx/drivers_context/ps3_ctx.c @@ -15,6 +15,7 @@ */ #include "../../driver.h" +#include "../../runloop.h" #include "../../ps3/sdk_defines.h" #ifdef HAVE_LIBDBGFONT @@ -220,7 +221,7 @@ static void gfx_ctx_ps3_update_window_title(void *data) video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static void gfx_ctx_ps3_get_video_size(void *data, diff --git a/gfx/drivers_context/sdl_gl_ctx.c b/gfx/drivers_context/sdl_gl_ctx.c index 094bcd4944..1d9c43cb88 100644 --- a/gfx/drivers_context/sdl_gl_ctx.c +++ b/gfx/drivers_context/sdl_gl_ctx.c @@ -15,6 +15,7 @@ */ #include "../../driver.h" +#include "../../runloop.h" #include "../gl_common.h" #include "../video_monitor.h" @@ -290,7 +291,7 @@ static void sdl_ctx_update_window_title(void *data) #endif } if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static void sdl_ctx_check_window(void *data, bool *quit, bool *resize,unsigned *width, diff --git a/gfx/drivers_context/vc_egl_ctx.c b/gfx/drivers_context/vc_egl_ctx.c index 4a92166f1d..c8608a6e9f 100644 --- a/gfx/drivers_context/vc_egl_ctx.c +++ b/gfx/drivers_context/vc_egl_ctx.c @@ -15,6 +15,7 @@ */ #include "../../driver.h" +#include "../../runloop.h" #include "../video_context_driver.h" #include "../gl_common.h" #include "../video_monitor.h" @@ -124,7 +125,7 @@ static void gfx_ctx_vc_update_window_title(void *data) video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + msg_queue_push(buf_fps, 1, 1, false); } static void gfx_ctx_vc_get_video_size(void *data, diff --git a/gfx/drivers_context/vivante_fbdev_ctx.c b/gfx/drivers_context/vivante_fbdev_ctx.c index 8138febf5d..050e27477b 100644 --- a/gfx/drivers_context/vivante_fbdev_ctx.c +++ b/gfx/drivers_context/vivante_fbdev_ctx.c @@ -16,6 +16,7 @@ #include "../../driver.h" #include "../../general.h" +#include "../../runloop.h" #include "../video_monitor.h" #include "../gl_common.h" @@ -193,7 +194,7 @@ static void gfx_ctx_vivante_update_window_title(void *data) video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static bool gfx_ctx_vivante_set_video_mode(void *data, diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index 2ca5c28888..482e538f34 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -16,6 +16,7 @@ #include "../../driver.h" #include "../../general.h" +#include "../../runloop.h" #include "../video_monitor.h" #include "../gl_common.h" @@ -341,7 +342,7 @@ static void gfx_ctx_wl_update_window_title(void *data) wl_shell_surface_set_title(wl->g_shell_surf, buf); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static void gfx_ctx_wl_get_video_size(void *data, diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index 93a1288f94..e92fc74b3c 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -22,6 +22,7 @@ #endif #include "../../driver.h" +#include "../../runloop.h" #include "../video_context_driver.h" #include "../gl_common.h" #include "../video_monitor.h" @@ -352,7 +353,7 @@ static void gfx_ctx_wgl_update_window_title(void *data) buf_fps, sizeof(buf_fps))) SetWindowText(g_hwnd, buf); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static void gfx_ctx_wgl_get_video_size(void *data, unsigned *width, unsigned *height) diff --git a/gfx/drivers_context/xegl_ctx.c b/gfx/drivers_context/xegl_ctx.c index a6dc7c6304..ead76b90b5 100644 --- a/gfx/drivers_context/xegl_ctx.c +++ b/gfx/drivers_context/xegl_ctx.c @@ -19,6 +19,7 @@ */ #include "../../driver.h" +#include "../../runloop.h" #include "../gl_common.h" #include "../video_monitor.h" #include "x11_common.h" @@ -227,7 +228,7 @@ static void gfx_ctx_xegl_update_window_title(void *data) buf_fps, sizeof(buf_fps))) XStoreName(g_dpy, g_win, buf); if (g_settings.fps_show) - msg_queue_push(g_runloop.msg_queue, buf_fps, 1, 1); + rarch_main_msg_queue_push(buf_fps, 1, 1, false); } static void gfx_ctx_xegl_get_video_size(void *data, diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 1c378086c7..e170b2a5b9 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -22,6 +22,7 @@ #include "video_monitor.h" #include "../general.h" #include "../retroarch.h" +#include "../runloop.h" static const video_driver_t *video_drivers[] = { #ifdef HAVE_OPENGL diff --git a/gfx/video_monitor.c b/gfx/video_monitor.c index 1986e96b79..200d9a6fbd 100644 --- a/gfx/video_monitor.c +++ b/gfx/video_monitor.c @@ -17,6 +17,7 @@ #include "video_monitor.h" #include "../general.h" #include "../retroarch.h" +#include "../runloop.h" #include "../performance.h" void video_monitor_adjust_system_rates(void) @@ -59,7 +60,7 @@ void video_monitor_set_refresh_rate(float hz) { char msg[PATH_MAX_LENGTH]; snprintf(msg, sizeof(msg), "Setting refresh rate to: %.3f Hz.", hz); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, false); RARCH_LOG("%s\n", msg); g_settings.video.refresh_rate = hz; diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index 0ead3bfdd3..31f584c43e 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -17,12 +17,12 @@ #include "video_thread_wrapper.h" #include "video_viewport.h" #include "../performance.h" +#include "../runloop.h" #include #include #include #include - static void *thread_init_never_call(const video_info_t *video, const input_driver_t **input, void **input_data) { diff --git a/input/drivers_joypad/apple_joypad_hid.c b/input/drivers_joypad/apple_joypad_hid.c index 87a39e3d01..777d7e5677 100644 --- a/input/drivers_joypad/apple_joypad_hid.c +++ b/input/drivers_joypad/apple_joypad_hid.c @@ -20,6 +20,7 @@ #include "../input_autodetect.h" #include "../input_common.h" #include "../../general.h" +#include "../../runloop.h" struct pad_connection { @@ -127,7 +128,7 @@ static void remove_device(void* context, IOReturn result, void* sender) snprintf(msg, sizeof(msg), "Joypad #%u (%s) disconnected.", connection->slot, "N/A"); - msg_queue_push(g_runloop.msg_queue, msg, 0, 60); + rarch_main_msg_queue_push(msg, 0, 60, false); RARCH_LOG("[apple_input]: %s\n", msg); apple->buttons[connection->slot] = 0; diff --git a/input/drivers_joypad/linuxraw_joypad.c b/input/drivers_joypad/linuxraw_joypad.c index 9282c1ba42..74842df141 100644 --- a/input/drivers_joypad/linuxraw_joypad.c +++ b/input/drivers_joypad/linuxraw_joypad.c @@ -17,6 +17,7 @@ #include "../input_autodetect.h" #include "../input_common.h" #include "../../general.h" +#include "../../runloop.h" #include #include #include @@ -97,7 +98,7 @@ static bool linuxraw_joypad_init_pad(const char *path, struct linuxraw_joypad *p { char msg[512]; snprintf(msg, sizeof(msg), "Joypad #%u (%s) connected.", (unsigned)(pad - linuxraw_pads), pad->ident); - msg_queue_push(g_runloop.msg_queue, msg, 0, 60); + rarch_main_msg_queue_push(msg, 0, 60, false); } #endif } @@ -153,7 +154,7 @@ static void handle_plugged_pad(void) { char msg[512]; snprintf(msg, sizeof(msg), "Joypad #%u (%s) disconnected.", idx, linuxraw_pads[idx].ident); - msg_queue_push(g_runloop.msg_queue, msg, 0, 60); + rarch_main_msg_queue_push(msg, 0, 60, false); } #endif diff --git a/input/drivers_joypad/udev_joypad.c b/input/drivers_joypad/udev_joypad.c index 62de17d2c6..e14a708d60 100644 --- a/input/drivers_joypad/udev_joypad.c +++ b/input/drivers_joypad/udev_joypad.c @@ -16,6 +16,7 @@ #include "../input_autodetect.h" #include "../input_common.h" #include "../../general.h" +#include "../../runloop.h" #include #include #include @@ -457,7 +458,7 @@ static void check_device(struct udev_device *dev, const char *path, bool hotplug { char msg[512]; snprintf(msg, sizeof(msg), "Joypad #%u (%s) connected.", pad, path); - msg_queue_push(g_runloop.msg_queue, msg, 0, 60); + rarch_main_msg_queue_push(msg, 0, 60, false); RARCH_LOG("[udev]: %s\n", msg); } #else @@ -482,7 +483,7 @@ static void udev_joypad_remove_device(const char *path) #ifndef IS_JOYCONFIG char msg[512]; snprintf(msg, sizeof(msg), "Joypad #%u (%s) disconnected.", i, udev_pads[i].ident); - msg_queue_push(g_runloop.msg_queue, msg, 0, 60); + rarch_main_msg_queue_push(msg, 0, 60, false); RARCH_LOG("[udev]: %s\n", msg); #endif free_pad(i, true); diff --git a/input/input_autodetect.c b/input/input_autodetect.c index 92a519a91b..444e0bf5b0 100644 --- a/input/input_autodetect.c +++ b/input/input_autodetect.c @@ -22,6 +22,7 @@ #include #include "../general.h" +#include "../runloop.h" static void input_autoconfigure_joypad_conf(config_file_t *conf, struct retro_keybind *binds) @@ -91,7 +92,7 @@ found: idx, name); if (!block_osd_spam) - msg_queue_push(g_runloop.msg_queue, msg, 0, 60); + rarch_main_msg_queue_push(msg, 0, 60, false); RARCH_LOG("%s\n", msg); return true; diff --git a/libretro_version_1.c b/libretro_version_1.c index 1c6c4b63cd..50d9f2bb24 100644 --- a/libretro_version_1.c +++ b/libretro_version_1.c @@ -25,6 +25,7 @@ #include #include #include "general.h" +#include "runloop.h" #include "retroarch.h" #include "performance.h" #include "input/keyboard_line.h" @@ -136,7 +137,7 @@ static void video_frame(const void *data, unsigned width, ) recording_dump_frame(data, width, height, pitch); - msg = msg_queue_pull(g_runloop.msg_queue); + msg = rarch_main_msg_queue_pull(); driver.current_msg = msg; if (video_frame_filter(data, width, height, pitch, diff --git a/location/location_driver.c b/location/location_driver.c index 6d02a944cf..d8609d0b61 100644 --- a/location/location_driver.c +++ b/location/location_driver.c @@ -19,6 +19,7 @@ #include "location_driver.h" #include "../driver.h" #include "../general.h" +#include "../runloop.h" static const location_driver_t *location_drivers[] = { #ifdef ANDROID @@ -147,8 +148,7 @@ bool driver_location_start(void) if (g_settings.location.allow) return driver.location->start(driver.location_data); - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, "Location is explicitly disabled.\n", 1, 180); + rarch_main_msg_queue_push("Location is explicitly disabled.\n", 1, 180, true); } return false; } diff --git a/menu/menu.c b/menu/menu.c index 3c0d464216..8245735090 100644 --- a/menu/menu.c +++ b/menu/menu.c @@ -21,6 +21,7 @@ #include "../dynamic.h" #include "../frontend/frontend.h" #include "../../retroarch.h" +#include "../../runloop.h" #include "../../performance.h" #include @@ -111,7 +112,7 @@ static void push_to_history_playlist(void) fill_pathname_base(tmp, g_extern.fullpath, sizeof(tmp)); snprintf(str, sizeof(str), "INFO - Loading %s ...", tmp); - msg_queue_push(g_runloop.msg_queue, str, 1, 1); + rarch_main_msg_queue_push(str, 1, 1, false); } content_playlist_push(g_defaults.history, diff --git a/menu/menu.h b/menu/menu.h index 0235864a72..9f87cd6da4 100644 --- a/menu/menu.h +++ b/menu/menu.h @@ -24,6 +24,7 @@ #include #include #include "../../general.h" +#include "../../runloop.h" #include "menu_input.h" #if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL) diff --git a/menu/menu_animation.c b/menu/menu_animation.c index 4d7fae0d89..794c0b9224 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -19,6 +19,7 @@ #include #include #include "../general.h" +#include "../runloop.h" /* from https://github.com/kikito/tween.lua/blob/master/tween.lua */ diff --git a/menu/menu_entries_cbs.c b/menu/menu_entries_cbs.c index 3c0bc03e8b..5c8661acd2 100644 --- a/menu/menu_entries_cbs.c +++ b/menu/menu_entries_cbs.c @@ -25,6 +25,7 @@ #include "../file_ops.h" #include "../config.def.h" #include "../retroarch.h" +#include "../runloop.h" #ifdef HAVE_NETWORKING #include "../net_http.h" @@ -115,8 +116,7 @@ int cb_core_updater_download(void *data_, size_t len) snprintf(msg, sizeof(msg), "Download complete: %s.", core_updater_path); - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, msg, 1, 90); + rarch_main_msg_queue_push(msg, 1, 90, true); #ifdef HAVE_ZLIB file_ext = path_get_extension(output_path); diff --git a/menu/menu_entries_cbs_iterate.c b/menu/menu_entries_cbs_iterate.c index 14477fedc8..99411fc9a7 100644 --- a/menu/menu_entries_cbs_iterate.c +++ b/menu/menu_entries_cbs_iterate.c @@ -23,6 +23,7 @@ #include "menu_navigation.h" #include "../retroarch.h" +#include "../runloop.h" #include "../input/input_autodetect.h" diff --git a/menu/menu_entries_cbs_representation.c b/menu/menu_entries_cbs_representation.c index 646a4a807c..621e0300ab 100644 --- a/menu/menu_entries_cbs_representation.c +++ b/menu/menu_entries_cbs_representation.c @@ -20,6 +20,7 @@ #include "menu_shader.h" #include "../performance.h" +#include "../runloop.h" static void menu_action_setting_disp_set_label_cheat_num_passes( file_list_t* list, diff --git a/netplay.c b/netplay.c index 067a19bc7d..e5e0788c25 100644 --- a/netplay.c +++ b/netplay.c @@ -21,6 +21,7 @@ #include "net_compat.h" #include "netplay.h" #include "general.h" +#include "runloop.h" #include "autosave.h" #include "dynamic.h" #include @@ -122,8 +123,7 @@ struct netplay static void warn_hangup(void) { RARCH_WARN("Netplay has disconnected. Will continue without connection ...\n"); - if (g_runloop.msg_queue) - msg_queue_push(g_runloop.msg_queue, "Netplay has disconnected. Will continue without connection.", 0, 480); + rarch_main_msg_queue_push("Netplay has disconnected. Will continue without connection.", 0, 480, false); } /** @@ -279,7 +279,7 @@ static bool netplay_get_cmd(netplay_t *netplay) netplay->flip_frame = flip_frame; RARCH_LOG("Netplay users are flipped.\n"); - msg_queue_push(g_runloop.msg_queue, "Netplay users are flipped.", 1, 180); + rarch_main_msg_queue_push("Netplay users are flipped.", 1, 180, false); return netplay_cmd_ack(netplay); @@ -606,7 +606,7 @@ static void log_connection(const struct sockaddr_storage *their_addr, char msg[512]; snprintf(msg, sizeof(msg), "Got connection from: \"%s (%s)\" (#%u)", nick, str, slot); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, false); RARCH_LOG("%s\n", msg); } } @@ -912,7 +912,7 @@ static bool send_info(netplay_t *netplay) snprintf(msg, sizeof(msg), "Connected to: \"%s\"", netplay->other_nick); RARCH_LOG("%s\n", msg); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, false); return true; } @@ -1062,7 +1062,7 @@ static bool get_info_spectate(netplay_t *netplay) } snprintf(msg, sizeof(msg), "Connected to \"%s\"", netplay->other_nick); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, false); RARCH_LOG("%s\n", msg); @@ -1265,7 +1265,7 @@ void netplay_flip_users(netplay_t *netplay) && netplay_get_response(netplay)) { RARCH_LOG("Netplay users are flipped.\n"); - msg_queue_push(g_runloop.msg_queue, "Netplay users are flipped.", 1, 180); + rarch_main_msg_queue_push("Netplay users are flipped.", 1, 180, false); /* Queue up a flip well enough in the future. */ netplay->flip ^= true; @@ -1281,7 +1281,7 @@ void netplay_flip_users(netplay_t *netplay) error: RARCH_WARN("%s\n", msg); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, false); } /** @@ -1367,9 +1367,7 @@ static int16_t netplay_get_spectate_input(netplay_t *netplay, bool port, return swap_if_big16(inp); RARCH_ERR("Connection with host was cut.\n"); - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, - "Connection with host was cut.", 1, 180); + rarch_main_msg_queue_push("Connection with host was cut.", 1, 180, true); pretro_set_input_state(netplay->cbs.state_cb); return netplay->cbs.state_cb(port, device, idx, id); @@ -1586,7 +1584,7 @@ static void netplay_post_frame_spectate(netplay_t *netplay) RARCH_LOG("Client (#%u) disconnected ...\n", i); snprintf(msg, sizeof(msg), "Client (#%u) disconnected.", i); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, false); socket_close(netplay->spectate_fds[i]); netplay->spectate_fds[i] = -1; diff --git a/record/record_driver.c b/record/record_driver.c index 2fce116c1b..8054262ffc 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -21,6 +21,7 @@ #include "../dynamic.h" #include "../general.h" #include "../retroarch.h" +#include "../runloop.h" #include "../intl/intl.h" #include "../gfx/video_viewport.h" @@ -122,9 +123,8 @@ void recording_dump_frame(const void *data, unsigned width, { static const char msg[] = "Recording terminated due to resize."; RARCH_WARN("%s\n", msg); - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, true); rarch_main_command(RARCH_CMD_RECORD_DEINIT); return; } diff --git a/runloop.c b/runloop.c index d0c8cb5972..7e49cb7d79 100644 --- a/runloop.c +++ b/runloop.c @@ -59,8 +59,7 @@ static void set_volume(float gain) g_settings.audio.volume = min(g_settings.audio.volume, 12.0f); snprintf(msg, sizeof(msg), "Volume: %.1f dB", g_settings.audio.volume); - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, true); RARCH_LOG("%s\n", msg); g_extern.audio_data.volume_gain = db_to_gain(g_settings.audio.volume); @@ -174,13 +173,10 @@ static void check_stateslots(bool pressed_increase, bool pressed_decrease) else return; - msg_queue_clear(g_runloop.msg_queue); - snprintf(msg, sizeof(msg), "State slot: %d", g_settings.state_slot); - if (g_runloop.msg_queue) - msg_queue_push(g_runloop.msg_queue, msg, 1, 180); + rarch_main_msg_queue_push(msg, 1, 180, true); RARCH_LOG("%s\n", msg); } @@ -243,16 +239,16 @@ static void check_rewind(bool pressed) g_extern.rewind.frame_is_reverse = true; setup_rewind_audio(); - msg_queue_push(g_runloop.msg_queue, RETRO_MSG_REWINDING, 0, - g_runloop.is_paused ? 1 : 30); + rarch_main_msg_queue_push(RETRO_MSG_REWINDING, 0, + g_runloop.is_paused ? 1 : 30, false); pretro_unserialize(buf, g_extern.rewind.size); if (g_extern.bsv.movie) bsv_movie_frame_rewind(g_extern.bsv.movie); } else - msg_queue_push(g_runloop.msg_queue, - RETRO_MSG_REWIND_REACHED_END, 0, 30); + rarch_main_msg_queue_push(RETRO_MSG_REWIND_REACHED_END, + 0, 30, false); } else { @@ -294,9 +290,8 @@ static void check_slowmotion(bool pressed) if (g_settings.video.black_frame_insertion) rarch_render_cached_frame(); - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, g_extern.rewind.frame_is_reverse ? - "Slow motion rewind." : "Slow motion.", 0, 30); + rarch_main_msg_queue_push(g_extern.rewind.frame_is_reverse ? + "Slow motion rewind." : "Slow motion.", 0, 30, true); } static bool check_movie_init(void) @@ -327,9 +322,8 @@ static bool check_movie_init(void) if (!g_extern.bsv.movie) ret = false; - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, g_extern.bsv.movie ? - msg : "Failed to start movie record.", 1, 180); + rarch_main_msg_queue_push(g_extern.bsv.movie ? + msg : "Failed to start movie record.", 1, 180, true); if (g_extern.bsv.movie) RARCH_LOG("Starting movie record to \"%s\".\n", path); @@ -351,9 +345,8 @@ static bool check_movie_record(void) if (!g_extern.bsv.movie) return false; - msg_queue_clear(g_runloop.msg_queue); - msg_queue_push(g_runloop.msg_queue, - RETRO_MSG_MOVIE_RECORD_STOPPING, 2, 180); + rarch_main_msg_queue_push( + RETRO_MSG_MOVIE_RECORD_STOPPING, 2, 180, true); RARCH_LOG(RETRO_LOG_MOVIE_RECORD_STOPPING); rarch_main_command(RARCH_CMD_BSV_MOVIE_DEINIT); @@ -373,8 +366,8 @@ static bool check_movie_playback(void) if (!g_extern.bsv.movie_end) return false; - msg_queue_push(g_runloop.msg_queue, - RETRO_MSG_MOVIE_PLAYBACK_ENDED, 1, 180); + rarch_main_msg_queue_push( + RETRO_MSG_MOVIE_PLAYBACK_ENDED, 1, 180, false); RARCH_LOG(RETRO_LOG_MOVIE_PLAYBACK_ENDED); rarch_main_command(RARCH_CMD_BSV_MOVIE_DEINIT); @@ -439,11 +432,9 @@ static void check_shader_dir(bool pressed_next, bool pressed_prev) else return; - msg_queue_clear(g_runloop.msg_queue); - snprintf(msg, sizeof(msg), "Shader #%u: \"%s\".", (unsigned)g_extern.shader_dir.ptr, shader); - msg_queue_push(g_runloop.msg_queue, msg, 1, 120); + rarch_main_msg_queue_push(msg, 1, 120, true); RARCH_LOG("Applying shader \"%s\".\n", shader); if (!video_driver_set_shader(type, shader)) @@ -902,6 +893,22 @@ static void rarch_main_iterate_linefeed_overlay(void) } #endif +const char *rarch_main_msg_queue_pull(void) +{ + return msg_queue_pull(g_runloop.msg_queue); +} + +void rarch_main_msg_queue_push(const char *msg, unsigned prio, unsigned duration, + bool flush) +{ + if (!g_runloop.msg_queue) + return; + + if (flush) + msg_queue_clear(g_runloop.msg_queue); + msg_queue_push(g_runloop.msg_queue, msg, 0, 60); +} + /** * rarch_main_iterate: * diff --git a/runloop.h b/runloop.h index 7fa9874445..85adcf3671 100644 --- a/runloop.h +++ b/runloop.h @@ -21,6 +21,15 @@ #include #include #include +#include "libretro.h" + +#ifndef AUDIO_BUFFER_FREE_SAMPLES_COUNT +#define AUDIO_BUFFER_FREE_SAMPLES_COUNT (8 * 1024) +#endif + +#ifndef MEASURE_FRAME_TIME_SAMPLES_COUNT +#define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024) +#endif #ifdef __cplusplus extern "C" { @@ -91,7 +100,71 @@ struct data_runloop nbio_handle_t nbio; }; +/* All libretro runloop-related globals go here. */ + +struct runloop +{ + /* Lifecycle state checks. */ + bool is_paused; + bool is_idle; + bool is_menu; + bool is_slowmotion; + + struct + { + struct + { + unsigned count; + unsigned max; + struct + { + struct + { + struct + { + bool is_updated; + } label; + + struct + { + bool is_active; + } animation; + + struct + { + bool dirty; + } framebuf; + + struct + { + bool active; + } action; + } menu; + } current; + } video; + + struct + { + retro_time_t minimum_time; + retro_time_t last_time; + } limit; + } frames; + + struct + { + unsigned buffer_free_samples[AUDIO_BUFFER_FREE_SAMPLES_COUNT]; + uint64_t buffer_free_samples_count; + + retro_time_t frame_time_samples[MEASURE_FRAME_TIME_SAMPLES_COUNT]; + uint64_t frame_time_samples_count; + } measure_data; + + msg_queue_t *msg_queue; +}; + +/* Public data structures. */ extern struct data_runloop g_data_runloop; +extern struct runloop g_runloop; /** * rarch_main_iterate: @@ -103,6 +176,11 @@ extern struct data_runloop g_data_runloop; **/ int rarch_main_iterate(void); +void rarch_main_msg_queue_push(const char *msg, unsigned prio, + unsigned duration, bool flush); + +const char *rarch_main_msg_queue_pull(void); + void rarch_main_data_iterate(void); void rarch_main_data_init_queues(void); diff --git a/screenshot.c b/screenshot.c index b8e9c68840..93fb86cb14 100644 --- a/screenshot.c +++ b/screenshot.c @@ -26,6 +26,7 @@ #include #include "gfx/scaler/scaler.h" #include "retroarch.h" +#include "runloop.h" #include "retroarch_logger.h" #include "screenshot.h" #include "gfx/video_viewport.h" @@ -257,9 +258,6 @@ bool take_screenshot(void) != RETRO_HW_CONTEXT_NONE) && driver.video->read_viewport && driver.video->viewport_info; - /* Clear out message queue to avoid OSD fonts to appear on screenshot. */ - msg_queue_clear(g_runloop.msg_queue); - if (viewport_read) { #ifdef HAVE_MENU @@ -292,7 +290,7 @@ bool take_screenshot(void) msg = RETRO_MSG_TAKE_SCREENSHOT_FAILED; } - msg_queue_push(g_runloop.msg_queue, msg, 1, g_runloop.is_paused ? 1 : 180); + rarch_main_msg_queue_push(msg, 1, g_runloop.is_paused ? 1 : 180, true); if (g_runloop.is_paused) rarch_render_cached_frame(); diff --git a/settings_data.c b/settings_data.c index 57f60377b9..5d350ff339 100644 --- a/settings_data.c +++ b/settings_data.c @@ -25,6 +25,7 @@ #include "file_ext.h" #include "settings.h" #include "retroarch.h" +#include "runloop.h" #include "performance.h" #if defined(__CELLOS_LV2__) diff --git a/tools/retroarch-joyconfig.c b/tools/retroarch-joyconfig.c index 706e3ba43e..9d649ab950 100644 --- a/tools/retroarch-joyconfig.c +++ b/tools/retroarch-joyconfig.c @@ -491,3 +491,8 @@ int main(int argc, char *argv[]) free(g_auto_path); return 0; } + +void rarch_main_msg_queue_push(const char *msg, unsigned prio, unsigned duration, + bool flush) +{ +}