doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Lib.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __LIB_H__
30 #define __LIB_H__
31 
32 
33 /*
34 ===============================================================================
35 
36  idLib contains stateless support classes and concrete types. Some classes
37  do have static variables, but such variables are initialized once and
38  read-only after initialization (they do not maintain a modifiable state).
39 
40  The interface pointers idSys, idCommon, idCVarSystem and idFileSystem
41  should be set before using idLib. The pointers stored here should not
42  be used by any part of the engine except for idLib.
43 
44  The frameNumber should be continuously set to the number of the current
45  frame if frame base memory logging is required.
46 
47 ===============================================================================
48 */
49 
50 class idLib {
51 public:
52  static class idSys * sys;
53  static class idCommon * common;
54  static class idCVarSystem * cvarSystem;
55  static class idFileSystem * fileSystem;
56  static int frameNumber;
57 
58  static void Init( void );
59  static void ShutDown( void );
60 
61  // wrapper to idCommon functions
62  static void Error( const char *fmt, ... );
63  static void Warning( const char *fmt, ... );
64 };
65 
66 
67 /*
68 ===============================================================================
69 
70  Types and defines used throughout the engine.
71 
72 ===============================================================================
73 */
74 
75 typedef unsigned char byte; // 8 bits
76 typedef unsigned short word; // 16 bits
77 typedef unsigned int dword; // 32 bits
78 typedef unsigned int uint;
79 typedef unsigned long ulong;
80 
81 typedef int qhandle_t;
82 
83 class idFile;
84 class idVec3;
85 class idVec4;
86 
87 #ifndef NULL
88 #define NULL ((void *)0)
89 #endif
90 
91 #ifndef BIT
92 #define BIT( num ) ( 1 << ( num ) )
93 #endif
94 
95 #define MAX_STRING_CHARS 1024 // max length of a string
96 
97 // maximum world size
98 #define MAX_WORLD_COORD ( 128 * 1024 )
99 #define MIN_WORLD_COORD ( -128 * 1024 )
100 #define MAX_WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD )
101 
102 // basic colors
103 extern idVec4 colorBlack;
104 extern idVec4 colorWhite;
105 extern idVec4 colorRed;
106 extern idVec4 colorGreen;
107 extern idVec4 colorBlue;
108 extern idVec4 colorYellow;
109 extern idVec4 colorMagenta;
110 extern idVec4 colorCyan;
111 extern idVec4 colorOrange;
112 extern idVec4 colorPurple;
113 extern idVec4 colorPink;
114 extern idVec4 colorBrown;
115 extern idVec4 colorLtGrey;
116 extern idVec4 colorMdGrey;
117 extern idVec4 colorDkGrey;
118 
119 // packs color floats in the range [0,1] into an integer
120 dword PackColor( const idVec3 &color );
121 void UnpackColor( const dword color, idVec3 &unpackedColor );
122 dword PackColor( const idVec4 &color );
123 void UnpackColor( const dword color, idVec4 &unpackedColor );
124 
125 // little/big endian conversion
126 short BigShort( short l );
127 short LittleShort( short l );
128 int BigLong( int l );
129 int LittleLong( int l );
130 float BigFloat( float l );
131 float LittleFloat( float l );
132 void BigRevBytes( void *bp, int elsize, int elcount );
133 void LittleRevBytes( void *bp, int elsize, int elcount );
134 void LittleBitField( void *bp, int elsize );
135 void Swap_Init( void );
136 
137 bool Swap_IsBigEndian( void );
138 
139 // for base64
140 void SixtetsForInt( byte *out, int src);
141 int IntForSixtets( byte *in );
142 
143 
144 #ifdef _DEBUG
145 void AssertFailed( const char *file, int line, const char *expression );
146 #undef assert
147 #define assert( X ) if ( X ) { } else AssertFailed( __FILE__, __LINE__, #X )
148 #endif
149 
150 class idException {
151 public:
153 
154  idException( const char *text = "" ) { strcpy( error, text ); }
155 };
156 
157 // move from Math.h to keep gcc happy
158 template<class T> ID_INLINE T Max( T x, T y ) { return ( x > y ) ? x : y; }
159 template<class T> ID_INLINE T Min( T x, T y ) { return ( x < y ) ? x : y; }
160 
161 /*
162 ===============================================================================
163 
164  idLib headers.
165 
166 ===============================================================================
167 */
168 
169 // memory management and arrays
170 #include "Heap.h"
171 #include "containers/List.h"
172 
173 // math
174 #include "math/Simd.h"
175 #include "math/Math.h"
176 #include "math/Random.h"
177 #include "math/Complex.h"
178 #include "math/Vector.h"
179 #include "math/Matrix.h"
180 #include "math/Angles.h"
181 #include "math/Quat.h"
182 #include "math/Rotation.h"
183 #include "math/Plane.h"
184 #include "math/Pluecker.h"
185 #include "math/Polynomial.h"
186 #include "math/Extrapolate.h"
187 #include "math/Interpolate.h"
188 #include "math/Curve.h"
189 #include "math/Ode.h"
190 #include "math/Lcp.h"
191 
192 // bounding volumes
193 #include "bv/Sphere.h"
194 #include "bv/Bounds.h"
195 #include "bv/Box.h"
196 #include "bv/Frustum.h"
197 
198 // geometry
199 #include "geometry/DrawVert.h"
200 #include "geometry/JointTransform.h"
201 #include "geometry/Winding.h"
202 #include "geometry/Winding2D.h"
203 #include "geometry/Surface.h"
204 #include "geometry/Surface_Patch.h"
207 #include "geometry/TraceModel.h"
208 
209 // text manipulation
210 #include "Str.h"
211 #include "Token.h"
212 #include "Lexer.h"
213 #include "Parser.h"
214 #include "Base64.h"
215 #include "CmdArgs.h"
216 
217 // containers
218 #include "containers/BTree.h"
219 #include "containers/BinSearch.h"
220 #include "containers/HashIndex.h"
221 #include "containers/HashTable.h"
222 #include "containers/StaticList.h"
223 #include "containers/LinkList.h"
224 #include "containers/Hierarchy.h"
225 #include "containers/Queue.h"
226 #include "containers/Stack.h"
227 #include "containers/StrList.h"
228 #include "containers/StrPool.h"
229 #include "containers/VectorSet.h"
230 #include "containers/PlaneSet.h"
231 
232 // hashing
233 #include "hashing/CRC32.h"
234 #include "hashing/MD4.h"
235 #include "hashing/MD5.h"
236 
237 // misc
238 #include "Dict.h"
239 #include "LangDict.h"
240 #include "BitMsg.h"
241 #include "MapFile.h"
242 #include "Timer.h"
243 
244 #endif /* !__LIB_H__ */
byte color[4]
Definition: MegaTexture.cpp:54
int LittleLong(int l)
Definition: Lib.cpp:281
unsigned int dword
Definition: Lib.h:77
idVec4 colorRed
Definition: Lib.cpp:117
int qhandle_t
Definition: Lib.h:81
unsigned int uint
Definition: Lib.h:78
void AssertFailed(const char *file, int line, const char *expression)
Definition: Lib.cpp:576
static void Warning(const char *fmt,...)
Definition: Lib.cpp:246
static void ShutDown(void)
Definition: Lib.cpp:91
idVec4 colorMagenta
Definition: Lib.cpp:121
ID_INLINE T Max(T x, T y)
Definition: Lib.h:158
void UnpackColor(const dword color, idVec3 &unpackedColor)
Definition: Lib.cpp:211
GLenum GLint GLint y
Definition: glext.h:2849
idException(const char *text="")
Definition: Lib.h:154
idVec4 colorDkGrey
Definition: Lib.cpp:129
Definition: Vector.h:316
void LittleBitField(void *bp, int elsize)
Definition: Lib.cpp:286
short BigShort(short l)
Definition: Lib.cpp:278
bool Swap_IsBigEndian(void)
Definition: Lib.cpp:563
static class idSys * sys
Definition: Lib.h:52
GLuint src
Definition: glext.h:5390
GLenum GLint x
Definition: glext.h:2849
idVec4 colorMdGrey
Definition: Lib.cpp:128
list l
Definition: prepare.py:17
int IntForSixtets(byte *in)
Definition: Lib.cpp:289
Definition: File.h:50
static class idFileSystem * fileSystem
Definition: Lib.h:55
idVec4 colorPurple
Definition: Lib.cpp:124
Definition: Vector.h:808
#define MAX_STRING_CHARS
Definition: Lib.h:95
idVec4 colorYellow
Definition: Lib.cpp:120
idVec4 colorGreen
Definition: Lib.cpp:118
void SixtetsForInt(byte *out, int src)
Definition: Lib.cpp:288
static int frameNumber
Definition: Lib.h:56
int BigLong(int l)
Definition: Lib.cpp:280
void LittleRevBytes(void *bp, int elsize, int elcount)
Definition: Lib.cpp:285
idVec4 colorBlack
Definition: Lib.cpp:115
idVec4 colorBlue
Definition: Lib.cpp:119
dword PackColor(const idVec3 &color)
Definition: Lib.cpp:190
idVec4 colorOrange
Definition: Lib.cpp:123
Definition: Lib.h:50
idVec4 colorCyan
Definition: Lib.cpp:122
short LittleShort(short l)
Definition: Lib.cpp:279
unsigned short word
Definition: Lib.h:76
GLuint in
Definition: glext.h:5388
static void Init(void)
Definition: Lib.cpp:57
char error[MAX_STRING_CHARS]
Definition: Lib.h:152
unsigned char byte
Definition: Lib.h:75
float BigFloat(float l)
Definition: Lib.cpp:282
static class idCVarSystem * cvarSystem
Definition: Lib.h:54
static void Error(const char *fmt,...)
Definition: Lib.cpp:230
idVec4 colorWhite
Definition: Lib.cpp:116
float LittleFloat(float l)
Definition: Lib.cpp:283
void Swap_Init(void)
Definition: Lib.cpp:525
unsigned long ulong
Definition: Lib.h:79
idVec4 colorLtGrey
Definition: Lib.cpp:127
idVec4 colorPink
Definition: Lib.cpp:125
idVec4 colorBrown
Definition: Lib.cpp:126
Definition: eax4.h:1413
ID_INLINE T Min(T x, T y)
Definition: Lib.h:159
void BigRevBytes(void *bp, int elsize, int elcount)
Definition: Lib.cpp:284
static class idCommon * common
Definition: Lib.h:53