Lib.h (9254B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 BFG Edition 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 BFG Edition 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 #include <stddef.h> 33 34 /* 35 =============================================================================== 36 37 idLib contains stateless support classes and concrete types. Some classes 38 do have static variables, but such variables are initialized once and 39 read-only after initialization (they do not maintain a modifiable state). 40 41 The interface pointers idSys, idCommon, idCVarSystem and idFileSystem 42 should be set before using idLib. The pointers stored here should not 43 be used by any part of the engine except for idLib. 44 45 =============================================================================== 46 */ 47 48 class idLib { 49 private: 50 static bool mainThreadInitialized; 51 static ID_TLS isMainThread; 52 53 public: 54 static class idSys * sys; 55 static class idCommon * common; 56 static class idCVarSystem * cvarSystem; 57 static class idFileSystem * fileSystem; 58 static int frameNumber; 59 60 static void Init(); 61 static void ShutDown(); 62 63 // wrapper to idCommon functions 64 static void Printf( const char *fmt, ... ); 65 static void PrintfIf( const bool test, const char *fmt, ... ); 66 NO_RETURN static void Error( const char *fmt, ... ); 67 NO_RETURN static void FatalError( const char *fmt, ... ); 68 static void Warning( const char *fmt, ... ); 69 static void WarningIf( const bool test, const char *fmt, ... ); 70 71 // the extra check for mainThreadInitialized is necessary for this to be accurate 72 // when called by startup code that happens before idLib::Init 73 static bool IsMainThread() { return ( 0 == mainThreadInitialized ) || ( 1 == isMainThread ); } 74 }; 75 76 77 /* 78 =============================================================================== 79 80 Types and defines used throughout the engine. 81 82 =============================================================================== 83 */ 84 85 typedef int qhandle_t; 86 87 class idFile; 88 class idVec3; 89 class idVec4; 90 91 #ifndef NULL 92 #define NULL ((void *)0) 93 #endif 94 95 #ifndef BIT 96 #define BIT( num ) ( 1ULL << ( num ) ) 97 #endif 98 99 #define MAX_STRING_CHARS 1024 // max length of a string 100 #define MAX_PRINT_MSG 16384 // buffer size for our various printf routines 101 102 // maximum world size 103 #define MAX_WORLD_COORD ( 128 * 1024 ) 104 #define MIN_WORLD_COORD ( -128 * 1024 ) 105 #define MAX_WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD ) 106 107 #define SIZE_KB( x ) ( ( (x) + 1023 ) / 1024 ) 108 #define SIZE_MB( x ) ( ( ( SIZE_KB( x ) ) + 1023 ) / 1024 ) 109 #define SIZE_GB( x ) ( ( ( SIZE_MB( x ) ) + 1023 ) / 1024 ) 110 111 // basic colors 112 extern idVec4 colorBlack; 113 extern idVec4 colorWhite; 114 extern idVec4 colorRed; 115 extern idVec4 colorGreen; 116 extern idVec4 colorBlue; 117 extern idVec4 colorYellow; 118 extern idVec4 colorMagenta; 119 extern idVec4 colorCyan; 120 extern idVec4 colorOrange; 121 extern idVec4 colorPurple; 122 extern idVec4 colorPink; 123 extern idVec4 colorBrown; 124 extern idVec4 colorLtGrey; 125 extern idVec4 colorMdGrey; 126 extern idVec4 colorDkGrey; 127 128 // packs color floats in the range [0,1] into an integer 129 dword PackColor( const idVec3 &color ); 130 void UnpackColor( const dword color, idVec3 &unpackedColor ); 131 dword PackColor( const idVec4 &color ); 132 void UnpackColor( const dword color, idVec4 &unpackedColor ); 133 134 // little/big endian conversion 135 short BigShort( short l ); 136 short LittleShort( short l ); 137 int BigLong( int l ); 138 int LittleLong( int l ); 139 float BigFloat( float l ); 140 float LittleFloat( float l ); 141 void BigRevBytes( void *bp, int elsize, int elcount ); 142 void LittleRevBytes( void *bp, int elsize, int elcount ); 143 void LittleBitField( void *bp, int elsize ); 144 void Swap_Init(); 145 146 bool Swap_IsBigEndian(); 147 148 // for base64 149 void SixtetsForInt( byte *out, int src); 150 int IntForSixtets( byte *in ); 151 152 /* 153 ================================================ 154 idException 155 ================================================ 156 */ 157 class idException { 158 public: 159 static const int MAX_ERROR_LEN = 2048; 160 161 idException( const char *text = "" ) { 162 strncpy( error, text, MAX_ERROR_LEN ); 163 } 164 165 // this really, really should be a const function, but it's referenced too many places to change right now 166 const char * GetError() { 167 return error; 168 } 169 170 protected: 171 // if GetError() were correctly const this would be named GetError(), too 172 char * GetErrorBuffer() { 173 return error; 174 } 175 int GetErrorBufferSize() { 176 return MAX_ERROR_LEN; 177 } 178 179 private: 180 friend class idFatalException; 181 static char error[MAX_ERROR_LEN]; 182 }; 183 184 /* 185 ================================================ 186 idFatalException 187 ================================================ 188 */ 189 class idFatalException { 190 public: 191 static const int MAX_ERROR_LEN = 2048; 192 193 idFatalException( const char *text = "" ) { 194 strncpy( idException::error, text, MAX_ERROR_LEN ); 195 } 196 197 // this really, really should be a const function, but it's referenced too many places to change right now 198 const char * GetError() { 199 return idException::error; 200 } 201 202 protected: 203 // if GetError() were correctly const this would be named GetError(), too 204 char * GetErrorBuffer() { 205 return idException::error; 206 } 207 int GetErrorBufferSize() { 208 return MAX_ERROR_LEN; 209 } 210 }; 211 212 /* 213 ================================================ 214 idNetworkLoadException 215 ================================================ 216 */ 217 class idNetworkLoadException : public idException { 218 public: 219 idNetworkLoadException( const char * text = "" ) : idException( text ) { } 220 }; 221 222 /* 223 =============================================================================== 224 225 idLib headers. 226 227 =============================================================================== 228 */ 229 230 // System 231 #include "sys/sys_assert.h" 232 #include "sys/sys_threading.h" 233 234 // memory management and arrays 235 #include "Heap.h" 236 #include "containers/Sort.h" 237 #include "containers/List.h" 238 239 // math 240 #include "math/Simd.h" 241 #include "math/Math.h" 242 #include "math/Random.h" 243 #include "math/Complex.h" 244 #include "math/Vector.h" 245 #include "math/VecX.h" 246 #include "math/VectorI.h" 247 #include "math/Matrix.h" 248 #include "math/MatX.h" 249 #include "math/Angles.h" 250 #include "math/Quat.h" 251 #include "math/Rotation.h" 252 #include "math/Plane.h" 253 #include "math/Pluecker.h" 254 #include "math/Polynomial.h" 255 #include "math/Extrapolate.h" 256 #include "math/Interpolate.h" 257 #include "math/Curve.h" 258 #include "math/Ode.h" 259 #include "math/Lcp.h" 260 261 // bounding volumes 262 #include "bv/Sphere.h" 263 #include "bv/Bounds.h" 264 #include "bv/Box.h" 265 266 // geometry 267 #include "geometry/RenderMatrix.h" 268 #include "geometry/JointTransform.h" 269 #include "geometry/DrawVert.h" 270 #include "geometry/Winding.h" 271 #include "geometry/Winding2D.h" 272 #include "geometry/Surface.h" 273 #include "geometry/Surface_Patch.h" 274 #include "geometry/Surface_Polytope.h" 275 #include "geometry/Surface_SweptSpline.h" 276 #include "geometry/TraceModel.h" 277 278 // text manipulation 279 #include "Str.h" 280 #include "StrStatic.h" 281 #include "Token.h" 282 #include "Lexer.h" 283 #include "Parser.h" 284 #include "Base64.h" 285 #include "CmdArgs.h" 286 287 // containers 288 #include "containers/Array.h" 289 #include "containers/BTree.h" 290 #include "containers/BinSearch.h" 291 #include "containers/HashIndex.h" 292 #include "containers/HashTable.h" 293 #include "containers/StaticList.h" 294 #include "containers/LinkList.h" 295 #include "containers/Hierarchy.h" 296 #include "containers/Queue.h" 297 #include "containers/Stack.h" 298 #include "containers/StrList.h" 299 #include "containers/StrPool.h" 300 #include "containers/VectorSet.h" 301 #include "containers/PlaneSet.h" 302 303 // hashing 304 #include "hashing/CRC32.h" 305 #include "hashing/MD4.h" 306 #include "hashing/MD5.h" 307 308 // misc 309 #include "Dict.h" 310 #include "LangDict.h" 311 #include "DataQueue.h" 312 #include "BitMsg.h" 313 #include "MapFile.h" 314 #include "Timer.h" 315 #include "Thread.h" 316 #include "Swap.h" 317 #include "Callback.h" 318 #include "ParallelJobList.h" 319 320 #include "SoftwareCache.h" 321 322 #endif /* !__LIB_H__ */