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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Client Side Effects for the env_portal_path_track.
//
//=============================================================================//
#include "cbase.h"
#include "env_portal_path_track_shared.h"
#include "particles_simple.h"
#include "particles_attractor.h"
class C_EnvPortalPathTrack : public C_BaseEntity
{
DECLARE_CLASS( C_EnvPortalPathTrack, C_BaseEntity );
DECLARE_CLIENTCLASS();
public:
void OnDataChanged( DataUpdateType_t updateType );
RenderGroup_t GetRenderGroup( void );
void ClientThink( void );
void NotifyShouldTransmit( ShouldTransmitState_t state );
void UpdateParticles_Inactive( void );
void UpdateParticles_Active( void );
private:
float m_flScale;
int m_nState;
float m_flDuration;
float m_flStartTime;
bool m_bTrackActive;
bool m_bEndpointActive;
bool SetupEmitters( void ); // Init our particle emitters
CSmartPtr<CSimpleEmitter> m_pSimpleEmitter; // particle system, emits particles
CSmartPtr<CParticleAttractor> m_pAttractorEmitter; // particle system, attracts particles
};
IMPLEMENT_CLIENTCLASS_DT( C_EnvPortalPathTrack, DT_EnvPortalPathTrack, CEnvPortalPathTrack )
RecvPropBool( RECVINFO(m_bTrackActive) ),
RecvPropBool( RECVINFO(m_bEndpointActive) ),
RecvPropInt( RECVINFO(m_nState) ),
END_RECV_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
// Output : RenderGroup_t
//-----------------------------------------------------------------------------
RenderGroup_t C_EnvPortalPathTrack::GetRenderGroup( void )
{
return RENDER_GROUP_TRANSLUCENT_ENTITY;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : updateType -
//-----------------------------------------------------------------------------
void C_EnvPortalPathTrack::OnDataChanged( DataUpdateType_t updateType )
{
BaseClass::OnDataChanged( updateType );
if ( updateType == DATA_UPDATE_CREATED )
{
SetNextClientThink( CLIENT_THINK_ALWAYS );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool C_EnvPortalPathTrack::SetupEmitters( void )
{
// Setup the basic core emitter
if ( m_pSimpleEmitter.IsValid() == false )
{
m_pSimpleEmitter = CSimpleEmitter::Create( "portaltracktrainendpoint" );
if ( m_pSimpleEmitter.IsValid() == false )
return false;
}
// Setup the attractor emitter
if ( m_pAttractorEmitter.IsValid() == false )
{
m_pAttractorEmitter = CParticleAttractor::Create( GetAbsOrigin(), "portaltracktrainendpointattractor" );
if ( m_pAttractorEmitter.IsValid() == false )
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EnvPortalPathTrack::ClientThink( void )
{
if ( gpGlobals->frametime <= 0.0f )
return;
switch( m_nState )
{
case PORTAL_PATH_TRACK_STATE_OFF:
break;
case PORTAL_PATH_TRACK_STATE_INACTIVE:
UpdateParticles_Inactive();
break;
case PORTAL_PATH_TRACK_STATE_ACTIVE:
UpdateParticles_Active();
break;
}
}
void C_EnvPortalPathTrack::UpdateParticles_Inactive( void )
{
}
void C_EnvPortalPathTrack::UpdateParticles_Active ( void )
{
// Emitters must be valid
if ( SetupEmitters() == false )
return;
// Reset our sort origin
m_pSimpleEmitter->SetSortOrigin( GetAbsOrigin() );
SimpleParticle *sParticle;
// Do the charging particles
m_pAttractorEmitter->SetAttractorOrigin( GetAbsOrigin() );
Vector forward, right, up;
AngleVectors( GetAbsAngles(), &forward, &right, &up );
Vector offset;
float dist;
int numParticles = floor( 4.0f );
for ( int i = 0; i < numParticles; i++ )
{
dist = random->RandomFloat( 4.0f, 64.0f );
offset = forward * dist;
dist = RemapValClamped( dist, 4.0f, 64.0f, 6.0f, 1.0f );
offset += right * random->RandomFloat( -4.0f * dist, 4.0f * dist );
offset += up * random->RandomFloat( -4.0f * dist, 4.0f * dist );
offset += GetAbsOrigin();
sParticle = (SimpleParticle *) m_pAttractorEmitter->AddParticle( sizeof(SimpleParticle), m_pAttractorEmitter->GetPMaterial( "effects/strider_muzzle" ), offset );
if ( sParticle == NULL )
return;
sParticle->m_vecVelocity = Vector(0,0,8);
sParticle->m_flDieTime = 0.5f;
sParticle->m_flLifetime = 0.0f;
sParticle->m_flRoll = Helper_RandomInt( 0, 360 );
sParticle->m_flRollDelta = 0.0f;
float alpha = 255;
sParticle->m_uchColor[0] = alpha;
sParticle->m_uchColor[1] = alpha;
sParticle->m_uchColor[2] = alpha;
sParticle->m_uchStartAlpha = alpha;
sParticle->m_uchEndAlpha = 0;
sParticle->m_uchStartSize = random->RandomFloat( 1, 2 );
sParticle->m_uchEndSize = 0;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_EnvPortalPathTrack::NotifyShouldTransmit( ShouldTransmitState_t state )
{
BaseClass::NotifyShouldTransmit( state );
// Turn off
if ( state == SHOULDTRANSMIT_END )
{
SetNextClientThink( CLIENT_THINK_NEVER );
}
// Turn on
if ( state == SHOULDTRANSMIT_START )
{
SetNextClientThink( CLIENT_THINK_ALWAYS );
}
}
|