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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: provide client-side access to the new particle system, with similar
// usage to CSimpleEmitter
//
// $NoKeywords: $
//===========================================================================//
#ifndef PARTICLES_NEW_H
#define PARTICLES_NEW_H
#ifdef _WIN32
#pragma once
#endif
#include "particlemgr.h"
#include "particles/particles.h"
#include "particlesphererenderer.h"
#include "smartptr.h"
#include "particles_simple.h"
#include "tier1/utlobjectreference.h"
//-----------------------------------------------------------------------------
// Particle effect
//-----------------------------------------------------------------------------
class CNewParticleEffect : public IParticleEffect, public CParticleCollection, public CDefaultClientRenderable
{
public:
DECLARE_CLASS_NOBASE( CNewParticleEffect );
DECLARE_REFERENCED_CLASS( CNewParticleEffect );
public:
friend class CRefCountAccessor;
// list management
CNewParticleEffect *m_pNext;
CNewParticleEffect *m_pPrev;
// Call this before adding a bunch of particles to give it a rough estimate of where
// your particles are for sorting amongst other translucent entities.
void SetSortOrigin( const Vector &vSortOrigin );
bool ShouldDraw( void );
virtual bool IsTransparent( void );
virtual bool IsTwoPass( void );
virtual bool UsesPowerOfTwoFrameBufferTexture( void );
virtual bool UsesFullFrameBufferTexture( void );
const QAngle& GetRenderAngles( void );
const matrix3x4_t& RenderableToWorldTransform();
void GetRenderBounds( Vector& mins, Vector& maxs );
// check if the new bounds of the particle system needs its client-leaf info needs to be updated
void DetectChanges( void );
const Vector &GetRenderOrigin( void );
PMaterialHandle GetPMaterial( const char *name );
bool RecalculateBoundingBox();
Particle* AddParticle( unsigned int particleSize, PMaterialHandle material, const Vector &origin );
const char *GetEffectName();
void SetDontRemove( bool bSet );
void SetDrawn( bool bDrawn );
void SetFirstFrameFlag( bool bFirst );
void SetNeedsBBoxUpdate( bool bNeedsUpdate );
void SetAutoUpdateBBox( bool bNeedsUpdate );
void SetRemoveFlag( void );
bool GetRemoveFlag( void );
bool GetFirstFrameFlag( void );
bool GetNeedsBBoxUpdate( void );
bool GetAutoUpdateBBox( void );
bool ShouldPerformCullCheck() const;
void MarkShouldPerformCullCheck( bool bEnable );
CBaseEntity *GetOwner( void ) { return m_hOwner; }
void SetOwner( CBaseEntity *pOwner ) { m_hOwner = pOwner; }
CNewParticleEffect* ReplaceWith( const char *pParticleSystemName );
static CSmartPtr<CNewParticleEffect> Create( CBaseEntity *pOwner, const char *pParticleSystemName,
const char *pDebugName = NULL );
static CSmartPtr<CNewParticleEffect> Create( CBaseEntity *pOwner, CParticleSystemDefinition *pDef,
const char *pDebugName = NULL );
virtual int DrawModel( int flags );
void DebugDrawBbox ( bool bCulled );
// CParticleCollection overrides
public:
void StopEmission( bool bInfiniteOnly = false, bool bRemoveAllParticles = false, bool bWakeOnStop = false );
void SetDormant( bool bDormant );
void SetControlPoint( int nWhichPoint, const Vector &v );
void SetControlPointEntity( int nWhichPoint, CBaseEntity *pEntity );
void SetControlPointOrientation( int nWhichPoint, const Quaternion &q );
void SetControlPointOrientation( int nWhichPoint, const Vector &forward, const Vector &right, const Vector &up );
void SetControlPointForwardVector( int nWhichPoint, const Vector &v );
void SetControlPointUpVector( int nWhichPoint, const Vector &v );
void SetControlPointRightVector( int nWhichPoint, const Vector &v );
void SetIsViewModelEffect ( bool bIsViewModelEffect ) { m_bViewModelEffect = bIsViewModelEffect; }
bool GetIsViewModelEffect () { return m_bViewModelEffect; }
FORCEINLINE EHANDLE const &GetControlPointEntity( int nWhichPoint )
{
return m_hControlPointOwners[ nWhichPoint ];
}
// IParticleEffect overrides
public:
virtual void SimulateParticles( CParticleSimulateIterator *pIterator )
{
}
virtual void RenderParticles( CParticleRenderIterator *pIterator )
{
}
virtual void SetParticleCullRadius( float radius );
virtual void NotifyRemove( void );
virtual const Vector & GetSortOrigin( void );
// virtual void NotifyDestroyParticle( Particle* pParticle );
virtual void Update( float flTimeDelta );
// All Create() functions should call this so the effect deletes itself
// when it is removed from the particle manager.
void SetDynamicallyAllocated( bool bDynamic = true );
virtual bool ShouldSimulate() const { return m_bSimulate; }
virtual void SetShouldSimulate( bool bSim ) { m_bSimulate = bSim; }
int AllocateToolParticleEffectId();
int GetToolParticleEffectId() const;
CNewParticleEffect( CBaseEntity *pOwner, const char *pEffectName );
CNewParticleEffect( CBaseEntity *pOwner, CParticleSystemDefinition *pEffect );
virtual ~CNewParticleEffect();
protected:
// Returns nonzero if Release() has been called.
int IsReleased();
// Used to track down bugs.
const char *m_pDebugName;
bool m_bDontRemove : 1;
bool m_bRemove : 1;
bool m_bDrawn : 1;
bool m_bNeedsBBoxUpdate : 1;
bool m_bIsFirstFrame : 1;
bool m_bAutoUpdateBBox : 1;
bool m_bAllocated : 1;
bool m_bSimulate : 1;
bool m_bShouldPerformCullCheck : 1;
int m_nToolParticleEffectId;
Vector m_vSortOrigin;
EHANDLE m_hOwner;
EHANDLE m_hControlPointOwners[MAX_PARTICLE_CONTROL_POINTS];
// holds the min/max bounds used to manage this thing in the client leaf system
Vector m_LastMin;
Vector m_LastMax;
bool m_bViewModelEffect;
private:
// Update the reference count.
void AddRef();
void Release();
void RecordControlPointOrientation( int nWhichPoint );
void Construct();
int m_RefCount; // When this goes to zero and the effect has no more active
// particles, (and it's dynamically allocated), it will delete itself.
CNewParticleEffect( const CNewParticleEffect & ); // not defined, not accessible
};
//-----------------------------------------------------------------------------
// Inline methods
//-----------------------------------------------------------------------------
inline int CNewParticleEffect::GetToolParticleEffectId() const
{
return m_nToolParticleEffectId;
}
inline int CNewParticleEffect::AllocateToolParticleEffectId()
{
m_nToolParticleEffectId = ParticleMgr()->AllocateToolParticleEffectId();
return m_nToolParticleEffectId;
}
// Call this before adding a bunch of particles to give it a rough estimate of where
// your particles are for sorting amongst other translucent entities.
inline void CNewParticleEffect::SetSortOrigin( const Vector &vSortOrigin )
{
m_vSortOrigin = vSortOrigin;
}
inline const Vector &CNewParticleEffect::GetSortOrigin( void )
{
return m_vSortOrigin;
}
inline bool CNewParticleEffect::ShouldDraw( void )
{
return true;
}
inline bool CNewParticleEffect::IsTransparent( void )
{
return CParticleCollection::IsTranslucent();
}
inline const QAngle& CNewParticleEffect::GetRenderAngles( void )
{
return vec3_angle;
}
inline const matrix3x4_t & CNewParticleEffect::RenderableToWorldTransform()
{
static matrix3x4_t mat;
SetIdentityMatrix( mat );
PositionMatrix( GetRenderOrigin(), mat );
return mat;
}
inline Vector const &CNewParticleEffect::GetRenderOrigin( void )
{
return m_vSortOrigin;
}
inline PMaterialHandle CNewParticleEffect::GetPMaterial(const char *name)
{
//!!
Assert( 0 );
return NULL;
}
inline Particle* CNewParticleEffect::AddParticle( unsigned int particleSize, PMaterialHandle material, const Vector &origin )
{
//!!
Assert( 0 );
return NULL;
}
inline const char *CNewParticleEffect::GetEffectName()
{
return GetName();
}
inline void CNewParticleEffect::SetDontRemove( bool bSet )
{
m_bDontRemove = bSet;
}
inline void CNewParticleEffect::SetDrawn( bool bDrawn )
{
m_bDrawn = bDrawn;
}
inline void CNewParticleEffect::SetFirstFrameFlag( bool bFirst )
{
m_bIsFirstFrame = bFirst;
}
inline void CNewParticleEffect::SetDynamicallyAllocated( bool bDynamic )
{
m_bAllocated = bDynamic;
}
inline void CNewParticleEffect::SetNeedsBBoxUpdate( bool bNeedsUpdate )
{
m_bNeedsBBoxUpdate = bNeedsUpdate;
}
inline void CNewParticleEffect::SetAutoUpdateBBox( bool bNeedsUpdate )
{
m_bAutoUpdateBBox = bNeedsUpdate;
}
inline void CNewParticleEffect::SetRemoveFlag( void )
{
m_bRemove = true;
}
inline bool CNewParticleEffect::GetRemoveFlag( void )
{
return m_bRemove;
}
inline bool CNewParticleEffect::GetFirstFrameFlag( void )
{
return m_bIsFirstFrame;
}
inline bool CNewParticleEffect::GetNeedsBBoxUpdate( void )
{
return m_bNeedsBBoxUpdate;
}
inline bool CNewParticleEffect::GetAutoUpdateBBox( void )
{
return m_bAutoUpdateBBox;
}
inline bool CNewParticleEffect::ShouldPerformCullCheck() const
{
return m_bShouldPerformCullCheck;
}
inline void CNewParticleEffect::MarkShouldPerformCullCheck( bool bEnable )
{
m_bShouldPerformCullCheck = bEnable;
}
inline CSmartPtr<CNewParticleEffect> CNewParticleEffect::Create( CBaseEntity *pOwner, const char *pParticleSystemName, const char *pDebugName )
{
CNewParticleEffect *pRet = new CNewParticleEffect( pOwner, pParticleSystemName );
pRet->m_pDebugName = pDebugName ? pDebugName : pParticleSystemName;
pRet->SetDynamicallyAllocated( true );
return pRet;
}
inline CSmartPtr<CNewParticleEffect> CNewParticleEffect::Create( CBaseEntity *pOwner, CParticleSystemDefinition *pDef, const char *pDebugName )
{
CNewParticleEffect *pRet = new CNewParticleEffect( pOwner, pDef );
pRet->m_pDebugName = pDebugName ? pDebugName : pDef->GetName();
pRet->SetDynamicallyAllocated( true );
return pRet;
}
//--------------------------------------------------------------------------------
// If you use an HPARTICLEFFECT instead of a cnewparticleeffect *, you get a pointer
// which will go to null when the effect is deleted
//--------------------------------------------------------------------------------
typedef CUtlReference<CNewParticleEffect> HPARTICLEFFECT;
#endif // PARTICLES_NEW_H
|