aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/fx_sparks.h
blob: bdfbe43e9c2641c1f5e1eb8d996b03e62da2d4c8 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $Workfile:     $
// $Date:         $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//

#include "particles_simple.h"
#include "particlemgr.h"
#include "c_pixel_visibility.h"
#include "fx_fleck.h"

#include "tier0/memdbgon.h"

#define	bitsPARTICLE_TRAIL_VELOCITY_DAMPEN	0x00000001	//Dampen the velocity as the particles move
#define	bitsPARTICLE_TRAIL_COLLIDE			0x00000002	//Do collision with simulation
#define	bitsPARTICLE_TRAIL_FADE				0x00000004	//Fade away
#define	bitsPARTICLE_TRAIL_FADE_IN			0x00000008	//Fade in

class TrailParticle : public Particle
{
public:

	Vector		m_vecVelocity;
	color32		m_color;				// Particle color
	float		m_flDieTime;			// How long it lives for.
	float		m_flLifetime;			// How long it has been alive for so far.
	float		m_flLength;				// Length of the tail (in seconds!)
	float		m_flWidth;				// Width of the spark
};

inline void Color32ToFloat4( float colorOut[4], const color32 & colorIn )
{
	colorOut[0] = colorIn.r * (1.0f/255.0f);
	colorOut[1] = colorIn.g * (1.0f/255.0f);
	colorOut[2] = colorIn.b * (1.0f/255.0f);
	colorOut[3] = colorIn.a * (1.0f/255.0f);
}

inline void FloatToColor32( color32 &out, float r, float g, float b, float a )
{
	out.r = r * 255;
	out.g = g * 255;
	out.b = b * 255;
	out.a = a * 255;
}

inline void Float4ToColor32( color32 &out, float colorIn[4] )
{
	out.r = colorIn[0] * 255;
	out.g = colorIn[1] * 255;
	out.b = colorIn[2] * 255;
	out.a = colorIn[3] * 255;
}

inline void Color32Init( color32 &out, int r, int g, int b, int a )
{
	out.r = r;
	out.g = g;
	out.b = b;
	out.a = a;
}
//
// CTrailParticles
//

class CTrailParticles : public CSimpleEmitter
{
	DECLARE_CLASS( CTrailParticles, CSimpleEmitter );
public:
	CTrailParticles( const char *pDebugName );
	
	static CTrailParticles	*Create( const char *pDebugName )	{	return new CTrailParticles( pDebugName );	}

	virtual void RenderParticles( CParticleRenderIterator *pIterator );
	virtual void SimulateParticles( CParticleSimulateIterator *pIterator );

	//Setup for point emission
	virtual void	Setup( const Vector &origin, const Vector *direction, float angularSpread, float minSpeed, float maxSpeed, float gravity, float dampen, int flags, bool bNotCollideable = false );
	
	void SetFlag( int flags )				{	m_fFlags |= flags;	}
	void SetVelocityDampen( float dampen )	{	m_flVelocityDampen = dampen;	}
	void SetGravity( float gravity )		{	m_ParticleCollision.SetGravity( gravity );	}
	void SetCollisionDamped( float dampen )	{	m_ParticleCollision.SetCollisionDampen( dampen );	}
	void SetAngularCollisionDampen( float dampen )	{ m_ParticleCollision.SetAngularCollisionDampen( dampen );	}

	CParticleCollision	m_ParticleCollision;

protected:

	int					m_fFlags;
	float				m_flVelocityDampen;

private:
	CTrailParticles( const CTrailParticles & ); // not defined, not accessible
};

//
// Sphere trails
//

class CSphereTrails : public CSimpleEmitter
{
	DECLARE_CLASS( CSphereTrails, CSimpleEmitter );
public:
	CSphereTrails( const char *pDebugName, const Vector &origin, float innerRadius, float outerRadius, float speed, int entityIndex, int attachment );
	
	virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
	virtual void RenderParticles( CParticleRenderIterator *pIterator );
	virtual void Update( float flTimeDelta );
	virtual void StartRender();

	void AddStreaks( float count );
	Vector	m_particleOrigin;
	float	m_life;
	float	m_outerRadius;
	float	m_innerRadius;
	float	m_effectSpeed;
	float	m_streakSpeed;
	float	m_count;
	float	m_growth;
	int		m_entityIndex;
	int		m_attachment;
	PMaterialHandle m_hMaterial;
	Vector	m_boneOrigin;
	float	m_dieTime;

private:
	CSphereTrails( const CSphereTrails & ); // not defined, not accessible
};


// Simple glow emitter won't draw any of it's particles until/unless the pixel visibility test succeeds
class CSimpleGlowEmitter : public CSimpleEmitter
{
	DECLARE_CLASS( CSimpleGlowEmitter, CSimpleEmitter );
public:
	CSimpleGlowEmitter( const char *pDebugName, const Vector &sortOrigin, float flDeathTime );
	static CSimpleGlowEmitter	*Create( const char *pDebugName, const Vector &sortOrigin, float flDeathTime );

	virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
	virtual void RenderParticles( CParticleRenderIterator *pIterator );
protected:

	bool WasTestedInView( unsigned char viewMask );
	bool IsVisibleInView( unsigned char viewMask );
	void SetTestedInView( unsigned char viewMask, bool bTested );
	void SetVisibleInView( unsigned char viewMask, bool bVisible );
	unsigned char CurrentViewMask() const;

	float				m_flDeathTime;			// How long it has been alive for so far.
	float				m_startTime;
	pixelvis_handle_t	m_queryHandle;
private:
	unsigned char		m_wasTested;
	unsigned char		m_isVisible;

private:
	CSimpleGlowEmitter( const CSimpleGlowEmitter & ); // not defined, not accessible
};

#include "tier0/memdbgoff.h"