RetroArch/menu/menu.c

355 lines
8.9 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 16:46:50 +00:00
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* 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-06-05 16:23:06 +00:00
#include <file/file_path.h>
2015-01-10 03:53:37 +00:00
#include "menu.h"
#include "menu_display.h"
#include "menu_entry.h"
#include "menu_shader.h"
2015-06-13 17:12:10 +00:00
2014-10-28 18:54:23 +00:00
#include "../dynamic.h"
2015-06-13 17:12:10 +00:00
#include "../general.h"
2014-10-28 18:54:23 +00:00
#include "../frontend/frontend.h"
#include "../retroarch.h"
#include "../performance.h"
static void menu_environment_get(int *argc, char *argv[],
void *args, void *params_data)
{
struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*)params_data;
2015-03-21 03:43:18 +00:00
global_t *global = global_get_ptr();
2015-03-20 19:43:22 +00:00
settings_t *settings = config_get_ptr();
2015-04-14 10:56:37 +00:00
menu_handle_t *menu = menu_driver_get_ptr();
if (!wrap_args)
return;
2015-04-14 10:56:37 +00:00
wrap_args->no_content = menu->load_no_content;
2015-03-21 03:43:18 +00:00
if (!global->has_set_verbosity)
wrap_args->verbose = global->verbosity;
wrap_args->config_path = *global->config_path ? global->config_path : NULL;
wrap_args->sram_path = *global->savefile_dir ? global->savefile_dir : NULL;
wrap_args->state_path = *global->savestate_dir ? global->savestate_dir : NULL;
wrap_args->content_path = *global->fullpath ? global->fullpath : NULL;
if (!global->has_set_libretro)
2015-03-20 19:43:22 +00:00
wrap_args->libretro_path = *settings->libretro ? settings->libretro : NULL;
wrap_args->touched = true;
}
static void menu_push_to_history_playlist(void)
{
2015-03-20 19:43:22 +00:00
settings_t *settings = config_get_ptr();
2015-03-21 03:43:18 +00:00
global_t *global = global_get_ptr();
2015-03-20 19:43:22 +00:00
if (!settings->history_list_enable)
2014-10-17 02:17:28 +00:00
return;
2015-03-21 03:43:18 +00:00
if (*global->fullpath)
{
2015-06-12 22:09:09 +00:00
char tmp[PATH_MAX_LENGTH] = {0};
char str[PATH_MAX_LENGTH] = {0};
2014-09-11 23:11:14 +00:00
2015-03-21 03:43:18 +00:00
fill_pathname_base(tmp, global->fullpath, sizeof(tmp));
snprintf(str, sizeof(str), "INFO - Loading %s ...", tmp);
rarch_main_msg_queue_push(str, 1, 1, false);
}
2014-10-12 00:31:25 +00:00
content_playlist_push(g_defaults.history,
2015-03-21 03:43:18 +00:00
global->fullpath,
2015-05-25 22:12:49 +00:00
NULL,
2015-03-20 19:43:22 +00:00
settings->libretro,
2015-05-25 22:12:49 +00:00
global->menu.info.library_name,
NULL,
2015-05-25 22:12:49 +00:00
NULL);
}
2015-01-10 05:09:30 +00:00
/**
* menu_load_content:
*
* Loads content into currently selected core.
* Will also optionally push the content entry to the history playlist.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool menu_load_content(void)
{
2015-04-14 10:56:37 +00:00
menu_handle_t *menu = menu_driver_get_ptr();
2015-06-15 00:37:32 +00:00
menu_display_t *disp = menu_display_get_ptr();
2015-03-21 03:43:18 +00:00
driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
/* redraw menu frame */
2015-06-15 00:37:32 +00:00
if (disp)
disp->msg_force = true;
menu_entry_iterate(MENU_ACTION_NOOP);
menu_display_fb();
2014-08-02 22:00:41 +00:00
if (!(main_load_content(0, NULL, NULL, menu_environment_get,
driver->frontend_ctx->process_args)))
{
2015-06-12 22:09:09 +00:00
char name[PATH_MAX_LENGTH] = {0};
char msg[PATH_MAX_LENGTH] = {0};
2015-03-21 03:43:18 +00:00
fill_pathname_base(name, global->fullpath, sizeof(name));
2013-05-01 01:45:02 +00:00
snprintf(msg, sizeof(msg), "Failed to load %s.\n", name);
rarch_main_msg_queue_push(msg, 1, 90, false);
2015-06-15 00:37:32 +00:00
if (disp)
disp->msg_force = true;
return false;
}
2015-04-14 10:56:37 +00:00
menu_shader_manager_init(menu);
event_command(EVENT_CMD_HISTORY_INIT);
2015-03-22 22:17:29 +00:00
2015-04-14 10:56:37 +00:00
if (*global->fullpath || (menu && menu->load_no_content))
menu_push_to_history_playlist();
2015-03-22 22:17:29 +00:00
event_command(EVENT_CMD_VIDEO_SET_ASPECT_RATIO);
event_command(EVENT_CMD_RESUME);
2014-08-02 16:41:43 +00:00
return true;
}
void menu_common_load_content(bool persist)
{
2015-06-15 00:37:32 +00:00
menu_display_t *disp = menu_display_get_ptr();
2015-06-14 02:01:21 +00:00
menu_handle_t *menu = menu_driver_get_ptr();
menu_list_t *menu_list = menu_list_get_ptr();
if (!menu || !menu_list)
return;
event_command(persist ? EVENT_CMD_LOAD_CONTENT_PERSIST : EVENT_CMD_LOAD_CONTENT);
2015-06-14 02:01:21 +00:00
menu_list_flush_stack(menu_list, NULL, MENU_SETTINGS);
2015-06-15 00:37:32 +00:00
disp->msg_force = true;
}
2015-01-09 20:54:08 +00:00
/**
* menu_init:
* @data : Menu context handle.
*
* Create and initialize menu handle.
*
* Returns: menu handle on success, otherwise NULL.
**/
void *menu_init(const void *data)
{
2015-03-22 03:48:50 +00:00
menu_handle_t *menu = NULL;
2015-06-15 00:08:25 +00:00
menu_display_t *disp = NULL;
menu_ctx_driver_t *menu_ctx = (menu_ctx_driver_t*)data;
2015-03-22 03:48:50 +00:00
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
if (!menu_ctx)
return NULL;
2014-07-25 21:33:49 +00:00
if (!(menu = (menu_handle_t*)menu_ctx->init()))
return NULL;
2015-03-20 19:43:22 +00:00
strlcpy(settings->menu.driver, menu_ctx->ident,
sizeof(settings->menu.driver));
if (!(menu->menu_list = (menu_list_t*)menu_list_new()))
2015-02-12 18:14:10 +00:00
goto error;
2015-03-21 03:43:18 +00:00
global->core_info_current = (core_info_t*)calloc(1, sizeof(core_info_t));
if (!global->core_info_current)
2015-02-12 18:14:10 +00:00
goto error;
#ifdef HAVE_SHADER_MANAGER
2015-01-19 20:24:08 +00:00
menu->shader = (struct video_shader*)calloc(1, sizeof(struct video_shader));
2015-02-12 18:14:10 +00:00
if (!menu->shader)
goto error;
#endif
2015-06-15 00:08:25 +00:00
2015-03-22 03:48:50 +00:00
menu->push_start_screen = settings->menu_show_start_screen;
2015-03-20 19:43:22 +00:00
settings->menu_show_start_screen = false;
menu_shader_manager_init(menu);
if (!menu_display_init(menu))
2015-02-12 18:14:10 +00:00
goto error;
2015-02-10 23:40:18 +00:00
2015-06-15 00:08:25 +00:00
disp = &menu->display;
rarch_assert(disp->msg_queue = msg_queue_new(8));
2015-02-23 23:01:45 +00:00
menu_display_fb_set_dirty();
menu_driver_set_alive();
return menu;
2015-02-12 18:14:10 +00:00
error:
if (menu->menu_list)
menu_list_free(menu->menu_list);
menu->menu_list = NULL;
2015-03-21 03:43:18 +00:00
if (global->core_info_current)
free(global->core_info_current);
global->core_info_current = NULL;
2015-02-12 18:14:10 +00:00
if (menu->shader)
free(menu->shader);
menu->shader = NULL;
if (menu)
free(menu);
return NULL;
}
2015-03-22 03:42:45 +00:00
2015-01-10 05:13:12 +00:00
/**
* menu_free_list:
* @menu : Menu handle.
2015-01-10 05:13:12 +00:00
*
* Frees menu lists.
**/
2015-05-15 12:42:55 +00:00
static void menu_free_list(menu_handle_t *menu)
{
if (!menu)
return;
menu_setting_free(menu->list_settings);
menu->list_settings = NULL;
2015-06-14 13:34:05 +00:00
menu_list_free(menu->menu_list);
menu->menu_list = NULL;
}
2015-01-09 20:54:08 +00:00
/**
* menu_free:
* @menu : Menu handle.
2015-01-09 20:54:08 +00:00
*
* Frees a menu handle
**/
void menu_free(menu_handle_t *menu)
{
2015-06-13 14:47:51 +00:00
global_t *global = global_get_ptr();
2015-06-15 00:08:25 +00:00
menu_display_t *disp = menu_display_get_ptr();
2015-06-15 00:08:25 +00:00
if (!menu || !disp)
return;
2015-05-15 12:42:55 +00:00
menu_free_list(menu);
2015-05-26 02:27:21 +00:00
if (menu->playlist)
content_playlist_free(menu->playlist);
menu->playlist = NULL;
2015-06-15 00:15:46 +00:00
menu_shader_free(menu);
menu_driver_free(menu);
#ifdef HAVE_DYNAMIC
2015-03-21 03:43:18 +00:00
libretro_free_system_info(&global->menu.info);
#endif
menu_display_free(menu);
2015-02-10 23:40:18 +00:00
menu_list_free(menu->menu_list);
menu->menu_list = NULL;
event_command(EVENT_CMD_HISTORY_DEINIT);
2014-08-02 15:42:01 +00:00
2015-03-21 03:43:18 +00:00
if (global->core_info)
core_info_list_free(global->core_info);
2015-03-21 03:43:18 +00:00
if (global->core_info_current)
free(global->core_info_current);
global->core_info_current = NULL;
menu_driver_unset_alive();
free(menu);
}
2015-01-09 20:54:08 +00:00
/**
* menu_iterate:
* @input : input sample for this frame
* @old_input : input sample of the previous frame
* @trigger_input : difference' input sample - difference
* between 'input' and 'old_input'
*
* Runs RetroArch menu for one frame.
*
* Returns: 0 on success, -1 if we need to quit out of the loop.
**/
int menu_iterate(retro_input_t input,
retro_input_t old_input, retro_input_t trigger_input)
{
2015-06-13 20:57:55 +00:00
int32_t ret = 0;
unsigned action = 0;
runloop_t *runloop = rarch_main_get_ptr();
menu_handle_t *menu = menu_driver_get_ptr();
menu_input_t *menu_input = menu_input_get_ptr();
2015-03-06 15:00:46 +00:00
menu_animation_update_time(menu->animation);
2015-03-08 21:24:44 +00:00
2015-06-15 02:35:14 +00:00
menu_input->joypad.state = menu_input_frame(input, trigger_input);
2015-06-13 20:57:55 +00:00
action = menu_input->joypad.state;
2015-05-15 19:26:37 +00:00
ret = menu_entry_iterate(action);
if (menu_driver_alive() && !runloop->is_idle)
menu_display_fb();
menu_driver_set_texture();
if (ret)
return -1;
return 0;
}
2015-05-15 20:22:23 +00:00
int menu_do_refresh(unsigned action)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu || menu->nonblocking_refresh)
return -1;
if (!menu_needs_refresh())
return -1;
return menu_entry_iterate(MENU_ACTION_REFRESH);
}
2015-05-15 20:06:42 +00:00
bool menu_needs_refresh(void)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return false;
return menu->need_refresh;
}
void menu_set_refresh(void)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
menu->need_refresh = true;
}
void menu_unset_refresh(void)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
menu->need_refresh = false;
}