11#include <emscripten.h>
12#include <emscripten/html5.h>
16EM_JS(
float, js_GetViewportWidth, (
void), {
17 return document.documentElement.clientWidth
19EM_JS(
float, js_GetViewportHeight, (
void), {
20 return document.documentElement.clientHeight
22static EM_BOOL
em_on_resize(
int etype,
const EmscriptenUiEvent *event,
void *UData)
38#ifdef WASM_USER_ADJUSTABLE
39EM_JS(
char *, js_listfiles, (
const char *directory), {
40 if(UTF8ToString(directory) ==
"")
42 console.log(
"listing cwd");
43 return stringToNewUTF8(FS.readdir(FS.cwd()).toString());
48 return stringToNewUTF8(FS.readdir(UTF8ToString(directory)).toString());
52 return stringToNewUTF8(
"directory not found");
63EM_JS(
char *, js_upload, (
const char *todirectory), {
64 if (UTF8ToString(todirectory).slice(-1) !=
"/")
66 currentname = UTF8ToString(todirectory) +
"/";
70 currentname = UTF8ToString(todirectory);
73 file_selector.click();
74 return stringToNewUTF8(
"Upload started");
84EM_JS(
char *, js_rm, (
const char *path), {
85 const mode = FS.lookupPath(UTF8ToString(path)).node.mode;
89 FS.unlink(UTF8ToString(path));
90 return stringToNewUTF8(
"File removed");
93 return stringToNewUTF8(UTF8ToString(path)+
" is not a File.");
107EM_JS(
char *, js_rmdir, (
const char *path), {
108 const mode = FS.lookupPath(UTF8ToString(path)).node.mode;
113 FS.rmdir(UTF8ToString(path));
117 return stringToNewUTF8(
"Unable to remove directory. Is it not empty?");
119 return stringToNewUTF8(
"Directory removed");
122 return stringToNewUTF8(UTF8ToString(path)+
" is not a directory.");
136EM_JS(
char *, js_mkd, (
const char *path), {
139 FS.mkdir(UTF8ToString(path));
143 return stringToNewUTF8(
"Unable to create directory. Does it already exist?");
145 return stringToNewUTF8(UTF8ToString(path)+
" directory was created.");
159EM_JS(
char *, js_move, (
const char *oldpath,
const char *newpath), {
162 FS.rename(UTF8ToString(oldpath),UTF8ToString(newpath))
166 return stringToNewUTF8(
"unable to move.");
168 return stringToNewUTF8(
"File Moved");
185 Con_Printf(
"Not Enough Arguments (Expected URL and subprotocol)\n");
191 Con_Printf(
"subprotocol must be either binary or text\n");
196EM_JS(
bool, js_syncFS, (
bool populate), {
197 FS.syncfs(populate, function(err) {
200 alert(
"FileSystem Save Error: " + err);
204 alert(
"Filesystem Saved!");
226 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title,
string,
NULL);
245EM_JS(
char *, js_getclipboard, (
void), {
246 return stringToNewUTF8(
"clipboard access requires JSPI which is not currently enabled.");
254 cliptext = js_getclipboard();
255 if (cliptext !=
NULL) {
269 Sys_Error(
"SDL_Init failed: %s\n", SDL_GetError());
276 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, EM_FALSE,
em_on_resize);
281#ifdef WASM_USER_ADJUSTABLE
282 Cmd_AddCommand(
CF_SHARED,
"em_ls", em_listfiles_f,
"Lists Files in specified directory defaulting to the current working directory (Emscripten Only)");
283 Cmd_AddCommand(
CF_SHARED,
"em_upload", em_upload_f,
"Upload file to specified directory defaulting to basedir (Emscripten Only)");
285 Cmd_AddCommand(
CF_SHARED,
"em_rmdir", em_rmdir_f,
"Remove a directory from game Filesystem (Emscripten Only)");
296 return SDL_GetTicks();
301 SDL_Delay(milliseconds);
void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description)
called by the init functions of other parts of the program to register commands and functions to call...
static int Cmd_Argc(cmd_state_t *cmd)
static const char * Cmd_Argv(cmd_state_t *cmd, int arg)
Cmd_Argv(cmd, ) will return an empty string (not a NULL) if arg > argc, so string operations are alwa...
#define dp_strlcpy(dst, src, dsize)
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
void Cvar_SetValueQuick(cvar_t *var, float value)
void Cvar_SetQuick(cvar_t *var, const char *value)
char fs_basedir[MAX_OSPATH]
GLsizeiptr const GLvoid * data
#define MAX_INPUTLINE
maximum size of console commandline, QuakeC strings, and many other text processing buffers
command interpreter state - the tokenizing and execution of commands, as well as pointers to which cv...
void Sys_Error(const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
Causes the entire program to exit ASAP.
int Sys_Main(int argc, char *argv[])
main() but renamed so we can wrap it in sys_sdl.c and sys_null.c to avoid needing to include SDL....
int Sys_CheckParm(const char *parm)
static qbool nocrashdialog
unsigned int Sys_SDL_GetTicks(void)
void Sys_SDL_Dialog(const char *title, const char *string)
char * Sys_SDL_GetClipboardData(void)
void Sys_SDL_Shutdown(void)
INFO: This is only called by Host_Shutdown so we dont need testing for recursion.
void Sys_SDL_Delay(unsigned int milliseconds)
static EM_BOOL em_on_resize(int etype, const EmscriptenUiEvent *event, void *UData)
static void em_savefs_f(cmd_state_t *cmd)
EM_JS(float, js_GetViewportWidth,(void), { return document.documentElement.clientWidth })
void Sys_EM_Register_Commands(void)
qbool sys_supportsdlgetticks