From 7378299282cb6ff4f8a2682f9ef8aa437d664c5f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 18 Mar 2015 06:47:22 +0100 Subject: [PATCH] Create rarch_main_get_ptr --- apple/iOS/platform.m | 65 ++++++++++++++----------- audio/audio_driver.c | 26 +++++----- driver.c | 4 +- file_ops.c | 4 +- frontend/drivers/platform_android.c | 11 +++-- gfx/d3d/d3d.cpp | 12 +++-- gfx/d3d/render_chain_xdk.h | 6 ++- gfx/drivers/gl.c | 17 ++++--- gfx/drivers/sdl2_gfx.c | 3 +- gfx/drivers/vg.c | 5 +- gfx/video_driver.c | 3 +- gfx/video_monitor.c | 32 +++++++----- gfx/video_thread_wrapper.c | 3 +- input/drivers_joypad/ps3_input_joypad.c | 3 +- libretro_version_1.c | 8 +-- menu/drivers/glui.c | 16 +++--- menu/drivers/rgui.c | 30 +++++++----- menu/drivers/rmenu.c | 15 +++--- menu/drivers/rmenu_xui.cpp | 11 +++-- menu/drivers/xmb.c | 12 +++-- menu/menu.c | 15 +++--- menu/menu_animation.c | 6 ++- menu/menu_entries_cbs_iterate.c | 3 +- menu/menu_entries_cbs_representation.c | 6 ++- retroarch.c | 38 +++++++++------ runloop.c | 10 ++++ runloop.h | 5 +- runloop_data.c | 3 +- screenshot.c | 5 +- settings_data.c | 7 ++- tools/retroarch-joyconfig.c | 1 - 31 files changed, 232 insertions(+), 153 deletions(-) diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index 06056bc23c..1a8c6162ca 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -231,11 +231,14 @@ enum void switch_to_ios(void) { + RetroArch_iOS *ap; + runloop_t *runloop = rarch_main_get_ptr(); + if (!apple_platform) return; - RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform; - g_runloop.is_idle = true; + ap = (RetroArch_iOS *)apple_platform; + runloop->is_idle = true; [ap showPauseMenu:ap]; } @@ -288,29 +291,30 @@ static void rarch_main_event_pump(void) - (void) rarch_draw:(id)sender { - int ret = 0; - - if (displayLink == nil) - goto exit; - - rarch_main_event_pump(); - - ret = rarch_main_iterate(); - - if (ret == -1) - goto exit; - - if (g_runloop.is_idle) - return; - - if (g_view) - [g_view display]; - - return; - + runloop_t *runloop = rarch_main_get_ptr(); + int ret = 0; + + if (displayLink == nil) + goto exit; + + rarch_main_event_pump(); + + ret = rarch_main_iterate(); + + if (ret == -1) + goto exit; + + if (runloop->is_idle) + return; + + if (g_view) + [g_view display]; + + return; + exit: - main_exit_save_config(); - main_exit(NULL); + main_exit_save_config(); + main_exit(NULL); } - (void) apple_start_iteration @@ -375,19 +379,24 @@ exit: - (void)showGameView { + runloop_t *runloop = rarch_main_get_ptr(); + [self popToRootViewControllerAnimated:NO]; [self setToolbarHidden:true animated:NO]; [[UIApplication sharedApplication] setStatusBarHidden:true withAnimation:UIStatusBarAnimationNone]; [[UIApplication sharedApplication] setIdleTimerDisabled:true]; [self.window setRootViewController:[RAGameView get]]; - g_runloop.is_paused = false; - g_runloop.is_idle = false; + + runloop->is_paused = false; + runloop->is_idle = false; } - (IBAction)showPauseMenu:(id)sender { - g_runloop.is_paused = true; - g_runloop.is_idle = true; + runloop_t *runloop = rarch_main_get_ptr(); + + runloop->is_paused = true; + runloop->is_idle = true; [[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:UIStatusBarAnimationNone]; [[UIApplication sharedApplication] setIdleTimerDisabled:false]; [self.window setRootViewController:self]; diff --git a/audio/audio_driver.c b/audio/audio_driver.c index ace584e1f7..27b9837409 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -95,20 +95,23 @@ static void compute_audio_buffer_statistics(void) float avg_filled, deviation; uint64_t accum = 0, accum_var = 0; unsigned low_water_count = 0, high_water_count = 0; - unsigned samples = min(g_runloop.measure_data.buffer_free_samples_count, + unsigned samples = 0; + runloop_t *runloop = rarch_main_get_ptr(); + + samples = min(runloop->measure_data.buffer_free_samples_count, AUDIO_BUFFER_FREE_SAMPLES_COUNT); if (samples < 3) return; for (i = 1; i < samples; i++) - accum += g_runloop.measure_data.buffer_free_samples[i]; + accum += runloop->measure_data.buffer_free_samples[i]; avg = accum / (samples - 1); for (i = 1; i < samples; i++) { - int diff = avg - g_runloop.measure_data.buffer_free_samples[i]; + int diff = avg - runloop->measure_data.buffer_free_samples[i]; accum_var += diff * diff; } @@ -121,9 +124,9 @@ static void compute_audio_buffer_statistics(void) for (i = 1; i < samples; i++) { - if (g_runloop.measure_data.buffer_free_samples[i] >= low_water_size) + if (runloop->measure_data.buffer_free_samples[i] >= low_water_size) low_water_count++; - else if (g_runloop.measure_data.buffer_free_samples[i] <= high_water_size) + else if (runloop->measure_data.buffer_free_samples[i] <= high_water_size) high_water_count++; } @@ -265,6 +268,7 @@ void uninit_audio(void) void init_audio(void) { size_t outsamples_max, max_bufsamples = AUDIO_CHUNK_SIZE_NONBLOCKING * 2; + runloop_t *runloop = rarch_main_get_ptr(); audio_convert_init_simd(); @@ -383,7 +387,7 @@ void init_audio(void) rarch_main_command(RARCH_CMD_DSP_FILTER_DEINIT); - g_runloop.measure_data.buffer_free_samples_count = 0; + runloop->measure_data.buffer_free_samples_count = 0; if (driver.audio_active && !g_settings.audio.mute_enable && g_extern.system.audio_callback.callback) @@ -419,24 +423,24 @@ bool audio_driver_mute_toggle(void) void audio_driver_readjust_input_rate(void) { double direction, adjust; - int half_size, delta_mid, avail; + int half_size, delta_mid; unsigned write_idx; - - avail = driver.audio->write_avail(driver.audio_data); + int avail = driver.audio->write_avail(driver.audio_data); + runloop_t *runloop = rarch_main_get_ptr(); #if 0 RARCH_LOG_OUTPUT("Audio buffer is %u%% full\n", (unsigned)(100 - (avail * 100) / g_extern.audio_data.driver_buffer_size)); #endif - write_idx = g_runloop.measure_data.buffer_free_samples_count++ & + write_idx = runloop->measure_data.buffer_free_samples_count++ & (AUDIO_BUFFER_FREE_SAMPLES_COUNT - 1); half_size = g_extern.audio_data.driver_buffer_size / 2; delta_mid = avail - half_size; direction = (double)delta_mid / half_size; adjust = 1.0 + g_settings.audio.rate_control_delta * direction; - g_runloop.measure_data.buffer_free_samples[write_idx] = avail; + runloop->measure_data.buffer_free_samples[write_idx] = avail; g_extern.audio_data.src_ratio = g_extern.audio_data.orig_src_ratio * adjust; #if 0 diff --git a/driver.c b/driver.c index f7f15ebcaa..f6e01021ce 100644 --- a/driver.c +++ b/driver.c @@ -321,7 +321,9 @@ void init_drivers(int flags) if (flags & DRIVER_VIDEO) { - g_runloop.frames.video.count = 0; + runloop_t *runloop = rarch_main_get_ptr(); + + runloop->frames.video.count = 0; init_video(); diff --git a/file_ops.c b/file_ops.c index 0bb393ccf2..bbc388c3f9 100644 --- a/file_ops.c +++ b/file_ops.c @@ -167,8 +167,10 @@ bool read_compressed_file(const char * path, void **buf, } //We split carchive path and relative path: - strlcpy(archive_path,path,sizeof(archive_path)); + strlcpy(archive_path, path, sizeof(archive_path)); + archive_found = (char*)strchr(archive_path,'#'); + rarch_assert(archive_found != NULL); //We assure that there is something after the '#' symbol diff --git a/frontend/drivers/platform_android.c b/frontend/drivers/platform_android.c index 07a7ebcfd5..589e4265a7 100644 --- a/frontend/drivers/platform_android.c +++ b/frontend/drivers/platform_android.c @@ -36,6 +36,7 @@ void engine_handle_cmd(void *data) { int8_t cmd; struct android_app *android_app = (struct android_app*)g_android; + runloop_t *runloop = rarch_main_get_ptr(); if (read(android_app->msgread, &cmd, sizeof(cmd)) != sizeof(cmd)) cmd = -1; @@ -69,7 +70,7 @@ void engine_handle_cmd(void *data) scond_broadcast(android_app->cond); slock_unlock(android_app->mutex); - if (g_runloop.is_paused) + if (runloop->is_paused) rarch_main_command(RARCH_CMD_REINIT); break; @@ -96,8 +97,8 @@ void engine_handle_cmd(void *data) if (!g_extern.system.shutdown) { RARCH_LOG("Pausing RetroArch.\n"); - g_runloop.is_paused = true; - g_runloop.is_idle = true; + runloop->is_paused = true; + runloop->is_idle = true; } break; @@ -126,8 +127,8 @@ void engine_handle_cmd(void *data) break; case APP_CMD_GAINED_FOCUS: - g_runloop.is_paused = false; - g_runloop.is_idle = false; + runloop->is_paused = false; + runloop->is_idle = false; if ((android_app->sensor_state_mask & (1ULL << RETRO_SENSOR_ACCELEROMETER_ENABLE)) diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index 8c0a1e3e52..3d9488e320 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -406,13 +406,14 @@ static void d3d_set_nonblock_state(void *data, bool state) static bool d3d_alive(void *data) { - d3d_video_t *d3d = (d3d_video_t*)data; - bool quit = false; - bool resize = false; + d3d_video_t *d3d = (d3d_video_t*)data; + bool quit = false; + bool resize = false; + runloop_t *runloop = rarch_main_get_ptr(); if (d3d->ctx_driver && d3d->ctx_driver->check_window) d3d->ctx_driver->check_window(d3d, &quit, &resize, - &d3d->screen_width, &d3d->screen_height, g_runloop.frames.video.count); + &d3d->screen_width, &d3d->screen_height, runloop->frames.video.count); if (quit) d3d->quitting = quit; @@ -1604,6 +1605,7 @@ static bool d3d_frame(void *data, const void *frame, unsigned i = 0; d3d_video_t *d3d = (d3d_video_t*)data; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; + runloop_t *runloop = rarch_main_get_ptr(); (void)i; @@ -1705,7 +1707,7 @@ static bool d3d_frame(void *data, const void *frame, #endif #ifdef HAVE_MENU - if (g_runloop.is_menu + if (runloop->is_menu && driver.menu_ctx && driver.menu_ctx->frame) driver.menu_ctx->frame(); diff --git a/gfx/d3d/render_chain_xdk.h b/gfx/d3d/render_chain_xdk.h index ab562d432e..1e5937d045 100644 --- a/gfx/d3d/render_chain_xdk.h +++ b/gfx/d3d/render_chain_xdk.h @@ -114,6 +114,7 @@ static void renderchain_render_pass(void *data, const void *frame, unsigned widt { d3d_video_t *d3d = (d3d_video_t*)data; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; + runloop_t *runloop = rarch_main_get_ptr(); #if defined(_XBOX1) d3dr->SetFlickerFilter(g_extern.console.screen.flicker_filter_index); @@ -138,7 +139,7 @@ static void renderchain_render_pass(void *data, const void *frame, unsigned widt d3d_draw_primitive(d3dr, D3DPT_TRIANGLESTRIP, 0, 2); - g_runloop.frames.video.count++; + runloop->frames.video.count++; renderchain_set_mvp(d3d, d3d->screen_width, d3d->screen_height, d3d->dev_rotation); } @@ -146,6 +147,7 @@ static void renderchain_render_pass(void *data, const void *frame, unsigned widt static void renderchain_set_vertices(void *data, unsigned pass, unsigned width, unsigned height) { d3d_video_t *d3d = (d3d_video_t*)data; + runloop_t *runloop = rarch_main_get_ptr(); if (d3d->last_width != width || d3d->last_height != height) { @@ -222,7 +224,7 @@ static void renderchain_set_vertices(void *data, unsigned pass, unsigned width, d3d->shader->use(d3d, pass); if (d3d->shader->set_params) d3d->shader->set_params(d3d, width, height, d3d->tex_w, d3d->tex_h, d3d->screen_width, - d3d->screen_height, g_runloop.frames.video.count, + d3d->screen_height, runloop->frames.video.count, NULL, NULL, NULL, 0); } #endif diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 3f61e2764b..24ea1e6ba0 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -959,6 +959,7 @@ static void gl_frame_fbo(gl_t *gl, GLfloat xamt, yamt; unsigned fbo_tex_info_cnt = 0; GLfloat fbo_tex_coords[8] = {0.0f}; + runloop_t *runloop = rarch_main_get_ptr(); /* Render the rest of our passes. */ gl->coords.tex_coord = fbo_tex_coords; @@ -998,7 +999,7 @@ static void gl_frame_fbo(gl_t *gl, gl_set_viewport(gl, rect->img_width, rect->img_height, true, false); gl->shader->set_params(gl, prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, - gl->vp.width, gl->vp.height, g_runloop.frames.video.count, + gl->vp.width, gl->vp.height, runloop->frames.video.count, tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); gl->coords.vertices = 4; @@ -1045,7 +1046,7 @@ static void gl_frame_fbo(gl_t *gl, gl->shader->set_params(gl, prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, - gl->vp.width, gl->vp.height, g_runloop.frames.video.count, + gl->vp.width, gl->vp.height, runloop->frames.video.count, tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); gl->coords.vertex = gl->vertex_ptr; @@ -1462,6 +1463,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { gl_t *gl = (gl_t*)data; + runloop_t *runloop = rarch_main_get_ptr(); RARCH_PERFORMANCE_INIT(frame_run); RARCH_PERFORMANCE_START(frame_run); @@ -1571,7 +1573,7 @@ static bool gl_frame(void *data, const void *frame, gl->shader->set_params(gl, width, height, gl->tex_w, gl->tex_h, gl->vp.width, gl->vp.height, - g_runloop.frames.video.count, + runloop->frames.video.count, &gl->tex_info, gl->prev_info, NULL, 0); gl->coords.vertices = 4; @@ -1587,7 +1589,7 @@ static bool gl_frame(void *data, const void *frame, gl_set_prev_texture(gl, &gl->tex_info); #if defined(HAVE_MENU) - if (g_runloop.is_menu + if (runloop->is_menu && driver.menu_ctx && driver.menu_ctx->frame) driver.menu_ctx->frame(); @@ -1643,8 +1645,8 @@ static bool gl_frame(void *data, const void *frame, /* Disable BFI during fast forward, slow-motion, * and pause to prevent flicker. */ if (g_settings.video.black_frame_insertion && - !driver.nonblock_state && !g_runloop.is_slowmotion - && !g_runloop.is_paused) + !driver.nonblock_state && !runloop->is_slowmotion + && !runloop->is_paused) { gl->ctx_driver->swap_buffers(gl); glClear(GL_COLOR_BUFFER_BIT); @@ -2430,13 +2432,14 @@ static bool gl_alive(void *data) { bool quit = false, resize = false; gl_t *gl = (gl_t*)data; + runloop_t *runloop = rarch_main_get_ptr(); if (!gl) return false; gl->ctx_driver->check_window(gl, &quit, &resize, &gl->win_width, &gl->win_height, - g_runloop.frames.video.count); + runloop->frames.video.count); if (quit) gl->quitting = true; diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 52e409c85e..4b47e41fe7 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -484,6 +484,7 @@ static bool sdl2_gfx_frame(void *data, const void *frame, unsigned width, { char buf[128]; sdl2_video_t *vid = (sdl2_video_t*)data; + runloop_t *runloop = rarch_main_get_ptr(); if (vid->should_resize) sdl_refresh_viewport(vid); @@ -503,7 +504,7 @@ static bool sdl2_gfx_frame(void *data, const void *frame, unsigned width, SDL_RenderCopyEx(vid->renderer, vid->frame.tex, NULL, NULL, vid->rotation, NULL, SDL_FLIP_NONE); #ifdef HAVE_MENU - if (g_runloop.is_menu + if (runloop->is_menu && driver.menu_ctx && driver.menu_ctx->frame) driver.menu_ctx->frame(); #endif diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index a8a258e1d3..ea3cb6ff2b 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -406,12 +406,13 @@ static bool vg_frame(void *data, const void *frame, unsigned width, unsigned hei static bool vg_alive(void *data) { - vg_t *vg = (vg_t*)data; bool quit; + vg_t *vg = (vg_t*)data; + runloop_t *runloop = rarch_main_get_ptr(); vg->driver->check_window(vg, &quit, &vg->should_resize, &vg->mScreenWidth, &vg->mScreenHeight, - g_runloop.frames.video.count); + runloop->frames.video.count); return !quit; } diff --git a/gfx/video_driver.c b/gfx/video_driver.c index e170b2a5b9..f7734139fc 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -391,6 +391,7 @@ void init_video(void) const struct retro_game_geometry *geom = NULL; video_info_t video = {0}; static uint16_t dummy_pixels[32] = {0}; + runloop_t *runloop = rarch_main_get_ptr(); init_video_filter(g_extern.system.pix_fmt); rarch_main_command(RARCH_CMD_SHADER_DIR_INIT); @@ -529,7 +530,7 @@ void init_video(void) rarch_main_command(RARCH_CMD_OVERLAY_DEINIT); rarch_main_command(RARCH_CMD_OVERLAY_INIT); - g_runloop.measure_data.frame_time_samples_count = 0; + runloop->measure_data.frame_time_samples_count = 0; g_extern.frame_cache.width = 4; g_extern.frame_cache.height = 4; diff --git a/gfx/video_monitor.c b/gfx/video_monitor.c index 200d9a6fbd..40b8c4d8ab 100644 --- a/gfx/video_monitor.c +++ b/gfx/video_monitor.c @@ -75,6 +75,7 @@ void video_monitor_compute_fps_statistics(void) { double avg_fps = 0.0, stddev = 0.0; unsigned samples = 0; + runloop_t *runloop = rarch_main_get_ptr(); if (g_settings.video.threaded) { @@ -82,7 +83,7 @@ void video_monitor_compute_fps_statistics(void) return; } - if (g_runloop.measure_data.frame_time_samples_count < + if (runloop->measure_data.frame_time_samples_count < 2 * MEASURE_FRAME_TIME_SAMPLES_COUNT) { RARCH_LOG( @@ -118,20 +119,23 @@ bool video_monitor_fps_statistics(double *refresh_rate, { unsigned i; retro_time_t accum = 0, avg, accum_var = 0; - unsigned samples = min(MEASURE_FRAME_TIME_SAMPLES_COUNT, - g_runloop.measure_data.frame_time_samples_count); + unsigned samples = 0; + runloop_t *runloop = rarch_main_get_ptr(); + + samples = min(MEASURE_FRAME_TIME_SAMPLES_COUNT, + runloop->measure_data.frame_time_samples_count); if (g_settings.video.threaded || (samples < 2)) return false; /* Measure statistics on frame time (microsecs), *not* FPS. */ for (i = 0; i < samples; i++) - accum += g_runloop.measure_data.frame_time_samples[i]; + accum += runloop->measure_data.frame_time_samples[i]; #if 0 for (i = 0; i < samples; i++) RARCH_LOG("Interval #%u: %d usec / frame.\n", - i, (int)g_runloop.measure_data.frame_time_samples[i]); + i, (int)runloop->measure_data.frame_time_samples[i]); #endif avg = accum / samples; @@ -139,7 +143,7 @@ bool video_monitor_fps_statistics(double *refresh_rate, /* Drop first measurement. It is likely to be bad. */ for (i = 0; i < samples; i++) { - retro_time_t diff = g_runloop.measure_data.frame_time_samples[i] - avg; + retro_time_t diff = runloop->measure_data.frame_time_samples[i] - avg; accum_var += diff * diff; } @@ -172,37 +176,39 @@ bool video_monitor_fps_statistics(double *refresh_rate, bool video_monitor_get_fps(char *buf, size_t size, char *buf_fps, size_t size_fps) { + static float last_fps; retro_time_t new_time; static retro_time_t curr_time; static retro_time_t fps_time; - static float last_fps; + runloop_t *runloop = rarch_main_get_ptr(); + *buf = '\0'; new_time = rarch_get_time_usec(); - if (g_runloop.frames.video.count) + if (runloop->frames.video.count) { bool ret = false; unsigned write_index = - g_runloop.measure_data.frame_time_samples_count++ & + runloop->measure_data.frame_time_samples_count++ & (MEASURE_FRAME_TIME_SAMPLES_COUNT - 1); - g_runloop.measure_data.frame_time_samples[write_index] = + runloop->measure_data.frame_time_samples[write_index] = new_time - fps_time; fps_time = new_time; - if ((g_runloop.frames.video.count % FPS_UPDATE_INTERVAL) == 0) + if ((runloop->frames.video.count % FPS_UPDATE_INTERVAL) == 0) { last_fps = TIME_TO_FPS(curr_time, new_time, FPS_UPDATE_INTERVAL); curr_time = new_time; snprintf(buf, size, "%s || FPS: %6.1f || Frames: %u", - g_extern.title_buf, last_fps, g_runloop.frames.video.count); + g_extern.title_buf, last_fps, runloop->frames.video.count); ret = true; } if (buf_fps) snprintf(buf_fps, size_fps, "FPS: %6.1f || Frames: %u", - last_fps, g_runloop.frames.video.count); + last_fps, runloop->frames.video.count); return ret; } diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index fb7cc8743a..12aca11564 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -393,8 +393,9 @@ static bool thread_alive(void *data) { bool ret; thread_video_t *thr = (thread_video_t*)data; + runloop_t *runloop = rarch_main_get_ptr(); - if (g_runloop.is_paused) + if (runloop->is_paused) { thread_send_cmd(thr, CMD_ALIVE); thread_wait_reply(thr, CMD_ALIVE); diff --git a/input/drivers_joypad/ps3_input_joypad.c b/input/drivers_joypad/ps3_input_joypad.c index e3075f6411..f1efa0bf0b 100644 --- a/input/drivers_joypad/ps3_input_joypad.c +++ b/input/drivers_joypad/ps3_input_joypad.c @@ -119,6 +119,7 @@ static void ps3_joypad_poll(void) unsigned port; CellPadInfo2 pad_info; uint64_t *lifecycle_state = (uint64_t*)&g_extern.lifecycle_state; + runloop_t *runloop = rarch_main_get_ptr(); for (port = 0; port < MAX_PADS; port++) { @@ -158,7 +159,7 @@ static void ps3_joypad_poll(void) *state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_TRIANGLE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0; *state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_SQUARE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - if (g_runloop.is_menu) + if (runloop->is_menu) { int value = 0; if (cellSysutilGetSystemParamInt(CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN, &value) == 0) diff --git a/libretro_version_1.c b/libretro_version_1.c index 78b59e2ef9..59e037f6cb 100644 --- a/libretro_version_1.c +++ b/libretro_version_1.c @@ -113,6 +113,7 @@ static void video_frame(const void *data, unsigned width, { unsigned output_width = 0, output_height = 0, output_pitch = 0; const char *msg = NULL; + runloop_t *runloop = rarch_main_get_ptr(); if (!driver.video_active) return; @@ -152,7 +153,7 @@ static void video_frame(const void *data, unsigned width, if (driver.video->frame(driver.video_data, data, width, height, pitch, msg)) { - g_runloop.frames.video.count++; + runloop->frames.video.count++; return; } @@ -177,6 +178,7 @@ bool retro_flush_audio(const int16_t *data, size_t samples) size_t output_size = sizeof(float); struct resampler_data src_data = {0}; struct rarch_dsp_data dsp_data = {0}; + runloop_t *runloop = rarch_main_get_ptr(); if (driver.recording_data) { @@ -188,7 +190,7 @@ bool retro_flush_audio(const int16_t *data, size_t samples) driver.recording->push_audio(driver.recording_data, &ffemu_data); } - if (g_runloop.is_paused || g_settings.audio.mute_enable) + if (runloop->is_paused || g_settings.audio.mute_enable) return true; if (!driver.audio_active || !g_extern.audio_data.data) return false; @@ -225,7 +227,7 @@ bool retro_flush_audio(const int16_t *data, size_t samples) audio_driver_readjust_input_rate(); src_data.ratio = g_extern.audio_data.src_ratio; - if (g_runloop.is_slowmotion) + if (runloop->is_slowmotion) src_data.ratio *= g_settings.slowmotion_ratio; RARCH_PERFORMANCE_INIT(resampler_proc); diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 900d4f9394..414cd9f632 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -268,6 +268,7 @@ static void glui_render(void) glui_handle_t *glui = NULL; gl_t *gl = NULL; menu_handle_t *menu = menu_driver_resolve(); + runloop_t *runloop = rarch_main_get_ptr(); if (!menu) return; @@ -291,9 +292,9 @@ static void glui_render(void) menu->frame_buf.width = gl->win_width; menu->frame_buf.height = gl->win_height; - g_runloop.frames.video.current.menu.animation.is_active = false; - g_runloop.frames.video.current.menu.label.is_updated = false; - g_runloop.frames.video.current.menu.framebuf.dirty = false; + runloop->frames.video.current.menu.animation.is_active = false; + runloop->frames.video.current.menu.label.is_updated = false; + runloop->frames.video.current.menu.framebuf.dirty = false; menu->mouse.ptr = (menu->mouse.y - glui->margin) / glui->line_height - 2 + menu->begin; @@ -328,6 +329,7 @@ static void glui_frame(void) menu_handle_t *menu = menu_driver_resolve(); const uint32_t normal_color = FONT_COLOR_ARGB_TO_RGBA(g_settings.menu.entry_normal_color); const uint32_t hover_color = FONT_COLOR_ARGB_TO_RGBA(g_settings.menu.entry_hover_color); + runloop_t *runloop = rarch_main_get_ptr(); if (!menu) return; @@ -343,7 +345,7 @@ static void glui_frame(void) return; if (menu->need_refresh - && g_runloop.is_menu + && runloop->is_menu && !menu->msg_force) return; @@ -361,7 +363,7 @@ static void glui_frame(void) get_title(label, dir, menu_type, title, sizeof(title)); menu_animation_ticker_line(title_buf, glui->term_width - 3, - g_runloop.frames.video.count / glui->margin, title, true); + runloop->frames.video.count / glui->margin, title, true); glui_blit_line(gl, glui->margin * 2, glui->margin + glui->line_height, title_buf, FONT_COLOR_ARGB_TO_RGBA(g_settings.menu.title_color)); @@ -428,9 +430,9 @@ static void glui_frame(void) selected = (i == menu->navigation.selection_ptr); menu_animation_ticker_line(entry_title_buf, glui->term_width - (w + 1 + 2), - g_runloop.frames.video.count / glui->margin, path_buf, selected); + runloop->frames.video.count / glui->margin, path_buf, selected); menu_animation_ticker_line(type_str_buf, w, - g_runloop.frames.video.count / glui->margin, type_str, selected); + runloop->frames.video.count / glui->margin, type_str, selected); strlcpy(message, entry_title_buf, sizeof(message)); diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 69855fb4e8..793e4375f5 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -58,6 +58,7 @@ static int rgui_entry_iterate(unsigned action) const char *label = NULL; menu_file_list_cbs_t *cbs = NULL; menu_handle_t *menu = menu_driver_resolve(); + runloop_t *runloop = rarch_main_get_ptr(); if (!menu) return -1; @@ -65,10 +66,10 @@ static int rgui_entry_iterate(unsigned action) return -1; if (action != MENU_ACTION_NOOP || menu->need_refresh || - g_runloop.frames.video.current.menu.label.is_updated || - g_runloop.frames.video.current.menu.animation.is_active) + runloop->frames.video.current.menu.label.is_updated || + runloop->frames.video.current.menu.animation.is_active) { - g_runloop.frames.video.current.menu.framebuf.dirty = true; + runloop->frames.video.current.menu.framebuf.dirty = true; } @@ -353,24 +354,25 @@ static void rgui_render(void) const char *core_name = NULL; const char *core_version = NULL; menu_handle_t *menu = menu_driver_resolve(); + runloop_t *runloop = rarch_main_get_ptr(); if (!menu) return; - if (menu->need_refresh && g_runloop.is_menu + if (menu->need_refresh && runloop->is_menu && !menu->msg_force) return; - if (g_runloop.is_idle) + if (runloop->is_idle) return; if (!menu_display_update_pending()) return; /* ensures the framebuffer will be rendered on the screen */ - g_runloop.frames.video.current.menu.framebuf.dirty = true; - g_runloop.frames.video.current.menu.animation.is_active = false; - g_runloop.frames.video.current.menu.label.is_updated = false; + runloop->frames.video.current.menu.framebuf.dirty = true; + runloop->frames.video.current.menu.animation.is_active = false; + runloop->frames.video.current.menu.label.is_updated = false; menu->mouse.ptr = menu->mouse.y / 11 - 2 + menu->begin; @@ -402,7 +404,7 @@ static void rgui_render(void) get_title(label, dir, menu_type, title, sizeof(title)); menu_animation_ticker_line(title_buf, RGUI_TERM_WIDTH - 3, - g_runloop.frames.video.count / RGUI_TERM_START_X, title, true); + runloop->frames.video.count / RGUI_TERM_START_X, title, true); hover_color = HOVER_COLOR; normal_color = NORMAL_COLOR; @@ -476,8 +478,8 @@ static void rgui_render(void) continue; menu_animation_ticker_line(entry_title_buf, RGUI_TERM_WIDTH - (w + 1 + 2), - g_runloop.frames.video.count / RGUI_TERM_START_X, path_buf, selected); - menu_animation_ticker_line(type_str_buf, w, g_runloop.frames.video.count / RGUI_TERM_START_X, + runloop->frames.video.count / RGUI_TERM_START_X, path_buf, selected); + menu_animation_ticker_line(type_str_buf, w, runloop->frames.video.count / RGUI_TERM_START_X, type_str, selected); snprintf(message, sizeof(message), "%c %-*.*s %-*s", @@ -580,6 +582,8 @@ static void rgui_free(void *data) static void rgui_set_texture(void) { menu_handle_t *menu = menu_driver_resolve(); + runloop_t *runloop = rarch_main_get_ptr(); + if (!menu) return; @@ -589,10 +593,10 @@ static void rgui_set_texture(void) return; if (!driver.video_poke->set_texture_frame) return; - if (!g_runloop.frames.video.current.menu.framebuf.dirty) + if (!runloop->frames.video.current.menu.framebuf.dirty) return; - g_runloop.frames.video.current.menu.framebuf.dirty = false; + runloop->frames.video.current.menu.framebuf.dirty = false; driver.video_poke->set_texture_frame(driver.video_data, menu->frame_buf.data, false, menu->frame_buf.width, menu->frame_buf.height, 1.0f); diff --git a/menu/drivers/rmenu.c b/menu/drivers/rmenu.c index d2ba575fa5..adecdfffc8 100644 --- a/menu/drivers/rmenu.c +++ b/menu/drivers/rmenu.c @@ -154,6 +154,7 @@ static void rmenu_render(void) const char *core_version = NULL; unsigned menu_type = 0; menu_handle_t *menu = menu_driver_resolve(); + runloop_t *runloop = rarch_main_get_ptr(); if (!menu) return; @@ -164,13 +165,13 @@ static void rmenu_render(void) return; } - if (menu->need_refresh && g_runloop.is_menu + if (menu->need_refresh && runloop->is_menu && !menu->msg_force) return; - g_runloop.frames.video.current.menu.animation.is_active = false; - g_runloop.frames.video.current.menu.label.is_updated = false; - g_runloop.frames.video.current.menu.framebuf.dirty = false; + runloop->frames.video.current.menu.animation.is_active = false; + runloop->frames.video.current.menu.label.is_updated = false; + runloop->frames.video.current.menu.framebuf.dirty = false; if (!menu->menu_list->selection_buf) return; @@ -195,7 +196,7 @@ static void rmenu_render(void) get_title(label, dir, menu_type, title, sizeof(title)); menu_animation_ticker_line(title_buf, RMENU_TERM_WIDTH, - g_runloop.frames.video.count / 15, title, true); + runloop->frames.video.count / 15, title, true); font_parms.x = POSITION_EDGE_MIN + POSITION_OFFSET; font_parms.y = POSITION_EDGE_MIN + POSITION_RENDER_OFFSET @@ -262,8 +263,8 @@ static void rmenu_render(void) selected = (i == menu->navigation.selection_ptr); menu_animation_ticker_line(entry_title_buf, RMENU_TERM_WIDTH - (w + 1 + 2), - g_runloop.frames.video.count / 15, path, selected); - menu_animation_ticker_line(type_str_buf, w, g_runloop.frames.video.count / 15, + runloop->frames.video.count / 15, path, selected); + menu_animation_ticker_line(type_str_buf, w, runloop->frames.video.count / 15, type_str, selected); snprintf(message, sizeof(message), "%c %s", diff --git a/menu/drivers/rmenu_xui.cpp b/menu/drivers/rmenu_xui.cpp index c5aa835ed7..b785c6d320 100644 --- a/menu/drivers/rmenu_xui.cpp +++ b/menu/drivers/rmenu_xui.cpp @@ -553,16 +553,17 @@ static void rmenu_xui_render(void) const char *dir = NULL, *label = NULL; unsigned menu_type = 0; menu_handle_t *menu = menu_driver_resolve(); + runloop_t *runloop = rarch_main_get_ptr(); if (!menu) return; if (menu->need_refresh && - g_runloop.is_menu && !menu->msg_force) + runloop->is_menu && !menu->msg_force) return; - g_runloop.frames.video.current.menu.animation.is_active = false; - g_runloop.frames.video.current.menu.label.is_updated = false; - g_runloop.frames.video.current.menu.framebuf.dirty = false; + runloop->frames.video.current.menu.animation.is_active = false; + runloop->frames.video.current.menu.label.is_updated = false; + runloop->frames.video.current.menu.framebuf.dirty = false; rmenu_xui_render_background(); @@ -573,7 +574,7 @@ static void rmenu_xui_render(void) get_title(label, dir, menu_type, title, sizeof(title)); mbstowcs(strw_buffer, title, sizeof(strw_buffer) / sizeof(wchar_t)); XuiTextElementSetText(m_menutitle, strw_buffer); - menu_animation_ticker_line(title, RXUI_TERM_WIDTH - 3, g_runloop.frames.video.count / 15, title, true); + menu_animation_ticker_line(title, RXUI_TERM_WIDTH - 3, runloop->frames.video.count / 15, title, true); } if (XuiHandleIsValid(m_menutitle)) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 68e0495261..3e3e64ad5b 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -1049,6 +1049,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl, menu_file_list_cbs_t *cbs = NULL; GLuint icon = 0; xmb_node_t *node = (xmb_node_t*)file_list_get_userdata_at_offset(list, i); + runloop_t *runloop = rarch_main_get_ptr(); if (!node) continue; @@ -1101,7 +1102,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl, icon = xmb->textures.list[XMB_TEXTURE_RESUME].id; - menu_animation_ticker_line(name, 35, g_runloop.frames.video.count / 20, path_buf, + menu_animation_ticker_line(name, 35, runloop->frames.video.count / 20, path_buf, (i == current)); xmb_draw_text(gl, xmb, name, @@ -1109,7 +1110,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl, xmb->margins.screen.top + node->y + xmb->margins.label.top, 1, node->label_alpha, 0); - menu_animation_ticker_line(value, 35, g_runloop.frames.video.count / 20, type_str, + menu_animation_ticker_line(value, 35, runloop->frames.video.count / 20, type_str, (i == current)); if(( strcmp(type_str, "...") @@ -1203,6 +1204,7 @@ static void xmb_draw_cursor(gl_t *gl, xmb_handle_t *xmb, float x, float y) static void xmb_render(void) { unsigned i, current, end; + runloop_t *runloop = rarch_main_get_ptr(); menu_handle_t *menu = menu_driver_resolve(); if (!menu) @@ -1226,9 +1228,9 @@ static void xmb_render(void) menu->mouse.ptr = i; } - g_runloop.frames.video.current.menu.animation.is_active = false; - g_runloop.frames.video.current.menu.label.is_updated = false; - g_runloop.frames.video.current.menu.framebuf.dirty = false; + runloop->frames.video.current.menu.animation.is_active = false; + runloop->frames.video.current.menu.label.is_updated = false; + runloop->frames.video.current.menu.framebuf.dirty = false; } static void xmb_frame(void) diff --git a/menu/menu.c b/menu/menu.c index 4dafcf8835..3fbd5e0854 100644 --- a/menu/menu.c +++ b/menu/menu.c @@ -27,9 +27,10 @@ bool menu_display_update_pending(void) { - if (g_runloop.frames.video.current.menu.animation.is_active || - g_runloop.frames.video.current.menu.label.is_updated || - g_runloop.frames.video.current.menu.framebuf.dirty) + runloop_t *runloop = rarch_main_get_ptr(); + if (runloop->frames.video.current.menu.animation.is_active || + runloop->frames.video.current.menu.label.is_updated || + runloop->frames.video.current.menu.framebuf.dirty) return true; return false; } @@ -181,6 +182,7 @@ void *menu_init(const void *data) { menu_handle_t *menu = NULL; menu_ctx_driver_t *menu_ctx = (menu_ctx_driver_t*)data; + runloop_t *runloop = rarch_main_get_ptr(); if (!menu_ctx) return NULL; @@ -217,7 +219,7 @@ void *menu_init(const void *data) rarch_assert(menu->msg_queue = msg_queue_new(8)); - g_runloop.frames.video.current.menu.framebuf.dirty = true; + runloop->frames.video.current.menu.framebuf.dirty = true; return menu; error: @@ -387,6 +389,7 @@ int menu_iterate(retro_input_t input, static retro_time_t last_clock_update = 0; int32_t ret = 0; unsigned action = menu_input_frame(input, trigger_input); + runloop_t *runloop = rarch_main_get_ptr(); menu_handle_t *menu = menu_driver_resolve(); @@ -400,14 +403,14 @@ int menu_iterate(retro_input_t input, if (menu->cur_time - last_clock_update > 1000000 && g_settings.menu.timedate_enable) { - g_runloop.frames.video.current.menu.label.is_updated = true; + runloop->frames.video.current.menu.label.is_updated = true; last_clock_update = menu->cur_time; } if (driver.menu_ctx && driver.menu_ctx->entry_iterate) ret = driver.menu_ctx->entry_iterate(action); - if (g_runloop.is_menu && !g_runloop.is_idle) + if (runloop->is_menu && !runloop->is_idle) draw_frame(); if (driver.menu_ctx && driver.menu_ctx->set_texture) diff --git a/menu/menu_animation.c b/menu/menu_animation.c index 63aa9e702a..e1a2cba527 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -439,6 +439,7 @@ bool menu_animation_update(animation_t *animation, float dt) { unsigned i; unsigned active_tweens = 0; + runloop_t *runloop = rarch_main_get_ptr(); for(i = 0; i < animation->size; i++) menu_animation_iterate(&animation->list[i], dt, &active_tweens); @@ -449,7 +450,7 @@ bool menu_animation_update(animation_t *animation, float dt) return false; } - g_runloop.frames.video.current.menu.animation.is_active = true; + runloop->frames.video.current.menu.animation.is_active = true; return true; } @@ -472,6 +473,7 @@ void menu_animation_ticker_line(char *buf, size_t len, unsigned idx, unsigned phase_left_moving, phase_right_stop; unsigned left_offset, right_offset; size_t str_len = strlen(str); + runloop_t *runloop = rarch_main_get_ptr(); if (str_len <= len) { @@ -512,5 +514,5 @@ void menu_animation_ticker_line(char *buf, size_t len, unsigned idx, else strlcpy(buf, str + right_offset, len + 1); - g_runloop.frames.video.current.menu.animation.is_active = true; + runloop->frames.video.current.menu.animation.is_active = true; } diff --git a/menu/menu_entries_cbs_iterate.c b/menu/menu_entries_cbs_iterate.c index 446fa357a9..a218aaf6bc 100644 --- a/menu/menu_entries_cbs_iterate.c +++ b/menu/menu_entries_cbs_iterate.c @@ -581,6 +581,7 @@ static int mouse_iterate(unsigned *action) { const struct retro_keybind *binds[MAX_USERS]; menu_handle_t *menu = menu_driver_resolve(); + runloop_t *runloop = rarch_main_get_ptr(); if (!menu) return -1; @@ -651,7 +652,7 @@ static int mouse_iterate(unsigned *action) || menu->mouse.wheelup || menu->mouse.wheeldown || menu->mouse.hwheelup || menu->mouse.hwheeldown || menu->mouse.scrollup || menu->mouse.scrolldown) - g_runloop.frames.video.current.menu.animation.is_active = true; + runloop->frames.video.current.menu.animation.is_active = true; return 0; } diff --git a/menu/menu_entries_cbs_representation.c b/menu/menu_entries_cbs_representation.c index 621e0300ab..3373517cc0 100644 --- a/menu/menu_entries_cbs_representation.c +++ b/menu/menu_entries_cbs_representation.c @@ -379,6 +379,7 @@ static void menu_action_setting_disp_set_label_perf_counters( const struct retro_perf_counter **counters = (const struct retro_perf_counter **)perf_counters_rarch; unsigned offset = type - MENU_SETTINGS_PERF_COUNTERS_BEGIN; + runloop_t *runloop = rarch_main_get_ptr(); *type_str = '\0'; *w = 19; @@ -399,7 +400,7 @@ static void menu_action_setting_disp_set_label_perf_counters( (unsigned long long)counters[offset]->call_cnt), (unsigned long long)counters[offset]->call_cnt); - g_runloop.frames.video.current.menu.label.is_updated = true; + runloop->frames.video.current.menu.label.is_updated = true; } static void menu_action_setting_disp_set_label_libretro_perf_counters( @@ -414,6 +415,7 @@ static void menu_action_setting_disp_set_label_libretro_perf_counters( const struct retro_perf_counter **counters = (const struct retro_perf_counter **)perf_counters_libretro; unsigned offset = type - MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN; + runloop_t *runloop = rarch_main_get_ptr(); *type_str = '\0'; *w = 19; @@ -434,7 +436,7 @@ static void menu_action_setting_disp_set_label_libretro_perf_counters( (unsigned long long)counters[offset]->call_cnt), (unsigned long long)counters[offset]->call_cnt); - g_runloop.frames.video.current.menu.label.is_updated = true; + runloop->frames.video.current.menu.label.is_updated = true; } static void menu_action_setting_disp_set_label_menu_more( diff --git a/retroarch.c b/retroarch.c index 2c84d3924c..4be1b0c9d2 100644 --- a/retroarch.c +++ b/retroarch.c @@ -77,9 +77,10 @@ **/ void rarch_render_cached_frame(void) { - void *recording = driver.recording_data; + void *recording = driver.recording_data; + runloop_t *runloop = rarch_main_get_ptr(); - if (g_runloop.is_idle) + if (runloop->is_idle) return; /* Cannot allow recording when pushing duped frames. */ @@ -378,6 +379,8 @@ static void set_paths(const char *path) **/ static void parse_input(int argc, char *argv[]) { + runloop_t *runloop = rarch_main_get_ptr(); + g_extern.libretro_no_content = false; g_extern.libretro_dummy = false; g_extern.has_set_save_path = false; @@ -656,7 +659,7 @@ static void parse_input(int argc, char *argv[]) break; case 'm': - g_runloop.frames.video.max = strtoul(optarg, NULL, 10); + runloop->frames.video.max = strtoul(optarg, NULL, 10); break; case 0: @@ -1617,8 +1620,8 @@ static void main_clear_state_extern(void) rarch_main_command(RARCH_CMD_HISTORY_DEINIT); memset(&g_extern, 0, sizeof(g_extern)); - memset(&g_runloop, 0, sizeof(g_runloop)); + rarch_main_clear_state(); rarch_main_data_clear_state(); } @@ -1757,8 +1760,10 @@ static void validate_cpu_features(void) **/ static void init_system_av_info(void) { + runloop_t *runloop = rarch_main_get_ptr(); + pretro_get_system_av_info(&g_extern.system.av_info); - g_runloop.frames.limit.last_time = rarch_get_time_usec(); + runloop->frames.limit.last_time = rarch_get_time_usec(); } static void deinit_core(void) @@ -1956,6 +1961,8 @@ void rarch_main_init_wrap(const struct rarch_main_wrap *args, void rarch_main_set_state(unsigned cmd) { + runloop_t *runloop = rarch_main_get_ptr(); + switch (cmd) { case RARCH_ACTION_STATE_MENU_RUNNING: @@ -1984,7 +1991,7 @@ void rarch_main_set_state(unsigned cmd) menu->need_refresh = true; g_extern.system.frame_time_last = 0; - g_runloop.is_menu = true; + runloop->is_menu = true; } #endif break; @@ -2004,7 +2011,7 @@ void rarch_main_set_state(unsigned cmd) if (driver.menu_ctx && driver.menu_ctx->toggle) driver.menu_ctx->toggle(false); - g_runloop.is_menu = false; + runloop->is_menu = false; driver_set_nonblock_state(driver.nonblock_state); @@ -2161,6 +2168,7 @@ bool rarch_main_command(unsigned cmd) { unsigned i = 0; bool boolean = false; + runloop_t *runloop = rarch_main_get_ptr(); (void)i; @@ -2229,7 +2237,7 @@ bool rarch_main_command(unsigned cmd) g_extern.pending.windowed_scale = 0; break; case RARCH_CMD_MENU_TOGGLE: - if (g_runloop.is_menu) + if (runloop->is_menu) rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); else rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING); @@ -2286,8 +2294,8 @@ bool rarch_main_command(unsigned cmd) driver.input->poll(driver.input_data); #ifdef HAVE_MENU - g_runloop.frames.video.current.menu.framebuf.dirty = true; - if (g_runloop.is_menu) + runloop->frames.video.current.menu.framebuf.dirty = true; + if (runloop->is_menu) rarch_main_command(RARCH_CMD_VIDEO_SET_BLOCKING_STATE); #endif break; @@ -2543,7 +2551,7 @@ bool rarch_main_command(unsigned cmd) #endif break; case RARCH_CMD_PAUSE_CHECKS: - if (g_runloop.is_paused) + if (runloop->is_paused) { RARCH_LOG("Paused.\n"); rarch_main_command(RARCH_CMD_AUDIO_STOP); @@ -2558,19 +2566,19 @@ bool rarch_main_command(unsigned cmd) } break; case RARCH_CMD_PAUSE_TOGGLE: - g_runloop.is_paused = !g_runloop.is_paused; + runloop->is_paused = !runloop->is_paused; rarch_main_command(RARCH_CMD_PAUSE_CHECKS); break; case RARCH_CMD_UNPAUSE: - g_runloop.is_paused = false; + runloop->is_paused = false; rarch_main_command(RARCH_CMD_PAUSE_CHECKS); break; case RARCH_CMD_PAUSE: - g_runloop.is_paused = true; + runloop->is_paused = true; rarch_main_command(RARCH_CMD_PAUSE_CHECKS); break; case RARCH_CMD_MENU_PAUSE_LIBRETRO: - if (g_runloop.is_menu) + if (runloop->is_menu) { if (g_settings.menu.pause_libretro) rarch_main_command(RARCH_CMD_AUDIO_STOP); diff --git a/runloop.c b/runloop.c index af53a45061..3c1f632491 100644 --- a/runloop.c +++ b/runloop.c @@ -924,6 +924,16 @@ void rarch_main_msg_queue_init(void) rarch_assert(g_runloop.msg_queue = msg_queue_new(8)); } +runloop_t *rarch_main_get_ptr(void) +{ + return &g_runloop; +} + +void rarch_main_clear_state(void) +{ + memset(&g_runloop, 0, sizeof(g_runloop)); +} + /** * rarch_main_iterate: * diff --git a/runloop.h b/runloop.h index 488fbffcfa..f43cf5cb25 100644 --- a/runloop.h +++ b/runloop.h @@ -108,8 +108,7 @@ typedef struct runloop msg_queue_t *msg_queue; } runloop_t; -/* Public data structures. */ -extern struct runloop g_runloop; +runloop_t *rarch_main_get_ptr(void); /** * rarch_main_iterate: @@ -134,6 +133,8 @@ void rarch_main_data_msg_queue_push(unsigned type, const char *msg, const char *msg2, unsigned prio, unsigned duration, bool flush); +void rarch_main_clear_state(void); + void rarch_main_data_clear_state(void); void rarch_main_data_iterate(void); diff --git a/runloop_data.c b/runloop_data.c index 1f0362161d..ec5ebb855f 100644 --- a/runloop_data.c +++ b/runloop_data.c @@ -684,7 +684,8 @@ static void rarch_main_data_db_iterate(void) #ifdef HAVE_OVERLAY static void rarch_main_data_overlay_iterate(void) { - if (g_runloop.is_idle) + runloop_t *runloop = rarch_main_get_ptr(); + if (runloop->is_idle) return; if (!driver.overlay) return; diff --git a/screenshot.c b/screenshot.c index 9ad2104c2d..e6c03dcd41 100644 --- a/screenshot.c +++ b/screenshot.c @@ -248,6 +248,7 @@ bool take_screenshot(void) bool viewport_read = false; bool ret = true; const char *msg = NULL; + runloop_t *runloop = rarch_main_get_ptr(); /* No way to infer screenshot directory. */ if ((!*g_settings.screenshot_directory) && (!*g_extern.basename)) @@ -319,9 +320,9 @@ bool take_screenshot(void) msg = RETRO_MSG_TAKE_SCREENSHOT_FAILED; } - rarch_main_msg_queue_push(msg, 1, g_runloop.is_paused ? 1 : 180, true); + rarch_main_msg_queue_push(msg, 1, runloop->is_paused ? 1 : 180, true); - if (g_runloop.is_paused) + if (runloop->is_paused) rarch_render_cached_frame(); return ret; diff --git a/settings_data.c b/settings_data.c index 57f1e78092..3b62ceb35c 100644 --- a/settings_data.c +++ b/settings_data.c @@ -381,11 +381,12 @@ static int setting_data_action_start_video_refresh_rate_auto( void *data) { rarch_setting_t *setting = (rarch_setting_t*)data; + runloop_t *runloop = rarch_main_get_ptr(); if (!setting) return -1; - g_runloop.measure_data.frame_time_samples_count = 0; + runloop->measure_data.frame_time_samples_count = 0; return 0; } @@ -1182,9 +1183,11 @@ static void setting_data_get_string_representation_st_float_video_refresh_rate_a if (video_monitor_fps_statistics(&video_refresh_rate, &deviation, &sample_points)) { + runloop_t *runloop = rarch_main_get_ptr(); + snprintf(type_str, type_str_size, "%.3f Hz (%.1f%% dev, %u samples)", video_refresh_rate, 100.0 * deviation, sample_points); - g_runloop.frames.video.current.menu.label.is_updated = true; + runloop->frames.video.current.menu.label.is_updated = true; } else strlcpy(type_str, "N/A", type_str_size); diff --git a/tools/retroarch-joyconfig.c b/tools/retroarch-joyconfig.c index 8aa554ef31..ad523a6ba1 100644 --- a/tools/retroarch-joyconfig.c +++ b/tools/retroarch-joyconfig.c @@ -34,7 +34,6 @@ * with special #ifdefs. */ struct settings g_settings; -struct runloop g_runloop; struct global g_extern; driver_t driver;