RetroArch/frontend/drivers/platform_emscripten.c

212 lines
8.5 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
2017-01-22 13:40:32 +01:00
* Copyright (C) 2011-2017 - 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>
2018-01-14 02:33:22 -06:00
#include <emscripten/html5.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 <file/file_path.h>
2017-05-23 20:45:14 +02:00
#include <string/stdstring.h>
2017-06-28 04:41:38 +02:00
#include <retro_timers.h>
#include <gfx/video_frame.h>
#include <glsym/glsym.h>
2016-09-11 14:54:34 +02:00
#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 "../../verbosity.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"
2020-11-20 03:55:55 +01:00
#include "../../paths.h"
2016-08-28 22:54:00 -05:00
void dummyErrnoCodes(void);
2020-07-09 07:46:40 +02:00
void emscripten_mainloop(void);
void cmd_savefiles(void)
{
2020-02-01 03:27:58 +01:00
command_event(CMD_EVENT_SAVE_FILES, NULL);
}
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;
unsigned i;
2016-08-28 22:50:56 -05:00
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.dirs[DEFAULT_DIR_CORE], base_path,
"cores", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE]));
2016-08-28 22:50:56 -05:00
/* bundle data */
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_ASSETS], base_path,
"bundle/assets", sizeof(g_defaults.dirs[DEFAULT_DIR_ASSETS]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_AUTOCONFIG], base_path,
"bundle/autoconfig", sizeof(g_defaults.dirs[DEFAULT_DIR_AUTOCONFIG]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CURSOR], base_path,
"bundle/database/cursors", sizeof(g_defaults.dirs[DEFAULT_DIR_CURSOR]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_DATABASE], base_path,
"bundle/database/rdb", sizeof(g_defaults.dirs[DEFAULT_DIR_DATABASE]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], base_path,
"bundle/info", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_OVERLAY], base_path,
"bundle/overlays", sizeof(g_defaults.dirs[DEFAULT_DIR_OVERLAY]));
2019-04-16 17:41:06 +01:00
#ifdef HAVE_VIDEO_LAYOUT
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_VIDEO_LAYOUT], base_path,
"bundle/layouts", sizeof(g_defaults.dirs[DEFAULT_DIR_VIDEO_LAYOUT]));
#endif
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SHADER], base_path,
"bundle/shaders", sizeof(g_defaults.dirs[DEFAULT_DIR_SHADER]));
2021-01-06 13:04:38 +00:00
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_AUDIO_FILTER], base_path,
"bundle/filters/audio", sizeof(g_defaults.dirs[DEFAULT_DIR_AUDIO_FILTER]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_VIDEO_FILTER], base_path,
"bundle/filters/video", sizeof(g_defaults.dirs[DEFAULT_DIR_VIDEO_FILTER]));
2016-09-07 20:09:06 -05:00
/* user data dirs */
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CHEATS], user_path,
"cheats", sizeof(g_defaults.dirs[DEFAULT_DIR_CHEATS]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG], user_path,
"config", sizeof(g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_MENU_CONTENT], user_path,
"content", sizeof(g_defaults.dirs[DEFAULT_DIR_MENU_CONTENT]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_ASSETS], user_path,
"content/downloads", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_ASSETS]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_PLAYLIST], user_path,
"playlists", sizeof(g_defaults.dirs[DEFAULT_DIR_PLAYLIST]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_REMAP], g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG],
"remaps", sizeof(g_defaults.dirs[DEFAULT_DIR_REMAP]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SRAM], user_path,
"saves", sizeof(g_defaults.dirs[DEFAULT_DIR_SRAM]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SCREENSHOT], user_path,
"screenshots", sizeof(g_defaults.dirs[DEFAULT_DIR_SCREENSHOT]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SAVESTATE], user_path,
"states", sizeof(g_defaults.dirs[DEFAULT_DIR_SAVESTATE]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SYSTEM], user_path,
"system", sizeof(g_defaults.dirs[DEFAULT_DIR_SYSTEM]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_THUMBNAILS], user_path,
"thumbnails", sizeof(g_defaults.dirs[DEFAULT_DIR_THUMBNAILS]));
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_LOGS], user_path,
"logs", sizeof(g_defaults.dirs[DEFAULT_DIR_LOGS]));
2016-08-28 23:49:49 -05:00
2016-09-07 20:09:06 -05:00
/* cache dir */
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CACHE], "/tmp/",
"retroarch", sizeof(g_defaults.dirs[DEFAULT_DIR_CACHE]));
2016-09-07 20:09:06 -05:00
/* history and main config */
strlcpy(g_defaults.dirs[DEFAULT_DIR_CONTENT_HISTORY],
user_path, sizeof(g_defaults.dirs[DEFAULT_DIR_CONTENT_HISTORY]));
2020-08-16 04:38:02 +02:00
fill_pathname_join(g_defaults.path_config, user_path,
2020-08-22 01:06:10 +02:00
FILE_PATH_MAIN_CONFIG, sizeof(g_defaults.path_config));
2020-11-20 03:55:55 +01:00
#ifndef IS_SALAMANDER
2020-11-20 03:55:55 +01:00
dir_check_defaults("custom.ini");
#endif
2016-08-28 22:50:56 -05:00
}
2014-06-18 20:31:41 -04:00
int main(int argc, char *argv[])
{
dummyErrnoCodes();
2018-01-14 02:33:22 -06:00
emscripten_set_canvas_element_size("#canvas", 800, 600);
emscripten_set_element_css_size("#canvas", 800.0, 600.0);
emscripten_set_main_loop(emscripten_mainloop, 0, 0);
2015-04-20 21:31:25 +02:00
rarch_main(argc, argv, NULL);
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_total_mem */
NULL, /* get_free_mem */
NULL, /* install_sighandlers */
NULL, /* get_signal_handler_state */
NULL, /* set_signal_handler_state */
NULL, /* destroy_signal_handler_state */
NULL, /* attach_console */
NULL, /* detach_console */
NULL, /* get_lakka_version */
NULL, /* set_screen_brightness */
NULL, /* watch_path_for_changes */
NULL, /* check_for_path_changes */
NULL, /* set_sustained_performance_mode */
NULL, /* get_cpu_model_name */
NULL, /* get_user_language */
NULL, /* is_narrator_running */
NULL, /* accessibility_speak */
"emscripten", /* ident */
NULL /* get_video_driver */
};