/** * rarch_main_iterate: * * Run Libretro core in RetroArch for one frame. * * Returns: 0 on success, 1 if we have to wait until button input in order * to wake up the loop, -1 if we forcibly quit out of the RetroArch iteration loop. **/ int rarch_main_iterate(void) { unsigned i; retro_input_t trigger_input, old_input; event_cmd_state_t cmd = {0}; int ret = 0; static retro_input_t last_input = 0; driver_t *driver = driver_get_ptr(); settings_t *settings = config_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); rarch_system_info_t *system = rarch_system_info_get_ptr(); old_input = last_input; last_input = input; if (driver->flushing_input) driver->flushing_input = (input) ? input_flush(runloop, &input) : false; trigger_input = input & ~old_input; rarch_main_cmd_get_state(&cmd, input, old_input, trigger_input); if (time_to_exit(driver, global, runloop, &cmd)) return rarch_main_iterate_quit(settings, global); if (system->frame_time.callback) rarch_update_frame_time(driver, settings, runloop); do_pre_state_checks(settings, global, runloop, &cmd); #ifdef HAVE_OVERLAY rarch_main_iterate_linefeed_overlay(driver, settings); #endif #ifdef HAVE_MENU if (menu_driver_alive()) { menu_handle_t *menu = menu_driver_get_ptr(); if (menu) if (menu_iterate(input, old_input, trigger_input) == -1) rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); if (!input && settings->menu.pause_libretro) ret = 1; goto success; } #endif if (global->exec) { global->exec = false; return rarch_main_iterate_quit(settings, global); } if (do_state_checks(driver, settings, global, runloop, &cmd)) { /* RetroArch has been paused */ driver->retro_ctx.poll_cb(); rarch_sleep(10); return 1; } #if defined(HAVE_THREADS) lock_autosave(); #endif #ifdef HAVE_NETPLAY if (driver->netplay_data) netplay_pre_frame((netplay_t*)driver->netplay_data); #endif if (global->bsv.movie) bsv_movie_set_frame_start(global->bsv.movie); if (system->camera_callback.caps) driver_camera_poll(); /* Update binds for analog dpad modes. */ for (i = 0; i < settings->input.max_users; i++) { if (!settings->input.analog_dpad_mode[i]) continue; input_push_analog_dpad(settings->input.binds[i], settings->input.analog_dpad_mode[i]); input_push_analog_dpad(settings->input.autoconf_binds[i], settings->input.analog_dpad_mode[i]); } if ((settings->video.frame_delay > 0) && !driver->nonblock_state) rarch_sleep(settings->video.frame_delay); /* Run libretro for one frame. */ pretro_run(); for (i = 0; i < settings->input.max_users; i++) { if (!settings->input.analog_dpad_mode[i]) continue; input_pop_analog_dpad(settings->input.binds[i]); input_pop_analog_dpad(settings->input.autoconf_binds[i]); } if (global->bsv.movie) bsv_movie_set_frame_end(global->bsv.movie); #ifdef HAVE_NETPLAY if (driver->netplay_data) netplay_post_frame((netplay_t*)driver->netplay_data); #endif #if defined(HAVE_THREADS) unlock_autosave(); #endif success: if (settings->fastforward_ratio_throttle_enable) rarch_limit_frame_time(settings, runloop); return ret; }
/** * rarch_main_iterate: * * Run Libretro core in RetroArch for one frame. * * Returns: 0 on success, 1 if we have to wait until button input in order * to wake up the loop, -1 if we forcibly quit out of the RetroArch iteration loop. **/ int rarch_main_iterate(unsigned *sleep_ms) { unsigned i; retro_input_t trigger_input; event_cmd_state_t cmd; bool do_quit = false; static retro_input_t last_input = 0; driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); retro_input_t input = input_keys_pressed(driver, settings, global); rarch_system_info_t *system = rarch_system_info_get_ptr(); retro_input_t old_input = last_input; last_input = input; if (driver->flushing_input) { driver->flushing_input = false; if (input) { input = 0; /* If core was paused before entering menu, evoke * pause toggle to wake it up. */ if (main_is_paused) BIT64_SET(input, RARCH_PAUSE_TOGGLE); driver->flushing_input = true; } } trigger_input = input & ~old_input; rarch_main_cmd_get_state(driver, settings, &cmd, input, old_input, trigger_input); if (time_to_exit(driver, global, system, &cmd)) do_quit = true; if (system->frame_time.callback) rarch_update_frame_time(driver, settings->slowmotion_ratio, system); do_pre_state_checks(settings, global, &cmd); #ifdef HAVE_OVERLAY rarch_main_iterate_linefeed_overlay(driver, settings); #endif if (global->exec) { global->exec = false; do_quit = true; } if (do_quit) { /* Quits out of RetroArch main loop. * On special case, loads dummy core * instead of exiting RetroArch completely. * Aborts core shutdown if invoked. */ if (global->core_shutdown_initiated && settings->load_dummy_on_core_shutdown) { if (!event_command(EVENT_CMD_PREPARE_DUMMY)) return -1; system->shutdown = false; global->core_shutdown_initiated = false; return 0; } return -1; } #ifdef HAVE_MENU if (menu_driver_alive()) { menu_handle_t *menu = menu_driver_get_ptr(); if (menu) if (menu_iterate(true, menu_input_frame(input, trigger_input)) == -1) rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED); if (!input && settings->menu.pause_libretro) return 1; return rarch_limit_frame_time(settings->fastforward_ratio, sleep_ms); } #endif if (do_state_checks(driver, settings, global, &cmd)) { /* RetroArch has been paused. */ driver->retro_ctx.poll_cb(); *sleep_ms = 10; return 1; } #if defined(HAVE_THREADS) lock_autosave(); #endif #ifdef HAVE_NETPLAY if (driver->netplay_data) netplay_pre_frame((netplay_t*)driver->netplay_data); #endif if (global->bsv.movie) bsv_movie_set_frame_start(global->bsv.movie); if (system->camera_callback.caps) driver_camera_poll(); /* Update binds for analog dpad modes. */ for (i = 0; i < settings->input.max_users; i++) { if (!settings->input.analog_dpad_mode[i]) continue; input_push_analog_dpad(settings->input.binds[i], settings->input.analog_dpad_mode[i]); input_push_analog_dpad(settings->input.autoconf_binds[i], settings->input.analog_dpad_mode[i]); } if ((settings->video.frame_delay > 0) && !driver->nonblock_state) rarch_sleep(settings->video.frame_delay); /* Run libretro for one frame. */ pretro_run(); for (i = 0; i < settings->input.max_users; i++) { if (!settings->input.analog_dpad_mode[i]) continue; input_pop_analog_dpad(settings->input.binds[i]); input_pop_analog_dpad(settings->input.autoconf_binds[i]); } if (global->bsv.movie) bsv_movie_set_frame_end(global->bsv.movie); #ifdef HAVE_NETPLAY if (driver->netplay_data) netplay_post_frame((netplay_t*)driver->netplay_data); #endif #if defined(HAVE_THREADS) unlock_autosave(); #endif return rarch_limit_frame_time(settings->fastforward_ratio, sleep_ms); }