From 3b176eed6f6d5a7b45e1d8997dbda894365ff699 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 4 Dec 2015 12:26:39 +0100 Subject: [PATCH] move frame_time_last out of system_t struct and make it a static local variable inside rarch_main_iterate --- driver.c | 3 +-- menu/menu_driver.c | 3 ++- runloop.c | 24 ++++++++++++++++++++---- runloop.h | 3 +++ system.h | 1 - 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/driver.c b/driver.c index 103be03c56..5bac3b4005 100644 --- a/driver.c +++ b/driver.c @@ -356,7 +356,6 @@ static void menu_update_libretro_info(void) void init_drivers(int flags) { driver_t *driver = driver_get_ptr(); - rarch_system_info_t *system = rarch_system_info_get_ptr(); if (flags & DRIVER_VIDEO) video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_OWN_DRIVER, NULL); @@ -390,7 +389,7 @@ void init_drivers(int flags) hw_render->context_reset(); video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT_ACK, NULL); - system->frame_time_last = 0; + runloop_ctl(RUNLOOP_CTL_SET_FRAME_TIME_LAST, NULL); } if (flags & DRIVER_AUDIO) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index d01757b9e4..df54aff4d4 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -316,7 +316,8 @@ void menu_driver_toggle(bool latch) { global->frontend_key_event = system->key_event; system->key_event = menu_input_key_event; - system->frame_time_last = 0; + + runloop_ctl(RUNLOOP_CTL_SET_FRAME_TIME_LAST, NULL); } } else diff --git a/runloop.c b/runloop.c index ea464cfc79..97b6353132 100644 --- a/runloop.c +++ b/runloop.c @@ -351,6 +351,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) { static char runloop_fullpath[PATH_MAX_LENGTH]; static unsigned runloop_max_frames = false; + static bool runloop_frame_time_last = false; static bool runloop_set_frame_limit = false; static bool runloop_paused = false; static bool runloop_idle = false; @@ -371,6 +372,14 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) return runloop_max_frames && (*frame_count >= runloop_max_frames); } break; + case RUNLOOP_CTL_SET_FRAME_TIME_LAST: + runloop_frame_time_last = true; + break; + case RUNLOOP_CTL_UNSET_FRAME_TIME_LAST: + runloop_frame_time_last = false; + break; + case RUNLOOP_CTL_IS_FRAME_TIME_LAST: + return runloop_frame_time_last; case RUNLOOP_CTL_SET_FRAME_LIMIT: runloop_set_frame_limit = true; break; @@ -968,6 +977,7 @@ int rarch_main_iterate(unsigned *sleep_ms) retro_input_t trigger_input; event_cmd_state_t cmd; retro_time_t current, target, to_sleep_ms; + static retro_usec_t frame_time_last; static retro_time_t frame_limit_minimum_time = 0.0; static retro_time_t frame_limit_last_time = 0.0; static retro_input_t last_input = 0; @@ -979,6 +989,12 @@ int rarch_main_iterate(unsigned *sleep_ms) retro_input_t old_input = last_input; last_input = input; + if (runloop_ctl(RUNLOOP_CTL_IS_FRAME_TIME_LAST, NULL)) + { + frame_time_last = 0; + runloop_ctl(RUNLOOP_CTL_UNSET_FRAME_TIME_LAST, NULL); + } + if (runloop_ctl(RUNLOOP_CTL_SHOULD_SET_FRAME_LIMIT, NULL)) { struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); @@ -1015,23 +1031,23 @@ int rarch_main_iterate(unsigned *sleep_ms) bool is_slowmotion; retro_time_t current = retro_get_time_usec(); - retro_time_t delta = current - system->frame_time_last; + retro_time_t delta = current - frame_time_last; bool is_locked_fps = (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL) || input_driver_ctl(RARCH_INPUT_CTL_IS_NONBLOCK_STATE, NULL)) | !!driver->recording_data; runloop_ctl(RUNLOOP_CTL_IS_SLOWMOTION, &is_slowmotion); - if (!system->frame_time_last || is_locked_fps) + if (!frame_time_last || is_locked_fps) delta = system->frame_time.reference; if (!is_locked_fps && is_slowmotion) delta /= settings->slowmotion_ratio; - system->frame_time_last = current; + frame_time_last = current; if (is_locked_fps) - system->frame_time_last = 0; + frame_time_last = 0; system->frame_time.callback(delta); } diff --git a/runloop.h b/runloop.h index 0b937d82ea..500e76b2ba 100644 --- a/runloop.h +++ b/runloop.h @@ -37,6 +37,9 @@ enum runloop_ctl_state RUNLOOP_CTL_SET_FRAME_LIMIT = 0, RUNLOOP_CTL_UNSET_FRAME_LIMIT, RUNLOOP_CTL_SHOULD_SET_FRAME_LIMIT, + RUNLOOP_CTL_SET_FRAME_TIME_LAST, + RUNLOOP_CTL_UNSET_FRAME_TIME_LAST, + RUNLOOP_CTL_IS_FRAME_TIME_LAST, RUNLOOP_CTL_IS_FRAME_COUNT_END, RUNLOOP_CTL_IS_IDLE, RUNLOOP_CTL_GET_WINDOWED_SCALE, diff --git a/system.h b/system.h index 888210e2fa..20fe8000d6 100644 --- a/system.h +++ b/system.h @@ -48,7 +48,6 @@ typedef struct rarch_system_info struct retro_location_callback location_callback; struct retro_frame_time_callback frame_time; - retro_usec_t frame_time_last; core_option_manager_t *core_options;