FTEQW
Documentation of the FTE engine source tree.
quakedef.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// quakedef.h -- primary header for client
21
22#ifndef __QUAKEDEF_H__
23#define __QUAKEDEF_H__
24
25#include "../common/bothdefs.h" //first thing included by ALL files.
26
27//for msvc #pragma message lines
28#if defined(_MSC_VER)
29#define MSVC_LINE __FILE__"("STRINGIFY(__LINE__)"):"
30#define warningmsg(s) message(MSVC_LINE s)
31#elif __GNUC__ >=4
32#define warningmsg(s) message(s)
33#endif
34
35#ifdef MSVCDISABLEWARNINGS
36//#pragma warning( disable : 4244 4127 4201 4214 4514 4305 4115 4018)
37/*#pragma warning( disable : 4244) //conversion from const double to float
38#pragma warning( disable : 4305) //truncation from const double to float
39#pragma warning( disable : 4018) //signed/unsigned mismatch... fix these?
40#pragma warning( disable : 4706) //assignment within conditional expression - watch for these in GCC where they can be fixed but still functional.
41#pragma warning( disable : 4100) //unreferenced formal parameter
42#pragma warning( disable : 4201) //nonstandard extension used : nameless struct/union
43#pragma warning( disable : 4213) //nonstandard extension used : cast on l-value
44#pragma warning( disable : 4127) //conditional expression is constant - fixme?
45*/
46#pragma warning( 4 : 4244) //conversion from const double to float
47#pragma warning( 4 : 4305) //truncation from const double to float
48#pragma warning( 4 : 4018) //truncation from const double to float
49
50#pragma warning( 2 : 4701)
51#pragma warning(2:4132 4268)// const object not initialized
52
53#pragma warning(2:4032) // function arg has different type from declaration
54#pragma warning(2:4092) // 'sizeof' value too big
55#pragma warning(2:4132 4268)// const object not initialized
56//#pragma warning(2:4152) // pointer conversion between function and data
57#pragma warning(2:4239) // standard doesn't allow this conversion
58#pragma warning(2:4701) // local variable used without being initialized
59//#pragma warning(2:4706) // if (a=b) instead of (if a==b)
60#pragma warning(2:4709) // comma in array subscript
61#pragma warning(3:4061) // not all enum values tested in switch statement
62#pragma warning(3:4710) // inline function was not inlined
63#pragma warning(3:4121) // space added for structure alignment
64#pragma warning(3:4505) // unreferenced local function removed
65#pragma warning(3:4019) // empty statement at global scope
66//#pragma warning(3:4057) // pointers refer to different base types
67#pragma warning(3:4125) // decimal digit terminates octal escape
68#pragma warning(2:4131) // old-style function declarator
69#pragma warning(3:4211) // extern redefined as static
70//#pragma warning(3:4213) // cast on left side of = is non-standard
71#pragma warning(3:4222) // member function at file scope shouldn't be static
72#pragma warning(3:4234 4235)// keyword not supported or reserved for future
73#pragma warning(3:4504) // type ambiguous; simplify code
74#pragma warning(3:4507) // explicit linkage specified after default linkage
75#pragma warning(3:4515) // namespace uses itself
76#pragma warning(3:4516 4517)// access declarations are deprecated
77#pragma warning(3:4670) // base class of thrown object is inaccessible
78#pragma warning(3:4671) // copy ctor of thrown object is inaccessible
79#pragma warning(3:4673) // thrown object cannot be handled in catch block
80#pragma warning(3:4674) // dtor of thrown object is inaccessible
81#pragma warning(3:4705) // statement has no effect (example: a+1;)
82
83#pragma warning(3:4013) // function undefined, assuming extern returning int
84
85
86#pragma warning( 4 : 4267) //truncation from const double to float
87#pragma warning( 4 : 4710) //function not inlined
88
89#pragma warning( error : 4020)
90
91#pragma warning(error:4013)
92
93//msvc... shut the fuck up.
94#define _CRT_SECURE_NO_DEPRECATE
95#define _CRT_NONSTDC_NO_DEPRECATE
96#endif
97
98
99
100#define QUAKEDEF_H__
101
102#ifdef __linux__
103#define PNG_SUCKS_WITH_SETJMP //cos it does.
104#endif
105
106//define PARANOID // speed sapping error checking
107
108#include <float.h>
109#include <math.h>
110#include <string.h>
111#include <stdarg.h>
112#include <stdio.h>
113#include <stdlib.h>
114#if defined(AVAIL_PNGLIB) && defined(PNG_SUCKS_WITH_SETJMP) && !defined(SERVERONLY)
115 #if defined(MINGW)
116 #include "./mingw-libs/png.h"
117 #elif defined(_WIN32)
118 #include "png.h"
119 #else
120 #include <png.h>
121 #endif
122#else
123 #ifdef FTE_TARGET_WEB
124 #include "web/ftejslib.h"
125 //officially, emscripten supports longjmp.
126 //unofficially, this makes firefox crash with memory issues.
127 #define setjmp(x) (x=0,x)
128 #define longjmp(b,r) emscriptenfte_abortmainloop(__func__, false)
129 typedef int jmp_buf;
130 #else
131 #include <setjmp.h>
132 #endif
133#endif
134#include <time.h>
135
136#ifdef USE_MSVCRT_DEBUG
137 #define _CRTDBG_MAP_ALLOC
138 #include <crtdbg.h>
139#endif
140#if defined(_WIN32) || defined(__DJGPP__)
141 #include <malloc.h>
142#elif !defined(alloca) //alloca.h isn't present on bsd (stdlib.h should define it to __builtin_alloca, and we can check for that here).
143 #include <alloca.h>
144#endif
145
146#ifdef FTE_TARGET_WEB //emscripten's filesystem is throwing all sorts of exceptions and making it hard to debug real bugs.
147 #define NOSTDIO
148#endif
149#ifdef NOSTDIO
150 #define stat stat_nolink
151 #define fopen fopen_nolink
152 #define fread fread_nolink
153 #define fwrite fwrite_nolink
154 #define fclose fclose_nolink
155 #define fseek fseek_nolink
156 #define open open_nolink
157 #define read read_nolink
158 #define write write_nolink
159 #define close close_nolink
160#endif
161
162#ifdef __cplusplus
163extern "C" {
164#endif
165
166#include "../common/common.h"
167#include "../common/bspfile.h"
168#include "vid.h"
169#include "../common/sys.h"
170#include "../common/zone.h"
171#include "../common/mathlib.h"
172#include "../common/cvar.h"
173#include "../common/translate.h"
174#include "../common/net.h"
175#ifndef WEBSVONLY
176#include "../common/protocol.h"
177#include "../common/cmd.h"
178#include "../common/console.h"
179#include "screen.h"
180#include "wad.h"
181#include "sbar.h"
182#include "sound.h"
183#include "merged.h"
184#include "render.h"
185#include "client.h"
186#include "../gl/gl_model.h"
187
188#include "../common/vm.h"
189
190#include "input.h"
191#include "keys.h"
192#include "view.h"
193#include "menu.h"
194#include "cdaudio.h"
195#include "../common/pmove.h"
196
197#include "../qclib/progtype.h"
198#include "../server/progdefs.h"
199#include "../server/progs.h"
200#include "../common/world.h"
201#include "../server/q2game.h"
202#include "../http/iweb.h"
203#ifdef CLIENTONLY
204#define SSV_IsSubServer() false
205#else
206#include "../server/server.h"
207#endif
208#endif
209
210#if defined(Q3CLIENT) || defined(Q3SERVER)
211#include "q3api.h"
212#endif
213
214#ifdef __cplusplus
215 #define q_max(a,b) ((a) > (b) ? (a) : (b))
216 #define q_min(a,b) ((a) < (b) ? (a) : (b))
217#else
218 #ifndef max
219 #define max(a,b) ((a) > (b) ? (a) : (b))
220 #define min(a,b) ((a) < (b) ? (a) : (b))
221 #endif
222 #define max3(a,b,c) max(max(a,b),c)
223#endif
224
225//msvcrt lacks any and all c99 support.
226#if defined(_WIN32)
227 #ifdef __GNUC__
228 #include <inttypes.h>
229 #else
230 #define PRIxPTR "p"
231 //totally different from any other system
232 #define PRIx64 "I64x"
233 #define PRIu64 "I64u"
234 #define PRIi64 "I64i"
235 #endif
236
237 #ifdef _WIN64
238 #define PRIxSIZE PRIx64
239 #define PRIuSIZE PRIu64
240 #define PRIiSIZE PRIi64
241 #else
242 //don't use I, for the sake of older libcs
243 #define PRIxSIZE "x"
244 #define PRIuSIZE "u"
245 #define PRIiSIZE "i"
246 #endif
247#else
248 #include <inttypes.h>
249 //these are non-standard. c99 would expect people to just use %zx etc
250 #if FTE_WORDSIZE != 32 || __STDC_VERSION__ >= 199901L || defined(__GNUC__)
251 //64bit systems are expected to have an awareness of c99
252 #define PRIxSIZE "zx"
253 #define PRIuSIZE "zu"
254 #define PRIiSIZE "zi"
255 #else
256 //regular old c89 for 32bit platforms.
257 #define PRIxSIZE PRIxPTR
258 #define PRIuSIZE PRIuPTR
259 #define PRIiSIZE PRIiPTR
260 #endif
261#endif
262
263
264#ifdef _WIN32
265 #if (_MSC_VER >= 1900)
266 // MSVC 14 has standardized snprintf functions, hurrah!
267 #elif (_MSC_VER >= 1400)
268 //with MSVC 8, use microsoft's vsnprintf_s. return values are still wrong though.
269 #define snprintf (void)linuxlike_snprintf_vc8
270 int VARGS linuxlike_snprintf_vc8(char *buffer, int size, const char *format, ...) LIKEPRINTF(3);
271 #define vsnprintf(a, b, c, d) (void)(vsnprintf_s(a, b, _TRUNCATE, c, d))
272 #else
273 //msvc crap. return values are wrong but at least we can null terminate it safely.
274 #define snprintf (void)linuxlike_snprintf
275 int VARGS linuxlike_snprintf(char *buffer, int size, const char *format, ...) LIKEPRINTF(3);
276 #define vsnprintf (void)linuxlike_vsnprintf
277 int VARGS linuxlike_vsnprintf(char *buffer, int size, const char *format, va_list argptr);
278 #endif
279
280 #ifdef _MSC_VER
281 //these are provided so we don't use them
282 //but mingw has some defines elsewhere and makes gcc moan
283// #define _vsnprintf unsafe_vsnprintf
284// #define _snprintf unsafe_snprintf
285
286 #ifndef strcasecmp
287 #define strcasecmp _stricmp
288 #endif
289 #ifndef strncasecmp
290 #define strncasecmp _strnicmp
291 #endif
292 #endif
293#endif
294
295//=============================================================================
296
297// the host system specifies the base of the directory tree, the
298// command line parms passed to the program, and the amount of memory
299// available for the program to use
300
301typedef struct quakeparms_s
302{
303 const char *basedir; //working directory
304 const char *binarydir; //exe directory
305 const char *manifest; //linked manifest data (for installer functionality etc)
306 int argc;
307 const char **argv;
309
310
311//=============================================================================
312
313#define MAX_NUM_ARGVS 128
314
315
317
318
319//
320// host
321//
323
324extern cvar_t fs_gamename;
325#ifdef PACKAGEMANAGER
327#endif
331extern cvar_t com_parseutf8;
332#ifdef HAVE_LEGACY
333extern cvar_t scr_usekfont;
335#endif
336extern cvar_t sys_ticrate;
337extern cvar_t sys_nostdout;
338extern cvar_t developer;
339extern cvar_t host_mapname;
340
341extern cvar_t password;
342
343extern qboolean host_initialized; // true if into command execution
344extern double host_frametime;
345extern qbyte *host_basepal;
347extern int host_framecount; // incremented every frame, never reset
348extern double realtime; // not bounded in any way, changed at
349 // start of every frame, never reset
350
355void Host_Shutdown(void);
356NORETURN void VARGS Host_Error (const char *error, ...) LIKEPRINTF(1);
357NORETURN void VARGS Host_EndGame (const char *message, ...) LIKEPRINTF(1);
359double Host_Frame (double time);
360qboolean Host_RunFile(const char *fname, int nlen, vfsfile_t *file);
361void Host_Quit_f (void);
362void VARGS Host_ClientCommands (char *fmt, ...) LIKEPRINTF(1);
364
365#ifdef LOADERTHREAD
366extern qboolean com_workererror; //supresses shutdown prints+threads
367extern cvar_t worker_flush;
368qboolean COM_DoWork(int thread, qboolean leavelocked);
369#define COM_MainThreadWork() while (COM_DoWork(0, false) && worker_flush.ival) /*called each frame to do any gl uploads or whatever*/
370#define COM_MainThreadFlush() while (COM_DoWork(0, false)) /*make sure the main thread has done ALL work pending*/
371void COM_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
372void COM_InsertWork(wgroup_t tg, void(*func)(void *ctx, void *data, size_t a, size_t b), void *ctx, void *data, size_t a, size_t b); //high priority
374void COM_WorkerFullSync(void);
375void COM_WorkerLock(void); //callable on main thread to temporarily suspend workers (in a safe location)
376void COM_WorkerUnlock(void);
377void COM_DestroyWorkerThread(void);
378void COM_WorkerPartialSync(void *priorityctx, int *address, int value); //aka: while(*address==value)wait();
379extern void *com_resourcemutex; //random mutex to simplify resource creation type stuff.
380void COM_WorkerAbort(char *message); //calls sys_error on the main thread, if running on a worker.
381#ifdef _DEBUG
382void COM_AssertMainThread(const char *msg);
383#else
384#define COM_AssertMainThread(msg)
385#endif
386#else
387#define com_workererror false
388#define COM_AddWork(t,f,a,b,c,d) (f)((a),(b),(c),(d))
389#define COM_InsertWork(t,f,a,b,c,d) (f)((a),(b),(c),(d))
390#define COM_WorkerPartialSync(c,a,v)
391#define COM_WorkerFullSync()
392#define COM_WorkerLock()
393#define COM_WorkerUnlock()
394#define COM_HasWork() false
395#define COM_DoWork(t,l) false
396#define COM_AssertMainThread(msg)
397#define COM_MainThreadWork() while(0)
398#define COM_MainThreadFlush()
399#define COM_DestroyWorkerThread()
400#define COM_WorkerAbort(m)
401#endif
402
403extern qboolean msg_suppress_1; // suppresses resolution and cache size console output
404 // an fullscreen DIB focus gain/loss
405
406#ifndef HAVE_CLIENT
407#define isDedicated true
408#elif !defined(HAVE_SERVER)
409#define isDedicated false
410#else
411extern qboolean isDedicated;
412#endif
413extern qboolean wantquit; //flagged if we want to force a quit, safely breaking out of any modal stuff
414
415
416
417#ifdef __cplusplus
418}
419#endif
420
421#endif //__QUAKEDEF_H__
qboolean
Definition: api_menu.h:34
double time
Definition: cl_main.c:306
cvar_t msg
Definition: cl_main.c:159
unsigned char qbyte
Definition: common.h:127
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: gl_vidcommon.c:351
static EGLSurface EGLSurface EGLContext ctx
Definition: gl_videgl.c:47
int error
Definition: gl_vidlinuxglx.c:447
GLint size
Definition: glquake.h:157
GLsizei GLboolean const GLfloat * value
Definition: glquake.h:164
GLenum format
Definition: glsupp.h:502
GLint GLfloat * parms
Definition: glsupp.h:612
char fname[MAX_QPATH]
Definition: m_mp3.c:160
char ** data
Definition: p_script.c:63
int b
Definition: pr_lua.c:242
const char * file
Definition: qcc_pr_lex.c:2518
void Host_ServerFrame(void)
qboolean COM_DoWork(int thread, qboolean leavelocked)
Definition: common.c:6076
cvar_t developer
Definition: common.c:72
cvar_t com_parseutf8
Definition: common.c:87
cvar_t host_mapname
Definition: common.c:91
cvar_t com_gamedirnativecode
Definition: common.c:89
quakeparms_t host_parms
Definition: common.c:32
void COM_WorkerUnlock(void)
Definition: common.c:6308
double host_frametime
Definition: common.c:29
qboolean com_workererror
Definition: common.c:5963
cvar_t fs_gamename
Definition: common.c:84
void Host_Init(quakeparms_t *parms)
Definition: cl_main.c:7441
void Host_Shutdown(void)
Definition: cl_main.c:7571
void COM_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)
Definition: common.c:6018
qboolean wantquit
Definition: common.c:104
qboolean COM_HasWork(void)
Definition: common.c:5974
void COM_WorkerFullSync(void)
Definition: common.c:6326
void COM_InsertWork(wgroup_t tg, void(*func)(void *ctx, void *data, size_t a, size_t b), void *ctx, void *data, size_t a, size_t b)
Definition: common.c:5984
cvar_t sys_nostdout
Definition: sv_sys_unix.c:66
void COM_DestroyWorkerThread(void)
Definition: common.c:6250
double realtime
Definition: common.c:30
qbyte * host_basepal
Definition: cl_main.c:332
cvar_t password
Definition: cl_main.c:148
qbyte * h2playertranslations
Definition: cl_main.c:333
int VARGS linuxlike_vsnprintf(char *buffer, int size, const char *format, va_list argptr)
Definition: sys_plugfte.c:212
void VARGS Host_ClientCommands(char *fmt,...) LIKEPRINTF(1)
void COM_WorkerPartialSync(void *priorityctx, int *address, int value)
Definition: common.c:6388
cvar_t sys_ticrate
void Host_Quit_f(void)
cvar_t ezcompat_markup
Definition: common.c:93
cvar_t scr_usekfont
Definition: common.c:95
NORETURN void VARGS Host_Error(const char *error,...) LIKEPRINTF(1)
Definition: cl_main.c:5763
void Host_FinishInit(void)
void * com_resourcemutex
Definition: common.c:5948
struct quakeparms_s quakeparms_t
cvar_t com_protocolname
Definition: common.c:85
int jmp_buf
Definition: quakedef.h:129
qboolean Host_RunFile(const char *fname, int nlen, vfsfile_t *file)
Definition: cl_main.c:6505
NORETURN void VARGS Host_EndGame(const char *message,...) LIKEPRINTF(1)
Definition: cl_main.c:5728
void COM_AssertMainThread(const char *msg)
Definition: common.c:6242
qboolean msg_suppress_1
Definition: common.c:102
qboolean Host_SimulationTime(float time)
Definition: cl_main.c:5841
cvar_t pkg_autoupdate
Definition: m_download.c:35
cvar_t worker_flush
Definition: common.c:5942
void Host_InitCommands(void)
qboolean host_initialized
Definition: common.c:31
void COM_WorkerLock(void)
Definition: common.c:6281
int VARGS linuxlike_snprintf(char *buffer, int size, const char *format,...) LIKEPRINTF(3)
Definition: sys_plugfte.c:193
void Host_ShutdownServer(qboolean crash)
double Host_Frame(double time)
Definition: cl_main.c:6651
cvar_t com_protocolversion
Definition: common.c:86
qboolean noclip_anglehack
Definition: cl_main.c:45
void COM_WorkerAbort(char *message)
Definition: common.c:6215
int VARGS linuxlike_snprintf_vc8(char *buffer, int size, const char *format,...) LIKEPRINTF(3)
Definition: sys_plugfte.c:228
int host_framecount
Definition: cl_main.c:330
qboolean isDedicated
Definition: sys_droid.c:26
uploadfmt_t fmt
Definition: r_2d.c:48
static ALC_API ALCvoid * buffer
Definition: snd_al.c:259
Definition: cvar.h:59
Definition: quakedef.h:302
const char * basedir
Definition: quakedef.h:303
const char * manifest
Definition: quakedef.h:305
int argc
Definition: quakedef.h:306
const char ** argv
Definition: quakedef.h:307
const char * binarydir
Definition: quakedef.h:304
netadr_t a
Definition: sv_master.c:141
enum wgroup_e wgroup_t
void * vfsfile_t
Definition: sys_plugfte.h:2