DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
sys_wasm.c File Reference
#include <SDL.h>
#include "darkplaces.h"
#include "fs.h"
#include "vid.h"
#include <emscripten.h>
#include <emscripten/html5.h>
#include <string.h>
+ Include dependency graph for sys_wasm.c:

Go to the source code of this file.

Functions

 EM_JS (bool, js_syncFS,(bool populate), { FS.syncfs(populate, function(err) { if(err) { alert("FileSystem Save Error: "+err);return false;} alert("Filesystem Saved!");return true;});})
 
 EM_JS (char *, js_getclipboard,(void), { return stringToNewUTF8("clipboard access requires JSPI which is not currently enabled.");})
 
 EM_JS (float, js_GetViewportHeight,(void), { return document.documentElement.clientHeight })
 
 EM_JS (float, js_GetViewportWidth,(void), { return document.documentElement.clientWidth })
 
static EM_BOOL em_on_resize (int etype, const EmscriptenUiEvent *event, void *UData)
 
static void em_savefs_f (cmd_state_t *cmd)
 
int main (int argc, char *argv[])
 
void Sys_EM_Register_Commands (void)
 
void Sys_SDL_Delay (unsigned int milliseconds)
 
void Sys_SDL_Dialog (const char *title, const char *string)
 
char * Sys_SDL_GetClipboardData (void)
 
unsigned int Sys_SDL_GetTicks (void)
 
void Sys_SDL_Init (void)
 
void Sys_SDL_Shutdown (void)
 INFO: This is only called by Host_Shutdown so we dont need testing for recursion.
 

Variables

static qbool nocrashdialog = true
 
qbool sys_supportsdlgetticks = true
 

Function Documentation

◆ EM_JS() [1/4]

EM_JS ( bool ,
js_syncFS ,
(bool populate) ,
{ FS.syncfs(populate, function(err) { if(err) { alert("FileSystem Save Error: "+err);return false;} alert("Filesystem Saved!");return true;});}  )

◆ EM_JS() [2/4]

EM_JS ( char * ,
js_getclipboard ,
(void) ,
{ return stringToNewUTF8("clipboard access requires JSPI which is not currently enabled.");}  )

◆ EM_JS() [3/4]

EM_JS ( float ,
js_GetViewportHeight ,
(void) ,
{ return document.documentElement.clientHeight }  )

◆ EM_JS() [4/4]

EM_JS ( float ,
js_GetViewportWidth ,
(void) ,
{ return document.documentElement.clientWidth }  )

◆ em_on_resize()

static EM_BOOL em_on_resize ( int etype,
const EmscriptenUiEvent * event,
void * UData )
static

Definition at line 22 of file sys_wasm.c.

23{
25 {
26 Cvar_SetValueQuick(&vid_width, js_GetViewportWidth());
27 Cvar_SetValueQuick(&vid_height, js_GetViewportHeight());
29 }
30 return EM_FALSE;
31}
void Cvar_SetValueQuick(cvar_t *var, float value)
Definition cvar.c:473
void Cvar_SetQuick(cvar_t *var, const char *value)
Definition cvar.c:436
int integer
Definition cvar.h:73
cvar_t vid_width
Definition vid_shared.c:136
cvar_t vid_height
Definition vid_shared.c:137
cvar_t vid_resizable
Definition vid_shared.c:164
cvar_t vid_fullscreen
Definition vid_shared.c:134

References Cvar_SetQuick(), Cvar_SetValueQuick(), cvar_t::integer, vid_fullscreen, vid_height, vid_resizable, and vid_width.

Referenced by Sys_SDL_Init().

◆ em_savefs_f()

static void em_savefs_f ( cmd_state_t * cmd)
static

Definition at line 208 of file sys_wasm.c.

209{
210 Con_Printf("Saving Files\n");
211 js_syncFS(false);
212}
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514

References Con_Printf().

Referenced by Sys_EM_Register_Commands().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 304 of file sys_wasm.c.

305{
306 return Sys_Main(argc, argv);
307}
string argv(float n)
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....

References argv(), and Sys_Main().

◆ Sys_EM_Register_Commands()

void Sys_EM_Register_Commands ( void )

Definition at line 279 of file sys_wasm.c.

