![]() |
DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
|
|
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
#include <dlfcn.h>
#include <signal.h>
#include "quakedef.h"
#include "taskqueue.h"
#include "thread.h"
#include "libcurl.h"
Go to the source code of this file.
Macros | |
#define | SUPPORTDLL |
Functions | |
void | Sys_AllowProfiling (qbool enable) |
int | Sys_CheckParm (const char *parm) |
char * | Sys_ConsoleInput (void) |
Reads a line from POSIX stdin or the Windows console. | |
double | Sys_DirtyTime (void) |
void | Sys_Error (const char *error,...) |
Causes the entire program to exit ASAP. | |
static const char * | Sys_FindExecutableName (void) |
static const char * | Sys_FindInPATH (const char *name, char namesep, const char *PATH, char pathsep, char *buf, size_t bufsize) |
static void | Sys_Frame (void) |
JS+WebGL doesn't support a main loop, only a function called to run a frame. | |
void | Sys_FreeLibrary (dllhandle_t *handle) |
void * | Sys_GetProcAddress (dllhandle_t handle, const char *name) |
static void | Sys_HandleCrash (int sig) |
Halt and try not to catch fire. | |
static void | Sys_HandleSignal (int sig) |
void | Sys_Init_Commands (void) |
called after command system is initialized but before first Con_Print | |
void | Sys_InitProcessNice (void) |
called to set process priority for dedicated servers | |
static void | Sys_InitSignals (void) |
SDL2 only handles SIGINT and SIGTERM by default and doesn't log anything. | |
qbool | Sys_LoadDependency (const char **dllnames, dllhandle_t *handle, const dllfunction_t *fcts) |
static qbool | Sys_LoadDependencyFunctions (dllhandle_t dllhandle, const dllfunction_t *fcts, qbool complain, qbool has_next) |
qbool | Sys_LoadLibrary (const char *name, dllhandle_t *handle) |
qbool | Sys_LoadSelf (dllhandle_t *handle) |
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.h in this file (would make the dedicated server require SDL). | |
void | Sys_MakeProcessMean (void) |
void | Sys_MakeProcessNice (void) |
void | Sys_Print (const char *text, size_t textlen) |
(may) output text to terminal which launched program is POSIX async-signal-safe textlen excludes any (optional) \0 terminator | |
void | Sys_Printf (const char *fmt,...) |
used to report failures inside Con_Printf() | |
void | Sys_ProvideSelfFD (void) |
static const char * | Sys_SigDesc (int sig) |
double | Sys_Sleep (double time) |
called to yield for a little bit so as not to hog cpu when paused or debugging | |
size_t | Sys_TimeString (char buf[], size_t bufsize, const char *timeformat) |
static void | Sys_UpdateOutFD_c (cvar_t *var) |
static double | Sys_UpdateTime (double newtime, double oldtime) |
Variables | |
static double | benchmark_time |
sys_t | sys |
static cvar_t | sys_debugsleep = {CF_SHARED, "sys_debugsleep", "0", "write requested and attained sleep times to standard output, to be used with gnuplot"} |
cvar_t | sys_libdir = {CF_READONLY | CF_SHARED, "sys_libdir", "", "Default engine library directory"} |
static cvar_t | sys_stdout = {CF_SHARED, "sys_stdout", "1", "0: nothing is written to stdout (-nostdout cmdline option sets this), 1: normal messages are written to stdout, 2: normal messages are written to stderr (-stderr cmdline option sets this)"} |
static cvar_t | sys_stdout_blocks = {CF_SHARED, "sys_stdout_blocks", "0", "1: writes to stdout and stderr streams will block (causing a stutter or complete halt) if the buffer is full, ensuring no messages are lost at a price"} |
cvar_t | sys_usenoclockbutbenchmark = {CF_SHARED, "sys_usenoclockbutbenchmark", "0", "don't use ANY real timing, and simulate a clock (for benchmarking); the game then runs as fast as possible. Run a QC mod with bots that does some stuff, then does a quit at the end, to benchmark a server. NEVER do this on a public server."} |
static cvar_t | sys_usesdldelay = {CF_SHARED, "sys_usesdldelay", "0", "use SDL_Delay() (low precision, for debugging)"} |
static cvar_t | sys_usesdlgetticks = {CF_SHARED, "sys_usesdlgetticks", "0", "use SDL_GetTicks() timer (low precision, for debugging)"} |
#define SUPPORTDLL |
Definition at line 7 of file sys_shared.c.
on some build/platform combinations (such as Linux gcc with the -pg profiling option) this can turn on/off profiling, used primarily to limit profiling to certain areas of the code, such as ingame performance without regard for loading/shutdown performance (-profilegameonly on commandline)
Definition at line 65 of file sys_shared.c.
Referenced by CL_DisconnectEx(), CL_SignonReply(), Host_Init(), Host_Shutdown(), Sys_Frame(), and Sys_Main().
int Sys_CheckParm | ( | const char * | parm | ) |
Definition at line 327 of file sys_shared.c.
References sys_t::argc, sys_t::argv, i, and sys.
Referenced by CDAudio_Init(), CDAudio_Startup(), CL_DisconnectEx(), CL_EstablishConnection(), CL_FinishTimeDemo(), CL_PlayVideo_f(), CL_Screen_Init(), CL_SignonReply(), CL_Startdemos_f(), CL_StopPlayback(), Cmd_Exec(), COM_InitGameType(), COM_SetGameType(), Con_Init(), Con_ToggleConsole_f(), FS_Init_Dir(), FS_Init_SelfPack(), FS_mkdir(), FS_Rescan(), FS_SysOpenFiledesc(), GL_CheckExtension(), Host_Init(), Host_InitSession(), Host_LockSession(), Host_SaveConfig(), Host_Shutdown(), Key_Event(), LibAV_LoadLibrary(), LibAvW_OpenLibrary(), MR_Init(), NetConn_Init(), OGG_OpenLibrary(), Palette_Load(), PRVM_Init(), S_Init(), S_Startup(), SV_ServerOptions(), Sys_Main(), Sys_SDL_Init(), VID_InitModeGL(), VID_Start(), XMP_LoadModFile(), and XMP_OpenLibrary().
char * Sys_ConsoleInput | ( | void | ) |
Reads a line from POSIX stdin or the Windows console.
Definition at line 667 of file sys_shared.c.
References fgets(), MAX_INPUTLINE, and NULL.
Referenced by Cbuf_Frame_Input().
double Sys_DirtyTime | ( | void | ) |
Definition at line 417 of file sys_shared.c.
References benchmark_time, Con_Printf(), Cvar_SetValueQuick(), cvar_t::integer, Sys_Error(), Sys_SDL_GetTicks(), sys_supportsdlgetticks, sys_usenoclockbutbenchmark, and sys_usesdlgetticks.
Referenced by CL_Frame(), CL_KeepaliveMessage(), CL_TimeRefresh_f(), CL_UpdateScreen(), CLVM_ExecuteProgram(), Crypto_ServerParsePacket(), Host_Init(), PRVM_CallProfile(), PRVM_Prog_Load(), R_TimeReport(), R_TimeReport_BeginFrame(), R_TimeReport_EndFrame(), SV_Frame(), SV_ThreadFunc(), SVVM_ExecuteProgram(), Sys_Frame(), Sys_Sleep(), VM_CL_R_AddDynamicLight(), VM_CL_R_AddEntities(), VM_CL_R_AddEntity(), VM_CL_R_RenderScene(), VM_gettime(), and while().
void Sys_Error | ( | const char * | error, |
... ) |
Causes the entire program to exit ASAP.
Trailing
should be omitted.
Definition at line 724 of file sys_shared.c.
References client_t::active, server_t::active, CL_Stop_f(), server_static_t::clients, cls, cmd_local, CON_ERROR, Con_Printf(), client_static_t::demorecording, dp_strlcat, dpvsnprintf(), engineversion, error(), host, host_client, host_failed, host_shutdown, i, MAX_INPUTLINE, server_static_t::maxclients, O_NONBLOCK, sys_t::outfd, S_StopAllSounds(), host_static_t::state, sv, SV_DropClient(), svs, sys, Sys_SDL_Dialog(), and VID_Shutdown().
Referenced by _Mem_Alloc(), _Mem_AllocPool(), _Mem_CheckSentinels(), _Mem_CheckSentinelsGlobal(), _Mem_EmptyPool(), _Mem_Free(), _Mem_FreeBlock(), _Mem_FreePool(), Buffer_Callback(), CL_CutDemo(), CL_ExpandEntities(), Clump_AllocBlock(), Clump_FreeBlock(), COM_ChangeGameTypeForGameDirs(), FS_SetGameDirs(), GL_InitFunctions(), GL_Setup(), Host_Error(), Host_LockSession(), M_Menu_Keys_f(), Mem_ExpandableArray_FreeRecord(), MVM_error_cmd(), PHYS_NudgeOutOfSolid(), R_BufferData_Store(), R_Mesh_TexBind(), R_Mesh_TexBound(), R_Mesh_TexCoordPointer(), R_RegisterModule(), R_SetupTexture(), R_UploadFullTexture(), R_UploadPartialTexture(), RSurf_DrawBatch(), SCR_CaptureVideo_Avi_BeginVideo(), SCR_CaptureVideo_Ogg_Interleave(), SCR_CaptureVideo_RIFF_IndexEntry(), SCR_CaptureVideo_RIFF_MakeIxChunk(), SCR_CaptureVideo_RIFF_OverflowCheck(), setuptex(), SV_SendClientMessages(), Sys_DirtyTime(), Sys_SDL_Delay(), Sys_SDL_GetTicks(), Sys_SDL_Init(), Sys_Sleep(), VID_Init(), VID_InitMode(), VID_InitModeGL(), VID_Restart_f(), VID_Start(), and VM_nudgeoutofsolid().
|
static |
Definition at line 797 of file sys_shared.c.
References sys_t::argv, MAX_OSPATH, n, NULL, sys, and Sys_FindInPATH().
Referenced by Sys_ProvideSelfFD().
|
static |
Definition at line 773 of file sys_shared.c.
References buf, dpsnprintf(), FS_SysFileExists(), and name.
Referenced by Sys_FindExecutableName().
JS+WebGL doesn't support a main loop, only a function called to run a frame.
Definition at line 1133 of file sys_shared.c.
References host_static_t::abortframe, host_static_t::dirtytime, host, host_active, Host_Frame(), Host_Shutdown(), host_shutdown, cvar_t::integer, host_static_t::realtime, host_static_t::restless, host_static_t::sleeptime, host_static_t::state, Sys_AllowProfiling(), Sys_DirtyTime(), Sys_Sleep(), Sys_UpdateTime(), time, and vid_vsync.
Referenced by Sys_Main().
void Sys_FreeLibrary | ( | dllhandle_t * | handle | ) |
Definition at line 245 of file sys_shared.c.
References NULL.
Referenced by Crypto_CloseLibrary(), Crypto_Rijndael_CloseLibrary(), CURL_CloseLibrary(), Font_CloseLibrary(), FS_Shutdown(), JPEG_CloseLibrary(), LibAV_LoadLibrary(), LibAvW_CloseLibrary(), LibAvW_OpenLibrary(), OGG_CloseLibrary(), PK3_CloseLibrary(), PNG_CloseLibrary(), PNG_OpenLibrary(), SCR_CaptureVideo_Ogg_CloseDLL(), Sys_LoadDependency(), XMP_CloseLibrary(), and XMP_OpenLibrary().
void * Sys_GetProcAddress | ( | dllhandle_t | handle, |
const char * | name ) |
Definition at line 261 of file sys_shared.c.
Referenced by Sys_LoadDependencyFunctions().
Halt and try not to catch fire.
Writing to any file could corrupt it, any uneccessary code could crash while we crash. Try to use only POSIX async-signal-safe library functions here (see: man signal-safety).
Definition at line 994 of file sys_shared.c.
References dp_strlcat, dp_strlcpy, engineversion, host, host_failed, host_failing, i, O_NONBLOCK, sys_t::outfd, S_StopAllSounds(), host_static_t::state, strlen(), sys, Sys_Print(), Sys_SDL_Dialog(), Sys_SigDesc(), and VID_Shutdown().
Referenced by Sys_InitSignals().
Definition at line 1068 of file sys_shared.c.
References host, host_failed, host_failing, host_shutdown, host_static_t::state, strlen(), Sys_Print(), and Sys_SigDesc().
Referenced by Sys_InitSignals().
called after command system is initialized but before first Con_Print
Definition at line 353 of file sys_shared.c.
References Cvar_RegisterCallback(), Cvar_RegisterVariable(), sys_debugsleep, sys_libdir, sys_stdout, sys_stdout_blocks, sys_supportsdlgetticks, Sys_UpdateOutFD_c(), sys_usenoclockbutbenchmark, sys_usesdldelay, and sys_usesdlgetticks.
Referenced by Host_Init().
called to set process priority for dedicated servers
Definition at line 955 of file sys_shared.c.
Referenced by Host_Init().
SDL2 only handles SIGINT and SIGTERM by default and doesn't log anything.
Definition at line 1090 of file sys_shared.c.
References Sys_HandleCrash(), and Sys_HandleSignal().
Referenced by Sys_Main().
qbool Sys_LoadDependency | ( | const char ** | dllnames, |
dllhandle_t * | handle, | ||
const dllfunction_t * | fcts ) |
Loads a dependency library.
dllnames | a NULL terminated array of possible names for the DLL you want to load. |
handle | |
fcts |
Definition at line 131 of file sys_shared.c.
References sys_t::argv, Con_DPrintf(), Con_Printf(), dp_strlcat, dp_strlcpy, dllfunction_t::funcvariable, i, MAX_OSPATH, dllfunction_t::name, NULL, sys, Sys_FreeLibrary(), Sys_LoadDependencyFunctions(), and Sys_LoadLibrary().
Referenced by Crypto_OpenLibrary(), Crypto_Rijndael_OpenLibrary(), CURL_OpenLibrary(), Font_OpenLibrary(), FS_ChooseUserDir(), JPEG_OpenLibrary(), LibAV_LoadLibrary(), LibAvW_OpenLibrary(), OGG_OpenLibrary(), PK3_OpenLibrary(), PNG_OpenLibrary(), SCR_CaptureVideo_Ogg_OpenLibrary(), VID_Shared_Init(), and XMP_OpenLibrary().
|
static |
Definition at line 91 of file sys_shared.c.
References Con_DPrintf(), dllfunction_t::funcvariable, dllfunction_t::name, NULL, and Sys_GetProcAddress().
Referenced by Sys_LoadDependency().
qbool Sys_LoadLibrary | ( | const char * | name, |
dllhandle_t * | handle ) |
Loads a library.
name | a string of the library filename |
handle |
Definition at line 224 of file sys_shared.c.
Referenced by Sys_LoadDependency().
qbool Sys_LoadSelf | ( | dllhandle_t * | handle | ) |
Definition at line 116 of file sys_shared.c.
References NULL.
main() but renamed so we can wrap it in sys_sdl.c and sys_null.c to avoid needing to include SDL.h in this file (would make the dedicated server require SDL).
SDL builds need SDL.h in the file where main() is defined because SDL renames and wraps main().
Definition at line 1178 of file sys_shared.c.
References sys_t::argc, argv(), sys_t::argv, Host_Init(), cvar_t::integer, O_NONBLOCK, sys_t::selffd, cvar_t::string, sys, Sys_AllowProfiling(), Sys_CheckParm(), Sys_Frame(), Sys_InitSignals(), Sys_ProvideSelfFD(), sys_stdout, Sys_UpdateOutFD_c(), and cvar_t::value.
Referenced by main().
Definition at line 961 of file sys_shared.c.
Referenced by Host_AbortCurrentFrame(), and SV_SpawnServer().
void Sys_Print | ( | const char * | text, |
size_t | textlen ) |
(may) output text to terminal which launched program is POSIX async-signal-safe textlen excludes any (optional) \0 terminator
Definition at line 615 of file sys_shared.c.
References sys_t::argv, developer, cvar_t::integer, O_NONBLOCK, sys_t::outfd, sys, and sys_stdout_blocks.
Referenced by Con_MaskPrint(), dpvsnprintf(), Sys_HandleCrash(), Sys_HandleSignal(), and Sys_Printf().
void Sys_Printf | ( | const char * | fmt, |
... ) |
used to report failures inside Con_Printf()
Definition at line 652 of file sys_shared.c.
References dpvsnprintf(), MAX_INPUTLINE, and Sys_Print().
Referenced by _Thread_AtomicAdd(), _Thread_AtomicDecRef(), _Thread_AtomicGet(), _Thread_AtomicIncRef(), _Thread_AtomicLock(), _Thread_AtomicSet(), _Thread_AtomicTryLock(), _Thread_AtomicUnlock(), _Thread_CondBroadcast(), _Thread_CondSignal(), _Thread_CondWait(), _Thread_CreateBarrier(), _Thread_CreateCond(), _Thread_CreateMutex(), _Thread_CreateThread(), _Thread_DestroyBarrier(), _Thread_DestroyCond(), _Thread_DestroyMutex(), _Thread_LockMutex(), _Thread_UnlockMutex(), _Thread_WaitBarrier(), _Thread_WaitThread(), _Thread_WaitThread(), and Con_WordWidthFunc().
Definition at line 826 of file sys_shared.c.
References FS_SysOpenFD(), sys_t::selffd, sys, and Sys_FindExecutableName().
Referenced by Sys_Main().
|
static |
Definition at line 967 of file sys_shared.c.
Referenced by Sys_HandleCrash(), and Sys_HandleSignal().
double Sys_Sleep | ( | double | time | ) |
called to yield for a little bit so as not to hog cpu when paused or debugging
Definition at line 500 of file sys_shared.c.
References benchmark_time, ca_dedicated, cls, Con_Printf(), Curl_Select(), host, cvar_t::integer, lhnet_socketlist, LHNETADDRESSTYPE_INET4, LHNETADDRESSTYPE_INET6, lhnetsocket_t::list, List_For_Each_Entry, NULL, host_static_t::restless, client_static_t::state, sv_checkforpacketsduringsleep, sys_debugsleep, Sys_DirtyTime(), Sys_Error(), Sys_SDL_Delay(), sys_supportsdlgetticks, sys_usenoclockbutbenchmark, sys_usesdldelay, and time.
Referenced by attempt_malloc(), CL_Frame(), SV_ThreadFunc(), Sys_Frame(), and TaskQueue_ThreadFunc().
size_t Sys_TimeString | ( | char | buf[], |
size_t | bufsize, | ||
const char * | timeformat ) |
Definition at line 45 of file sys_shared.c.
References buf, NULL, strlen(), time, and timeformat.
Referenced by CL_FinishTimeDemo(), CL_Locs_Save_f(), CL_ParseServerInfo(), Con_MaskPrint(), Sbar_ShowFPS(), SCR_ScreenShot_f(), and SV_SendServerinfo().
Definition at line 342 of file sys_shared.c.
References cvar_t::integer, sys_t::outfd, sys, and sys_stdout.
Referenced by Sys_Init_Commands(), and Sys_Main().
|
inlinestatic |
Definition at line 1109 of file sys_shared.c.
References Con_Printf(), CON_WARN, and time.
Referenced by Sys_Frame().
|
static |
Definition at line 317 of file sys_shared.c.
Referenced by Sys_DirtyTime(), and Sys_Sleep().
sys_t sys |
Definition at line 42 of file sys_shared.c.
Referenced by CL_FinishTimeDemo(), Cmd_StuffCmds_f(), COM_Init_Commands(), COM_InitGameType(), COM_InsertFlags(), COM_SetGameType(), Con_MaskPrint(), FS_Init_Dir(), FS_Init_SelfPack(), FS_Rescan(), Host_Error(), Host_Init(), Host_InitSession(), MVM_error_cmd(), NetConn_Init(), Palette_Load(), S_Startup(), SV_ServerOptions(), Sys_CheckParm(), Sys_Error(), Sys_FindExecutableName(), Sys_HandleCrash(), Sys_LoadDependency(), Sys_Main(), Sys_Print(), Sys_ProvideSelfFD(), Sys_UpdateOutFD_c(), VID_InitModeGL(), VID_Start(), and VM_Warning().
|
static |
Definition at line 305 of file sys_shared.c.
Referenced by Sys_Init_Commands(), and Sys_Sleep().
cvar_t sys_libdir = {CF_READONLY | CF_SHARED, "sys_libdir", "", "Default engine library directory"} |
Definition at line 302 of file sys_shared.c.
Referenced by Sys_Init_Commands().
|
static |
Definition at line 312 of file sys_shared.c.
Referenced by Sys_Init_Commands(), Sys_Main(), and Sys_UpdateOutFD_c().
|
static |
Definition at line 314 of file sys_shared.c.
Referenced by Sys_Init_Commands(), and Sys_Print().
cvar_t sys_usenoclockbutbenchmark = {CF_SHARED, "sys_usenoclockbutbenchmark", "0", "don't use ANY real timing, and simulate a clock (for benchmarking); the game then runs as fast as possible. Run a QC mod with bots that does some stuff, then does a quit at the end, to benchmark a server. NEVER do this on a public server."} |
Definition at line 301 of file sys_shared.c.
Referenced by Sys_DirtyTime(), Sys_Init_Commands(), and Sys_Sleep().
|
static |
|
static |
Definition at line 306 of file sys_shared.c.
Referenced by Sys_DirtyTime(), and Sys_Init_Commands().