]> git.xonotic.org Git - xonotic/darkplaces.git/blob - sys.h
Add a third masterextra and default it to dpm.dpmaster.org
[xonotic/darkplaces.git] / sys.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, 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(__linux__)
46 # define DP_OS_NAME             "Linux"
47 # define DP_OS_STR              "linux"
48 #elif defined(_WIN64)
49 # define DP_OS_NAME             "Windows64"
50 # define DP_OS_STR              "win64"
51 #elif defined(WIN32)
52 # define DP_OS_NAME             "Windows"
53 # define DP_OS_STR              "win32"
54 #elif defined(__FreeBSD__)
55 # define DP_OS_NAME             "FreeBSD"
56 # define DP_OS_STR              "freebsd"
57 #elif defined(__NetBSD__)
58 # define DP_OS_NAME             "NetBSD"
59 # define DP_OS_STR              "netbsd"
60 #elif defined(__OpenBSD__)
61 # define DP_OS_NAME             "OpenBSD"
62 # define DP_OS_STR              "openbsd"
63 #elif defined(__DragonFly__)
64 # define DP_OS_NAME             "DragonFlyBSD"
65 # define DP_OS_STR              "dragonflybsd"
66 #elif defined(__APPLE__)
67 # if TARGET_OS_IPHONE
68 #  define DP_OS_NAME "iOS"
69 #  define DP_OS_STR "ios"
70 #  define USE_GLES2              1
71 #  define LINK_TO_ZLIB   1
72 #  define LINK_TO_LIBVORBIS 1
73 #  define DP_MOBILETOUCH 1
74 #  define DP_FREETYPE_STATIC 1
75 # elif TARGET_OS_MAC
76 #  define DP_OS_NAME "macOS"
77 #  define DP_OS_STR "macos"
78 # endif 
79 #elif defined(__MORPHOS__)
80 # define DP_OS_NAME             "MorphOS"
81 # define DP_OS_STR              "morphos"
82 #elif defined (sun) || defined (__sun)
83 # if defined (__SVR4) || defined (__svr4__)
84 #  define DP_OS_NAME    "Solaris"
85 #  define DP_OS_STR             "solaris"
86 # else
87 #  define DP_OS_NAME    "SunOS"
88 #  define DP_OS_STR             "sunos"
89 # endif
90 #else
91 # define DP_OS_NAME             "Unknown"
92 # define DP_OS_STR              "unknown"
93 #endif
94
95 #if defined(__GNUC__) || (__clang__)
96 # if defined(__i386__)
97 #  define DP_ARCH_STR           "686"
98 #  define SSE_POSSIBLE
99 #  ifdef __SSE__
100 #   define SSE_PRESENT
101 #  endif
102 #  ifdef __SSE2__
103 #   define SSE2_PRESENT
104 #  endif
105 # elif defined(__x86_64__)
106 #  define DP_ARCH_STR           "x86_64"
107 #  define SSE_PRESENT
108 #  define SSE2_PRESENT
109 # elif defined(__powerpc__)
110 #  define DP_ARCH_STR           "ppc"
111 # endif
112 #elif defined(_WIN64)
113 # define DP_ARCH_STR            "x86_64"
114 # define SSE_PRESENT
115 # define SSE2_PRESENT
116 #elif defined(WIN32)
117 # define DP_ARCH_STR            "x86"
118 # define SSE_POSSIBLE
119 #endif
120
121 #ifdef SSE_PRESENT
122 # define SSE_POSSIBLE
123 #endif
124
125 #ifdef NO_SSE
126 # undef SSE_PRESENT
127 # undef SSE_POSSIBLE
128 # undef SSE2_PRESENT
129 #endif
130
131 #ifdef SSE_POSSIBLE
132 // runtime detection of SSE/SSE2 capabilities for x86
133 qbool Sys_HaveSSE(void);
134 qbool Sys_HaveSSE2(void);
135 #else
136 #define Sys_HaveSSE() false
137 #define Sys_HaveSSE2() false
138 #endif
139
140 typedef struct sys_s
141 {
142         int argc;
143         const char **argv;
144         int selffd;
145         int outfd;
146         int nicelevel;
147         qbool nicepossible;
148         qbool isnice;
149 } sys_t;
150
151 extern sys_t sys;
152
153 extern struct cvar_s sys_usenoclockbutbenchmark;
154
155 //
156 // DLL management
157 //
158
159 // Win32 specific
160 #ifdef WIN32
161 # include <windows.h>
162 typedef HMODULE dllhandle_t;
163
164 // Other platforms
165 #else
166   typedef void* dllhandle_t;
167 #endif
168
169 typedef struct dllfunction_s
170 {
171         const char *name;
172         void **funcvariable;
173 }
174 dllfunction_t;
175
176 qbool Sys_LoadSelf(dllhandle_t *handle);
177
178 /*! Loads a dependency library. 
179  * \param dllnames a NULL terminated array of possible names for the DLL you want to load.
180  * \param handle
181  * \param fcts
182  */
183 qbool Sys_LoadDependency (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts);
184
185 /*! Loads a library.
186  * \param name a string of the library filename
187  * \param handle
188  * \return true if library was loaded successfully
189  */
190 qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle);
191
192 void Sys_FreeLibrary (dllhandle_t* handle);
193 void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
194
195 int Sys_CheckParm (const char *parm);
196
197 /// called after command system is initialized but before first Con_Print
198 void Sys_Init_Commands (void);
199
200
201 /// \returns current timestamp
202 char *Sys_TimeString(const char *timeformat);
203
204 //
205 // system IO interface (these are the sys functions that need to be implemented in a new driver atm)
206 //
207
208 /// an error will cause the entire program to exit
209 void Sys_Error (const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN;
210
211 /// (may) output text to terminal which launched program
212 void Sys_Print(const char *text);
213 void Sys_Printf(const char *fmt, ...);
214
215 /// INFO: This is only called by Host_Shutdown so we dont need testing for recursion
216 void Sys_Shutdown (void);
217 void Sys_Quit (int returnvalue);
218
219 /*! on some build/platform combinations (such as Linux gcc with the -pg
220  * profiling option) this can turn on/off profiling, used primarily to limit
221  * profiling to certain areas of the code, such as ingame performance without
222  * regard for loading/shutdown performance (-profilegameonly on commandline)
223  */
224 #ifdef __cplusplus
225 extern "C"
226 #endif
227 void Sys_AllowProfiling (qbool enable);
228
229 typedef struct sys_cleantime_s
230 {
231         double dirtytime; // last value gotten from Sys_DirtyTime()
232         double cleantime; // sanitized linearly increasing time since app start
233 }
234 sys_cleantime_t;
235
236 double Sys_DirtyTime(void);
237
238 void Sys_ProvideSelfFD (void);
239
240 char *Sys_ConsoleInput (void);
241
242 /// called to yield for a little bit so as not to hog cpu when paused or debugging
243 void Sys_Sleep(int microseconds);
244
245 /// Perform Key_Event () callbacks until the input que is empty
246 void Sys_SendKeyEvents (void);
247
248 char *Sys_GetClipboardData (void);
249
250 extern qbool sys_supportsdlgetticks;
251 unsigned int Sys_SDL_GetTicks (void); // wrapper to call SDL_GetTicks
252 void Sys_SDL_Delay (unsigned int milliseconds); // wrapper to call SDL_Delay
253
254 /// called to set process priority for dedicated servers
255 void Sys_InitProcessNice (void);
256 void Sys_MakeProcessNice (void);
257 void Sys_MakeProcessMean (void);
258
259 #endif
260