No more separate runloop_t

This commit is contained in:
twinaphex 2015-08-03 20:15:46 +02:00
parent bd6ee135e9
commit 3d36cb02ac
9 changed files with 60 additions and 71 deletions

View File

@ -25,7 +25,6 @@
#include "d3d.h" #include "d3d.h"
#include "../video_viewport.h" #include "../video_viewport.h"
#include "../video_monitor.h" #include "../video_monitor.h"
#include "../../runloop.h"
#include "../../dynamic.h" #include "../../dynamic.h"
#include "render_chain_driver.h" #include "render_chain_driver.h"
@ -1633,7 +1632,6 @@ static bool d3d_frame(void *data, const void *frame,
unsigned i = 0; unsigned i = 0;
d3d_video_t *d3d = (d3d_video_t*)data; d3d_video_t *d3d = (d3d_video_t*)data;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;
runloop_t *runloop = rarch_main_get_ptr();
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const font_renderer_t *font_ctx = driver->font_osd_driver; const font_renderer_t *font_ctx = driver->font_osd_driver;

View File

@ -837,10 +837,10 @@ void video_driver_get_video_output_prev(void)
void video_driver_cached_frame(void) void video_driver_cached_frame(void)
{ {
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
void *recording = driver ? driver->recording_data : NULL; void *recording = driver ? driver->recording_data : NULL;
if (runloop->is_idle) if (global->is_idle)
return; return;
/* Cannot allow recording when pushing duped frames. */ /* Cannot allow recording when pushing duped frames. */

View File

@ -295,7 +295,7 @@ static void engine_handle_cmd(void)
{ {
int8_t cmd; int8_t cmd;
struct android_app *android_app = (struct android_app*)g_android; struct android_app *android_app = (struct android_app*)g_android;
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
rarch_system_info_t *system = rarch_system_info_get_ptr(); rarch_system_info_t *system = rarch_system_info_get_ptr();
@ -331,7 +331,7 @@ static void engine_handle_cmd(void)
scond_broadcast(android_app->cond); scond_broadcast(android_app->cond);
slock_unlock(android_app->mutex); slock_unlock(android_app->mutex);
if (runloop->is_paused) if (global->is_paused)
event_command(EVENT_CMD_REINIT); event_command(EVENT_CMD_REINIT);
break; break;
@ -358,8 +358,8 @@ static void engine_handle_cmd(void)
if (!system->shutdown) if (!system->shutdown)
{ {
RARCH_LOG("Pausing RetroArch.\n"); RARCH_LOG("Pausing RetroArch.\n");
runloop->is_paused = true; global->is_paused = true;
runloop->is_idle = true; global->is_idle = true;
} }
break; break;
@ -388,8 +388,8 @@ static void engine_handle_cmd(void)
break; break;
case APP_CMD_GAINED_FOCUS: case APP_CMD_GAINED_FOCUS:
runloop->is_paused = false; global->is_paused = false;
runloop->is_idle = false; global->is_idle = false;
if ((android_app->sensor_state_mask if ((android_app->sensor_state_mask
& (UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE)) & (UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE))

View File

@ -34,7 +34,6 @@
#include "../menu_video.h" #include "../menu_video.h"
#include "../../configuration.h" #include "../../configuration.h"
#include "../../runloop.h"
#include "../../gfx/drivers_font_renderer/bitmap.h" #include "../../gfx/drivers_font_renderer/bitmap.h"
#define RGUI_TERM_START_X (frame_buf->width / 21) #define RGUI_TERM_START_X (frame_buf->width / 21)
@ -374,8 +373,8 @@ static void rgui_render(void)
menu_display_t *disp = menu_display_get_ptr(); menu_display_t *disp = menu_display_get_ptr();
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr(); menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
menu_navigation_t *nav = menu_navigation_get_ptr(); menu_navigation_t *nav = menu_navigation_get_ptr();
runloop_t *runloop = rarch_main_get_ptr();
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
menu_animation_t *anim = menu_animation_get_ptr(); menu_animation_t *anim = menu_animation_get_ptr();
uint64_t frame_count = video_driver_get_frame_count(); uint64_t frame_count = video_driver_get_frame_count();
@ -398,7 +397,7 @@ static void rgui_render(void)
if (menu_entries_needs_refresh() && menu_driver_alive() && !disp->msg_force) if (menu_entries_needs_refresh() && menu_driver_alive() && !disp->msg_force)
return; return;
if (runloop->is_idle) if (global->is_idle)
return; return;
if (!menu_display_update_pending()) if (!menu_display_update_pending())

View File

@ -352,7 +352,7 @@ int menu_iterate(retro_input_t input,
{ {
int32_t ret = 0; int32_t ret = 0;
unsigned action = 0; unsigned action = 0;
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
menu_display_t *disp = menu_display_get_ptr(); menu_display_t *disp = menu_display_get_ptr();
menu_input_t *menu_input = menu_input_get_ptr(); menu_input_t *menu_input = menu_input_get_ptr();
@ -364,7 +364,7 @@ int menu_iterate(retro_input_t input,
ret = menu_entry_iterate(action); ret = menu_entry_iterate(action);
if (menu_driver_alive() && !runloop->is_idle) if (menu_driver_alive() && !global->is_idle)
menu_display_fb(); menu_display_fb();
menu_driver_set_texture(); menu_driver_set_texture();

View File

@ -1153,12 +1153,12 @@ static void validate_cpu_features(void)
**/ **/
void rarch_init_system_av_info(void) void rarch_init_system_av_info(void)
{ {
runloop_t *runloop = rarch_main_get_ptr();
struct retro_system_av_info *av_info = struct retro_system_av_info *av_info =
video_viewport_get_system_av_info(); video_viewport_get_system_av_info();
global_t *global = global_get_ptr();
pretro_get_system_av_info(av_info); pretro_get_system_av_info(av_info);
runloop->frames.limit.last_time = rarch_get_time_usec(); global->frames.limit.last_time = rarch_get_time_usec();
} }
/** /**

View File

@ -42,7 +42,6 @@
#include "netplay.h" #include "netplay.h"
#endif #endif
static struct runloop g_runloop;
static struct global g_extern; static struct global g_extern;
/** /**
@ -511,9 +510,9 @@ static int do_pause_state_checks(
* Returns: 1 if RetroArch is in pause mode, 0 otherwise. * Returns: 1 if RetroArch is in pause mode, 0 otherwise.
**/ **/
static int do_state_checks(driver_t *driver, settings_t *settings, static int do_state_checks(driver_t *driver, settings_t *settings,
global_t *global, runloop_t *runloop, event_cmd_state_t *cmd) global_t *global, event_cmd_state_t *cmd)
{ {
if (runloop->is_idle) if (global->is_idle)
return 1; return 1;
if (cmd->screenshot_pressed) if (cmd->screenshot_pressed)
@ -656,7 +655,7 @@ static void rarch_update_frame_time(driver_t *driver, settings_t *settings,
* *
* Limit frame time if fast forward ratio throttle is enabled. * Limit frame time if fast forward ratio throttle is enabled.
**/ **/
static void rarch_limit_frame_time(settings_t *settings, runloop_t *runloop) static void rarch_limit_frame_time(settings_t *settings, global_t *global)
{ {
retro_time_t target = 0; retro_time_t target = 0;
retro_time_t to_sleep_ms = 0; retro_time_t to_sleep_ms = 0;
@ -666,23 +665,23 @@ static void rarch_limit_frame_time(settings_t *settings, runloop_t *runloop)
double effective_fps = av_info->timing.fps * settings->fastforward_ratio; double effective_fps = av_info->timing.fps * settings->fastforward_ratio;
double mft_f = 1000000.0f / effective_fps; double mft_f = 1000000.0f / effective_fps;
runloop->frames.limit.minimum_time = (retro_time_t) roundf(mft_f); global->frames.limit.minimum_time = (retro_time_t) roundf(mft_f);
target = runloop->frames.limit.last_time + target = global->frames.limit.last_time +
runloop->frames.limit.minimum_time; global->frames.limit.minimum_time;
to_sleep_ms = (target - current) / 1000; to_sleep_ms = (target - current) / 1000;
if (to_sleep_ms <= 0) if (to_sleep_ms <= 0)
{ {
runloop->frames.limit.last_time = rarch_get_time_usec(); global->frames.limit.last_time = rarch_get_time_usec();
return; return;
} }
rarch_sleep((unsigned int)to_sleep_ms); rarch_sleep((unsigned int)to_sleep_ms);
/* Combat jitter a bit. */ /* Combat jitter a bit. */
runloop->frames.limit.last_time += global->frames.limit.last_time +=
runloop->frames.limit.minimum_time; global->frames.limit.minimum_time;
} }
/** /**
@ -866,14 +865,15 @@ global_t *global_get_ptr(void)
return &g_extern; return &g_extern;
} }
runloop_t *rarch_main_get_ptr(void)
{
return &g_runloop;
}
void rarch_main_state_free(void) void rarch_main_state_free(void)
{ {
memset(&g_runloop, 0, sizeof(g_runloop)); g_extern.is_idle = false;
g_extern.ui_companion_is_on_foreground = false;
g_extern.frames.limit.minimum_time = 0.0;
g_extern.frames.limit.last_time = 0.0;
g_extern.is_slowmotion = false;
g_extern.is_paused = false;
g_extern.max_frames = 0;
} }
void rarch_main_global_free(void) void rarch_main_global_free(void)
@ -913,10 +913,10 @@ void rarch_main_clear_state(void)
bool rarch_main_is_idle(void) bool rarch_main_is_idle(void)
{ {
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
if (!runloop) if (!global)
return false; return false;
return runloop->is_idle; return global->is_idle;
} }
static bool rarch_main_cmd_get_state_menu_toggle_button_combo( static bool rarch_main_cmd_get_state_menu_toggle_button_combo(
@ -1022,7 +1022,6 @@ int rarch_main_iterate(void)
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
runloop_t *runloop = rarch_main_get_ptr();
retro_input_t input = input_keys_pressed(driver, settings, global); retro_input_t input = input_keys_pressed(driver, settings, global);
rarch_system_info_t *system = rarch_system_info_get_ptr(); rarch_system_info_t *system = rarch_system_info_get_ptr();
@ -1068,7 +1067,7 @@ int rarch_main_iterate(void)
return rarch_main_iterate_quit(settings, global); return rarch_main_iterate_quit(settings, global);
} }
if (do_state_checks(driver, settings, global, runloop, &cmd)) if (do_state_checks(driver, settings, global, &cmd))
{ {
/* RetroArch has been paused */ /* RetroArch has been paused */
driver->retro_ctx.poll_cb(); driver->retro_ctx.poll_cb();
@ -1134,7 +1133,7 @@ int rarch_main_iterate(void)
success: success:
if (settings->fastforward_ratio_throttle_enable) if (settings->fastforward_ratio_throttle_enable)
rarch_limit_frame_time(settings, runloop); rarch_limit_frame_time(settings, global);
return ret; return ret;
} }

View File

@ -32,9 +32,15 @@
extern "C" { extern "C" {
#endif #endif
/* All libretro runloop-related globals go here. */ typedef struct rarch_resolution
{
unsigned idx;
unsigned id;
} rarch_resolution_t;
typedef struct runloop /* All run-time- / command line flag-related globals go here. */
typedef struct global
{ {
/* Lifecycle state checks. */ /* Lifecycle state checks. */
bool is_idle; bool is_idle;
@ -48,18 +54,7 @@ typedef struct runloop
retro_time_t last_time; retro_time_t last_time;
} limit; } limit;
} frames; } frames;
} runloop_t;
typedef struct rarch_resolution
{
unsigned idx;
unsigned id;
} rarch_resolution_t;
/* All run-time- / command line flag-related globals go here. */
typedef struct global
{
bool is_slowmotion; bool is_slowmotion;
bool is_paused; bool is_paused;
unsigned max_frames; unsigned max_frames;
@ -318,8 +313,6 @@ typedef struct global
retro_keyboard_event_t frontend_key_event; retro_keyboard_event_t frontend_key_event;
} global_t; } global_t;
runloop_t *rarch_main_get_ptr(void);
global_t *global_get_ptr(void); global_t *global_get_ptr(void);
/** /**

View File

@ -44,9 +44,9 @@ void apple_rarch_exited(void);
static void rarch_draw(void) static void rarch_draw(void)
{ {
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
int ret = 0; int ret = 0;
bool iterate = iterate_observer && !runloop->is_paused; bool iterate = iterate_observer && !global->is_paused;
if (iterate) if (iterate)
{ {
@ -70,7 +70,7 @@ static void rarch_draw(void)
return; return;
} }
if (runloop->is_idle) if (global->is_idle)
return; return;
CFRunLoopWakeUp(CFRunLoopGetMain()); CFRunLoopWakeUp(CFRunLoopGetMain());
} }
@ -398,7 +398,7 @@ void apple_stop_iterate_timer()
- (void)showGameView - (void)showGameView
{ {
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
[self popToRootViewControllerAnimated:NO]; [self popToRootViewControllerAnimated:NO];
[self setToolbarHidden:true animated:NO]; [self setToolbarHidden:true animated:NO];
@ -406,20 +406,20 @@ void apple_stop_iterate_timer()
[[UIApplication sharedApplication] setIdleTimerDisabled:true]; [[UIApplication sharedApplication] setIdleTimerDisabled:true];
[self.window setRootViewController:[CocoaView get]]; [self.window setRootViewController:[CocoaView get]];
runloop->is_paused = false; global->is_paused = false;
runloop->is_idle = false; global->is_idle = false;
runloop->ui_companion_is_on_foreground = false; global->ui_companion_is_on_foreground = false;
} }
- (IBAction)showPauseMenu:(id)sender - (IBAction)showPauseMenu:(id)sender
{ {
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
if (runloop) if (global)
{ {
runloop->is_paused = true; global->is_paused = true;
runloop->is_idle = true; global->is_idle = true;
runloop->ui_companion_is_on_foreground = true; global->ui_companion_is_on_foreground = true;
} }
[[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:UIStatusBarAnimationNone]; [[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:UIStatusBarAnimationNone];
@ -429,9 +429,9 @@ void apple_stop_iterate_timer()
- (void)toggleUI - (void)toggleUI
{ {
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
if (runloop->ui_companion_is_on_foreground) if (global->ui_companion_is_on_foreground)
{ {
[self showGameView]; [self showGameView];
} }
@ -505,15 +505,15 @@ typedef struct ui_companion_cocoatouch
static void ui_companion_cocoatouch_switch_to_ios(void *data) static void ui_companion_cocoatouch_switch_to_ios(void *data)
{ {
RetroArch_iOS *ap = NULL; RetroArch_iOS *ap = NULL;
runloop_t *runloop = rarch_main_get_ptr(); global_t *global = global_get_ptr();
(void)data; (void)data;
if (!apple_platform) if (!apple_platform)
return; return;
ap = (RetroArch_iOS *)apple_platform; ap = (RetroArch_iOS *)apple_platform;
runloop->is_idle = true; global->is_idle = true;
[ap showPauseMenu:ap]; [ap showPauseMenu:ap];
} }