forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEffectsClient.cpp
231 lines (197 loc) · 6.97 KB
/
EffectsClient.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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Utility code.
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "IEffects.h"
#include "fx.h"
#include "c_te_legacytempents.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Client-server neutral effects interface
//-----------------------------------------------------------------------------
class CEffectsClient : public IEffects
{
public:
CEffectsClient();
virtual ~CEffectsClient();
// Members of the IEffect interface
virtual void Beam( const Vector &Start, const Vector &End, int nModelIndex,
int nHaloIndex, unsigned char frameStart, unsigned char frameRate,
float flLife, unsigned char width, unsigned char endWidth, unsigned char fadeLength,
unsigned char noise, unsigned char red, unsigned char green,
unsigned char blue, unsigned char brightness, unsigned char speed);
virtual void Smoke( const Vector &origin, int modelIndex, float scale, float framerate );
virtual void Sparks( const Vector &position, int nMagnitude = 1, int nTrailLength = 1, const Vector *pvecDir = NULL );
virtual void Dust( const Vector &pos, const Vector &dir, float size, float speed );
virtual void MuzzleFlash( const Vector &origin, const QAngle &angles, float fScale, int type );
virtual void MetalSparks( const Vector &position, const Vector &direction );
virtual void EnergySplash( const Vector &position, const Vector &direction, bool bExplosive = false );
virtual void Ricochet( const Vector &position, const Vector &direction );
// FIXME: Should these methods remain in this interface? Or go in some
// other client-server neutral interface?
virtual float Time();
virtual bool IsServer();
virtual void SuppressEffectsSounds( bool bSuppress );
private:
//-----------------------------------------------------------------------------
// Purpose: Returning true means don't even call TE func
// Input : filter -
// *suppress_host -
// Output : static bool
//-----------------------------------------------------------------------------
bool SuppressTE( C_RecipientFilter& filter )
{
if ( !CanPredict() )
return true;
if ( !filter.GetRecipientCount() )
{
// Suppress it
return true;
}
// There's at least one recipient
return false;
}
bool m_bSuppressSound;
};
//-----------------------------------------------------------------------------
// Client-server neutral effects interface accessor
//-----------------------------------------------------------------------------
static CEffectsClient s_EffectClient;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CEffectsClient, IEffects, IEFFECTS_INTERFACE_VERSION, s_EffectClient);
IEffects *g_pEffects = &s_EffectClient;
ConVar r_decals( "r_decals", "2048" );
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
CEffectsClient::CEffectsClient()
{
m_bSuppressSound = false;
}
CEffectsClient::~CEffectsClient()
{
}
//-----------------------------------------------------------------------------
// Suppress sound on effects
//-----------------------------------------------------------------------------
void CEffectsClient::SuppressEffectsSounds( bool bSuppress )
{
m_bSuppressSound = bSuppress;
}
//-----------------------------------------------------------------------------
// Generates a beam
//-----------------------------------------------------------------------------
void CEffectsClient::Beam( const Vector &vecStartPoint, const Vector &vecEndPoint,
int nModelIndex, int nHaloIndex, unsigned char frameStart, unsigned char nFrameRate,
float flLife, unsigned char nWidth, unsigned char nEndWidth, unsigned char nFadeLength,
unsigned char noise, unsigned char r, unsigned char g,
unsigned char b, unsigned char brightness, unsigned char nSpeed)
{
Assert(0);
// CBroadcastRecipientFilter filter;
// if ( !SuppressTE( filter ) )
// {
// beams->CreateBeamPoints( vecStartPoint, vecEndPoint, nModelIndex, nHaloIndex,
// m_fHaloScale,
// flLife, 0.1 * nWidth, 0.1 * nEndWidth, nFadeLength, 0.01 * nAmplitude, a, 0.1 * nSpeed,
// m_nStartFrame, 0.1 * nFrameRate, r, g, b );
// }
}
//-----------------------------------------------------------------------------
// Generates various tempent effects
//-----------------------------------------------------------------------------
void CEffectsClient::Smoke( const Vector &vecOrigin, int modelIndex, float scale, float framerate )
{
CPVSFilter filter( vecOrigin );
if ( !SuppressTE( filter ) )
{
int iColor = random->RandomInt(20,35);
color32 color;
color.r = iColor;
color.g = iColor;
color.b = iColor;
color.a = iColor;
QAngle angles;
VectorAngles( Vector(0,0,1), angles );
FX_Smoke( vecOrigin, angles, scale * 0.1f, 4, (unsigned char *)&color, 255 );
}
}
void CEffectsClient::Sparks( const Vector &position, int nMagnitude, int nTrailLength, const Vector *pVecDir )
{
CPVSFilter filter( position );
if ( !SuppressTE( filter ) )
{
FX_ElectricSpark( position, nMagnitude, nTrailLength, pVecDir );
}
}
void CEffectsClient::Dust( const Vector &pos, const Vector &dir, float size, float speed )
{
CPVSFilter filter( pos );
if ( !SuppressTE( filter ) )
{
FX_Dust( pos, dir, size, speed );
}
}
void CEffectsClient::MuzzleFlash( const Vector &vecOrigin, const QAngle &vecAngles, float flScale, int iType )
{
CPVSFilter filter( vecOrigin );
if ( !SuppressTE( filter ) )
{
switch( iType )
{
case MUZZLEFLASH_TYPE_DEFAULT:
FX_MuzzleEffect( vecOrigin, vecAngles, flScale, INVALID_EHANDLE_INDEX );
break;
case MUZZLEFLASH_TYPE_GUNSHIP:
FX_GunshipMuzzleEffect( vecOrigin, vecAngles, flScale, INVALID_EHANDLE_INDEX );
break;
case MUZZLEFLASH_TYPE_STRIDER:
FX_StriderMuzzleEffect( vecOrigin, vecAngles, flScale, INVALID_EHANDLE_INDEX );
break;
default:
Msg("No case for Muzzleflash type: %d\n", iType );
break;
}
}
}
void CEffectsClient::MetalSparks( const Vector &position, const Vector &direction )
{
CPVSFilter filter( position );
if ( !SuppressTE( filter ) )
{
FX_MetalSpark( position, direction, direction );
}
}
void CEffectsClient::EnergySplash( const Vector &position, const Vector &direction, bool bExplosive )
{
CPVSFilter filter( position );
if ( !SuppressTE( filter ) )
{
FX_EnergySplash( position, direction, bExplosive );
}
}
void CEffectsClient::Ricochet( const Vector &position, const Vector &direction )
{
CPVSFilter filter( position );
if ( !SuppressTE( filter ) )
{
FX_MetalSpark( position, direction, direction );
if ( !m_bSuppressSound )
{
FX_RicochetSound( position );
}
}
}
// FIXME: Should these methods remain in this interface? Or go in some
// other client-server neutral interface?
float CEffectsClient::Time()
{
return gpGlobals->curtime;
}
bool CEffectsClient::IsServer()
{
return false;
}