]> git.xonotic.org Git - xonotic/darkplaces.git/blob - sys.h
physics: fix and refactor unsticking
[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
154 //
155 // DLL management
156 //
157
158 // Win32 specific
159 #ifdef WIN32
160 # include <windows.h>
161 typedef HMODULE dllhandle_t;
162
163 // Other platforms
164 #else
165   typedef void* dllhandle_t;
166 #endif
167
168 typedef struct dllfunction_s
169 {
170         const char *name;
171         void **funcvariable;
172 }
173 dllfunction_t;
174
175 qbool Sys_LoadSelf(dllhandle_t *handle);
176
177 /*! Loads a dependency library. 
178  * \param dllnames a NULL terminated array of possible names for the DLL you want to load.
179  * \param handle
180  * \param fcts
181  */
182 qbool Sys_LoadDependency (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts);
183
184 /*! Loads a library.
185  * \param name a string of the library filename
186  * \param handle
187  * \return true if library was loaded successfully
188  */
189 qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle);
190
191 void Sys_FreeLibrary (dllhandle_t* handle);
192 void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
193
194 int Sys_CheckParm (const char *parm);
195
196 /// called after command system is initialized but before first Con_Print
197 void Sys_Init_Commands (void);
198
199
200 /// \returns current timestamp
201 char *Sys_TimeString(const char *timeformat);
202
203 //
204 // system IO interface (these are the sys functions that need to be implemented in a new driver atm)
205 //
206
207 /// Causes the entire program to exit ASAP.
208 /// Trailing \n should be omitted.
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 /// is POSIX async-signal-safe
213 /// textlen excludes any (optional) \0 terminator
214 void Sys_Print(const char *text, size_t textlen);
215 /// used to report failures inside Con_Printf()
216 void Sys_Printf(const char *fmt, ...);
217
218 /// INFO: This is only called by Host_Shutdown so we dont need testing for recursion
219 void Sys_SDL_Shutdown(void);
220
221 /*! on some build/platform combinations (such as Linux gcc with the -pg
222  * profiling option) this can turn on/off profiling, used primarily to limit
223  * profiling to certain areas of the code, such as ingame performance without
224  * regard for loading/shutdown performance (-profilegameonly on commandline)
225  */
226 #ifdef __cplusplus
227 extern "C"
228 #endif
229 void Sys_AllowProfiling (qbool enable);
230
231 typedef struct sys_cleantime_s
232 {
233         double dirtytime; // last value gotten from Sys_DirtyTime()
234         double cleantime; // sanitized linearly increasing time since app start
235 }
236 sys_cleantime_t;
237
238 double Sys_DirtyTime(void);
239
240 void Sys_ProvideSelfFD (void);
241
242 /// Reads a line from POSIX stdin or the Windows console
243 char *Sys_ConsoleInput (void);
244
245 /// called to yield for a little bit so as not to hog cpu when paused or debugging
246 double Sys_Sleep(double time);
247
248 void Sys_SDL_Dialog(const char *title, const char *string);
249 void Sys_SDL_Init(void);
250 /// Perform Key_Event () callbacks until the input que is empty
251 void Sys_SDL_HandleEvents(void);
252
253 char *Sys_SDL_GetClipboardData (void);
254
255 extern qbool sys_supportsdlgetticks;
256 unsigned int Sys_SDL_GetTicks (void); // wrapper to call SDL_GetTicks
257 void Sys_SDL_Delay (unsigned int milliseconds); // wrapper to call SDL_Delay
258
259 /// called to set process priority for dedicated servers
260 void Sys_InitProcessNice (void);
261 void Sys_MakeProcessNice (void);
262 void Sys_MakeProcessMean (void);
263
264 int Sys_Main(int argc, char *argv[]);
265
266 #endif
267