2015-08-07 17:49:49 +00:00
# include "quakedef.h"
# ifdef MULTITHREAD
# include <SDL_thread.h>
# endif
# include <SDL_loadso.h>
# include <emscripten/emscripten.h>
# include "ftejslib.h"
# ifndef isDedicated
qboolean isDedicated ;
# endif
quakeparms_t parms ;
void Sys_Error ( const char * error , . . . )
{
va_list argptr ;
char string [ 1024 ] ;
va_start ( argptr , error ) ;
vsnprintf ( string , sizeof ( string ) , error , argptr ) ;
va_end ( argptr ) ;
2019-03-12 06:41:52 +00:00
COM_WorkerAbort ( string ) ;
2015-08-07 17:49:49 +00:00
Sys_Printf ( " Error: %s \n " , string ) ;
Con_Print ( " Quake Error: " ) ;
Con_Print ( string ) ;
Con_Print ( " \n " ) ;
Host_Shutdown ( ) ;
emscriptenfte_alert ( string ) ;
2021-10-22 22:27:58 +00:00
emscriptenfte_abortmainloop ( " Sys_Error " , true ) ;
2015-08-07 17:49:49 +00:00
exit ( 1 ) ;
}
void Sys_RecentServer ( char * command , char * target , char * title , char * desc )
{
}
qboolean Sys_RandomBytes ( qbyte * string , int len )
{
return false ;
}
//print into stdout
void Sys_Printf ( char * fmt , . . . )
{
va_list argptr ;
char buf [ 1024 ] ;
va_start ( argptr , fmt ) ;
vsnprintf ( buf , sizeof ( buf ) , fmt , argptr ) ;
emscriptenfte_print ( buf ) ;
va_end ( argptr ) ;
}
2021-10-12 04:41:49 +00:00
# if 1
//use Performance.now() instead of Date.now() - its likely to both provide higher precision and no NTP/etc issues.
double Sys_DoubleTime ( void )
{
double t = emscriptenfte_uptime_ms ( ) / 1000 ; //we need it as seconds...
static double old = - 99999999 ;
if ( t < old )
t = old ; //don't let t step backwards, ever. this shouldn't happen, but some CPUs don't keep their high-precision timers synced properly.
return old = t ;
}
unsigned int Sys_Milliseconds ( void )
{
return Sys_DoubleTime ( ) * ( uint64_t ) 1000 ;
}
# else
2015-08-07 17:49:49 +00:00
unsigned int Sys_Milliseconds ( void )
{
static int first = true ;
static unsigned long oldtime = 0 , curtime = 0 ;
unsigned long newtime ;
newtime = emscriptenfte_ticks_ms ( ) ; //return Date.now()
if ( first )
{
first = false ;
oldtime = newtime ;
}
if ( newtime < oldtime )
Con_Printf ( " Sys_Milliseconds stepped backwards! \n " ) ;
else
curtime + = newtime - oldtime ;
oldtime = newtime ;
return curtime ;
}
//return the current time, in the form of a double
double Sys_DoubleTime ( void )
{
return Sys_Milliseconds ( ) / 1000.0 ;
}
2021-10-12 04:41:49 +00:00
# endif
2015-08-07 17:49:49 +00:00
//create a directory
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
void Sys_mkdir ( const char * path )
2015-08-07 17:49:49 +00:00
{
}
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
qboolean Sys_rmdir ( const char * path )
{
return true ;
}
2015-08-07 17:49:49 +00:00
//unlink a file
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
qboolean Sys_remove ( const char * path )
2015-08-07 17:49:49 +00:00
{
emscriptenfte_buf_delete ( path ) ;
return true ;
}
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
qboolean Sys_Rename ( const char * oldfname , const char * newfname )
2015-08-07 17:49:49 +00:00
{
return emscriptenfte_buf_rename ( oldfname , newfname ) ;
2019-04-17 19:57:26 +00:00
}
qboolean Sys_GetFreeDiskSpace ( const char * path , quint64_t * freespace )
{ //not implemented. we could try querying local storage quotas, but our filesystem is otherwise purely ram so doesn't have much of a limit in 64bit browsers. hurrah for swap space.
2015-08-07 17:49:49 +00:00
return false ;
}
//someone used the 'quit' command
# include "glquake.h"
void Sys_Quit ( void )
{
if ( host_initialized )
{
qglClearColor ( 0 , 0 , 0 , 1 ) ;
qglClear ( GL_COLOR_BUFFER_BIT ) ;
Draw_FunString ( 0 , 0 , " Reload the page to restart " ) ;
Host_Shutdown ( ) ;
}
exit ( 0 ) ;
}
2021-10-22 22:27:58 +00:00
struct enumctx_s
{
char name [ MAX_OSPATH ] ;
const char * gpath ;
size_t gpathlen ;
const char * match ;
int ( * callback ) ( const char * , qofs_t , time_t mtime , void * , searchpathfuncs_t * ) ;
void * ctx ;
searchpathfuncs_t * spath ;
int ret ;
} ;
static void Sys_EnumeratedFile ( void * vctx , size_t fsize )
{ //called for each enumerated file.
//we don't need the whole EnumerateFiles2 thing as our filesystem is flat, so */* isn't an issue for us (we don't expect a lot of different 'files' if only because they're a pain to download).
struct enumctx_s * ctx = vctx ;
if ( ! ctx - > ret )
return ; //we're meant to stop when if it returns false...
if ( ! strncmp ( ctx - > name , ctx - > gpath , ctx - > gpathlen ) ) //ignore any gamedir prefix
if ( wildcmp ( ctx - > match , ctx - > name + ctx - > gpathlen ) ) //match it within the searched gamedir...
ctx - > ret = ctx - > callback ( ctx - > name + ctx - > gpathlen , fsize , 0 , ctx - > ctx , ctx - > spath ) ; //call the callback
}
2015-08-07 17:49:49 +00:00
int Sys_EnumerateFiles ( const char * gpath , const char * match , int ( * func ) ( const char * , qofs_t , time_t mtime , void * , searchpathfuncs_t * ) , void * parm , searchpathfuncs_t * spath )
{
2021-10-22 22:27:58 +00:00
struct enumctx_s ctx ;
char tmp [ MAX_OSPATH ] ;
if ( ! gpath )
gpath = " " ;
ctx . gpathlen = strlen ( gpath ) ;
if ( ctx . gpathlen & & gpath [ ctx . gpathlen - 1 ] ! = ' / ' )
{ //make sure gpath is /-terminated.
if ( ctx . gpathlen > = sizeof ( tmp ) - 1 )
return false ; //just no...
Q_strncpyz ( tmp , gpath , sizeof ( tmp ) ) ;
gpath = tmp ;
tmp [ ctx . gpathlen + + ] = ' / ' ;
}
ctx . gpath = gpath ;
ctx . match = match ;
ctx . callback = func ;
ctx . ctx = parm ;
ctx . spath = spath ;
ctx . ret = true ;
emscritenfte_buf_enumerate ( Sys_EnumeratedFile , & ctx , sizeof ( ctx . name ) ) ;
return ctx . ret ;
2015-08-07 17:49:49 +00:00
}
//blink window if possible (it's not)
void Sys_ServerActivity ( void )
{
}
void Sys_CloseLibrary ( dllhandle_t * lib )
{
}
dllhandle_t * Sys_LoadLibrary ( const char * name , dllfunction_t * funcs )
{
return NULL ;
}
void * Sys_GetAddressForName ( dllhandle_t * module , const char * exportname )
{
return NULL ;
}
2016-07-15 12:26:24 +00:00
void Sys_BrowserRedirect_f ( void )
{
emscriptenfte_window_location ( Cmd_Argv ( 1 ) ) ;
}
2015-08-07 17:49:49 +00:00
2021-08-19 06:01:42 +00:00
char * Sys_URIScheme_NeedsRegistering ( void )
{ //just disables the prompts that we can't honour anyway.
return NULL ;
}
2015-08-07 17:49:49 +00:00
void Sys_Init ( void )
{
extern cvar_t vid_width , vid_height , vid_fullscreen ;
//vid_fullscreen takes effect only on mouse clicks, any suggestion to do a vid_restart is pointless.
2018-01-22 19:18:04 +00:00
vid_fullscreen . flags & = ~ CVAR_VIDEOLATCH ;
2015-08-07 17:49:49 +00:00
//these are not really supported. so silence any spam that suggests we do something about something not even supported.
2018-01-22 19:18:04 +00:00
vid_width . flags & = ~ CVAR_VIDEOLATCH ;
vid_height . flags & = ~ CVAR_VIDEOLATCH ;
2016-07-15 12:26:24 +00:00
Cmd_AddCommand ( " sys_browserredirect " , Sys_BrowserRedirect_f ) ;
2015-08-07 17:49:49 +00:00
}
void Sys_Shutdown ( void )
{
}
int VARGS Sys_DebugLog ( char * file , char * fmt , . . . )
{
return 0 ;
} ;
qboolean Sys_InitTerminal ( void )
{
return true ;
}
char * Sys_ConsoleInput ( void )
{
return NULL ;
}
void Sys_CloseTerminal ( void )
{
}
2021-10-12 04:41:49 +00:00
int Sys_MainLoop ( double newtime )
2015-08-07 17:49:49 +00:00
{
extern cvar_t vid_vsync ;
2021-10-12 04:41:49 +00:00
static double oldtime ;
double time ;
if ( newtime )
newtime / = 1000 ; //use RAF's timing for slightly greater precision.
else
newtime = Sys_DoubleTime ( ) ; //otherwise fall back on internally consistent timing...
if ( newtime < oldtime )
newtime = oldtime ; //don't let ourselves go backwards...
2015-08-07 17:49:49 +00:00
if ( ! oldtime )
oldtime = newtime ;
time = newtime - oldtime ;
if ( ! host_initialized )
{
Sys_Printf ( " Host_Init \n " ) ;
Host_Init ( & parms ) ;
return 1 ;
}
oldtime = newtime ;
Host_Frame ( time ) ;
return vid_vsync . ival ;
}
int QDECL main ( int argc , char * * argv )
{
memset ( & parms , 0 , sizeof ( parms ) ) ;
parms . basedir = " " ;
parms . argc = argc ;
parms . argv = ( const char * * ) argv ;
2017-04-18 11:12:17 +00:00
# ifdef CONFIG_MANIFEST_TEXT
parms . manifest = CONFIG_MANIFEST_TEXT ;
# endif
2015-08-07 17:49:49 +00:00
COM_InitArgv ( parms . argc , parms . argv ) ;
TL_InitLanguages ( " " ) ;
emscriptenfte_setupmainloop ( Sys_MainLoop ) ;
return 0 ;
}
qboolean Sys_GetDesktopParameters ( int * width , int * height , int * bpp , int * refreshrate )
{
return false ;
}
2019-03-23 07:06:37 +00:00
# ifdef WEBCLIENT
qboolean Sys_RunInstaller ( void )
{ //not implemented
return false ;
}
# endif
2015-08-07 17:49:49 +00:00
2018-10-11 10:31:23 +00:00
# define SYS_CLIPBOARD_SIZE 256
2015-08-07 17:49:49 +00:00
static char * clipboard_buffer ;
2020-07-14 01:16:20 +00:00
void Sys_Clipboard_PasteText ( clipboardtype_t cbt , void ( * callback ) ( void * cb , const char * utf8 ) , void * ctx )
2015-08-07 17:49:49 +00:00
{
2018-10-11 10:31:23 +00:00
callback ( ctx , clipboard_buffer ) ;
2015-08-07 17:49:49 +00:00
}
2018-12-06 04:55:35 +00:00
void Sys_SaveClipboard ( clipboardtype_t cbt , const char * text )
2015-08-07 17:49:49 +00:00
{
free ( clipboard_buffer ) ;
clipboard_buffer = strdup ( text ) ;
}
# ifdef MULTITHREAD
/* Thread creation calls */
void * Sys_CreateThread ( char * name , int ( * func ) ( void * ) , void * args , int priority , int stacksize )
{
// SDL threads do not support setting thread stack size
return ( void * ) SDL_CreateThread ( func , args ) ;
}
void Sys_WaitOnThread ( void * thread )
{
SDL_WaitThread ( ( SDL_Thread * ) thread , NULL ) ;
}
/* Mutex calls */
// SDL mutexes don't have try-locks for mutexes in the spec so we stick with 1-value semaphores
void * Sys_CreateMutex ( void )
{
return ( void * ) SDL_CreateSemaphore ( 1 ) ;
}
qboolean Sys_TryLockMutex ( void * mutex )
{
return ! SDL_SemTryWait ( mutex ) ;
}
qboolean Sys_LockMutex ( void * mutex )
{
return ! SDL_SemWait ( mutex ) ;
}
qboolean Sys_UnlockMutex ( void * mutex )
{
return ! SDL_SemPost ( mutex ) ;
}
void Sys_DestroyMutex ( void * mutex )
{
SDL_DestroySemaphore ( mutex ) ;
}
/* Conditional wait calls */
typedef struct condvar_s
{
SDL_mutex * mutex ;
SDL_cond * cond ;
} condvar_t ;
void * Sys_CreateConditional ( void )
{
condvar_t * condv ;
SDL_mutex * mutex ;
SDL_cond * cond ;
condv = ( condvar_t * ) malloc ( sizeof ( condvar_t ) ) ;
if ( ! condv )
return NULL ;
mutex = SDL_CreateMutex ( ) ;
cond = SDL_CreateCond ( ) ;
if ( mutex )
{
if ( cond )
{
condv - > cond = cond ;
condv - > mutex = mutex ;
return ( void * ) condv ;
}
else
SDL_DestroyMutex ( mutex ) ;
}
free ( condv ) ;
return NULL ;
}
qboolean Sys_LockConditional ( void * condv )
{
return ! SDL_mutexP ( ( ( condvar_t * ) condv ) - > mutex ) ;
}
qboolean Sys_UnlockConditional ( void * condv )
{
return ! SDL_mutexV ( ( ( condvar_t * ) condv ) - > mutex ) ;
}
qboolean Sys_ConditionWait ( void * condv )
{
return ! SDL_CondWait ( ( ( condvar_t * ) condv ) - > cond , ( ( condvar_t * ) condv ) - > mutex ) ;
}
qboolean Sys_ConditionSignal ( void * condv )
{
return ! SDL_CondSignal ( ( ( condvar_t * ) condv ) - > cond ) ;
}
qboolean Sys_ConditionBroadcast ( void * condv )
{
return ! SDL_CondBroadcast ( ( ( condvar_t * ) condv ) - > cond ) ;
}
void Sys_DestroyConditional ( void * condv )
{
condvar_t * cv = ( condvar_t * ) condv ;
SDL_DestroyCond ( cv - > cond ) ;
SDL_DestroyMutex ( cv - > mutex ) ;
free ( cv ) ;
}
# endif
void Sys_Sleep ( double seconds )
{
2021-10-22 22:27:58 +00:00
//SDL_Delay(seconds * 1000);
2015-08-07 17:49:49 +00:00
}