RetroArch/runloop.c

1545 lines
46 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2016-01-10 03:06:50 +00:00
* Copyright (C) 2011-2016 - Daniel De Matteis
2015-01-07 16:46:50 +00:00
* Copyright (C) 2012-2015 - Michael Lelli
* Copyright (C) 2014-2015 - Jay McCarthy
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
2015-11-28 23:19:01 +00:00
#include <stdarg.h>
2015-11-23 20:58:39 +00:00
#include <math.h>
#include <lists/dir_list.h>
2014-10-21 22:23:06 +00:00
#include <file/file_path.h>
2015-03-15 03:30:46 +00:00
#include <retro_inline.h>
2015-11-28 23:19:01 +00:00
#include <retro_assert.h>
#include <queues/message_queue.h>
#ifdef HAVE_THREADS
#include <rthreads/rthreads.h>
#endif
2016-02-09 17:13:47 +00:00
#include <queues/task_queue.h>
2015-12-26 06:07:01 +00:00
#include <string/stdstring.h>
#include <features/features_cpu.h>
2015-06-13 17:12:10 +00:00
2015-06-22 09:45:00 +00:00
#include <compat/strl.h>
2015-06-14 16:46:00 +00:00
2015-11-11 20:10:13 +00:00
#ifdef HAVE_CHEEVOS
#include "cheevos.h"
2015-11-11 20:10:13 +00:00
#endif
2015-11-30 18:23:13 +00:00
#include "autosave.h"
#include "core_info.h"
2015-06-13 17:12:10 +00:00
#include "configuration.h"
2015-12-01 00:47:26 +00:00
#include "movie.h"
2015-01-09 16:40:47 +00:00
#include "retroarch.h"
2015-01-09 17:40:33 +00:00
#include "runloop.h"
2016-05-09 23:25:47 +00:00
#include "managers/core_option_manager.h"
#include "managers/cheat_manager.h"
#include "managers/state_manager.h"
#include "system.h"
2016-03-20 16:28:24 +00:00
#include "list_special.h"
2015-11-23 18:40:09 +00:00
#include "audio/audio_driver.h"
#include "camera/camera_driver.h"
#include "record/record_driver.h"
#include "input/input_driver.h"
#include "ui/ui_companion_driver.h"
2016-05-08 03:29:10 +00:00
#include "core.h"
2015-06-13 17:12:10 +00:00
#include "msg_hash.h"
2015-11-28 15:13:16 +00:00
#include "input/input_keyboard.h"
#include "tasks/tasks_internal.h"
#ifdef HAVE_MENU
2015-12-06 16:55:27 +00:00
#include "menu/menu_driver.h"
#include "menu/menu_content.h"
#endif
#ifdef HAVE_NETPLAY
#include "network/netplay/netplay.h"
#endif
2015-11-23 11:03:38 +00:00
#include "verbosity.h"
2015-12-07 12:56:33 +00:00
#ifdef HAVE_ZLIB
#define DEFAULT_EXT "zip"
#else
#define DEFAULT_EXT ""
#endif
2015-12-26 10:10:13 +00:00
#define SHADER_EXT_GLSL 0x7c976537U
#define SHADER_EXT_GLSLP 0x0f840c87U
#define SHADER_EXT_CG 0x0059776fU
#define SHADER_EXT_CGP 0x0b8865bfU
2016-02-16 19:24:00 +00:00
#define SHADER_EXT_SLANG 0x105ce63aU
#define SHADER_EXT_SLANGP 0x1bf9adeaU
2015-12-26 10:10:13 +00:00
#define runloop_cmd_triggered(cmd, id) BIT64_GET(cmd->state[2], id)
#define runloop_cmd_press(cmd, id) BIT64_GET(cmd->state[0], id)
#define runloop_cmd_pressed(cmd, id) BIT64_GET(cmd->state[1], id)
#ifdef HAVE_MENU
#define runloop_cmd_menu_press(cmd) (BIT64_GET(cmd->state[2], RARCH_MENU_TOGGLE) || \
runloop_cmd_get_state_menu_toggle_button_combo( \
settings, cmd->state[0], \
cmd->state[1], cmd->state[2]))
#endif
2016-05-11 17:25:15 +00:00
struct rarch_dir_list
{
struct string_list *list;
size_t ptr;
};
typedef struct event_cmd_state
{
2015-12-07 10:23:32 +00:00
retro_input_t state[3];
} event_cmd_state_t;
static rarch_dir_list_t runloop_shader_dir;
static char runloop_fullpath[PATH_MAX_LENGTH];
static rarch_system_info_t runloop_system;
static unsigned runloop_pending_windowed_scale;
static struct retro_frame_time_callback runloop_frame_time;
static retro_keyboard_event_t runloop_key_event = NULL;
static retro_keyboard_event_t runloop_frontend_key_event = NULL;
static retro_usec_t runloop_frame_time_last = 0;
static unsigned runloop_max_frames = false;
static bool runloop_force_nonblock = false;
static bool runloop_frame_time_last_enable = false;
static bool runloop_set_frame_limit = false;
static bool runloop_paused = false;
static bool runloop_idle = false;
static bool runloop_exec = false;
static bool runloop_slowmotion = false;
static bool runloop_shutdown_initiated = false;
static bool runloop_core_shutdown_initiated = false;
static bool runloop_perfcnt_enable = false;
static bool runloop_overrides_active = false;
static bool runloop_game_options_active = false;
static core_option_manager_t *runloop_core_options = NULL;
#ifdef HAVE_THREADS
2016-05-08 04:09:39 +00:00
static slock_t *_runloop_msg_queue_lock = NULL;
#endif
static msg_queue_t *runloop_msg_queue = NULL;
global_t *global_get_ptr(void)
{
static struct global g_extern;
return &g_extern;
}
2016-05-08 04:09:39 +00:00
static void runloop_msg_queue_lock(void)
{
#ifdef HAVE_THREADS
slock_lock(_runloop_msg_queue_lock);
#endif
}
static void runloop_msg_queue_unlock(void)
{
#ifdef HAVE_THREADS
slock_unlock(_runloop_msg_queue_lock);
#endif
}
static bool runloop_msg_queue_push_internal(runloop_ctx_msg_info_t *msg_info)
{
if (!msg_info || !runloop_msg_queue)
return false;
msg_queue_push(runloop_msg_queue, msg_info->msg,
msg_info->prio, msg_info->duration);
if (ui_companion_is_on_foreground())
{
const ui_companion_driver_t *ui = ui_companion_get_ptr();
if (ui->msg_queue_push)
ui->msg_queue_push(msg_info->msg,
msg_info->prio, msg_info->duration, msg_info->flush);
}
return true;
}
2016-01-26 04:44:21 +00:00
void runloop_msg_queue_push(const char *msg,
unsigned prio, unsigned duration,
2015-11-28 23:19:01 +00:00
bool flush)
{
2016-02-03 16:56:40 +00:00
runloop_ctx_msg_info_t msg_info;
2015-11-29 23:13:51 +00:00
settings_t *settings = config_get_ptr();
2016-02-03 16:56:40 +00:00
if(!settings->video.font_enable)
2015-11-28 23:19:01 +00:00
return;
2016-05-08 04:09:39 +00:00
runloop_msg_queue_lock();
2015-11-28 23:19:01 +00:00
if (flush)
2016-02-03 16:50:53 +00:00
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_CLEAR, NULL);
2015-11-28 23:19:01 +00:00
2016-02-03 16:56:40 +00:00
msg_info.msg = msg;
msg_info.prio = prio;
msg_info.duration = duration;
msg_info.flush = flush;
2015-11-28 23:19:01 +00:00
runloop_msg_queue_push_internal(&msg_info);
2016-02-03 16:50:53 +00:00
2016-05-08 04:09:39 +00:00
runloop_msg_queue_unlock();
2015-11-28 23:19:01 +00:00
}
2016-05-08 03:21:31 +00:00
char* runloop_msg_queue_pull(void)
{
runloop_ctx_msg_info_t msg_info;
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_PULL, &msg_info);
return strdup(msg_info.msg);
}
2016-05-08 04:58:52 +00:00
/* Checks if movie is being played back. */
static bool runloop_check_movie_playback(void)
{
if (!bsv_movie_ctl(BSV_MOVIE_CTL_END, NULL))
return false;
runloop_msg_queue_push(
msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED), 1, 180, false);
RARCH_LOG("%s\n", msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED));
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_BSV_MOVIE_DEINIT, NULL);
2016-05-08 04:58:52 +00:00
bsv_movie_ctl(BSV_MOVIE_CTL_UNSET_END, NULL);
bsv_movie_ctl(BSV_MOVIE_CTL_UNSET_PLAYBACK, NULL);
return true;
}
/* Checks if movie is being recorded. */
static bool runloop_check_movie_record(void)
{
if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
return false;
runloop_msg_queue_push(
msg_hash_to_str(MSG_MOVIE_RECORD_STOPPED), 2, 180, true);
RARCH_LOG("%s\n", msg_hash_to_str(MSG_MOVIE_RECORD_STOPPED));
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_BSV_MOVIE_DEINIT, NULL);
2016-05-08 04:58:52 +00:00
return true;
}
2016-05-11 17:28:22 +00:00
static bool runloop_check_movie_init(void)
{
char msg[128], path[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
return false;
settings->rewind_granularity = 1;
if (settings->state_slot > 0)
snprintf(path, sizeof(path), "%s%d",
bsv_movie_get_path(), settings->state_slot);
else
strlcpy(path, bsv_movie_get_path(), sizeof(path));
strlcat(path, ".bsv", sizeof(path));
snprintf(msg, sizeof(msg), "%s \"%s\".",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
path);
bsv_movie_init_handle(path, RARCH_MOVIE_RECORD);
if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
return false;
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
{
runloop_msg_queue_push(msg, 1, 180, true);
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
path);
}
else
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD),
1, 180, true);
RARCH_ERR("%s\n",
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD));
}
return true;
}
static bool runloop_check_movie(void)
{
if (bsv_movie_ctl(BSV_MOVIE_CTL_PLAYBACK_ON, NULL))
return runloop_check_movie_playback();
if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
return runloop_check_movie_init();
return runloop_check_movie_record();
}
2016-05-08 04:58:52 +00:00
/* Checks if slowmotion toggle/hold was being pressed and/or held. */
static bool runloop_check_slowmotion(bool *ptr)
{
settings_t *settings = config_get_ptr();
if (!ptr)
return false;
runloop_slowmotion = *ptr;
if (!runloop_slowmotion)
return false;
if (settings->video.black_frame_insertion)
2016-05-08 12:00:51 +00:00
video_driver_cached_frame_render();
2016-05-08 04:58:52 +00:00
if (state_manager_frame_is_reversed())
runloop_msg_queue_push(msg_hash_to_str(MSG_SLOW_MOTION_REWIND), 0, 30, true);
else
runloop_msg_queue_push(msg_hash_to_str(MSG_SLOW_MOTION), 0, 30, true);
return true;
}
#ifdef HAVE_MENU
2015-12-07 14:36:58 +00:00
static bool runloop_cmd_get_state_menu_toggle_button_combo(
settings_t *settings,
retro_input_t input, retro_input_t old_input,
retro_input_t trigger_input)
{
switch (settings->input.menu_toggle_gamepad_combo)
{
case 0:
return false;
case 1:
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_DOWN))
return false;
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_Y))
return false;
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_L))
return false;
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_R))
return false;
break;
case 2:
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_L3))
return false;
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_R3))
return false;
break;
}
2016-05-08 21:12:04 +00:00
input_driver_set_flushing_input();
return true;
}
#endif
2015-01-07 02:53:36 +00:00
/**
2016-05-09 23:44:13 +00:00
* runloop_check_pause:
2015-01-07 02:53:36 +00:00
* @pressed : was libretro pause key pressed?
* @frameadvance_pressed : was frameadvance key pressed?
*
* Check if libretro pause key was pressed. If so, pause or
2015-01-07 02:53:36 +00:00
* unpause the libretro core.
*
* Returns: true if libretro pause key was toggled, otherwise false.
**/
2016-05-09 23:44:13 +00:00
static bool runloop_check_pause(settings_t *settings,
bool focus, bool pause_pressed,
bool frameadvance_pressed)
{
static bool old_focus = true;
2016-05-09 18:51:53 +00:00
enum event_command cmd = CMD_EVENT_NONE;
bool old_is_paused = runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL);
/* FRAMEADVANCE will set us into pause mode. */
pause_pressed |= !old_is_paused && frameadvance_pressed;
if (focus && pause_pressed)
2016-05-09 18:51:53 +00:00
cmd = CMD_EVENT_PAUSE_TOGGLE;
else if (focus && !old_focus)
2016-05-09 18:51:53 +00:00
cmd = CMD_EVENT_UNPAUSE;
else if (!focus && old_focus)
2016-05-09 18:51:53 +00:00
cmd = CMD_EVENT_PAUSE;
2014-10-05 02:10:00 +00:00
old_focus = focus;
2016-05-09 18:51:53 +00:00
if (cmd != CMD_EVENT_NONE)
2016-05-09 18:20:50 +00:00
command_event(cmd, NULL);
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL) == old_is_paused)
2014-10-08 14:12:00 +00:00
return false;
2014-10-08 14:12:00 +00:00
return true;
}
/**
2016-05-09 23:44:13 +00:00
* runloop_check_fast_forward_button:
* @fastforward_pressed : is fastforward key pressed?
* @hold_pressed : is fastforward key pressed and held?
* @old_hold_pressed : was fastforward key pressed and held the last frame?
*
* Checks if the fast forward key has been pressed for this frame.
*
**/
2016-05-09 23:44:13 +00:00
static void runloop_check_fast_forward_button(bool fastforward_pressed,
bool hold_pressed, bool old_hold_pressed)
{
2015-01-07 02:53:36 +00:00
/* To avoid continous switching if we hold the button down, we require
* that the button must go from pressed to unpressed back to pressed
2015-01-07 02:53:36 +00:00
* to be able to toggle between then.
*/
if (fastforward_pressed)
{
2016-05-08 21:12:04 +00:00
if (input_driver_is_nonblock_state())
input_driver_unset_nonblock_state();
else
2016-05-08 21:12:04 +00:00
input_driver_set_nonblock_state();
}
else if (old_hold_pressed != hold_pressed)
{
if (hold_pressed)
2016-05-08 21:12:04 +00:00
input_driver_set_nonblock_state();
else
2016-05-08 21:12:04 +00:00
input_driver_unset_nonblock_state();
}
else
return;
driver_ctl(RARCH_DRIVER_CTL_SET_NONBLOCK_STATE, NULL);
}
/**
2016-05-09 23:44:13 +00:00
* runloop_check_stateslots:
* @pressed_increase : is state slot increase key pressed?
* @pressed_decrease : is state slot decrease key pressed?
*
* Checks if the state increase/decrease keys have been pressed
* for this frame.
**/
2016-05-09 23:44:13 +00:00
static void runloop_check_stateslots(settings_t *settings,
2015-07-12 17:06:24 +00:00
bool pressed_increase, bool pressed_decrease)
{
2015-12-04 09:23:39 +00:00
char msg[128];
/* Save state slots */
if (pressed_increase)
2015-03-20 18:48:23 +00:00
settings->state_slot++;
else if (pressed_decrease)
{
2015-03-20 18:48:23 +00:00
if (settings->state_slot > 0)
settings->state_slot--;
2014-10-04 23:59:15 +00:00
}
else
return;
2014-10-04 23:59:15 +00:00
2015-07-01 17:30:34 +00:00
snprintf(msg, sizeof(msg), "%s: %d",
msg_hash_to_str(MSG_STATE_SLOT),
2015-03-20 18:48:23 +00:00
settings->state_slot);
2014-10-04 23:59:15 +00:00
2015-12-07 14:32:14 +00:00
runloop_msg_queue_push(msg, 1, 180, true);
2014-10-04 23:59:15 +00:00
RARCH_LOG("%s\n", msg);
}
static void shader_dir_free(rarch_dir_list_t *dir_list)
2015-12-01 02:55:31 +00:00
{
if (!dir_list)
return;
dir_list_free(dir_list->list);
dir_list->list = NULL;
dir_list->ptr = 0;
2015-12-01 02:55:31 +00:00
}
static bool shader_dir_init(rarch_dir_list_t *dir_list)
2015-12-01 02:55:31 +00:00
{
unsigned i;
settings_t *settings = config_get_ptr();
2016-04-28 18:49:13 +00:00
if (!*settings->directory.video_shader)
2015-12-01 02:55:31 +00:00
return false;
dir_list->list = dir_list_new_special(NULL, DIR_LIST_SHADERS, NULL);
2015-12-01 02:55:31 +00:00
if (!dir_list->list || dir_list->list->size == 0)
2015-12-01 02:55:31 +00:00
{
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_SHADER_DIR_DEINIT, NULL);
2015-12-01 02:55:31 +00:00
return false;
}
dir_list->ptr = 0;
dir_list_sort(dir_list->list, false);
2015-12-01 02:55:31 +00:00
for (i = 0; i < dir_list->list->size; i++)
2015-12-01 02:55:31 +00:00
RARCH_LOG("%s \"%s\"\n",
msg_hash_to_str(MSG_FOUND_SHADER),
dir_list->list->elems[i].data);
2015-12-01 02:55:31 +00:00
return true;
}
2015-01-10 20:47:30 +00:00
/**
2016-05-09 23:44:13 +00:00
* runloop_check_shader_dir:
2015-01-10 20:47:30 +00:00
* @pressed_next : was next shader key pressed?
* @pressed_previous : was previous shader key pressed?
*
* Checks if any one of the shader keys has been pressed for this frame:
2015-01-10 20:47:30 +00:00
* a) Next shader index.
* b) Previous shader index.
*
* Will also immediately apply the shader.
**/
2016-05-09 23:44:13 +00:00
static void runloop_check_shader_dir(rarch_dir_list_t *dir_list,
2016-01-26 04:44:21 +00:00
bool pressed_next, bool pressed_prev)
{
2015-06-14 16:46:00 +00:00
uint32_t ext_hash;
char msg[128];
2015-06-12 15:00:37 +00:00
const char *shader = NULL;
const char *ext = NULL;
enum rarch_shader_type type = RARCH_SHADER_NONE;
if (!dir_list || !dir_list->list)
return;
if (pressed_next)
{
dir_list->ptr = (dir_list->ptr + 1) %
dir_list->list->size;
}
else if (pressed_prev)
{
if (dir_list->ptr == 0)
dir_list->ptr = dir_list->list->size - 1;
else
dir_list->ptr--;
}
2014-10-05 03:46:27 +00:00
else
return;
shader = dir_list->list->elems[dir_list->ptr].data;
2015-06-14 16:46:00 +00:00
ext = path_get_extension(shader);
2015-07-01 22:56:51 +00:00
ext_hash = msg_hash_calculate(ext);
2015-06-14 16:46:00 +00:00
switch (ext_hash)
{
case SHADER_EXT_GLSL:
case SHADER_EXT_GLSLP:
type = RARCH_SHADER_GLSL;
break;
2016-02-16 19:24:00 +00:00
case SHADER_EXT_SLANG:
case SHADER_EXT_SLANGP:
type = RARCH_SHADER_SLANG;
break;
2015-06-14 16:46:00 +00:00
case SHADER_EXT_CG:
case SHADER_EXT_CGP:
type = RARCH_SHADER_CG;
break;
default:
return;
}
2015-07-01 17:30:34 +00:00
snprintf(msg, sizeof(msg), "%s #%u: \"%s\".",
msg_hash_to_str(MSG_SHADER),
(unsigned)dir_list->ptr, shader);
2015-12-07 14:32:14 +00:00
runloop_msg_queue_push(msg, 1, 120, true);
2016-02-03 16:56:40 +00:00
2015-07-01 17:30:34 +00:00
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_APPLYING_SHADER),
shader);
2015-02-10 16:20:02 +00:00
if (!video_driver_set_shader(type, shader))
2015-08-29 13:05:40 +00:00
RARCH_WARN("%s\n", msg_hash_to_str(MSG_FAILED_TO_APPLY_SHADER));
}
2015-12-07 13:16:34 +00:00
/**
* rarch_game_specific_options:
*
* Returns: true (1) if a game specific core
* options path has been found,
2015-12-07 13:16:34 +00:00
* otherwise false (0).
**/
static bool rarch_game_specific_options(char **output)
{
2016-01-21 01:19:38 +00:00
char game_path[PATH_MAX_LENGTH];
config_file_t *option_file = NULL;
2016-05-09 05:09:26 +00:00
if (!retroarch_validate_game_options(game_path, sizeof(game_path), false))
return false;
2015-12-07 13:16:34 +00:00
option_file = config_file_new(game_path);
if (!option_file)
return false;
config_file_free(option_file);
2016-01-26 04:44:21 +00:00
RARCH_LOG("Per-Game Options: "
"game-specific core options found at %s\n", game_path);
2015-12-07 13:16:34 +00:00
*output = strdup(game_path);
return true;
}
2015-09-26 13:00:29 +00:00
2016-05-15 08:14:23 +00:00
static bool runloop_is_focused(void)
{
settings_t *settings = config_get_ptr();
if (settings->pause_nonactive)
return video_driver_is_focused();
return true;
}
static bool runloop_check_pause_state(event_cmd_state_t *cmd)
{
bool check_is_oneshot = false;
if (!cmd)
return false;
check_is_oneshot = runloop_cmd_triggered(cmd,
RARCH_FRAMEADVANCE)
|| runloop_cmd_press(cmd, RARCH_REWIND);
if (!runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
return true;
if (runloop_cmd_triggered(cmd, RARCH_FULLSCREEN_TOGGLE_KEY))
{
command_event(CMD_EVENT_FULLSCREEN_TOGGLE, NULL);
video_driver_cached_frame_render();
}
if (!check_is_oneshot)
return false;
return true;
}
static bool runloop_check_idle_state(event_cmd_state_t *cmd)
{
settings_t *settings = config_get_ptr();
bool focused = runloop_is_focused();
runloop_check_pause(settings, focused,
runloop_cmd_triggered(cmd, RARCH_PAUSE_TOGGLE),
runloop_cmd_triggered(cmd, RARCH_FRAMEADVANCE));
if (!runloop_check_pause_state(cmd) || !focused)
return false;
return true;
}
2016-04-10 13:40:46 +00:00
static bool runloop_check_state(event_cmd_state_t *cmd, rarch_dir_list_t *shader_dir)
{
bool tmp = false;
settings_t *settings = config_get_ptr();
if (!cmd || runloop_ctl(RUNLOOP_CTL_IS_IDLE, NULL))
return false;
if (runloop_cmd_triggered(cmd, RARCH_SCREENSHOT))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_TAKE_SCREENSHOT, NULL);
2016-04-10 13:40:46 +00:00
if (runloop_cmd_triggered(cmd, RARCH_MUTE))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_AUDIO_MUTE_TOGGLE, NULL);
2016-04-10 13:40:46 +00:00
if (runloop_cmd_triggered(cmd, RARCH_OSK))
{
if (input_keyboard_ctl(
RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED, NULL))
input_keyboard_ctl(
RARCH_INPUT_KEYBOARD_CTL_UNSET_LINEFEED_ENABLED, NULL);
else
input_keyboard_ctl(
RARCH_INPUT_KEYBOARD_CTL_SET_LINEFEED_ENABLED, NULL);
}
if (runloop_cmd_press(cmd, RARCH_VOLUME_UP))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_VOLUME_UP, NULL);
2016-04-10 13:40:46 +00:00
else if (runloop_cmd_press(cmd, RARCH_VOLUME_DOWN))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_VOLUME_DOWN, NULL);
2016-04-10 13:40:46 +00:00
#ifdef HAVE_NETPLAY
tmp = runloop_cmd_triggered(cmd, RARCH_NETPLAY_FLIP);
netplay_driver_ctl(RARCH_NETPLAY_CTL_FLIP_PLAYERS, &tmp);
tmp = runloop_cmd_triggered(cmd, RARCH_FULLSCREEN_TOGGLE_KEY);
netplay_driver_ctl(RARCH_NETPLAY_CTL_FULLSCREEN_TOGGLE, &tmp);
#endif
2016-05-15 08:14:23 +00:00
if (!runloop_check_idle_state(cmd))
2016-04-10 13:40:46 +00:00
return false;
2016-05-09 23:44:13 +00:00
runloop_check_fast_forward_button(
2016-04-10 13:40:46 +00:00
runloop_cmd_triggered(cmd, RARCH_FAST_FORWARD_KEY),
runloop_cmd_press (cmd, RARCH_FAST_FORWARD_HOLD_KEY),
runloop_cmd_pressed (cmd, RARCH_FAST_FORWARD_HOLD_KEY));
2016-05-09 23:44:13 +00:00
runloop_check_stateslots(settings,
2016-04-10 13:40:46 +00:00
runloop_cmd_triggered(cmd, RARCH_STATE_SLOT_PLUS),
runloop_cmd_triggered(cmd, RARCH_STATE_SLOT_MINUS)
);
if (runloop_cmd_triggered(cmd, RARCH_SAVE_STATE_KEY))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_SAVE_STATE, NULL);
2016-04-10 13:40:46 +00:00
else if (runloop_cmd_triggered(cmd, RARCH_LOAD_STATE_KEY))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_LOAD_STATE, NULL);
2016-04-10 13:40:46 +00:00
#ifdef HAVE_CHEEVOS
if(!settings->cheevos.hardcore_mode_enable)
#endif
state_manager_check_rewind(runloop_cmd_press(cmd, RARCH_REWIND));
tmp = runloop_cmd_press(cmd, RARCH_SLOWMOTION);
2016-05-08 04:58:52 +00:00
runloop_check_slowmotion(&tmp);
2016-04-10 13:40:46 +00:00
if (runloop_cmd_triggered(cmd, RARCH_MOVIE_RECORD_TOGGLE))
2016-05-11 17:28:22 +00:00
runloop_check_movie();
2016-04-10 13:40:46 +00:00
2016-05-09 23:44:13 +00:00
runloop_check_shader_dir(shader_dir,
2016-04-10 13:40:46 +00:00
runloop_cmd_triggered(cmd, RARCH_SHADER_NEXT),
runloop_cmd_triggered(cmd, RARCH_SHADER_PREV));
if (runloop_cmd_triggered(cmd, RARCH_DISK_EJECT_TOGGLE))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_DISK_EJECT_TOGGLE, NULL);
2016-04-10 13:40:46 +00:00
else if (runloop_cmd_triggered(cmd, RARCH_DISK_NEXT))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_DISK_NEXT, NULL);
2016-04-10 13:40:46 +00:00
else if (runloop_cmd_triggered(cmd, RARCH_DISK_PREV))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_DISK_PREV, NULL);
2016-04-10 13:40:46 +00:00
if (runloop_cmd_triggered(cmd, RARCH_RESET))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_RESET, NULL);
2016-04-10 13:40:46 +00:00
cheat_manager_state_checks(
runloop_cmd_triggered(cmd, RARCH_CHEAT_INDEX_PLUS),
runloop_cmd_triggered(cmd, RARCH_CHEAT_INDEX_MINUS),
runloop_cmd_triggered(cmd, RARCH_CHEAT_TOGGLE));
return true;
}
2016-05-08 04:36:52 +00:00
static bool runloop_is_frame_count_end(void)
{
2016-05-08 12:00:51 +00:00
uint64_t *frame_count =
video_driver_get_frame_count_ptr();
2016-05-08 04:36:52 +00:00
return runloop_max_frames && (*frame_count >= runloop_max_frames);
}
2015-11-30 20:42:59 +00:00
bool runloop_ctl(enum runloop_ctl_state state, void *data)
2015-09-26 12:57:46 +00:00
{
settings_t *settings = config_get_ptr();
2015-09-26 12:57:46 +00:00
switch (state)
{
case RUNLOOP_CTL_SHADER_DIR_DEINIT:
shader_dir_free(&runloop_shader_dir);
2016-02-11 00:47:24 +00:00
break;
case RUNLOOP_CTL_SHADER_DIR_INIT:
return shader_dir_init(&runloop_shader_dir);
case RUNLOOP_CTL_SYSTEM_INFO_INIT:
core_get_system_info(&runloop_system.info);
if (!runloop_system.info.library_name)
runloop_system.info.library_name = msg_hash_to_str(MSG_UNKNOWN);
if (!runloop_system.info.library_version)
runloop_system.info.library_version = "v0";
video_driver_set_title_buf();
strlcpy(runloop_system.valid_extensions,
runloop_system.info.valid_extensions ?
runloop_system.info.valid_extensions : DEFAULT_EXT,
sizeof(runloop_system.valid_extensions));
break;
2015-12-09 08:37:54 +00:00
case RUNLOOP_CTL_GET_CORE_OPTION_SIZE:
{
unsigned *idx = (unsigned*)data;
if (!idx)
return false;
2016-05-09 23:21:55 +00:00
*idx = core_option_manager_size(runloop_core_options);
2015-12-09 08:37:54 +00:00
}
2016-02-11 00:47:24 +00:00
break;
2015-12-09 08:34:19 +00:00
case RUNLOOP_CTL_HAS_CORE_OPTIONS:
2016-04-06 00:30:20 +00:00
return runloop_core_options;
2016-05-15 08:09:41 +00:00
case RUNLOOP_CTL_CORE_OPTIONS_LIST_GET:
2016-04-06 00:30:20 +00:00
{
core_option_manager_t **coreopts = (core_option_manager_t**)data;
if (!coreopts)
return false;
*coreopts = runloop_core_options;
}
break;
case RUNLOOP_CTL_SYSTEM_INFO_GET:
{
rarch_system_info_t **system = (rarch_system_info_t**)data;
if (!system)
return false;
*system = &runloop_system;
}
break;
case RUNLOOP_CTL_SYSTEM_INFO_FREE:
/* No longer valid. */
if (runloop_system.subsystem.data)
free(runloop_system.subsystem.data);
runloop_system.subsystem.data = NULL;
runloop_system.subsystem.size = 0;
if (runloop_system.ports.data)
free(runloop_system.ports.data);
runloop_system.ports.data = NULL;
runloop_system.ports.size = 0;
if (runloop_system.mmaps.descriptors)
free((void *)runloop_system.mmaps.descriptors);
runloop_system.mmaps.descriptors = NULL;
runloop_system.mmaps.num_descriptors = 0;
runloop_key_event = NULL;
runloop_frontend_key_event = NULL;
audio_driver_unset_callback();
memset(&runloop_system, 0, sizeof(rarch_system_info_t));
break;
case RUNLOOP_CTL_SET_FRAME_TIME_LAST:
2016-03-12 13:47:10 +00:00
runloop_frame_time_last_enable = true;
break;
case RUNLOOP_CTL_UNSET_FRAME_TIME_LAST:
2016-03-12 13:47:10 +00:00
if (!runloop_ctl(RUNLOOP_CTL_IS_FRAME_TIME_LAST, NULL))
return false;
runloop_frame_time_last = 0;
runloop_frame_time_last_enable = false;
break;
case RUNLOOP_CTL_SET_OVERRIDES_ACTIVE:
runloop_overrides_active = true;
break;
case RUNLOOP_CTL_UNSET_OVERRIDES_ACTIVE:
runloop_overrides_active = false;
break;
case RUNLOOP_CTL_IS_OVERRIDES_ACTIVE:
return runloop_overrides_active;
case RUNLOOP_CTL_SET_GAME_OPTIONS_ACTIVE:
runloop_game_options_active = true;
break;
case RUNLOOP_CTL_UNSET_GAME_OPTIONS_ACTIVE:
runloop_game_options_active = false;
break;
case RUNLOOP_CTL_IS_GAME_OPTIONS_ACTIVE:
return runloop_game_options_active;
case RUNLOOP_CTL_IS_FRAME_TIME_LAST:
2016-03-12 13:47:10 +00:00
return runloop_frame_time_last_enable;
case RUNLOOP_CTL_SET_FRAME_LIMIT:
runloop_set_frame_limit = true;
break;
case RUNLOOP_CTL_UNSET_FRAME_LIMIT:
runloop_set_frame_limit = false;
break;
case RUNLOOP_CTL_SHOULD_SET_FRAME_LIMIT:
return runloop_set_frame_limit;
2015-12-10 11:37:24 +00:00
case RUNLOOP_CTL_GET_PERFCNT:
{
2015-12-10 11:37:24 +00:00
bool **perfcnt = (bool**)data;
if (!perfcnt)
return false;
*perfcnt = &runloop_perfcnt_enable;
}
2016-02-11 00:47:24 +00:00
break;
2015-12-10 11:37:24 +00:00
case RUNLOOP_CTL_SET_PERFCNT_ENABLE:
runloop_perfcnt_enable = true;
2015-11-30 20:56:35 +00:00
break;
case RUNLOOP_CTL_UNSET_PERFCNT_ENABLE:
2015-12-10 11:37:24 +00:00
runloop_perfcnt_enable = false;
2015-11-30 20:56:35 +00:00
break;
case RUNLOOP_CTL_IS_PERFCNT_ENABLE:
2015-12-10 11:37:24 +00:00
return runloop_perfcnt_enable;
case RUNLOOP_CTL_SET_NONBLOCK_FORCED:
runloop_force_nonblock = true;
break;
case RUNLOOP_CTL_UNSET_NONBLOCK_FORCED:
runloop_force_nonblock = false;
break;
case RUNLOOP_CTL_IS_NONBLOCK_FORCED:
return runloop_force_nonblock;
case RUNLOOP_CTL_SET_FRAME_TIME:
{
const struct retro_frame_time_callback *info =
(const struct retro_frame_time_callback*)data;
#ifdef HAVE_NETPLAY
global_t *global = global_get_ptr();
/* retro_run() will be called in very strange and
* mysterious ways, have to disable it. */
if (global->netplay.enable)
return false;
#endif
runloop_frame_time = *info;
}
break;
2015-12-01 02:46:56 +00:00
case RUNLOOP_CTL_GET_WINDOWED_SCALE:
{
unsigned **scale = (unsigned**)data;
if (!scale)
return false;
2015-12-01 02:51:34 +00:00
*scale = (unsigned*)&runloop_pending_windowed_scale;
2015-12-01 02:46:56 +00:00
}
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_WINDOWED_SCALE:
{
unsigned *idx = (unsigned*)data;
if (!idx)
return false;
2015-12-01 02:51:34 +00:00
runloop_pending_windowed_scale = *idx;
}
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_LIBRETRO_PATH:
{
const char *fullpath = (const char*)data;
if (!fullpath)
return false;
2016-04-28 18:49:13 +00:00
strlcpy(
settings->path.libretro,
fullpath,
sizeof(settings->path.libretro));
}
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_CLEAR_CONTENT_PATH:
*runloop_fullpath = '\0';
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_GET_CONTENT_PATH:
{
char **fullpath = (char**)data;
if (!fullpath)
return false;
*fullpath = (char*)runloop_fullpath;
}
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_CONTENT_PATH:
{
const char *fullpath = (const char*)data;
if (!fullpath)
return false;
strlcpy(runloop_fullpath, fullpath, sizeof(runloop_fullpath));
}
break;
case RUNLOOP_CTL_FRAME_TIME_FREE:
memset(&runloop_frame_time, 0, sizeof(struct retro_frame_time_callback));
runloop_frame_time_last = 0;
runloop_max_frames = 0;
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_STATE_FREE:
2016-03-12 13:47:10 +00:00
runloop_perfcnt_enable = false;
runloop_idle = false;
runloop_paused = false;
runloop_slowmotion = false;
runloop_frame_time_last_enable = false;
runloop_set_frame_limit = false;
runloop_overrides_active = false;
runloop_ctl(RUNLOOP_CTL_FRAME_TIME_FREE, NULL);
2015-09-26 19:32:41 +00:00
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_GLOBAL_FREE:
{
2016-01-22 13:43:11 +00:00
global_t *global = NULL;
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_TEMPORARY_CONTENT_DEINIT, NULL);
command_event(CMD_EVENT_SUBSYSTEM_FULLPATHS_DEINIT, NULL);
command_event(CMD_EVENT_RECORD_DEINIT, NULL);
command_event(CMD_EVENT_LOG_FILE_DEINIT, NULL);
rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL);
runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL);
runloop_overrides_active = false;
2016-05-07 23:33:57 +00:00
core_unset_input_descriptors();
2016-04-05 22:20:14 +00:00
global = global_get_ptr();
memset(global, 0, sizeof(struct global));
}
2015-09-26 19:30:20 +00:00
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_CLEAR_STATE:
2015-12-11 09:43:53 +00:00
driver_ctl(RARCH_DRIVER_CTL_DEINIT, NULL);
2015-11-30 20:42:59 +00:00
runloop_ctl(RUNLOOP_CTL_STATE_FREE, NULL);
runloop_ctl(RUNLOOP_CTL_GLOBAL_FREE, NULL);
2015-09-26 13:35:01 +00:00
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_MAX_FRAMES:
2015-09-26 12:57:46 +00:00
{
unsigned *ptr = (unsigned*)data;
if (!ptr)
return false;
runloop_max_frames = *ptr;
2015-09-26 12:57:46 +00:00
}
2015-09-26 13:35:01 +00:00
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_IS_IDLE:
return runloop_idle;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_IDLE:
2015-09-26 12:57:46 +00:00
{
bool *ptr = (bool*)data;
if (!ptr)
return false;
runloop_idle = *ptr;
2015-09-26 12:57:46 +00:00
}
2015-09-26 13:35:01 +00:00
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_IS_SLOWMOTION:
2016-02-29 00:33:14 +00:00
return runloop_slowmotion;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_SLOWMOTION:
2015-09-26 12:57:46 +00:00
{
bool *ptr = (bool*)data;
if (!ptr)
return false;
runloop_slowmotion = *ptr;
2015-09-26 12:57:46 +00:00
}
2015-09-26 13:35:01 +00:00
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_PAUSED:
2015-09-26 12:57:46 +00:00
{
bool *ptr = (bool*)data;
if (!ptr)
return false;
runloop_paused = *ptr;
2015-09-26 12:57:46 +00:00
}
2015-09-26 13:35:01 +00:00
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_IS_PAUSED:
return runloop_paused;
2016-02-03 16:48:01 +00:00
case RUNLOOP_CTL_MSG_QUEUE_PULL:
2016-05-08 04:09:39 +00:00
runloop_msg_queue_lock();
2016-02-03 16:48:01 +00:00
{
const char **ret = (const char**)data;
if (!ret)
return false;
2016-02-03 16:56:40 +00:00
*ret = msg_queue_pull(runloop_msg_queue);
2016-02-03 16:48:01 +00:00
}
2016-05-08 04:09:39 +00:00
runloop_msg_queue_unlock();
2016-02-11 00:47:24 +00:00
break;
case RUNLOOP_CTL_MSG_QUEUE_FREE:
#ifdef HAVE_THREADS
2016-05-08 04:09:39 +00:00
slock_free(_runloop_msg_queue_lock);
_runloop_msg_queue_lock = NULL;
2015-12-07 06:52:11 +00:00
#endif
break;
2016-02-03 16:50:53 +00:00
case RUNLOOP_CTL_MSG_QUEUE_CLEAR:
2016-02-03 16:56:40 +00:00
msg_queue_clear(runloop_msg_queue);
2016-02-11 00:47:24 +00:00
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_MSG_QUEUE_DEINIT:
2016-02-03 16:56:40 +00:00
if (!runloop_msg_queue)
2015-12-04 09:23:39 +00:00
return true;
2016-05-08 04:09:39 +00:00
runloop_msg_queue_lock();
2015-12-04 09:23:39 +00:00
2016-02-03 16:56:40 +00:00
msg_queue_free(runloop_msg_queue);
2015-12-04 09:23:39 +00:00
2016-05-08 04:09:39 +00:00
runloop_msg_queue_unlock();
2015-12-04 09:23:39 +00:00
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_FREE, NULL);
2016-02-03 16:56:40 +00:00
runloop_msg_queue = NULL;
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_MSG_QUEUE_INIT:
2015-11-30 20:42:59 +00:00
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_DEINIT, NULL);
2016-02-03 16:56:40 +00:00
runloop_msg_queue = msg_queue_new(8);
retro_assert(runloop_msg_queue);
#ifdef HAVE_THREADS
2016-05-08 04:09:39 +00:00
_runloop_msg_queue_lock = slock_new();
retro_assert(_runloop_msg_queue_lock);
#endif
break;
case RUNLOOP_CTL_TASK_INIT:
{
2016-02-09 17:38:57 +00:00
bool threaded_enable = false;
#ifdef HAVE_THREADS
threaded_enable = settings->threaded_data_runloop_enable;
#endif
2016-05-23 12:45:43 +00:00
task_queue_ctl(TASK_QUEUE_CTL_DEINIT, NULL);
2016-02-09 17:26:27 +00:00
task_queue_ctl(TASK_QUEUE_CTL_INIT, &threaded_enable);
}
break;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_CORE_SHUTDOWN:
runloop_core_shutdown_initiated = true;
break;
case RUNLOOP_CTL_UNSET_CORE_SHUTDOWN:
runloop_core_shutdown_initiated = false;
break;
case RUNLOOP_CTL_IS_CORE_SHUTDOWN:
return runloop_core_shutdown_initiated;
case RUNLOOP_CTL_SET_SHUTDOWN:
runloop_shutdown_initiated = true;
break;
case RUNLOOP_CTL_UNSET_SHUTDOWN:
runloop_shutdown_initiated = false;
break;
case RUNLOOP_CTL_IS_SHUTDOWN:
return runloop_shutdown_initiated;
2015-11-30 20:35:50 +00:00
case RUNLOOP_CTL_SET_EXEC:
runloop_exec = true;
break;
case RUNLOOP_CTL_UNSET_EXEC:
runloop_exec = false;
break;
case RUNLOOP_CTL_IS_EXEC:
return runloop_exec;
2015-11-30 22:29:46 +00:00
case RUNLOOP_CTL_DATA_DEINIT:
2016-02-09 17:26:27 +00:00
task_queue_ctl(TASK_QUEUE_CTL_DEINIT, NULL);
2015-11-30 22:29:46 +00:00
break;
case RUNLOOP_CTL_IS_CORE_OPTION_UPDATED:
2016-04-06 00:30:20 +00:00
if (!runloop_core_options)
2016-01-23 18:42:05 +00:00
return false;
2016-05-09 23:21:55 +00:00
return core_option_manager_updated(runloop_core_options);
case RUNLOOP_CTL_CORE_OPTION_PREV:
{
unsigned *idx = (unsigned*)data;
if (!idx)
return false;
2016-05-09 23:21:55 +00:00
core_option_manager_prev(runloop_core_options, *idx);
if (ui_companion_is_on_foreground())
ui_companion_driver_notify_refresh();
}
2016-02-11 00:47:24 +00:00
break;
case RUNLOOP_CTL_CORE_OPTION_NEXT:
{
unsigned *idx = (unsigned*)data;
if (!idx)
return false;
2016-05-09 23:21:55 +00:00
core_option_manager_next(runloop_core_options, *idx);
if (ui_companion_is_on_foreground())
ui_companion_driver_notify_refresh();
}
2016-02-11 00:47:24 +00:00
break;
case RUNLOOP_CTL_CORE_OPTIONS_GET:
{
struct retro_variable *var = (struct retro_variable*)data;
2016-04-06 00:30:20 +00:00
if (!runloop_core_options || !var)
return false;
RARCH_LOG("Environ GET_VARIABLE %s:\n", var->key);
2016-05-09 23:21:55 +00:00
core_option_manager_get(runloop_core_options, var);
RARCH_LOG("\t%s\n", var->value ? var->value : "N/A");
}
2016-02-11 00:47:24 +00:00
break;
2015-12-07 13:16:34 +00:00
case RUNLOOP_CTL_CORE_OPTIONS_INIT:
{
char *game_options_path = NULL;
bool ret = false;
char buf[PATH_MAX_LENGTH] = {0};
global_t *global = global_get_ptr();
2016-04-28 17:52:25 +00:00
const char *options_path = settings->path.core_options;
2016-01-26 04:44:21 +00:00
const struct retro_variable *vars =
(const struct retro_variable*)data;
2015-12-07 13:16:34 +00:00
if (!*options_path && *global->path.config)
{
fill_pathname_resolve_relative(buf, global->path.config,
"retroarch-core-options.cfg", sizeof(buf));
options_path = buf;
}
if (settings->game_specific_options)
ret = rarch_game_specific_options(&game_options_path);
if(ret)
{
runloop_ctl(RUNLOOP_CTL_SET_GAME_OPTIONS_ACTIVE, NULL);
2016-04-06 00:30:20 +00:00
runloop_core_options =
2016-05-09 23:21:55 +00:00
core_option_manager_new(game_options_path, vars);
2015-12-07 13:16:34 +00:00
free(game_options_path);
}
else
{
runloop_ctl(RUNLOOP_CTL_UNSET_GAME_OPTIONS_ACTIVE, NULL);
2016-04-06 00:30:20 +00:00
runloop_core_options =
2016-05-09 23:21:55 +00:00
core_option_manager_new(options_path, vars);
}
2015-12-07 13:16:34 +00:00
}
break;
2016-04-06 00:30:20 +00:00
case RUNLOOP_CTL_CORE_OPTIONS_FREE:
if (runloop_core_options)
2016-05-09 23:21:55 +00:00
core_option_manager_free(runloop_core_options);
2016-04-06 00:30:20 +00:00
runloop_core_options = NULL;
break;
case RUNLOOP_CTL_CORE_OPTIONS_DEINIT:
{
2016-03-02 04:29:12 +00:00
global_t *global = global_get_ptr();
2016-04-06 00:30:20 +00:00
if (!runloop_core_options)
2016-03-02 04:29:12 +00:00
return false;
2016-03-02 04:29:12 +00:00
/* check if game options file was just created and flush
to that file instead */
2016-04-06 00:30:20 +00:00
if(global && !string_is_empty(global->path.core_options_path))
2016-03-02 04:29:12 +00:00
{
2016-05-09 23:21:55 +00:00
core_option_manager_flush_game_specific(runloop_core_options,
2016-03-02 04:29:12 +00:00
global->path.core_options_path);
global->path.core_options_path[0] = '\0';
}
else
2016-05-09 23:21:55 +00:00
core_option_manager_flush(runloop_core_options);
2016-03-02 04:29:12 +00:00
if (runloop_ctl(RUNLOOP_CTL_IS_GAME_OPTIONS_ACTIVE, NULL))
runloop_ctl(RUNLOOP_CTL_UNSET_GAME_OPTIONS_ACTIVE, NULL);
2016-04-06 00:30:20 +00:00
runloop_ctl(RUNLOOP_CTL_CORE_OPTIONS_FREE, NULL);
2016-03-02 04:29:12 +00:00
}
2016-02-11 00:47:24 +00:00
break;
2015-12-13 13:31:06 +00:00
case RUNLOOP_CTL_KEY_EVENT_GET:
{
2016-01-26 04:44:21 +00:00
retro_keyboard_event_t **key_event =
(retro_keyboard_event_t**)data;
2015-12-13 13:31:06 +00:00
if (!key_event)
return false;
*key_event = &runloop_key_event;
}
break;
case RUNLOOP_CTL_FRONTEND_KEY_EVENT_GET:
{
2016-01-26 04:44:21 +00:00
retro_keyboard_event_t **key_event =
(retro_keyboard_event_t**)data;
2016-01-21 18:45:43 +00:00
if (!key_event)
return false;
*key_event = &runloop_frontend_key_event;
}
break;
case RUNLOOP_CTL_NONE:
2015-09-26 13:35:01 +00:00
default:
2016-02-11 00:47:24 +00:00
break;
2015-09-26 12:57:46 +00:00
}
2015-09-26 13:35:01 +00:00
return true;
2015-09-26 12:57:46 +00:00
}
#ifdef HAVE_OVERLAY
static void runloop_iterate_linefeed_overlay(settings_t *settings)
{
static char prev_overlay_restore = false;
2016-05-08 21:12:04 +00:00
bool osk_enable = input_driver_is_onscreen_keyboard_enabled();
if (osk_enable && !input_keyboard_ctl(
RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED, NULL))
{
2016-05-08 21:12:04 +00:00
input_driver_unset_onscreen_keyboard_enabled();
prev_overlay_restore = true;
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_OVERLAY_DEINIT, NULL);
}
else if (!osk_enable && input_keyboard_ctl(
RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED, NULL))
{
2016-05-08 21:12:04 +00:00
input_driver_set_onscreen_keyboard_enabled();
prev_overlay_restore = false;
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_OVERLAY_INIT, NULL);
}
else if (prev_overlay_restore)
{
2015-07-09 02:05:59 +00:00
if (!settings->input.overlay_hide_in_menu)
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_OVERLAY_INIT, NULL);
prev_overlay_restore = false;
}
}
#endif
2015-03-24 09:01:17 +00:00
2016-01-20 02:31:19 +00:00
/* Loads dummy core instead of exiting RetroArch completely.
* Aborts core shutdown if invoked. */
static int runloop_iterate_time_to_exit_load_dummy(void)
{
2016-05-16 15:19:16 +00:00
content_ctx_info_t content_info = {0};
2016-05-27 16:14:47 +00:00
if (!task_push_content_load_default(
2016-05-16 15:19:16 +00:00
NULL, NULL,
&content_info,
CORE_TYPE_DUMMY,
CONTENT_MODE_LOAD_NOTHING_WITH_DUMMY_CORE,
NULL, NULL))
2016-01-20 02:31:19 +00:00
return -1;
runloop_ctl(RUNLOOP_CTL_UNSET_SHUTDOWN, NULL);
runloop_ctl(RUNLOOP_CTL_UNSET_CORE_SHUTDOWN, NULL);
return 1;
}
2015-03-24 09:01:17 +00:00
/* Time to exit out of the main loop?
2015-09-30 17:09:05 +00:00
* Reasons for exiting:
* a) Shutdown environment callback was invoked.
* b) Quit key was pressed.
* c) Frame count exceeds or equals maximum amount of frames to run.
* d) Video driver no longer alive.
* e) End of BSV movie and BSV EOF exit is true. (TODO/FIXME - explain better)
*/
static INLINE int runloop_iterate_time_to_exit(bool quit_key_pressed)
2015-09-30 17:09:05 +00:00
{
2015-12-26 10:08:44 +00:00
settings_t *settings = NULL;
2016-02-03 16:10:54 +00:00
bool time_to_exit = runloop_ctl(RUNLOOP_CTL_IS_SHUTDOWN, NULL);
time_to_exit = time_to_exit || quit_key_pressed;
2016-05-08 12:00:51 +00:00
time_to_exit = time_to_exit || !video_driver_is_alive();
time_to_exit = time_to_exit || bsv_movie_ctl(BSV_MOVIE_CTL_END_EOF, NULL);
2016-05-08 04:36:52 +00:00
time_to_exit = time_to_exit || runloop_is_frame_count_end();
time_to_exit = time_to_exit || runloop_ctl(RUNLOOP_CTL_IS_EXEC, NULL);
if (!time_to_exit)
return 1;
if (runloop_ctl(RUNLOOP_CTL_IS_EXEC, NULL))
runloop_ctl(RUNLOOP_CTL_UNSET_EXEC, NULL);
2015-12-26 10:08:44 +00:00
if (!runloop_ctl(RUNLOOP_CTL_IS_CORE_SHUTDOWN, NULL))
return -1;
2016-01-20 02:31:19 +00:00
/* Quits out of RetroArch main loop. */
2015-12-26 10:08:44 +00:00
settings = config_get_ptr();
2016-01-20 02:32:03 +00:00
if (settings->load_dummy_on_core_shutdown)
return runloop_iterate_time_to_exit_load_dummy();
2015-09-30 17:09:05 +00:00
2016-01-20 02:32:03 +00:00
return -1;
2015-09-30 17:09:05 +00:00
}
2015-01-07 02:53:36 +00:00
/**
* runloop_iterate:
*
2015-01-09 21:24:38 +00:00
* Run Libretro core in RetroArch for one frame.
2015-01-07 02:53:36 +00:00
*
2016-01-26 04:44:21 +00:00
* 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.
2015-01-07 02:53:36 +00:00
**/
int runloop_iterate(unsigned *sleep_ms)
{
unsigned i;
2015-08-05 13:54:21 +00:00
event_cmd_state_t cmd;
2015-09-26 19:03:38 +00:00
retro_time_t current, target, to_sleep_ms;
event_cmd_state_t *cmd_ptr = &cmd;
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;
settings_t *settings = config_get_ptr();
2015-12-10 20:31:28 +00:00
cmd.state[1] = last_input;
cmd.state[0] = input_keys_pressed();
last_input = cmd.state[0];
2016-03-12 13:47:10 +00:00
runloop_ctl(RUNLOOP_CTL_UNSET_FRAME_TIME_LAST, NULL);
if (runloop_ctl(RUNLOOP_CTL_SHOULD_SET_FRAME_LIMIT, NULL))
{
2016-01-26 04:44:21 +00:00
struct retro_system_av_info *av_info =
video_viewport_get_system_av_info();
float fastforward_ratio =
(settings->fastforward_ratio == 0.0f)
? 1.0f : settings->fastforward_ratio;
2016-05-10 07:17:04 +00:00
frame_limit_last_time = cpu_features_get_time_usec();
frame_limit_minimum_time = (retro_time_t)roundf(1000000.0f
/ (av_info->timing.fps * fastforward_ratio));
runloop_ctl(RUNLOOP_CTL_UNSET_FRAME_LIMIT, NULL);
}
2015-06-26 17:37:03 +00:00
2016-05-08 21:12:04 +00:00
if (input_driver_is_flushing_input())
2015-08-06 01:17:56 +00:00
{
2016-05-08 21:12:04 +00:00
input_driver_unset_flushing_input();
2015-12-10 20:31:28 +00:00
if (cmd.state[0])
2015-08-06 01:17:56 +00:00
{
2015-12-10 20:31:28 +00:00
cmd.state[0] = 0;
2015-08-06 01:20:15 +00:00
/* If core was paused before entering menu, evoke
* pause toggle to wake it up. */
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
2015-12-10 20:31:28 +00:00
BIT64_SET(cmd.state[0], RARCH_PAUSE_TOGGLE);
2016-05-08 21:12:04 +00:00
input_driver_set_flushing_input();
2015-08-06 01:17:56 +00:00
}
}
2016-05-08 04:31:12 +00:00
if (runloop_frame_time.callback)
{
/* Updates frame timing if frame timing callback is in use by the core.
* Limits frame time if fast forward ratio throttle is enabled. */
2016-05-10 07:17:04 +00:00
retro_time_t current = cpu_features_get_time_usec();
2016-05-08 04:31:12 +00:00
retro_time_t delta = current - runloop_frame_time_last;
bool is_locked_fps = (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL) ||
2016-05-08 21:12:04 +00:00
input_driver_is_nonblock_state()) |
!!recording_driver_get_data_ptr();
2016-05-08 04:31:12 +00:00
if (!runloop_frame_time_last || is_locked_fps)
delta = runloop_frame_time.reference;
if (!is_locked_fps && runloop_ctl(RUNLOOP_CTL_IS_SLOWMOTION, NULL))
delta /= settings->slowmotion_ratio;
runloop_frame_time_last = current;
if (is_locked_fps)
runloop_frame_time_last = 0;
runloop_frame_time.callback(delta);
}
2015-12-10 20:31:28 +00:00
cmd.state[2] = cmd.state[0] & ~cmd.state[1]; /* trigger */
2015-10-22 16:29:35 +00:00
2015-12-07 14:36:58 +00:00
if (runloop_cmd_triggered(cmd_ptr, RARCH_OVERLAY_NEXT))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_OVERLAY_NEXT, NULL);
2015-09-26 13:08:52 +00:00
2015-12-07 14:36:58 +00:00
if (runloop_cmd_triggered(cmd_ptr, RARCH_FULLSCREEN_TOGGLE_KEY))
2015-12-04 10:21:06 +00:00
{
bool fullscreen_toggled = !runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL);
2015-10-27 23:55:11 +00:00
#ifdef HAVE_MENU
2016-01-26 04:44:21 +00:00
fullscreen_toggled = fullscreen_toggled ||
menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL);
2015-10-27 23:55:11 +00:00
#endif
2015-12-04 09:49:09 +00:00
2015-12-04 10:21:06 +00:00
if (fullscreen_toggled)
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_FULLSCREEN_TOGGLE, NULL);
2015-12-04 10:21:06 +00:00
}
2015-09-26 13:08:52 +00:00
2015-12-07 14:36:58 +00:00
if (runloop_cmd_triggered(cmd_ptr, RARCH_GRAB_MOUSE_TOGGLE))
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL);
2015-09-26 13:08:52 +00:00
#ifdef HAVE_MENU
2016-01-26 04:44:21 +00:00
if (runloop_cmd_menu_press(cmd_ptr) ||
rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
2015-09-26 19:03:38 +00:00
{
2015-12-05 12:49:22 +00:00
if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL))
2015-09-26 19:03:38 +00:00
{
2016-01-26 04:44:21 +00:00
if (rarch_ctl(RARCH_CTL_IS_INITED, NULL) &&
!rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL);
2015-09-26 19:03:38 +00:00
}
else
rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL);
2015-09-26 19:03:38 +00:00
}
2015-09-26 13:08:52 +00:00
#endif
#ifdef HAVE_OVERLAY
runloop_iterate_linefeed_overlay(settings);
#endif
2016-01-26 04:44:21 +00:00
if (runloop_iterate_time_to_exit(
runloop_cmd_press(cmd_ptr, RARCH_QUIT_KEY)) != 1)
{
frame_limit_last_time = 0.0;
2015-09-30 17:09:05 +00:00
return -1;
}
2015-08-27 10:43:35 +00:00
2015-08-27 10:48:35 +00:00
#ifdef HAVE_MENU
2015-12-05 12:49:22 +00:00
if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL))
2015-08-27 10:48:35 +00:00
{
2016-02-10 19:13:12 +00:00
menu_ctx_iterate_t iter;
2016-05-08 04:34:25 +00:00
bool focused = runloop_is_focused() &&
!ui_companion_is_on_foreground();
bool is_idle = runloop_ctl(RUNLOOP_CTL_IS_IDLE, NULL);
enum menu_action action = (enum menu_action)
menu_input_frame_retropad(cmd.state[0], cmd.state[2]);
2015-11-28 14:03:59 +00:00
2016-02-10 19:13:12 +00:00
iter.action = action;
2016-02-12 06:49:49 +00:00
if (!menu_driver_ctl(RARCH_MENU_CTL_ITERATE, &iter))
rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL);
2015-11-28 02:22:20 +00:00
if (focused || !is_idle)
menu_driver_ctl(RARCH_MENU_CTL_RENDER, NULL);
if (!focused || is_idle)
{
*sleep_ms = 10;
return 1;
}
2015-11-28 02:22:20 +00:00
if (!settings->menu.throttle_framerate)
{
if (!settings->fastforward_ratio)
return 0;
}
2015-09-26 19:03:38 +00:00
goto end;
2015-08-27 10:48:35 +00:00
}
#endif
2016-05-08 05:00:28 +00:00
if (!runloop_check_state(&cmd, &runloop_shader_dir))
{
/* RetroArch has been paused. */
2016-05-07 23:33:57 +00:00
core_poll();
*sleep_ms = 10;
return 1;
}
#if defined(HAVE_THREADS)
2016-05-09 06:17:35 +00:00
autosave_lock();
#endif
#ifdef HAVE_NETPLAY
netplay_driver_ctl(RARCH_NETPLAY_CTL_PRE_FRAME, NULL);
#endif
2015-11-30 23:04:04 +00:00
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
2015-11-30 23:16:48 +00:00
bsv_movie_ctl(BSV_MOVIE_CTL_SET_FRAME_START, NULL);
camera_driver_ctl(RARCH_CAMERA_CTL_POLL, NULL);
/* Update binds for analog dpad modes. */
2015-03-20 18:48:23 +00:00
for (i = 0; i < settings->input.max_users; i++)
{
2015-03-20 18:48:23 +00:00
if (!settings->input.analog_dpad_mode[i])
continue;
2015-03-20 18:48:23 +00:00
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) &&
2016-05-08 21:12:04 +00:00
!input_driver_is_nonblock_state())
2015-09-22 16:55:14 +00:00
retro_sleep(settings->video.frame_delay);
2016-05-07 23:33:57 +00:00
core_run();
#ifdef HAVE_CHEEVOS
cheevos_test();
#endif
2015-03-20 18:48:23 +00:00
for (i = 0; i < settings->input.max_users; i++)
{
2015-03-20 18:48:23 +00:00
if (!settings->input.analog_dpad_mode[i])
continue;
2015-03-20 18:48:23 +00:00
input_pop_analog_dpad(settings->input.binds[i]);
input_pop_analog_dpad(settings->input.autoconf_binds[i]);
}
2015-11-30 23:04:04 +00:00
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
2015-11-30 23:16:48 +00:00
bsv_movie_ctl(BSV_MOVIE_CTL_SET_FRAME_END, NULL);
#ifdef HAVE_NETPLAY
netplay_driver_ctl(RARCH_NETPLAY_CTL_POST_FRAME, NULL);
#endif
#if defined(HAVE_THREADS)
2016-05-09 06:17:35 +00:00
autosave_unlock();
#endif
if (!settings->fastforward_ratio)
return 0;
#ifdef HAVE_MENU
2015-09-26 19:03:38 +00:00
end:
#endif
2015-09-26 19:03:38 +00:00
2016-05-10 07:17:04 +00:00
current = cpu_features_get_time_usec();
2016-01-26 04:44:21 +00:00
target = frame_limit_last_time +
frame_limit_minimum_time;
2015-09-26 19:03:38 +00:00
to_sleep_ms = (target - current) / 1000;
if (to_sleep_ms > 0)
{
*sleep_ms = (unsigned)to_sleep_ms;
/* Combat jitter a bit. */
frame_limit_last_time += frame_limit_minimum_time;
return 1;
}
2016-05-10 07:17:04 +00:00
frame_limit_last_time = cpu_features_get_time_usec();
2015-09-26 19:03:38 +00:00
return 0;
}