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