forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasetypes.h
398 lines (309 loc) · 9.75 KB
/
basetypes.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef BASETYPES_H
#define BASETYPES_H
#include "commonmacros.h"
#include "wchartypes.h"
#include "tier0/valve_off.h"
#ifdef _WIN32
#pragma once
#endif
// This is a trick to get the DLL extension off the -D option on the command line.
#define DLLExtTokenPaste(x) #x
#define DLLExtTokenPaste2(x) DLLExtTokenPaste(x)
#define DLL_EXT_STRING DLLExtTokenPaste2( _DLL_EXT )
#include "protected_things.h"
// There's a different version of this file in the xbox codeline
// so the PC version built in the xbox branch includes things like
// tickrate changes.
#include "xbox_codeline_defines.h"
#ifdef IN_XBOX_CODELINE
#define XBOX_CODELINE_ONLY()
#else
#define XBOX_CODELINE_ONLY() Error_Compiling_Code_Only_Valid_in_Xbox_Codeline
#endif
// stdio.h
#ifndef NULL
#define NULL 0
#endif
#ifdef POSIX
#include <stdint.h>
#endif
#define ExecuteNTimes( nTimes, x ) \
{ \
static int __executeCount=0;\
if ( __executeCount < nTimes )\
{ \
x; \
++__executeCount; \
} \
}
#define ExecuteOnce( x ) ExecuteNTimes( 1, x )
template <typename T>
inline T AlignValue( T val, uintptr_t alignment )
{
return (T)( ( (uintptr_t)val + alignment - 1 ) & ~( alignment - 1 ) );
}
// Pad a number so it lies on an N byte boundary.
// So PAD_NUMBER(0,4) is 0 and PAD_NUMBER(1,4) is 4
#define PAD_NUMBER(number, boundary) \
( ((number) + ((boundary)-1)) / (boundary) ) * (boundary)
// In case this ever changes
#if !defined(M_PI) && !defined(HAVE_M_PI)
#define M_PI 3.14159265358979323846
#endif
#include "valve_minmax_on.h"
// #define COMPILETIME_MAX and COMPILETIME_MIN for max/min in constant expressions
#define COMPILETIME_MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#define COMPILETIME_MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
#ifndef MIN
#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#endif
#ifndef MAX
#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
#endif
#ifdef __cplusplus
// This is the preferred clamp operator. Using the clamp macro can lead to
// unexpected side-effects or more expensive code. Even the clamp (all
// lower-case) function can generate more expensive code because of the
// mixed types involved.
template< class T >
T Clamp( T const &val, T const &minVal, T const &maxVal )
{
if( val < minVal )
return minVal;
else if( val > maxVal )
return maxVal;
else
return val;
}
// This is the preferred Min operator. Using the MIN macro can lead to unexpected
// side-effects or more expensive code.
template< class T >
T Min( T const &val1, T const &val2 )
{
return val1 < val2 ? val1 : val2;
}
// This is the preferred Max operator. Using the MAX macro can lead to unexpected
// side-effects or more expensive code.
template< class T >
T Max( T const &val1, T const &val2 )
{
return val1 > val2 ? val1 : val2;
}
#endif
#ifndef FALSE
#define FALSE 0
#define TRUE (!FALSE)
#endif
#ifndef DONT_DEFINE_BOOL // Needed for Cocoa stuff to compile.
typedef int BOOL;
#endif
typedef int qboolean;
typedef unsigned long ULONG;
typedef unsigned char BYTE;
typedef unsigned char byte;
typedef unsigned short word;
#ifdef _WIN32
typedef wchar_t ucs2; // under windows wchar_t is ucs2
#else
typedef unsigned short ucs2;
#endif
enum ThreeState_t
{
TRS_FALSE,
TRS_TRUE,
TRS_NONE,
};
typedef float vec_t;
#if defined(__GNUC__)
#define fpmin __builtin_fminf
#define fpmax __builtin_fmaxf
#elif !defined(_X360)
#define fpmin min
#define fpmax max
#endif
//-----------------------------------------------------------------------------
// look for NANs, infinities, and underflows.
// This assumes the ANSI/IEEE 754-1985 standard
//-----------------------------------------------------------------------------
inline unsigned long& FloatBits( vec_t& f )
{
return *reinterpret_cast<unsigned long*>(&f);
}
inline unsigned long const& FloatBits( vec_t const& f )
{
return *reinterpret_cast<unsigned long const*>(&f);
}
inline vec_t BitsToFloat( unsigned long i )
{
return *reinterpret_cast<vec_t*>(&i);
}
inline bool IsFinite( vec_t f )
{
return ((FloatBits(f) & 0x7F800000) != 0x7F800000);
}
inline unsigned long FloatAbsBits( vec_t f )
{
return FloatBits(f) & 0x7FFFFFFF;
}
// Given today's processors, I cannot think of any circumstance
// where bit tricks would be faster than fabs. henryg 8/16/2011
#ifdef _MSC_VER
#ifndef _In_
#define _In_
#endif
extern "C" float fabsf(_In_ float);
#else
#include <math.h>
#endif
inline float FloatMakeNegative( vec_t f )
{
return -fabsf(f);
}
inline float FloatMakePositive( vec_t f )
{
return fabsf(f);
}
inline float FloatNegate( vec_t f )
{
return -f;
}
#define FLOAT32_NAN_BITS (unsigned long)0x7FC00000 // not a number!
#define FLOAT32_NAN BitsToFloat( FLOAT32_NAN_BITS )
#define VEC_T_NAN FLOAT32_NAN
// FIXME: why are these here? Hardly anyone actually needs them.
struct color24
{
byte r, g, b;
};
typedef struct color32_s
{
bool operator!=( const struct color32_s &other ) const;
byte r, g, b, a;
} color32;
inline bool color32::operator!=( const color32 &other ) const
{
return r != other.r || g != other.g || b != other.b || a != other.a;
}
struct colorVec
{
unsigned r, g, b, a;
};
#ifndef NOTE_UNUSED
#define NOTE_UNUSED(x) (void)(x) // for pesky compiler / lint warnings
#endif
struct vrect_t
{
int x,y,width,height;
vrect_t *pnext;
};
//-----------------------------------------------------------------------------
// MaterialRect_t struct - used for DrawDebugText
//-----------------------------------------------------------------------------
struct Rect_t
{
int x, y;
int width, height;
};
//-----------------------------------------------------------------------------
// Interval, used by soundemittersystem + the game
//-----------------------------------------------------------------------------
struct interval_t
{
float start;
float range;
};
//-----------------------------------------------------------------------------
// Declares a type-safe handle type; you can't assign one handle to the next
//-----------------------------------------------------------------------------
// 32-bit pointer handles.
// Typesafe 8-bit and 16-bit handles.
template< class HandleType >
class CBaseIntHandle
{
public:
inline bool operator==( const CBaseIntHandle &other ) { return m_Handle == other.m_Handle; }
inline bool operator!=( const CBaseIntHandle &other ) { return m_Handle != other.m_Handle; }
// Only the code that doles out these handles should use these functions.
// Everyone else should treat them as a transparent type.
inline HandleType GetHandleValue() { return m_Handle; }
inline void SetHandleValue( HandleType val ) { m_Handle = val; }
typedef HandleType HANDLE_TYPE;
protected:
HandleType m_Handle;
};
template< class DummyType >
class CIntHandle16 : public CBaseIntHandle< unsigned short >
{
public:
inline CIntHandle16() {}
static inline CIntHandle16<DummyType> MakeHandle( HANDLE_TYPE val )
{
return CIntHandle16<DummyType>( val );
}
protected:
inline CIntHandle16( HANDLE_TYPE val )
{
m_Handle = val;
}
};
template< class DummyType >
class CIntHandle32 : public CBaseIntHandle< unsigned long >
{
public:
inline CIntHandle32() {}
static inline CIntHandle32<DummyType> MakeHandle( HANDLE_TYPE val )
{
return CIntHandle32<DummyType>( val );
}
protected:
inline CIntHandle32( HANDLE_TYPE val )
{
m_Handle = val;
}
};
// NOTE: This macro is the same as windows uses; so don't change the guts of it
#define DECLARE_HANDLE_16BIT(name) typedef CIntHandle16< struct name##__handle * > name;
#define DECLARE_HANDLE_32BIT(name) typedef CIntHandle32< struct name##__handle * > name;
#define DECLARE_POINTER_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
#define FORWARD_DECLARE_HANDLE(name) typedef struct name##__ *name
// @TODO: Find a better home for this
#if !defined(_STATIC_LINKED) && !defined(PUBLISH_DLL_SUBSYSTEM)
// for platforms built with dynamic linking, the dll interface does not need spoofing
#define PUBLISH_DLL_SUBSYSTEM()
#endif
#define UID_PREFIX generated_id_
#define UID_CAT1(a,c) a ## c
#define UID_CAT2(a,c) UID_CAT1(a,c)
#define EXPAND_CONCAT(a,c) UID_CAT1(a,c)
#ifdef _MSC_VER
#define UNIQUE_ID UID_CAT2(UID_PREFIX,__COUNTER__)
#else
#define UNIQUE_ID UID_CAT2(UID_PREFIX,__LINE__)
#endif
// this allows enumerations to be used as flags, and still remain type-safe!
#define DEFINE_ENUM_BITWISE_OPERATORS( Type ) \
inline Type operator| ( Type a, Type b ) { return Type( int( a ) | int( b ) ); } \
inline Type operator& ( Type a, Type b ) { return Type( int( a ) & int( b ) ); } \
inline Type operator^ ( Type a, Type b ) { return Type( int( a ) ^ int( b ) ); } \
inline Type operator<< ( Type a, int b ) { return Type( int( a ) << b ); } \
inline Type operator>> ( Type a, int b ) { return Type( int( a ) >> b ); } \
inline Type &operator|= ( Type &a, Type b ) { return a = a | b; } \
inline Type &operator&= ( Type &a, Type b ) { return a = a & b; } \
inline Type &operator^= ( Type &a, Type b ) { return a = a ^ b; } \
inline Type &operator<<=( Type &a, int b ) { return a = a << b; } \
inline Type &operator>>=( Type &a, int b ) { return a = a >> b; } \
inline Type operator~( Type a ) { return Type( ~int( a ) ); }
// defines increment/decrement operators for enums for easy iteration
#define DEFINE_ENUM_INCREMENT_OPERATORS( Type ) \
inline Type &operator++( Type &a ) { return a = Type( int( a ) + 1 ); } \
inline Type &operator--( Type &a ) { return a = Type( int( a ) - 1 ); } \
inline Type operator++( Type &a, int ) { Type t = a; ++a; return t; } \
inline Type operator--( Type &a, int ) { Type t = a; --a; return t; }
#include "tier0/valve_on.h"
#endif // BASETYPES_H