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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "c_physicsprop.h"
#include "c_physbox.h"
#include "c_props.h"
#define CPhysBox C_PhysBox
#define CPhysicsProp C_PhysicsProp
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
IMPLEMENT_NETWORKCLASS_ALIASED( DynamicProp, DT_DynamicProp )
BEGIN_NETWORK_TABLE( CDynamicProp, DT_DynamicProp )
RecvPropBool(RECVINFO(m_bUseHitboxesForRenderBox)),
END_NETWORK_TABLE()
C_DynamicProp::C_DynamicProp( void )
{
m_iCachedFrameCount = -1;
}
C_DynamicProp::~C_DynamicProp( void )
{
}
bool C_DynamicProp::TestBoneFollowers( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr )
{
// UNDONE: There is no list of the bone followers that is networked to the client
// so instead we do a search for solid stuff here. This is not really great - a list would be
// preferable.
CBaseEntity *pList[128];
Vector mins, maxs;
CollisionProp()->WorldSpaceAABB( &mins, &maxs );
int count = UTIL_EntitiesInBox( pList, ARRAYSIZE(pList), mins, maxs, 0, PARTITION_CLIENT_SOLID_EDICTS );
for ( int i = 0; i < count; i++ )
{
if ( pList[i]->GetOwnerEntity() == this )
{
if ( pList[i]->TestCollision(ray, fContentsMask, tr) )
{
return true;
}
}
}
return false;
}
bool C_DynamicProp::TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr )
{
if ( IsSolidFlagSet(FSOLID_NOT_SOLID) )
{
// if this entity is marked non-solid and custom test it must have bone followers
if ( IsSolidFlagSet( FSOLID_CUSTOMBOXTEST ) && IsSolidFlagSet( FSOLID_CUSTOMRAYTEST ))
{
return TestBoneFollowers( ray, fContentsMask, tr );
}
}
return BaseClass::TestCollision( ray, fContentsMask, tr );
}
//-----------------------------------------------------------------------------
// implements these so ragdolls can handle frustum culling & leaf visibility
//-----------------------------------------------------------------------------
void C_DynamicProp::GetRenderBounds( Vector& theMins, Vector& theMaxs )
{
if ( m_bUseHitboxesForRenderBox )
{
if ( GetModel() )
{
studiohdr_t *pStudioHdr = modelinfo->GetStudiomodel( GetModel() );
if ( !pStudioHdr || GetSequence() == -1 )
{
theMins = vec3_origin;
theMaxs = vec3_origin;
return;
}
// Only recompute if it's a new frame
if ( gpGlobals->framecount != m_iCachedFrameCount )
{
ComputeEntitySpaceHitboxSurroundingBox( &m_vecCachedRenderMins, &m_vecCachedRenderMaxs );
m_iCachedFrameCount = gpGlobals->framecount;
}
theMins = m_vecCachedRenderMins;
theMaxs = m_vecCachedRenderMaxs;
return;
}
}
BaseClass::GetRenderBounds( theMins, theMaxs );
}
unsigned int C_DynamicProp::ComputeClientSideAnimationFlags()
{
if ( GetSequence() != -1 )
{
CStudioHdr *pStudioHdr = GetModelPtr();
if ( GetSequenceCycleRate(pStudioHdr, GetSequence()) != 0.0f )
{
return BaseClass::ComputeClientSideAnimationFlags();
}
}
// no sequence or no cycle rate, don't do any per-frame calcs
return 0;
}
// ------------------------------------------------------------------------------------------ //
// ------------------------------------------------------------------------------------------ //
class C_BasePropDoor : public C_DynamicProp
{
DECLARE_CLASS( C_BasePropDoor, C_DynamicProp );
public:
DECLARE_CLIENTCLASS();
// constructor, destructor
C_BasePropDoor( void );
virtual ~C_BasePropDoor( void );
virtual void OnDataChanged( DataUpdateType_t type );
virtual bool TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace );
private:
C_BasePropDoor( const C_BasePropDoor & );
};
IMPLEMENT_CLIENTCLASS_DT(C_BasePropDoor, DT_BasePropDoor, CBasePropDoor)
END_RECV_TABLE()
C_BasePropDoor::C_BasePropDoor( void )
{
}
C_BasePropDoor::~C_BasePropDoor( void )
{
}
void C_BasePropDoor::OnDataChanged( DataUpdateType_t type )
{
BaseClass::OnDataChanged( type );
if ( type == DATA_UPDATE_CREATED )
{
SetSolid(SOLID_VPHYSICS);
VPhysicsInitShadow( false, false );
}
else if ( VPhysicsGetObject() )
{
VPhysicsGetObject()->UpdateShadow( GetAbsOrigin(), GetAbsAngles(), false, TICK_INTERVAL );
}
}
bool C_BasePropDoor::TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace )
{
if ( !VPhysicsGetObject() )
return false;
CStudioHdr *pStudioHdr = GetModelPtr( );
if (!pStudioHdr)
return false;
physcollision->TraceBox( ray, VPhysicsGetObject()->GetCollide(), GetAbsOrigin(), GetAbsAngles(), &trace );
if ( trace.DidHit() )
{
trace.surface.surfaceProps = VPhysicsGetObject()->GetMaterialIndex();
return true;
}
return false;
}
// ------------------------------------------------------------------------------------------ //
// Special version of func_physbox.
// ------------------------------------------------------------------------------------------ //
#ifndef _XBOX
class CPhysBoxMultiplayer : public CPhysBox, public IMultiplayerPhysics
{
public:
DECLARE_CLASS( CPhysBoxMultiplayer, CPhysBox );
virtual int GetMultiplayerPhysicsMode()
{
return m_iPhysicsMode;
}
virtual float GetMass()
{
return m_fMass;
}
virtual bool IsAsleep()
{
Assert ( 0 );
return true;
}
CNetworkVar( int, m_iPhysicsMode ); // One of the PHYSICS_MULTIPLAYER_ defines.
CNetworkVar( float, m_fMass );
DECLARE_CLIENTCLASS();
};
IMPLEMENT_CLIENTCLASS_DT( CPhysBoxMultiplayer, DT_PhysBoxMultiplayer, CPhysBoxMultiplayer )
RecvPropInt( RECVINFO( m_iPhysicsMode ) ),
RecvPropFloat( RECVINFO( m_fMass ) ),
END_RECV_TABLE()
class CPhysicsPropMultiplayer : public CPhysicsProp, public IMultiplayerPhysics
{
DECLARE_CLASS( CPhysicsPropMultiplayer, CPhysicsProp );
virtual int GetMultiplayerPhysicsMode()
{
Assert( m_iPhysicsMode != PHYSICS_MULTIPLAYER_CLIENTSIDE );
Assert( m_iPhysicsMode != PHYSICS_MULTIPLAYER_AUTODETECT );
return m_iPhysicsMode;
}
virtual float GetMass()
{
return m_fMass;
}
virtual bool IsAsleep()
{
return !m_bAwake;
}
virtual void ComputeWorldSpaceSurroundingBox( Vector *mins, Vector *maxs )
{
Assert( mins != NULL && maxs != NULL );
if ( !mins || !maxs )
return;
// Take our saved collision bounds, and transform into world space
TransformAABB( EntityToWorldTransform(), m_collisionMins, m_collisionMaxs, *mins, *maxs );
}
CNetworkVar( int, m_iPhysicsMode ); // One of the PHYSICS_MULTIPLAYER_ defines.
CNetworkVar( float, m_fMass );
CNetworkVector( m_collisionMins );
CNetworkVector( m_collisionMaxs );
DECLARE_CLIENTCLASS();
};
IMPLEMENT_CLIENTCLASS_DT( CPhysicsPropMultiplayer, DT_PhysicsPropMultiplayer, CPhysicsPropMultiplayer )
RecvPropInt( RECVINFO( m_iPhysicsMode ) ),
RecvPropFloat( RECVINFO( m_fMass ) ),
RecvPropVector( RECVINFO( m_collisionMins ) ),
RecvPropVector( RECVINFO( m_collisionMaxs ) ),
END_RECV_TABLE()
#endif
|