FTEQW
Documentation of the FTE engine source tree.
sys.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// sys.h -- non-portable functions
21
22//
23// file IO
24// for the most part, we use stdio.
25// if your system doesn't have stdio then urm... well.
26//
27void Sys_mkdir (const char *path); //not all pre-unix systems have directories (including dos 1)
28qboolean Sys_rmdir (const char *path);
29qboolean Sys_remove (const char *path);
30qboolean Sys_Rename (const char *oldfname, const char *newfname);
31qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace); //false for not-implemented or other error. path will be a system path, but may be relative (if basedir isn't properly known). path MAY be a file, or may be a slash-terminated directory.
32qboolean Sys_FindGameData(const char *poshname, const char *gamename, char *basepath, int basepathlen, qboolean allowprompts);
33
34//
35// memory protection
36//
37void Sys_MakeCodeWriteable (void * startaddr, unsigned long length);
38
39//
40// system IO
41//
42int VARGS Sys_DebugLog(char *file, char *fmt, ...) LIKEPRINTF(2);
43
44NORETURN void VARGS Sys_Error (const char *error, ...) LIKEPRINTF(1);
45// an error will cause the entire program to exit
46
47void VARGS Sys_Printf (char *fmt, ...) LIKEPRINTF(1);
48// send text to the console
49void Sys_Warn (char *fmt, ...) LIKEPRINTF(1);
50//like Sys_Printf. dunno why there needs to be two of em.
51
52char *Sys_URIScheme_NeedsRegistering(void); //returns the name of one of the current manifests uri schemes that isn't registered (but should be registerable).
53void Sys_Quit (void);
54void Sys_RecentServer(char *command, char *target, char *title, char *desc);
56
57typedef struct dllfunction_s {
58 void **funcptr;
59 char *name;
61#define dllhandle_t void
62extern qboolean sys_nounload; //blocks Sys_CloseLibrary. set before stack trace fatal shutdowns.
63dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs);
64void Sys_CloseLibrary(dllhandle_t *lib);
65void *Sys_GetAddressForName(dllhandle_t *module, const char *exportname);
66char *Sys_GetNameForAddress(dllhandle_t *module, void *address);
67
71
72qboolean Sys_RunFile(const char *fname, int nlen);
73
74unsigned int Sys_Milliseconds (void);
75double Sys_DoubleTime (void);
76qboolean Sys_RandomBytes(qbyte *string, int len);
77
78qboolean Sys_ResolveFileURL(const char *inurl, int inlen, char *out, int outlen);
79
80char *Sys_ConsoleInput (void);
81
82typedef enum
83{
84 CBT_CLIPBOARD, //ctrl+c, ctrl+v
85 CBT_SELECTION, //select-to-copy, middle-to-paste
87void Sys_Clipboard_PasteText(clipboardtype_t clipboardtype, void (*callback)(void *ctx, const char *utf8), void *ctx); //calls the callback once the text is available (maybe instantly). utf8 arg may be NULL if the clipboard was unavailable.
88void Sys_SaveClipboard(clipboardtype_t clipboardtype, const char *text); //a stub would do nothing.
89
90//stuff for dynamic dedicated console -> gfx and back.
91void Sys_CloseTerminal (void);
93void Con_PrintToSys(void);
94
95void Sys_ServerActivity(void);
96//make window flash on the taskbar - someone said something/connected
97
98void Sys_SendKeyEvents (void);
99// Perform Key_Event () callbacks until the input que is empty
100
101int Sys_EnumerateFiles (const char *gpath, const char *match, int (QDECL *func)(const char *fname, qofs_t fsize, time_t modtime, void *parm, searchpathfuncs_t *spath), void *parm, searchpathfuncs_t *spath);
102
103void Sys_Vibrate(float count);
104
105qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refreshrate);
106
107#if defined(__GNUC__)
108 #define qatomic32_t qint32_t
109 #define FTE_Atomic32_Inc(ptr) __sync_add_and_fetch(ptr, 1) //returns the AFTER the operation.
110 #define FTE_Atomic32_Dec(ptr) __sync_add_and_fetch(ptr, -1) //returns the AFTER the operation.
111#elif defined(_WIN32)
112 #define qatomic32_t long
113 #define FTE_Atomic32_Inc(ptr) _InterlockedIncrement(ptr)
114 #define FTE_Atomic32_Dec(ptr) _InterlockedDecrement(ptr)
115#else
116 #define qatomic32_t qint32_t
117 #define FTE_Atomic32_Inc(ptr) FTE_Atomic32Mutex_Add(ptr, 1)
118 #define FTE_Atomic32_Dec(ptr) FTE_Atomic32Mutex_Add(ptr, -1)
119#endif
120
121
122typedef enum wgroup_e
123{
126 WG_COUNT = 2 //main and loaders
128typedef struct
129{
130 void *(QDECL *CreateMutex)(void);
131 qboolean (QDECL *LockMutex)(void *mutex);
132 qboolean (QDECL *UnlockMutex)(void *mutex);
133 void (QDECL *DestroyMutex)(void *mutex);
134
135 void (*AddWork)(wgroup_t thread, void(*func)(void *ctx, void *data, size_t a, size_t b), void *ctx, void *data, size_t a, size_t b); //low priority
136 void (*WaitForCompletion)(void *priorityctx, int *address, int sleepwhilevalue);
137#define plugthreadfuncs_name "Threading"
139
140#ifdef MULTITHREAD
141#if defined(_WIN32) && defined(_DEBUG)
142void Sys_SetThreadName(unsigned int dwThreadID, char *threadName);
143#endif
144
145void Sys_ThreadsInit(void);
146//qboolean Sys_IsThread(void *thread);
148qboolean Sys_IsThread(void *thread);
149void *Sys_CreateThread(char *name, int (*func)(void *), void *args, int priority, int stacksize);
150void Sys_WaitOnThread(void *thread);
151void Sys_DetachThread(void *thread);
152void Sys_ThreadAbort(void);
153
154#define THREADP_IDLE -5
155#define THREADP_NORMAL 0
156#define THREADP_HIGHEST 5
157
158void *QDECL Sys_CreateMutex(void);
159qboolean Sys_TryLockMutex(void *mutex);
160qboolean QDECL Sys_LockMutex(void *mutex);
161qboolean QDECL Sys_UnlockMutex(void *mutex);
162void QDECL Sys_DestroyMutex(void *mutex);
163
164/* Conditional wait calls */
165void *Sys_CreateConditional(void);
166qboolean Sys_LockConditional(void *condv);
168qboolean Sys_ConditionWait(void *condv); //lock first
169qboolean Sys_ConditionSignal(void *condv); //lock first
170qboolean Sys_ConditionBroadcast(void *condv); //lock first
171void Sys_DestroyConditional(void *condv);
172
173//to try to catch leaks more easily.
174#ifdef USE_MSVCRT_DEBUG
175void *Sys_CreateMutexNamed(char *file, int line);
176#define Sys_CreateMutex() Sys_CreateMutexNamed(__FILE__, __LINE__)
177#endif
178
179#else
180 #ifdef __GNUC__ //gcc complains about if (true) when these are maros. msvc complains about static not being called in headers. gah.
181 static inline qboolean Sys_MutexStub(void) {return qtrue;}
182 static inline void *Sys_CreateMutex(void) {return NULL;}
183 #define Sys_IsMainThread() Sys_MutexStub()
184 #define Sys_DestroyMutex(m) Sys_MutexStub()
185 #define Sys_IsMainThread() Sys_MutexStub()
186 #define Sys_LockMutex(m) Sys_MutexStub()
187 #define Sys_UnlockMutex(m) Sys_MutexStub()
188 #ifndef __cplusplus
189 static inline qboolean Sys_IsThread(void *thread) {return (!thread)?qtrue:qfalse;}
190 #endif
191 #else
192 #define Sys_IsMainThread() (qboolean)(qtrue)
193 #define Sys_CreateMutex() (void*)(NULL)
194 #define Sys_LockMutex(m) (qboolean)(qtrue)
195 #define Sys_UnlockMutex(m) (qboolean)(qtrue)
196 #define Sys_DestroyMutex(m) (void)0
197 #define Sys_IsThread(t) (!t)
198 #endif
199#endif
200
201void Sys_Sleep(double seconds);
202
203
204#define UPD_OFF 0
205#define UPD_STABLE 1
206#define UPD_TESTING 2
207
208#if defined(WEBCLIENT) && defined(PACKAGEMANAGER)
209 #if defined(_WIN32) && !defined(SERVERONLY) && !defined(_XBOX)
210 #define HAVEAUTOUPDATE
211 #endif
212 #if defined(__linux__) && !defined(ANDROID)
213 #define HAVEAUTOUPDATE
214 #endif
215#endif
216
217#ifdef HAVEAUTOUPDATE
218qboolean Sys_SetUpdatedBinary(const char *fname); //attempts to overwrite the working binary.
219qboolean Sys_EngineMayUpdate(void); //says whether the system code is able/allowed to overwrite itself.
220#else
221#define Sys_EngineMayUpdate() false
222#define Sys_SetUpdatedBinary(n) false
223#endif
224
225void Sys_Init (void);
226void Sys_Shutdown(void);
227
qboolean
Definition: api_menu.h:34
@ qtrue
Definition: api_menu.h:34
@ qfalse
Definition: api_menu.h:34
uint64_t qofs_t
Definition: api_menu.h:49
unsigned int width
Definition: bymorphed.h:4
unsigned int height
Definition: bymorphed.h:5
void(QDECL *vgui_frame)(void)
void dNearCallback * callback
Definition: com_phys_ode.c:655
unsigned char qbyte
Definition: common.h:127
char * text
Definition: decomp.c:375
static EGLSurface EGLSurface EGLContext ctx
Definition: gl_videgl.c:47
int error
Definition: gl_vidlinuxglx.c:447
GLsizei count
Definition: glquake.h:149
GLsizei const GLcharARB const GLint * length
Definition: glquake.h:149
GLuint GLcharARB * name
Definition: glquake.h:155
GLenum GLsizei len
Definition: glsupp.h:502
void * module
Definition: image.c:236
plugimageloaderfuncs_t * funcs
Definition: image.c:237
char fname[MAX_QPATH]
Definition: m_mp3.c:160
const char * desc
Definition: m_options.c:1101
dllhandle_t * lib
Definition: net_ssl_winsspi.c:83
char ** data
Definition: p_script.c:63
int b
Definition: pr_lua.c:242
qcc_targetformat_t target
Definition: qcc_pr_comp.c:1706
const char * file
Definition: qcc_pr_lex.c:2518
int outlen
Definition: qccgui.c:6543
uploadfmt_t fmt
Definition: r_2d.c:48
static LPCSTR LPCSTR LPVOID parm
Definition: snd_directx.c:1076
static SpeexBits spx_int16_t * out
Definition: snd_dma.c:492
Definition: sys.h:57
void ** funcptr
Definition: sys.h:58
char * name
Definition: sys.h:59
Definition: sys.h:129
qboolean(QDECL *LockMutex)(void *mutex)
void *QDECL * CreateMutex(void)
void(QDECL *DestroyMutex)(void *mutex)
qboolean(QDECL *UnlockMutex)(void *mutex)
Definition: fs.h:34
netadr_t a
Definition: sv_master.c:141
qboolean Sys_LockConditional(void *condv)
Definition: sys_morphos.c:436
void Sys_Sleep(double seconds)
Definition: sys_dos.c:182
void * Sys_GetAddressForName(dllhandle_t *module, const char *exportname)
Definition: sys_droid.c:946
qboolean Sys_TryLockMutex(void *mutex)
Definition: sys_morphos.c:430
qboolean LibPNG_Init(void)
Definition: image.c:1440
qboolean Sys_ConditionWait(void *condv)
Definition: sys_morphos.c:438
qboolean Sys_IsMainThread(void)
Definition: sys_sdl.c:1127
qboolean Sys_SetUpdatedBinary(const char *fname)
Definition: sys_sdl.c:1315
void Sys_DestroyConditional(void *condv)
Definition: sys_morphos.c:441
void Sys_Clipboard_PasteText(clipboardtype_t clipboardtype, void(*callback)(void *ctx, const char *utf8), void *ctx)
Definition: gl_vidlinuxglx.c:4694
qboolean LibZ_Init(void)
qboolean Sys_RandomBytes(qbyte *string, int len)
Definition: sys_droid.c:1044
void Sys_mkdir(const char *path)
Definition: sys_droid.c:984
qboolean Sys_ConditionBroadcast(void *condv)
Definition: sys_morphos.c:440
void Sys_SendKeyEvents(void)
Definition: in_sdl.c:1084
void VARGS Sys_Printf(char *fmt,...) LIKEPRINTF(1)
Definition: sys_droid.c:898
void Sys_ThreadsInit(void)
Definition: sys_sdl.c:1119
wgroup_e
Definition: sys.h:123
@ WG_MAIN
Definition: sys.h:124
@ WG_COUNT
Definition: sys.h:126
@ WG_LOADER
Definition: sys.h:125
dllhandle_t * Sys_LoadLibrary(const char *name, dllfunction_t *funcs)
Definition: sys_droid.c:950
void Con_PrintToSys(void)
Definition: console.c:1888
qboolean Sys_EngineMayUpdate(void)
Definition: sys_sdl.c:1321
unsigned int Sys_Milliseconds(void)
Definition: sys_droid.c:815
void Sys_DetachThread(void *thread)
Definition: sys_win_threads.c:161
void Sys_CloseLibrary(dllhandle_t *lib)
Definition: sys_droid.c:941
qboolean QDECL Sys_UnlockMutex(void *mutex)
Definition: sys_morphos.c:432
void Sys_WaitOnThread(void *thread)
Definition: sys_morphos.c:427
qboolean Sys_RunFile(const char *fname, int nlen)
qboolean QDECL Sys_LockMutex(void *mutex)
Definition: sys_morphos.c:431
char * Sys_ConsoleInput(void)
Definition: sys_droid.c:980
void Sys_CloseTerminal(void)
Definition: sys_droid.c:1086
qboolean Sys_IsThread(void *thread)
Definition: sys.h:189
void Sys_ThreadAbort(void)
Definition: sys_sdl.c:1131
qboolean sys_nounload
Definition: common.c:28
void Sys_Warn(char *fmt,...) LIKEPRINTF(1)
Definition: sys_droid.c:929
qboolean Sys_Rename(const char *oldfname, const char *newfname)
Definition: sys_droid.c:1000
void Sys_MakeCodeWriteable(void *startaddr, unsigned long length)
Definition: sys_linux.c:1609
void Sys_Quit(void)
Definition: sys_droid.c:864
qboolean Sys_ResolveFileURL(const char *inurl, int inlen, char *out, int outlen)
Definition: sys_win.c:1455
clipboardtype_t
Definition: sys.h:83
@ CBT_CLIPBOARD
Definition: sys.h:84
@ CBT_SELECTION
Definition: sys.h:85
qboolean Sys_InitTerminal(void)
Definition: sys_droid.c:1081
void QDECL Sys_DestroyMutex(void *mutex)
Definition: sys_morphos.c:433
void Sys_Vibrate(float count)
Definition: sys_droid.c:101
void Sys_RecentServer(char *command, char *target, char *title, char *desc)
Definition: sys_linux.c:91
qboolean LibJPEG_Init(void)
void * Sys_CreateConditional(void)
Definition: sys_morphos.c:435
void Sys_Shutdown(void)
Definition: sys_droid.c:860
void Sys_ServerActivity(void)
Definition: sys_droid.c:1057
struct dllfunction_s dllfunction_t
qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refreshrate)
Definition: sys_droid.c:1036
void * Sys_CreateMutexNamed(char *file, int line)
Definition: sys_win_threads.c:214
void Sys_SetThreadName(unsigned int dwThreadID, char *threadName)
Definition: sys_win_threads.c:52
qboolean Sys_remove(const char *path)
Definition: sys_droid.c:996
qboolean Sys_UnlockConditional(void *condv)
Definition: sys_morphos.c:437
char * Sys_URIScheme_NeedsRegistering(void)
Definition: sys_droid.c:1025
char * Sys_GetNameForAddress(dllhandle_t *module, void *address)
Definition: sys_win.c:525
qboolean Sys_ConditionSignal(void *condv)
Definition: sys_morphos.c:439
NORETURN void VARGS Sys_Error(const char *error,...) LIKEPRINTF(1)
Definition: sys_droid.c:878
qboolean Sys_rmdir(const char *path)
Definition: sys_droid.c:988
void *QDECL Sys_CreateMutex(void)
Definition: sys.h:182
qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace)
Definition: sys_droid.c:1008
qboolean Sys_FindGameData(const char *poshname, const char *gamename, char *basepath, int basepathlen, qboolean allowprompts)
Definition: fs.c:5438
void Sys_Init(void)
Definition: sys_droid.c:1029
qboolean Sys_RunInstaller(void)
Definition: sys_droid.c:1063
int VARGS Sys_DebugLog(char *file, char *fmt,...) LIKEPRINTF(2)
Definition: sys_linux.c:655
void * Sys_CreateThread(char *name, int(*func)(void *), void *args, int priority, int stacksize)
Definition: sys_morphos.c:426
void Sys_SaveClipboard(clipboardtype_t clipboardtype, const char *text)
Definition: sys_droid.c:1096
int Sys_EnumerateFiles(const char *gpath, const char *match, int(QDECL *func)(const char *fname, qofs_t fsize, time_t modtime, void *parm, searchpathfuncs_t *spath), void *parm, searchpathfuncs_t *spath)
Definition: sys_sdl.c:634
double Sys_DoubleTime(void)
Definition: sys_droid.c:803
enum wgroup_e wgroup_t
int bpp
Definition: sys_win.c:332