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 TARGET_OS_IPHONE /* must come first because it also defines MACOSX */
46 # define DP_OS_NAME "iPhoneOS"
47 # define DP_OS_STR "iphoneos"
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"
57 # define DP_OS_NAME "Windows64"
58 # define DP_OS_STR "win64"
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"
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"
85 # define DP_OS_NAME "SunOS"
86 # define DP_OS_STR "sunos"
89 # define DP_OS_NAME "Unknown"
90 # define DP_OS_STR "unknown"
93 #if defined(__GNUC__) || (__clang__)
94 # if defined(__i386__)
95 # define DP_ARCH_STR "686"
101 # define SSE2_PRESENT
103 # elif defined(__x86_64__)
104 # define DP_ARCH_STR "x86_64"
106 # define SSE2_PRESENT
107 # elif defined(__powerpc__)
108 # define DP_ARCH_STR "ppc"
110 #elif defined(_WIN64)
111 # define DP_ARCH_STR "x86_64"
113 # define SSE2_PRESENT
115 # define DP_ARCH_STR "x86"
116 # define SSE_POSSIBLE
120 # define SSE_POSSIBLE
130 // runtime detection of SSE/SSE2 capabilities for x86
131 qbool Sys_HaveSSE(void);
132 qbool Sys_HaveSSE2(void);
134 #define Sys_HaveSSE() false
135 #define Sys_HaveSSE2() false
151 extern struct cvar_s sys_usenoclockbutbenchmark;
159 # include <windows.h>
160 typedef HMODULE dllhandle_t;
164 typedef void* dllhandle_t;
167 typedef struct dllfunction_s
174 qbool Sys_LoadSelf(dllhandle_t *handle);
176 /*! Loads a dependency library.
177 * \param dllnames a NULL terminated array of possible names for the DLL you want to load.
181 qbool Sys_LoadDependency (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts);
184 * \param name a string of the library filename
186 * \return true if library was loaded successfully
188 qbool Sys_LoadLibrary(const char *name, dllhandle_t *handle);
190 void Sys_FreeLibrary (dllhandle_t* handle);
191 void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
193 int Sys_CheckParm (const char *parm);
195 /// called early in Host_Init
196 void Sys_InitConsole (void);
197 /// called after command system is initialized but before first Con_Print
198 void Sys_Init_Commands (void);
201 /// \returns current timestamp
202 char *Sys_TimeString(const char *timeformat);
205 // system IO interface (these are the sys functions that need to be implemented in a new driver atm)
208 /// an error will cause the entire program to exit
209 void Sys_Error (const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN;
211 /// (may) output text to terminal which launched program
212 void Sys_PrintToTerminal(const char *text);
213 void Sys_PrintfToTerminal(const char *fmt, ...);
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);
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)
227 void Sys_AllowProfiling (qbool enable);
229 typedef struct sys_cleantime_s
231 double dirtytime; // last value gotten from Sys_DirtyTime()
232 double cleantime; // sanitized linearly increasing time since app start
236 double Sys_DirtyTime(void);
238 void Sys_ProvideSelfFD (void);
240 char *Sys_ConsoleInput (void);
242 /// called to yield for a little bit so as not to hog cpu when paused or debugging
243 void Sys_Sleep(int microseconds);
245 /// Perform Key_Event () callbacks until the input que is empty
246 void Sys_SendKeyEvents (void);
248 char *Sys_GetClipboardData (void);
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
254 /// called to set process priority for dedicated servers
255 void Sys_InitProcessNice (void);
256 void Sys_MakeProcessNice (void);
257 void Sys_MakeProcessMean (void);