2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // sys.h -- non-portable functions
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
33 #if defined(__ANDROID__) /* must come first because it also defines linux */
34 # define DP_OS_NAME "Android"
35 # define DP_OS_STR "android"
38 # define LINK_TO_ZLIB 1
39 # define LINK_TO_LIBVORBIS 1
41 # define LINK_TO_LIBXMP 1 // nyov: if someone can test with the android NDK compiled libxmp?
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"
49 # define DP_OS_NAME "Windows64"
50 # define DP_OS_STR "win64"
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__)
68 # define DP_OS_NAME "iOS"
69 # define DP_OS_STR "ios"
71 # define LINK_TO_ZLIB 1
72 # define LINK_TO_LIBVORBIS 1
73 # define DP_MOBILETOUCH 1
74 # define DP_FREETYPE_STATIC 1
76 # define DP_OS_NAME "macOS"
77 # define DP_OS_STR "macos"
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"
87 # define DP_OS_NAME "SunOS"
88 # define DP_OS_STR "sunos"
91 # define DP_OS_NAME "Unknown"
92 # define DP_OS_STR "unknown"
95 #if defined(__GNUC__) || (__clang__)
96 # if defined(__i386__)
97 # define DP_ARCH_STR "686"
103 # define SSE2_PRESENT
105 # elif defined(__x86_64__)
106 # define DP_ARCH_STR "x86_64"
108 # define SSE2_PRESENT
109 # elif defined(__powerpc__)
110 # define DP_ARCH_STR "ppc"
112 #elif defined(_WIN64)
113 # define DP_ARCH_STR "x86_64"
115 # define SSE2_PRESENT
117 # define DP_ARCH_STR "x86"
118 # define SSE_POSSIBLE
122 # define SSE_POSSIBLE
132 // runtime detection of SSE/SSE2 capabilities for x86
133 qbool Sys_HaveSSE(void);
134 qbool Sys_HaveSSE2(void);
136 #define Sys_HaveSSE() false
137 #define Sys_HaveSSE2() false
160 # include <windows.h>
161 typedef HMODULE dllhandle_t;
165 typedef void* dllhandle_t;
168 typedef struct dllfunction_s
175 qbool Sys_LoadSelf(dllhandle_t *handle);
177 /*! Loads a dependency library.
178 * \param dllnames a NULL terminated array of possible names for the DLL you want to load.
182 qbool Sys_LoadDependency (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts);
185 * \param name a string of the library filename
187 * \return true if library was loaded successfully
189 qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle);
191 void Sys_FreeLibrary (dllhandle_t* handle);
192 void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
194 int Sys_CheckParm (const char *parm);
196 /// called after command system is initialized but before first Con_Print
197 void Sys_Init_Commands (void);
200 /// \returns current timestamp
201 char *Sys_TimeString(const char *timeformat);
204 // system IO interface (these are the sys functions that need to be implemented in a new driver atm)
207 /// Causes the entire program to exit ASAP.
208 /// Trailing \n should be omitted.
209 void Sys_Abort (const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN;
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, ...);
218 /// INFO: This is only called by Host_Shutdown so we dont need testing for recursion
219 void Sys_SDL_Shutdown(void);
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)
229 void Sys_AllowProfiling (qbool enable);
231 typedef struct sys_cleantime_s
233 double dirtytime; // last value gotten from Sys_DirtyTime()
234 double cleantime; // sanitized linearly increasing time since app start
238 double Sys_DirtyTime(void);
240 void Sys_ProvideSelfFD (void);
242 /// Reads a line from POSIX stdin or the Windows console
243 char *Sys_ConsoleInput (void);
245 /// called to yield for a little bit so as not to hog cpu when paused or debugging
246 double Sys_Sleep(double time);
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);
253 char *Sys_SDL_GetClipboardData (void);
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
259 /// called to set process priority for dedicated servers
260 void Sys_InitProcessNice (void);
261 void Sys_MakeProcessNice (void);
262 void Sys_MakeProcessMean (void);