}
-extern qboolean host_shuttingdown;
void Sys_Quit (int returnvalue)
{
// Unlock mutexes because the quit command may jump directly here, causing a deadlock
- if (cmd_client.text_lock)
- Cbuf_Unlock(&cmd_client);
- if (cmd_server.text_lock)
- Cbuf_Unlock(&cmd_server);
+ if ((&cmd_client)->cbuf->lock)
+ Cbuf_Unlock((&cmd_client)->cbuf);
+ if ((&cmd_server)->cbuf->lock)
+ Cbuf_Unlock((&cmd_server)->cbuf);
SV_UnlockThreadMutex();
TaskQueue_Frame(true);
- if (COM_CheckParm("-profilegameonly"))
+ if (Sys_CheckParm("-profilegameonly"))
Sys_AllowProfiling(false);
- host_shuttingdown = true;
+ host.state = host_shutdown;
Host_Shutdown();
exit(returnvalue);
}
#ifdef __cplusplus
extern "C"
#endif
-void Sys_AllowProfiling(qboolean enable)
+void Sys_AllowProfiling(qbool enable)
{
#ifdef __ANDROID__
#ifdef USE_PROFILER
else
moncleanup();
#endif
-#elif defined(__linux__) || defined(__FreeBSD__)
+#elif (defined(__linux__) && (defined(__GLIBC__) || defined(__GNU_LIBRARY__))) || defined(__FreeBSD__)
extern int moncontrol(int);
moncontrol(enable);
#endif
===============================================================================
*/
-static qboolean Sys_LoadLibraryFunctions(dllhandle_t dllhandle, const dllfunction_t *fcts, qboolean complain, qboolean has_next)
+static qbool Sys_LoadLibraryFunctions(dllhandle_t dllhandle, const dllfunction_t *fcts, qbool complain, qbool has_next)
{
const dllfunction_t *func;
if(dllhandle)
return false;
}
-qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
+qbool Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts)
{
#ifdef SUPPORTDLL
const dllfunction_t *func;
#else
dllhandle = dlopen (dllnames[i], RTLD_LAZY | RTLD_GLOBAL);
#endif
- if (Sys_LoadLibraryFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(com_argv[0], '/'))))
+ if (Sys_LoadLibraryFunctions(dllhandle, fcts, true, (dllnames[i+1] != NULL) || (strrchr(sys.argv[0], '/'))))
break;
else
Sys_UnloadLibrary (&dllhandle);
// see if the names can be loaded relative to the executable path
// (this is for Mac OSX which does not check next to the executable)
- if (!dllhandle && strrchr(com_argv[0], '/'))
+ if (!dllhandle && strrchr(sys.argv[0], '/'))
{
char path[MAX_OSPATH];
- strlcpy(path, com_argv[0], sizeof(path));
+ strlcpy(path, sys.argv[0], sizeof(path));
strrchr(path, '/')[1] = 0;
for (i = 0; dllnames[i] != NULL; i++)
{
}
Con_DPrintf(" - loaded.\n");
+ Con_Printf("Loaded library \"%s\"\n", dllnames[i]);
*handle = dllhandle;
return true;
static double benchmark_time; // actually always contains an integer amount of milliseconds, will eventually "overflow"
+/*
+================
+Sys_CheckParm
+
+Returns the position (1 to argc-1) in the program's argument list
+where the given parameter apears, or 0 if not present
+================
+*/
+int Sys_CheckParm (const char *parm)
+{
+ int i;
+
+ for (i=1 ; i<sys.argc ; i++)
+ {
+ if (!sys.argv[i])
+ continue; // NEXTSTEP sometimes clears appkit vars.
+ if (!strcmp (parm,sys.argv[i]))
+ return i;
+ }
+
+ return 0;
+}
+
void Sys_Init_Commands (void)
{
Cvar_RegisterVariable(&sys_debugsleep);
{
QueryPerformanceCounter (&PerformanceCount);
- #ifdef __BORLANDC__
- timescale = 1.0 / ((double) PerformanceFreq.u.LowPart + (double) PerformanceFreq.u.HighPart * 65536.0 * 65536.0);
- return ((double) PerformanceCount.u.LowPart + (double) PerformanceCount.u.HighPart * 65536.0 * 65536.0) * timescale;
- #else
timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
return ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
- #endif
}
else
{
static const char *Sys_FindExecutableName(void)
{
#if defined(WIN32)
- return com_argv[0];
+ return sys.argv[0];
#else
static char exenamebuf[MAX_OSPATH+1];
ssize_t n = -1;
exenamebuf[n] = 0;
return exenamebuf;
}
- if(strchr(com_argv[0], '/'))
- return com_argv[0]; // possibly a relative path
+ if(strchr(sys.argv[0], '/'))
+ return sys.argv[0]; // possibly a relative path
else
- return Sys_FindInPATH(com_argv[0], '/', getenv("PATH"), ':', exenamebuf, sizeof(exenamebuf));
+ return Sys_FindInPATH(sys.argv[0], '/', getenv("PATH"), ':', exenamebuf, sizeof(exenamebuf));
#endif
}
void Sys_ProvideSelfFD(void)
{
- if(com_selffd != -1)
+ if(sys.selffd != -1)
return;
- com_selffd = FS_SysOpenFD(Sys_FindExecutableName(), "rb", false);
+ sys.selffd = FS_SysOpenFD(Sys_FindExecutableName(), "rb", false);
}
// for x86 cpus only... (x64 has SSE2_PRESENT)
static int CPUID_Features(void)
{
int features = 0;
-# if defined(__GNUC__) && defined(__i386__)
+# if defined((__GNUC__) || (__clang__) || (__TINYC__)) && defined(__i386__)
__asm__ (
" movl %%ebx,%%edi\n"
" xorl %%eax,%%eax \n"
#endif
#ifdef SSE_POSSIBLE
-qboolean Sys_HaveSSE(void)
+qbool Sys_HaveSSE(void)
{
// COMMANDLINEOPTION: SSE: -nosse disables SSE support and detection
- if(COM_CheckParm("-nosse"))
+ if(Sys_CheckParm("-nosse"))
return false;
#ifdef SSE_PRESENT
return true;
#else
// COMMANDLINEOPTION: SSE: -forcesse enables SSE support and disables detection
- if(COM_CheckParm("-forcesse") || COM_CheckParm("-forcesse2"))
+ if(Sys_CheckParm("-forcesse") || Sys_CheckParm("-forcesse2"))
return true;
if(CPUID_Features() & (1 << 25))
return true;
#endif
}
-qboolean Sys_HaveSSE2(void)
+qbool Sys_HaveSSE2(void)
{
// COMMANDLINEOPTION: SSE2: -nosse2 disables SSE2 support and detection
- if(COM_CheckParm("-nosse") || COM_CheckParm("-nosse2"))
+ if(Sys_CheckParm("-nosse") || Sys_CheckParm("-nosse2"))
return false;
#ifdef SSE2_PRESENT
return true;
#else
// COMMANDLINEOPTION: SSE2: -forcesse2 enables SSE2 support and disables detection
- if(COM_CheckParm("-forcesse2"))
+ if(Sys_CheckParm("-forcesse2"))
return true;
if((CPUID_Features() & (3 << 25)) == (3 << 25)) // SSE is 1<<25, SSE2 is 1<<26
return true;
#if defined(__linux__)
#include <sys/resource.h>
#include <errno.h>
-static int nicelevel;
-static qboolean nicepossible;
-static qboolean isnice;
+
void Sys_InitProcessNice (void)
{
struct rlimit lim;
- nicepossible = false;
- if(COM_CheckParm("-nonice"))
+ sys.nicepossible = false;
+ if(Sys_CheckParm("-nonice"))
return;
errno = 0;
- nicelevel = getpriority(PRIO_PROCESS, 0);
+ sys.nicelevel = getpriority(PRIO_PROCESS, 0);
if(errno)
{
Con_Printf("Kernel does not support reading process priority - cannot use niceness\n");
Con_Printf("Kernel does not support lowering nice level again - cannot use niceness\n");
return;
}
- if(lim.rlim_cur != RLIM_INFINITY && nicelevel < (int) (20 - lim.rlim_cur))
+ if(lim.rlim_cur != RLIM_INFINITY && sys.nicelevel < (int) (20 - lim.rlim_cur))
{
Con_Printf("Current nice level is below the soft limit - cannot use niceness\n");
return;
}
- nicepossible = true;
- isnice = false;
+ sys.nicepossible = true;
+ sys.isnice = false;
}
void Sys_MakeProcessNice (void)
{
- if(!nicepossible)
+ if(!sys.nicepossible)
return;
- if(isnice)
+ if(sys.isnice)
return;
Con_DPrintf("Process is becoming 'nice'...\n");
if(setpriority(PRIO_PROCESS, 0, 19))
- Con_Errorf("Failed to raise nice level to %d\n", 19);
- isnice = true;
+ Con_Printf(CON_ERROR "Failed to raise nice level to %d\n", 19);
+ sys.isnice = true;
}
void Sys_MakeProcessMean (void)
{
- if(!nicepossible)
+ if(!sys.nicepossible)
return;
- if(!isnice)
+ if(!sys.isnice)
return;
Con_DPrintf("Process is becoming 'mean'...\n");
- if(setpriority(PRIO_PROCESS, 0, nicelevel))
- Con_Errorf("Failed to lower nice level to %d\n", nicelevel);
- isnice = false;
+ if(setpriority(PRIO_PROCESS, 0, sys.nicelevel))
+ Con_Printf(CON_ERROR "Failed to lower nice level to %d\n", sys.nicelevel);
+ sys.isnice = false;
}
#else
void Sys_InitProcessNice (void)