-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_trace.h
322 lines (270 loc) · 7.73 KB
/
c_trace.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
#include "i_base_player.h"
#include "Vector.h"
#include "RecvProps.h"
enum class TraceType
{
TRACE_EVERYTHING = 0,
TRACE_WORLD_ONLY,
TRACE_ENTITIES_ONLY,
TRACE_EVERYTHING_FILTER_PROPS,
};
class ITraceFilter
{
public:
virtual bool ShouldHitEntity(IHandleEntity* pEntity, int contentsMask) = 0;
virtual TraceType GetTraceType() const = 0;
};
//-----------------------------------------------------------------------------
// Classes are expected to inherit these + implement the ShouldHitEntity method
//-----------------------------------------------------------------------------
// This is the one most normal traces will inherit from
class CTraceFilter : public ITraceFilter
{
public:
bool ShouldHitEntity(IHandleEntity* pEntityHandle, int /*contentsMask*/)
{
ClientClass* eCC = ((IBasePlayer*)pEntityHandle)->GetClientClass();
if (eCC && strcmp(ccIgnore, str("")))
{
if (eCC->m_pNetworkName == ccIgnore)
return false;
}
return !(pEntityHandle == pSkip);
}
virtual TraceType GetTraceType() const
{
return TraceType::TRACE_EVERYTHING;
}
inline void SetIgnoreClass(char* Class)
{
ccIgnore = Class;
}
void* pSkip;
char* ccIgnore = new char[1];
};
class CTraceFilterOneEntity : public ITraceFilter {
public:
bool ShouldHitEntity(IHandleEntity* pEntityHandle, int /*contentsMask*/) {
return (pEntityHandle == pEntity);
}
TraceType GetTraceType() const {
return TraceType::TRACE_EVERYTHING;
}
void* pEntity;
};
class CTraceFilterSkipEntity : public ITraceFilter
{
public:
CTraceFilterSkipEntity(IHandleEntity* pEntityHandle)
{
pSkip = pEntityHandle;
}
bool ShouldHitEntity(IHandleEntity* pEntityHandle, int /*contentsMask*/)
{
return !(pEntityHandle == pSkip);
}
virtual TraceType GetTraceType() const
{
return TraceType::TRACE_EVERYTHING;
}
void* pSkip;
};
class CTraceFilterEntitiesOnly : public ITraceFilter
{
public:
bool ShouldHitEntity(IHandleEntity* pEntityHandle, int /*contentsMask*/)
{
return true;
}
virtual TraceType GetTraceType() const
{
return TraceType::TRACE_ENTITIES_ONLY;
}
};
//-----------------------------------------------------------------------------
// Classes need not inherit from these
//-----------------------------------------------------------------------------
class CTraceFilterWorldOnly : public ITraceFilter
{
public:
bool ShouldHitEntity(IHandleEntity* /*pServerEntity*/, int /*contentsMask*/)
{
return false;
}
virtual TraceType GetTraceType() const
{
return TraceType::TRACE_WORLD_ONLY;
}
};
class CTraceFilterWorldAndPropsOnly : public ITraceFilter
{
public:
bool ShouldHitEntity(IHandleEntity* /*pServerEntity*/, int /*contentsMask*/)
{
return false;
}
virtual TraceType GetTraceType() const
{
return TraceType::TRACE_EVERYTHING;
}
};
class CTraceFilterPlayersOnlySkipOne : public ITraceFilter
{
public:
CTraceFilterPlayersOnlySkipOne(IBasePlayer* ent)
{
e = ent;
}
bool ShouldHitEntity(IHandleEntity* pEntityHandle, int /*contentsMask*/)
{
return pEntityHandle != e && ((IBasePlayer*)pEntityHandle)->GetClientClass()->m_ClassID == 40;
}
virtual TraceType GetTraceType() const
{
return TraceType::TRACE_ENTITIES_ONLY;
}
private:
IBasePlayer* e;
};
class CTraceFilterSkipTwoEntities : public ITraceFilter
{
public:
CTraceFilterSkipTwoEntities(IBasePlayer* ent1, IBasePlayer* ent2)
{
e1 = ent1;
e2 = ent2;
}
bool ShouldHitEntity(IHandleEntity* pEntityHandle, int /*contentsMask*/)
{
return !(pEntityHandle == e1 || pEntityHandle == e2);
}
virtual TraceType GetTraceType() const
{
return TraceType::TRACE_EVERYTHING;
}
private:
IBasePlayer* e1;
IBasePlayer* e2;
};
class CTraceFilterHitAll : public CTraceFilter
{
public:
virtual bool ShouldHitEntity(IHandleEntity* /*pServerEntity*/, int /*contentsMask*/)
{
return true;
}
};
enum class DebugTraceCounterBehavior_t
{
kTRACE_COUNTER_SET = 0,
kTRACE_COUNTER_INC,
};
//-----------------------------------------------------------------------------
// Enumeration interface for EnumerateLinkEntities
//-----------------------------------------------------------------------------
class IEntityEnumerator
{
public:
// This gets called with each handle
virtual bool EnumEntity(IHandleEntity* pHandleEntity) = 0;
};
struct BrushSideInfo_t
{
Vector4D plane; // The plane of the brush side
unsigned short bevel; // Bevel plane?
unsigned short thin; // Thin?
};
class CPhysCollide;
struct cplane_t {
Vector normal;
float dist;
uint8_t type; // for fast side tests
uint8_t signbits; // signx + (signy<<1) + (signz<<1)
uint8_t pad[2];
};
struct vcollide_t
{
unsigned short solidCount : 15;
unsigned short isPacked : 1;
unsigned short descSize;
// VPhysicsSolids
CPhysCollide** solids;
char* pKeyValues;
void* pUserData;
};
struct cmodel_t
{
Vector mins, maxs;
Vector origin; // for sounds or lights
int headnode;
vcollide_t vcollisionData;
};
struct csurface_t
{
const char* name;
short surfaceProps;
unsigned short flags; // BUGBUG: These are declared per surface, not per material, but this database is per-material now
};
//-----------------------------------------------------------------------------
// A ray...
//-----------------------------------------------------------------------------
struct Ray_t
{
VectorAligned m_Start; // starting point, centered within the extents
VectorAligned m_Delta; // direction + length of the ray
VectorAligned m_StartOffset; // Add this to m_Start to Get the actual ray start
VectorAligned m_Extents; // Describes an axis aligned box extruded along a ray
const matrix* m_pWorldAxisTransform;
bool m_IsRay; // are the extents zero?
bool m_IsSwept; // is delta != 0?
Ray_t() : m_pWorldAxisTransform(NULL) {}
Ray_t(Vector const& start, Vector const& end) {
m_Delta = end - start;
m_IsSwept = (m_Delta.LengthSqr() != 0);
m_Extents.Init();
m_pWorldAxisTransform = NULL;
m_IsRay = true;
// Offset m_Start to be in the center of the box...
m_StartOffset.Init();
m_Start = start;
}
void Init(Vector const& start, Vector const& end)
{
m_Delta = end - start;
m_IsSwept = (m_Delta.LengthSqr() != 0);
m_Extents.Init();
m_pWorldAxisTransform = NULL;
m_IsRay = true;
// Offset m_Start to be in the center of the box...
m_StartOffset.Init();
m_Start = start;
}
void Init(Vector const& start, Vector const& end, Vector const& mins, Vector const& maxs)
{
m_Delta = end - start;
m_pWorldAxisTransform = NULL;
m_IsSwept = (m_Delta.LengthSqr() != 0);
m_Extents = maxs - mins;
m_Extents *= 0.5f;
m_IsRay = (m_Extents.LengthSqr() < 1e-6);
// Offset m_Start to be in the center of the box...
m_StartOffset = maxs + mins;
m_StartOffset *= 0.5f;
m_Start = start + m_StartOffset;
m_StartOffset *= -1.0f;
}
Vector InvDelta() const
{
Vector vecInvDelta;
for (int iAxis = 0; iAxis < 3; ++iAxis) {
if (m_Delta[iAxis] != 0.0f) {
vecInvDelta[iAxis] = 1.0f / m_Delta[iAxis];
}
else {
vecInvDelta[iAxis] = FLT_MAX;
}
}
return vecInvDelta;
}
private:
};