RetroArch/frontend/drivers/platform_emscripten.c

219 lines
7.4 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2014-01-01 01:50:59 +01:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2016-01-10 04:06:50 +01:00
* Copyright (C) 2011-2016 - Daniel De Matteis
2015-01-07 17:46:50 +01:00
* Copyright (C) 2012-2015 - Michael Lelli
*
* 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/>.
*/
#include <emscripten/emscripten.h>
2016-09-07 20:16:30 -05:00
#include <string.h>
2015-09-15 04:49:10 +02:00
2014-10-23 03:54:18 +02:00
#include <file/config_file.h>
2016-05-16 17:29:02 +02:00
#include <queues/task_queue.h>
2016-09-11 14:54:34 +02:00
#include <retro_stat.h>
#include <file/file_path.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#ifndef IS_SALAMANDER
#include <lists/file_list.h>
#endif
2015-09-15 04:49:10 +02:00
2016-09-11 14:54:34 +02:00
#include "../frontend.h"
#include "../frontend_driver.h"
2016-09-06 00:41:43 +02:00
#include "../../configuration.h"
2016-03-22 03:13:33 +01:00
#include "../../defaults.h"
#include "../../content.h"
2015-08-20 00:25:12 +02:00
#include "../../retroarch.h"
#include "../../runloop.h"
2016-05-09 20:30:47 +02:00
#include "../../command.h"
#include "../../tasks/tasks_internal.h"
2016-09-07 20:16:30 -05:00
#include "../../file_path_special.h"
2016-08-28 22:54:00 -05:00
static void emscripten_mainloop(void)
{
unsigned sleep_ms = 0;
2016-10-20 02:17:17 +02:00
event_cmd_state_t cmd;
int ret = 0;
runloop_poll(&cmd);
ret = runloop_iterate(&cmd, &sleep_ms);
if (ret == 1 && sleep_ms > 0)
2015-09-22 18:55:14 +02:00
retro_sleep(sleep_ms);
2016-05-16 17:29:02 +02:00
task_queue_ctl(TASK_QUEUE_CTL_CHECK, NULL);
if (ret != -1)
2015-01-11 06:57:35 +01:00
return;
main_exit(NULL);
exit(0);
}
void cmd_savefiles(void)
{
event_save_files();
}
void cmd_save_state(void)
{
2016-05-09 20:51:53 +02:00
command_event(CMD_EVENT_SAVE_STATE, NULL);
}
void cmd_load_state(void)
{
2016-05-09 20:51:53 +02:00
command_event(CMD_EVENT_LOAD_STATE, NULL);
}
void cmd_take_screenshot(void)
{
2016-05-09 20:51:53 +02:00
command_event(CMD_EVENT_TAKE_SCREENSHOT, NULL);
}
2016-08-28 22:50:56 -05:00
static void frontend_emscripten_get_env(int *argc, char *argv[],
void *args, void *params_data)
{
(void)args;
char base_path[PATH_MAX] = {0};
2016-09-07 20:09:06 -05:00
char user_path[PATH_MAX] = {0};
2016-08-28 22:50:56 -05:00
const char *home = getenv("HOME");
2016-09-07 20:19:51 -05:00
if (home)
2016-09-07 20:09:06 -05:00
{
2016-08-28 22:50:56 -05:00
snprintf(base_path, sizeof(base_path),
2016-09-07 20:09:06 -05:00
"%s/retroarch", home);
snprintf(user_path, sizeof(user_path),
2016-09-09 00:25:27 -05:00
"%s/retroarch/userdata", home);
2016-09-07 20:09:06 -05:00
}
2016-08-28 22:50:56 -05:00
else
2016-09-07 20:09:06 -05:00
{
2016-08-28 22:50:56 -05:00
snprintf(base_path, sizeof(base_path), "retroarch");
2016-09-09 00:25:27 -05:00
snprintf(user_path, sizeof(user_path), "retroarch/userdata");
2016-09-07 20:09:06 -05:00
}
2016-08-28 22:50:56 -05:00
fill_pathname_join(g_defaults.dir.core, base_path,
"cores", sizeof(g_defaults.dir.core));
/* bundle data */
2016-09-07 20:09:06 -05:00
fill_pathname_join(g_defaults.dir.assets, base_path,
"bundle/assets", sizeof(g_defaults.dir.assets));
fill_pathname_join(g_defaults.dir.autoconfig, base_path,
"bundle/autoconfig", sizeof(g_defaults.dir.autoconfig));
2016-08-28 22:50:56 -05:00
fill_pathname_join(g_defaults.dir.cursor, base_path,
2016-09-07 20:09:06 -05:00
"bundle/database/cursors", sizeof(g_defaults.dir.cursor));
2016-08-28 22:50:56 -05:00
fill_pathname_join(g_defaults.dir.database, base_path,
2016-09-07 20:09:06 -05:00
"bundle/database/rdb", sizeof(g_defaults.dir.database));
fill_pathname_join(g_defaults.dir.core_info, base_path,
"bundle/info", sizeof(g_defaults.dir.core_info));
fill_pathname_join(g_defaults.dir.overlay, base_path,
"bundle/overlays", sizeof(g_defaults.dir.overlay));
fill_pathname_join(g_defaults.dir.osk_overlay, base_path,
"bundle/overlays", sizeof(g_defaults.dir.osk_overlay));
2016-08-28 22:50:56 -05:00
fill_pathname_join(g_defaults.dir.shader, base_path,
2016-09-07 20:09:06 -05:00
"bundle/shaders", sizeof(g_defaults.dir.shader));
/* user data dirs */
fill_pathname_join(g_defaults.dir.cheats, user_path,
2016-08-28 22:50:56 -05:00
"cheats", sizeof(g_defaults.dir.cheats));
2016-09-07 20:09:06 -05:00
fill_pathname_join(g_defaults.dir.menu_config, user_path,
"config", sizeof(g_defaults.dir.menu_config));
fill_pathname_join(g_defaults.dir.menu_content, user_path,
"content", sizeof(g_defaults.dir.menu_content));
2016-09-07 20:09:06 -05:00
fill_pathname_join(g_defaults.dir.core_assets, user_path,
"content/downloads", sizeof(g_defaults.dir.core_assets));
2016-09-07 20:09:06 -05:00
fill_pathname_join(g_defaults.dir.playlist, user_path,
"playlists", sizeof(g_defaults.dir.playlist));
fill_pathname_join(g_defaults.dir.remap, g_defaults.dir.menu_config,
"remaps", sizeof(g_defaults.dir.remap));
fill_pathname_join(g_defaults.dir.sram, user_path,
2016-08-28 23:49:49 -05:00
"saves", sizeof(g_defaults.dir.sram));
2016-09-07 20:09:06 -05:00
fill_pathname_join(g_defaults.dir.screenshot, user_path,
"screenshots", sizeof(g_defaults.dir.screenshot));
fill_pathname_join(g_defaults.dir.savestate, user_path,
2016-08-28 23:49:49 -05:00
"states", sizeof(g_defaults.dir.savestate));
2016-09-07 20:09:06 -05:00
fill_pathname_join(g_defaults.dir.system, user_path,
"system", sizeof(g_defaults.dir.system));
fill_pathname_join(g_defaults.dir.thumbnails, user_path,
"thumbnails", sizeof(g_defaults.dir.thumbnails));
2016-08-28 23:49:49 -05:00
2016-09-07 20:09:06 -05:00
/* cache dir */
fill_pathname_join(g_defaults.dir.cache, "/tmp/",
"retroarch", sizeof(g_defaults.dir.cache));
2016-09-07 20:09:06 -05:00
/* history and main config */
2016-09-07 20:09:06 -05:00
strlcpy(g_defaults.dir.content_history,
user_path, sizeof(g_defaults.dir.content_history));
fill_pathname_join(g_defaults.path.config, user_path,
file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(g_defaults.path.config));
/* create user data dirs */
2016-09-07 20:09:06 -05:00
path_mkdir(g_defaults.dir.cheats);
path_mkdir(g_defaults.dir.core_assets);
2016-09-07 20:09:06 -05:00
path_mkdir(g_defaults.dir.menu_config);
path_mkdir(g_defaults.dir.menu_content);
path_mkdir(g_defaults.dir.playlist);
path_mkdir(g_defaults.dir.remap);
path_mkdir(g_defaults.dir.savestate);
path_mkdir(g_defaults.dir.screenshot);
path_mkdir(g_defaults.dir.sram);
path_mkdir(g_defaults.dir.system);
path_mkdir(g_defaults.dir.thumbnails);
/* create cache dir */
2016-09-07 20:09:06 -05:00
path_mkdir(g_defaults.dir.cache);
2016-08-28 23:03:49 -05:00
snprintf(g_defaults.settings.menu, sizeof(g_defaults.settings.menu), "rgui");
2016-08-28 22:50:56 -05:00
}
2014-06-18 20:31:41 -04:00
int main(int argc, char *argv[])
{
2015-03-20 22:22:06 +01:00
settings_t *settings = config_get_ptr();
emscripten_set_canvas_size(800, 600);
2015-04-20 21:31:25 +02:00
rarch_main(argc, argv, NULL);
2014-09-02 17:42:44 +02:00
emscripten_set_main_loop(emscripten_mainloop,
2015-03-20 22:22:06 +01:00
settings->video.vsync ? 0 : INT_MAX, 1);
return 0;
}
frontend_ctx_driver_t frontend_ctx_emscripten = {
2016-08-28 22:50:56 -05:00
frontend_emscripten_get_env, /* environment_get */
NULL, /* init */
NULL, /* deinit */
NULL, /* exitspawn */
NULL, /* process_args */
NULL, /* exec */
NULL, /* set_fork */
NULL, /* shutdown */
NULL, /* get_name */
NULL, /* get_os */
NULL, /* get_rating */
NULL, /* load_content */
NULL, /* get_architecture */
NULL, /* get_powerstate */
NULL, /* parse_drive_list */
NULL, /* get_mem_total */
NULL, /* get_mem_used */
NULL, /* install_sighandlers */
NULL, /* get_signal_handler_state */
NULL, /* set_signal_handler_state */
NULL, /* destroy_signal_handler_state */
NULL, /* attach_console */
NULL, /* detach_console */
"emscripten"
};