DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
sys.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// sys.h -- non-portable functions
21
22#ifndef SYS_H
23#define SYS_H
24
25#include "qtypes.h"
26#include "qdefs.h"
27
28/* Preprocessor macros to identify platform
29 DP_OS_NAME - "friendly" name of the OS, for humans to read
30 DP_OS_STR - "identifier" of the OS, more suited for code to use
31 DP_ARCH_STR - "identifier" of the processor architecture
32 */
33#if defined(__ANDROID__) /* must come first because it also defines linux */
34# define DP_OS_NAME "Android"
35# define DP_OS_STR "android"
36# define USE_GLES2 1
37# define USE_RWOPS 1
38# define LINK_TO_ZLIB 1
39# define LINK_TO_LIBVORBIS 1
40#ifdef USEXMP
41# define LINK_TO_LIBXMP 1 // nyov: if someone can test with the android NDK compiled libxmp?
42#endif
43# define DP_MOBILETOUCH 1
44# define DP_FREETYPE_STATIC 1
45#elif defined(__EMSCRIPTEN__) //this also defines linux, so it must come first
46# define DP_OS_NAME "Browser"
47# define DP_OS_STR "browser"
48# define DP_ARCH_STR "WASM-32"
49#elif defined(__linux__)
50# define DP_OS_NAME "Linux"
51# define DP_OS_STR "linux"
52#elif defined(_WIN64)
53# define DP_OS_NAME "Windows64"
54# define DP_OS_STR "win64"
55#elif defined(WIN32)
56# define DP_OS_NAME "Windows"
57# define DP_OS_STR "win32"
58#elif defined(__FreeBSD__)
59# define DP_OS_NAME "FreeBSD"
60# define DP_OS_STR "freebsd"
61#elif defined(__NetBSD__)
62# define DP_OS_NAME "NetBSD"
63# define DP_OS_STR "netbsd"
64#elif defined(__OpenBSD__)
65# define DP_OS_NAME "OpenBSD"
66# define DP_OS_STR "openbsd"
67#elif defined(__DragonFly__)
68# define DP_OS_NAME "DragonFlyBSD"
69# define DP_OS_STR "dragonflybsd"
70#elif defined(__APPLE__)
71# if TARGET_OS_IPHONE
72# define DP_OS_NAME "iOS"
73# define DP_OS_STR "ios"
74# define USE_GLES2 1
75# define LINK_TO_ZLIB 1
76# define LINK_TO_LIBVORBIS 1
77# define DP_MOBILETOUCH 1
78# define DP_FREETYPE_STATIC 1
79# elif TARGET_OS_MAC
80# define DP_OS_NAME "macOS"
81# define DP_OS_STR "macos"
82# endif
83#elif defined(__MORPHOS__)
84# define DP_OS_NAME "MorphOS"
85# define DP_OS_STR "morphos"
86#elif defined (sun) || defined (__sun)
87# if defined (__SVR4) || defined (__svr4__)
88# define DP_OS_NAME "Solaris"
89# define DP_OS_STR "solaris"
90# else
91# define DP_OS_NAME "SunOS"
92# define DP_OS_STR "sunos"
93# endif
94#else
95# define DP_OS_NAME "Unknown"
96# define DP_OS_STR "unknown"
97#endif
98
99#if defined(__GNUC__) || (__clang__)
100# if defined(__i386__)
101# define DP_ARCH_STR "686"
102# define SSE_POSSIBLE
103# ifdef __SSE__
104# define SSE_PRESENT
105# endif
106# ifdef __SSE2__
107# define SSE2_PRESENT
108# endif
109# elif defined(__x86_64__)
110# define DP_ARCH_STR "x86_64"
111# define SSE_PRESENT
112# define SSE2_PRESENT
113# elif defined(__powerpc__)
114# define DP_ARCH_STR "ppc"
115# endif
116#elif defined(_WIN64)
117# define DP_ARCH_STR "x86_64"
118# define SSE_PRESENT
119# define SSE2_PRESENT
120#elif defined(WIN32)
121# define DP_ARCH_STR "x86"
122# define SSE_POSSIBLE
123#endif
124
125#ifdef SSE_PRESENT
126# define SSE_POSSIBLE
127#endif
128
129#ifdef NO_SSE
130# undef SSE_PRESENT
131# undef SSE_POSSIBLE
132# undef SSE2_PRESENT
133#endif
134
135#ifdef SSE_POSSIBLE
136// runtime detection of SSE/SSE2 capabilities for x86
137qbool Sys_HaveSSE(void);
138qbool Sys_HaveSSE2(void);
139#else
140#define Sys_HaveSSE() false
141#define Sys_HaveSSE2() false
142#endif
143
144typedef struct sys_s
145{
146 int argc;
147 const char **argv;
149 int outfd;
153} sys_t;
154
155extern sys_t sys;
156
157
158//
159// DLL management
160//
161
162// Win32 specific
163#ifdef WIN32
164# include <windows.h>
165typedef HMODULE dllhandle_t;
166
167// Other platforms
168#else
169 typedef void* dllhandle_t;
170#endif
171
172typedef struct dllfunction_s
173{
174 const char *name;
176}
178
180
186qbool Sys_LoadDependency (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts);
187
193qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle);
194
195void Sys_FreeLibrary (dllhandle_t* handle);
196void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
197
198int Sys_CheckParm (const char *parm);
199
201void Sys_Init_Commands (void);
202
203
205size_t Sys_TimeString(char buf[], size_t bufsize, const char *timeformat);
206
207//
208// system IO interface (these are the sys functions that need to be implemented in a new driver atm)
209//
210
213void Sys_Error (const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN;
214
218void Sys_Print(const char *text, size_t textlen);
220void Sys_Printf(const char *fmt, ...);
221
223void Sys_SDL_Shutdown(void);
224
230#ifdef __cplusplus
231extern "C"
232#endif
233void Sys_AllowProfiling (qbool enable);
234
235typedef struct sys_cleantime_s
236{
237 double dirtytime; // last value gotten from Sys_DirtyTime()
238 double cleantime; // sanitized linearly increasing time since app start
239}
241
242double Sys_DirtyTime(void);
243
244void Sys_ProvideSelfFD (void);
245
247char *Sys_ConsoleInput (void);
248
250double Sys_Sleep(double time);
251
252void Sys_SDL_Dialog(const char *title, const char *string);
253void Sys_SDL_Init(void);
255void Sys_SDL_HandleEvents(void);
256
257char *Sys_SDL_GetClipboardData (void);
258
259#ifdef __EMSCRIPTEN__ //WASM-specific functions
260bool js_syncFS (bool x);
261void Sys_EM_Register_Commands(void);
262#endif
263
265unsigned int Sys_SDL_GetTicks (void); // wrapper to call SDL_GetTicks
266void Sys_SDL_Delay (unsigned int milliseconds); // wrapper to call SDL_Delay
267
269void Sys_InitProcessNice (void);
270void Sys_MakeProcessNice (void);
271void Sys_MakeProcessMean (void);
272
273int Sys_Main(int argc, char *argv[]);
274
275#endif
276
cvar_t timeformat
Definition host.c:56
float time
GLint GLenum GLint x
Definition glquake.h:651
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glquake.h:657
const GLchar * name
Definition glquake.h:601
void error(string err,...)
string argv(float n)
#define DP_FUNC_PRINTF(n)
Definition qdefs.h:14
#define DP_FUNC_NORETURN
Definition qdefs.h:16
bool qbool
Definition qtypes.h:9
void ** funcvariable
Definition sys.h:175
const char * name
Definition sys.h:174
double dirtytime
Definition sys.h:237
double cleantime
Definition sys.h:238
Definition sys.h:145
int nicelevel
Definition sys.h:150
qbool nicepossible
Definition sys.h:151
qbool isnice
Definition sys.h:152
int outfd
Definition sys.h:149
int argc
Definition sys.h:146
int selffd
Definition sys.h:148
const char ** argv
Definition sys.h:147
void Sys_SDL_Init(void)
Definition sys_null.c:22
size_t Sys_TimeString(char buf[], size_t bufsize, const char *timeformat)
Definition sys_shared.c:45
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 ...
Definition sys_shared.c:615
void Sys_InitProcessNice(void)
called to set process priority for dedicated servers
Definition sys_shared.c:955
unsigned int Sys_SDL_GetTicks(void)
Definition sys_null.c:27
void Sys_Printf(const char *fmt,...)
used to report failures inside Con_Printf()
Definition sys_shared.c:652
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
void * Sys_GetProcAddress(dllhandle_t handle, const char *name)
Definition sys_shared.c:261
char * Sys_ConsoleInput(void)
Reads a line from POSIX stdin or the Windows console.
Definition sys_shared.c:667
void Sys_MakeProcessNice(void)
Definition sys_shared.c:958
void Sys_SDL_Dialog(const char *title, const char *string)
Definition sys_null.c:13
#define Sys_HaveSSE()
Definition sys.h:140
#define Sys_HaveSSE2()
Definition sys.h:141
qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle)
Definition sys_shared.c:224
void * dllhandle_t
Definition sys.h:169
void Sys_AllowProfiling(qbool enable)
Definition sys_shared.c:65
qbool Sys_LoadDependency(const char **dllnames, dllhandle_t *handle, const dllfunction_t *fcts)
Definition sys_shared.c:131
char * Sys_SDL_GetClipboardData(void)
Definition sys_null.c:17
void Sys_SDL_Shutdown(void)
INFO: This is only called by Host_Shutdown so we dont need testing for recursion.
Definition sys_null.c:9
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....
void Sys_SDL_Delay(unsigned int milliseconds)
Definition sys_null.c:32
void Sys_SDL_HandleEvents(void)
Perform Key_Event () callbacks until the input que is empty.
Definition vid_null.c:50
double Sys_DirtyTime(void)
Definition sys_shared.c:417
void Sys_ProvideSelfFD(void)
Definition sys_shared.c:826
void Sys_MakeProcessMean(void)
Definition sys_shared.c:961
double Sys_Sleep(double time)
called to yield for a little bit so as not to hog cpu when paused or debugging
Definition sys_shared.c:500
void Sys_Init_Commands(void)
called after command system is initialized but before first Con_Print
Definition sys_shared.c:353
void Sys_FreeLibrary(dllhandle_t *handle)
Definition sys_shared.c:245
sys_t sys
Definition sys_shared.c:42
int Sys_CheckParm(const char *parm)
Definition sys_shared.c:327
qbool sys_supportsdlgetticks
Definition sys_null.c:26
qbool Sys_LoadSelf(dllhandle_t *handle)
Definition sys_shared.c:116
void Sys_EM_Register_Commands(void)
Definition sys_wasm.c:279