-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathLib.h
274 lines (220 loc) · 7.55 KB
/
Lib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*****************************************************************************
The Dark Mod GPL Source Code
This file is part of the The Dark Mod Source Code, originally based
on the Doom 3 GPL Source Code as published in 2011.
The Dark Mod Source Code is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version. For details, see LICENSE.TXT.
Project: The Dark Mod (http://www.thedarkmod.com/)
******************************************************************************/
#ifndef __LIB_H__
#define __LIB_H__
/*
===============================================================================
idLib contains stateless support classes and concrete types. Some classes
do have static variables, but such variables are initialized once and
read-only after initialization (they do not maintain a modifiable state).
The interface pointers idSys, idCommon, idCVarSystem and idFileSystem
should be set before using idLib. The pointers stored here should not
be used by any part of the engine except for idLib.
The frameNumber should be continuously set to the number of the current
frame if frame base memory logging is required.
===============================================================================
*/
class idLib {
public:
static class idSys * sys;
static class idCommon * common;
static class idCVarSystem * cvarSystem;
static class idFileSystem * fileSystem;
static int frameNumber;
static void Init( void );
static void ShutDown( void );
// wrapper to idCommon functions
static void Printf( const char* fmt, ... );
static void Error( const char *fmt, ... );
static void Warning( const char *fmt, ... );
};
/*
===============================================================================
Types and defines used throughout the engine.
===============================================================================
*/
typedef unsigned char byte; // 8 bits
typedef unsigned short word; // 16 bits
typedef unsigned int dword; // 32 bits
typedef unsigned int uint;
typedef int int32; //anon
typedef int qhandle_t;
class idFile;
class idVec3;
class idVec4;
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifndef BIT
#define BIT( num ) ( 1 << ( num ) )
#endif
#define MAX_STRING_CHARS 1024 // max length of a string
// maximum world size
#define MAX_WORLD_COORD ( 128 * 1024 )
#define MIN_WORLD_COORD ( -128 * 1024 )
#define MAX_WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD )
// basic colors
extern idVec4 colorBlack;
extern idVec4 colorWhite;
extern idVec4 colorRed;
extern idVec4 colorGreen;
extern idVec4 colorBlue;
extern idVec4 colorYellow;
extern idVec4 colorMagenta;
extern idVec4 colorCyan;
extern idVec4 colorOrange;
extern idVec4 colorPurple;
extern idVec4 colorPink;
extern idVec4 colorBrown;
extern idVec4 colorLtGrey;
extern idVec4 colorMdGrey;
extern idVec4 colorDkGrey;
// packs color floats in the range [0,1] into an integer
dword PackColor( const idVec3 &color );
void UnpackColor( const dword color, idVec3 &unpackedColor );
dword PackColor( const idVec4 &color );
void UnpackColor( const dword color, idVec4 &unpackedColor );
// little/big endian conversion
short BigShort( short l );
short LittleShort( short l );
int BigInt( int l );
int LittleInt( int l );
float BigFloat( float l );
float LittleFloat( float l );
void BigRevBytes( void *bp, int elsize, int elcount );
void LittleRevBytes( void *bp, int elsize, int elcount );
void LittleBitField( void *bp, int elsize );
void Swap_Init( void );
bool Swap_IsBigEndian( void );
// for base64
void SixtetsForInt( byte *out, int src);
int IntForSixtets( byte *in );
template<class Context, class MethodPtr> struct LambdaToFuncPtr_detail {};
template<class Context, class Lambda, class Ret, class... Args> struct LambdaToFuncPtr_detail<Context, Ret (Lambda::*)(Args...) const> {
// Oh crap! Why are they doing this to my beloved language?! =)))
static inline Ret thunk(Context context, Args... args) {
return ((Lambda*)context)->operator()(args...);
}
};
//stgatilov: converts C++11 lambda into function pointer with void* context as first argument
//note: if you need function pointer without context, just assign a noncapturing lambda to function pointer (C++ allows that)
template<class Lambda> inline auto LambdaToFuncPtr(Lambda &lambda) -> auto {
return &LambdaToFuncPtr_detail<void*, decltype(&Lambda::operator())>::thunk;
}
class idException {
public:
char error[MAX_STRING_CHARS];
// this really, really should be a const function, but it's referenced too many places to change right now
const char* GetError() {
return error;
}
idException( const char *text = "" ) { strcpy( error, text ); }
};
//stgatilov: hack which can be used to avoid costly initialization, e.g. for large arrays of idVec3
//use with extreme caution! (do not apply to nontrivial objects)
template<class T> struct idRaw {
alignas(T) char bytes[sizeof(T)];
ID_FORCE_INLINE T &Get() { return *(T*)bytes; }
ID_FORCE_INLINE const T &Get() const { return *(const T*)bytes; }
ID_FORCE_INLINE T *Ptr() { return (T*)bytes; }
ID_FORCE_INLINE const T *Ptr() const { return (const T*)bytes; }
void destructor() {
((T*)bytes)->~T();
}
void constructor() {
new(bytes) T();
}
template<class... Args> void constructor(Args&&... args) {
new(bytes) T(static_cast<Args&&>(args)...);
}
};
/*
===============================================================================
idLib headers.
===============================================================================
*/
// System
#include "sys/sys_assert.h"
#include "sys/sys_threading.h"
// memory management and arrays
#include "Heap.h"
#include "Allocators.h"
#include "containers/List.h"
// math
#include "math/Simd.h"
#include "math/Math.h"
#include "math/Random.h"
#include "math/Complex.h"
#include "math/Vector.h"
#include "math/Matrix.h"
#include "math/Angles.h"
#include "math/Quat.h"
#include "math/Rotation.h"
#include "math/Plane.h"
#include "math/Pluecker.h"
#include "math/Polynomial.h"
#include "math/Extrapolate.h"
#include "math/Interpolate.h"
#include "math/Curve.h"
#include "math/Ode.h"
#include "math/Lcp.h"
// bounding volumes
#include "bv/Sphere.h"
#include "bv/Bounds.h"
#include "bv/Box.h"
#include "bv/Frustum.h"
// geometry
#include "geometry/RenderMatrix.h"
#include "geometry/DrawVert.h"
#include "geometry/JointTransform.h"
#include "geometry/Winding.h"
#include "geometry/Winding2D.h"
#include "geometry/Surface.h"
#include "geometry/Surface_Patch.h"
#include "geometry/Surface_Polytope.h"
#include "geometry/Surface_SweptSpline.h"
#include "geometry/TraceModel.h"
// text manipulation
#include "Str.h"
#include "Token.h"
#include "Lexer.h"
#include "Parser.h"
//#include "Base64.h"
#include "CmdArgs.h"
// containers
#include "containers/BTree.h"
#include "containers/BinSearch.h"
#include "containers/HashIndex.h"
#include "containers/HashTable.h"
#include "containers/HashMap.h"
#include "containers/StaticList.h"
#include "containers/LinkList.h"
#include "containers/Hierarchy.h"
#include "containers/Queue.h"
#include "containers/Stack.h"
#include "containers/StrList.h"
#include "containers/StrPool.h"
#include "containers/VectorSet.h"
#include "containers/PlaneSet.h"
// hashing
//#include "hashing/CRC32.h"
#include "hashing/MD4.h"
#include "hashing/MD5.h"
// misc
#include "Dict.h"
#include "LangDict.h"
#include "BitMsg.h"
#include "MapFile.h"
#include "Timer.h"
#include "Thread.h"
#include "RevisionTracker.h"
#include "ParallelJobList.h"
#endif /* !__LIB_H__ */