280{
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)");
284 Cmd_AddCommand(CF_SHARED, "em_rm", em_rm_f, "Remove a file from game Filesystem (Emscripten Only)");
285 Cmd_AddCommand(CF_SHARED, "em_rmdir", em_rmdir_f, "Remove a directory from game Filesystem (Emscripten Only)");
286 Cmd_AddCommand(CF_SHARED, "em_mkdir", em_mkdir_f, "Make a directory in game Filesystem (Emscripten Only)");
287 Cmd_AddCommand(CF_SHARED, "em_mv", em_mv_f, "Rename or Move an item in game Filesystem (Emscripten only)");
288 Cmd_AddCommand(CF_SHARED, "em_wss", em_wss_f, "Set Websocket URL and Protocol (Emscripten Only)");
289#endif
290 Cmd_AddCommand(CF_SHARED, "em_save", em_savefs_f, "Save file changes to browser (Emscripten Only)");
291}
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...
Definition cmd.c:1661
#define CF_SHARED
Definition cmd.h:67
static void em_savefs_f(cmd_state_t *cmd)
Definition sys_wasm.c:208

References CF_SHARED, Cmd_AddCommand(), and em_savefs_f().

Referenced by FS_Init_Commands().

◆ Sys_SDL_Delay()

void Sys_SDL_Delay ( unsigned int milliseconds)

Definition at line 299 of file sys_wasm.c.

300{
301 SDL_Delay(milliseconds);
302}

References Sys_Error().

Referenced by Sys_Sleep().

◆ Sys_SDL_Dialog()

void Sys_SDL_Dialog ( const char * title,
const char * string )

Definition at line 223 of file sys_wasm.c.

224{
225 if(!nocrashdialog)
226 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, string, NULL);
227}
#define NULL
Definition qtypes.h:12
static qbool nocrashdialog
Definition sys_wasm.c:222

References nocrashdialog, and NULL.

Referenced by Sys_Error(), and Sys_HandleCrash().

◆ Sys_SDL_GetClipboardData()

char * Sys_SDL_GetClipboardData ( void )

Definition at line 248 of file sys_wasm.c.

249{
250 char *data = NULL;
251 char *cliptext;
252
253 // SDL_GetClipboardText() does nothing in a browser, see above
254 cliptext = js_getclipboard();
255 if (cliptext != NULL) {
256 size_t allocsize;
257 allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1);
258 data = (char *)Z_Malloc (allocsize);
259 dp_strlcpy (data, cliptext, allocsize);
260 free(cliptext);
261 }
262
263 return data;
264}
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
GLsizeiptr const GLvoid * data
Definition glquake.h:639
#define min(A, B)
Definition mathlib.h:37
float strlen(string s)
#define MAX_INPUTLINE
maximum size of console commandline, QuakeC strings, and many other text processing buffers
Definition qdefs.h:94
#define Z_Malloc(size)
Definition zone.h:161

References data, dp_strlcpy, MAX_INPUTLINE, min, NULL, strlen(), and Z_Malloc.

Referenced by Key_Parse_CommonKeys().

◆ Sys_SDL_GetTicks()

unsigned int Sys_SDL_GetTicks ( void )

Definition at line 294 of file sys_wasm.c.

295{
296 return SDL_GetTicks();
297}

References Sys_Error().

Referenced by Sys_DirtyTime().

◆ Sys_SDL_Init()

void Sys_SDL_Init ( void )

Definition at line 266 of file sys_wasm.c.

267{
268 if (SDL_Init(0) < 0)
269 Sys_Error("SDL_Init failed: %s\n", SDL_GetError());
270
271 // we don't know which systems we'll want to init, yet...
272 // COMMANDLINEOPTION: sdl: -nocrashdialog disables "Engine Error" crash dialog boxes
273 if(!Sys_CheckParm("-nocrashdialog"))
274 nocrashdialog = false;
275
276 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 0, EM_FALSE, em_on_resize);
277}
void Sys_Error(const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
Causes the entire program to exit ASAP.
Definition sys_shared.c:724
int Sys_CheckParm(const char *parm)
Definition sys_shared.c:327
static EM_BOOL em_on_resize(int etype, const EmscriptenUiEvent *event, void *UData)
Definition sys_wasm.c:22

References em_on_resize(), nocrashdialog, Sys_CheckParm(), and Sys_Error().

Referenced by Host_Init().

◆ Sys_SDL_Shutdown()

void Sys_SDL_Shutdown ( void )

INFO: This is only called by Host_Shutdown so we dont need testing for recursion.

Definition at line 214 of file sys_wasm.c.

215{
216 js_syncFS(false);
217 SDL_Quit();
218}

Referenced by Host_Shutdown().

Variable Documentation

◆ nocrashdialog

qbool nocrashdialog = true
static

Definition at line 222 of file sys_wasm.c.

Referenced by Sys_SDL_Dialog(), and Sys_SDL_Init().

◆ sys_supportsdlgetticks

qbool sys_supportsdlgetticks = true

Definition at line 293 of file sys_wasm.c.

Referenced by Sys_DirtyTime(), Sys_Init_Commands(), and Sys_Sleep().