forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc_fire_smoke.cpp
409 lines (340 loc) · 11.2 KB
/
c_fire_smoke.cpp
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
399
400
401
402
403
404
405
406
407
408
409
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "iviewrender.h"
#include "clienteffectprecachesystem.h"
#include "studio.h"
#include "bone_setup.h"
#include "engine/ivmodelinfo.h"
#include "c_fire_smoke.h"
#include "engine/IEngineSound.h"
#include "iefx.h"
#include "dlight.h"
#include "tier0/icommandline.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
CLIENTEFFECT_REGISTER_BEGIN( SmokeStackMaterials )
CLIENTEFFECT_MATERIAL( "particle/SmokeStack" )
CLIENTEFFECT_REGISTER_END()
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pRecvProp -
// *pStruct -
// *pVarData -
// *pIn -
// objectID -
//-----------------------------------------------------------------------------
void RecvProxy_Scale( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
C_FireSmoke *pFireSmoke = (C_FireSmoke *) pStruct;
float scale = pData->m_Value.m_Float;
//If changed, update our internal information
if ( ( pFireSmoke->m_flScale != scale ) && ( pFireSmoke->m_flScaleEnd != scale ) )
{
pFireSmoke->m_flScaleStart = pFireSmoke->m_flScaleRegister;
pFireSmoke->m_flScaleEnd = scale;
}
pFireSmoke->m_flScale = scale;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pRecvProp -
// *pStruct -
// *pVarData -
// *pIn -
// objectID -
//-----------------------------------------------------------------------------
void RecvProxy_ScaleTime( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
C_FireSmoke *pFireSmoke = (C_FireSmoke *) pStruct;
float time = pData->m_Value.m_Float;
//If changed, update our internal information
//if ( pFireSmoke->m_flScaleTime != time )
{
if ( time == -1.0f )
{
pFireSmoke->m_flScaleTimeStart = Helper_GetTime()-1.0f;
pFireSmoke->m_flScaleTimeEnd = pFireSmoke->m_flScaleTimeStart;
}
else
{
pFireSmoke->m_flScaleTimeStart = Helper_GetTime();
pFireSmoke->m_flScaleTimeEnd = Helper_GetTime() + time;
}
}
pFireSmoke->m_flScaleTime = time;
}
//Receive datatable
IMPLEMENT_CLIENTCLASS_DT( C_FireSmoke, DT_FireSmoke, CFireSmoke )
RecvPropFloat( RECVINFO( m_flStartScale )),
RecvPropFloat( RECVINFO( m_flScale ), 0, RecvProxy_Scale ),
RecvPropFloat( RECVINFO( m_flScaleTime ), 0, RecvProxy_ScaleTime ),
RecvPropInt( RECVINFO( m_nFlags ) ),
RecvPropInt( RECVINFO( m_nFlameModelIndex ) ),
RecvPropInt( RECVINFO( m_nFlameFromAboveModelIndex ) ),
END_RECV_TABLE()
//==================================================
// C_FireSmoke
//==================================================
C_FireSmoke::C_FireSmoke()
{
}
C_FireSmoke::~C_FireSmoke()
{
// Shut down our effect if we have it
if ( m_hEffect )
{
m_hEffect->StopEmission(false, false , true);
m_hEffect = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::Simulate( void )
{
}
#define FLAME_ALPHA_START 0.9f
#define FLAME_ALPHA_END 1.0f
#define FLAME_TRANS_START 0.75f
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::AddFlames( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : bnewentity -
//-----------------------------------------------------------------------------
void C_FireSmoke::OnDataChanged( DataUpdateType_t updateType )
{
BaseClass::OnDataChanged( updateType );
if ( updateType == DATA_UPDATE_CREATED )
{
Start();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::UpdateEffects( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool C_FireSmoke::ShouldDraw()
{
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::Start( void )
{
const char *lpszEffectName;
int nSize = (int) floor( m_flStartScale / 36.0f );
switch ( nSize )
{
case 0:
lpszEffectName = ( m_nFlags & bitsFIRESMOKE_SMOKE ) ? "env_fire_tiny_smoke" : "env_fire_tiny";
break;
case 1:
lpszEffectName = ( m_nFlags & bitsFIRESMOKE_SMOKE ) ? "env_fire_small_smoke" : "env_fire_small";
break;
case 2:
lpszEffectName = ( m_nFlags & bitsFIRESMOKE_SMOKE ) ? "env_fire_medium_smoke" : "env_fire_medium";
break;
case 3:
default:
lpszEffectName = ( m_nFlags & bitsFIRESMOKE_SMOKE ) ? "env_fire_large_smoke" : "env_fire_large";
break;
}
// Create the effect of the correct size
m_hEffect = ParticleProp()->Create( lpszEffectName, PATTACH_ABSORIGIN );
}
//-----------------------------------------------------------------------------
// Purpose: FIXME: what's the right way to do this?
//-----------------------------------------------------------------------------
void C_FireSmoke::StartClientOnly( void )
{
Start();
ClientEntityList().AddNonNetworkableEntity( this );
CollisionProp()->CreatePartitionHandle();
AddEffects( EF_NORECEIVESHADOW | EF_NOSHADOW );
AddToLeafSystem();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::RemoveClientOnly(void)
{
ClientThinkList()->RemoveThinkable( GetClientHandle() );
// Remove from the client entity list.
ClientEntityList().RemoveEntity( GetClientHandle() );
partition->Remove( PARTITION_CLIENT_SOLID_EDICTS | PARTITION_CLIENT_RESPONSIVE_EDICTS | PARTITION_CLIENT_NON_STATIC_EDICTS, CollisionProp()->GetPartitionHandle() );
RemoveFromLeafSystem();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::UpdateAnimation( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::UpdateFlames( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::UpdateScale( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::Update( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_FireSmoke::FindClipPlane( void )
{
}
//-----------------------------------------------------------------------------
// Purpose: Spawn smoke (...duh)
//-----------------------------------------------------------------------------
void C_FireSmoke::SpawnSmoke( void )
{
}
IMPLEMENT_CLIENTCLASS_DT( C_EntityFlame, DT_EntityFlame, CEntityFlame )
RecvPropEHandle(RECVINFO(m_hEntAttached)),
END_RECV_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
C_EntityFlame::C_EntityFlame( void ) :
m_hEffect( NULL )
{
m_hOldAttached = NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
C_EntityFlame::~C_EntityFlame( void )
{
StopEffect();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EntityFlame::StopEffect( void )
{
if ( m_hEffect )
{
ParticleProp()->StopEmission( m_hEffect, true );
m_hEffect->SetControlPointEntity( 0, NULL );
m_hEffect->SetControlPointEntity( 1, NULL );
m_hEffect = NULL;
}
if ( m_hEntAttached )
{
m_hEntAttached->RemoveFlag( FL_ONFIRE );
m_hEntAttached->SetEffectEntity( NULL );
m_hEntAttached->StopSound( "General.BurningFlesh" );
m_hEntAttached->StopSound( "General.BurningObject" );
m_hEntAttached = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EntityFlame::UpdateOnRemove( void )
{
StopEffect();
BaseClass::UpdateOnRemove();
}
void C_EntityFlame::CreateEffect( void )
{
if ( m_hEffect )
{
ParticleProp()->StopEmission( m_hEffect, true );
m_hEffect->SetControlPointEntity( 0, NULL );
m_hEffect->SetControlPointEntity( 1, NULL );
m_hEffect = NULL;
}
#ifdef TF_CLIENT_DLL
m_hEffect = ParticleProp()->Create( "burningplayer_red", PATTACH_ABSORIGIN_FOLLOW );
#else
m_hEffect = ParticleProp()->Create( "burning_character", PATTACH_ABSORIGIN_FOLLOW );
#endif
if ( m_hEffect )
{
C_BaseEntity *pEntity = m_hEntAttached;
m_hOldAttached = m_hEntAttached;
ParticleProp()->AddControlPoint( m_hEffect, 1, pEntity, PATTACH_ABSORIGIN_FOLLOW );
m_hEffect->SetControlPoint( 0, GetAbsOrigin() );
m_hEffect->SetControlPoint( 1, GetAbsOrigin() );
m_hEffect->SetControlPointEntity( 0, pEntity );
m_hEffect->SetControlPointEntity( 1, pEntity );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EntityFlame::OnDataChanged( DataUpdateType_t updateType )
{
if ( updateType == DATA_UPDATE_CREATED )
{
CreateEffect();
}
// FIXME: This is a bit of a shady path
if ( updateType == DATA_UPDATE_DATATABLE_CHANGED )
{
// If our owner changed, then recreate the effect
if ( m_hEntAttached != m_hOldAttached )
{
CreateEffect();
}
}
BaseClass::OnDataChanged( updateType );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EntityFlame::Simulate( void )
{
if ( gpGlobals->frametime <= 0.0f )
return;
#ifdef HL2_EPISODIC
if ( IsEffectActive(EF_BRIGHTLIGHT) || IsEffectActive(EF_DIMLIGHT) )
{
dlight_t *dl = effects->CL_AllocDlight ( index );
dl->origin = GetAbsOrigin();
dl->origin[2] += 16;
dl->color.r = 254;
dl->color.g = 174;
dl->color.b = 10;
dl->radius = random->RandomFloat(400,431);
dl->die = gpGlobals->curtime + 0.001;
}
#endif // HL2_EPISODIC
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EntityFlame::ClientThink( void )
{
StopEffect();
Release();
}