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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "baseanimating.h"
#include "SkyCamera.h"
#include "studio.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// HACK HACK: Must match cl_dll/cl_animevent.h!!!!
#define CL_EVENT_SPRITEGROUP_CREATE 6002
//-----------------------------------------------------------------------------
// An entity which emits other entities at points
//-----------------------------------------------------------------------------
class CEnvParticleScript : public CBaseAnimating
{
public:
DECLARE_CLASS( CEnvParticleScript, CBaseAnimating );
DECLARE_SERVERCLASS();
DECLARE_DATADESC();
CEnvParticleScript();
virtual void Precache();
virtual void Spawn();
virtual void Activate();
virtual int UpdateTransmitState();
void InputSetSequence( inputdata_t &inputdata );
private:
void PrecacheAnimationEventMaterials();
CNetworkVar( float, m_flSequenceScale );
};
//-----------------------------------------------------------------------------
// Save/load
//-----------------------------------------------------------------------------
BEGIN_DATADESC( CEnvParticleScript )
DEFINE_FIELD( m_flSequenceScale, FIELD_FLOAT ),
// Inputs
DEFINE_INPUTFUNC( FIELD_STRING, "SetSequence", InputSetSequence ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( env_particlescript, CEnvParticleScript );
//-----------------------------------------------------------------------------
// Datatable
//-----------------------------------------------------------------------------
IMPLEMENT_SERVERCLASS_ST( CEnvParticleScript, DT_EnvParticleScript )
SendPropFloat(SENDINFO(m_flSequenceScale), 0, SPROP_NOSCALE),
END_SEND_TABLE()
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CEnvParticleScript::CEnvParticleScript()
{
UseClientSideAnimation();
}
void CEnvParticleScript::PrecacheAnimationEventMaterials()
{
CStudioHdr *hdr = GetModelPtr();
if ( hdr )
{
int numseq = hdr->GetNumSeq();
for ( int i = 0; i < numseq; ++i )
{
mstudioseqdesc_t& seqdesc = hdr->pSeqdesc( i );
int ecount = seqdesc.numevents;
for ( int j = 0 ; j < ecount; ++j )
{
const mstudioevent_t* event = seqdesc.pEvent( j );
if ( event->event == CL_EVENT_SPRITEGROUP_CREATE )
{
char pAttachmentName[256];
char pSpriteName[256];
int nArgs = sscanf( event->pszOptions(), "%255s %255s", pAttachmentName, pSpriteName );
if ( nArgs == 2 )
{
PrecacheMaterial( pSpriteName );
}
}
}
}
}
}
//-----------------------------------------------------------------------------
// Precache
//-----------------------------------------------------------------------------
void CEnvParticleScript::Precache()
{
BaseClass::Precache();
PrecacheModel( STRING( GetModelName() ) );
// We need a model for its animation sequences even though we don't render it
SetModel( STRING( GetModelName() ) );
PrecacheAnimationEventMaterials();
}
//-----------------------------------------------------------------------------
// Spawn
//-----------------------------------------------------------------------------
void CEnvParticleScript::Spawn()
{
Precache();
BaseClass::Spawn();
AddEffects( EF_NOSHADOW );
// We need a model for its animation sequences even though we don't render it
SetModel( STRING( GetModelName() ) );
}
//-----------------------------------------------------------------------------
// Activate
//-----------------------------------------------------------------------------
void CEnvParticleScript::Activate()
{
BaseClass::Activate();
DetectInSkybox();
CSkyCamera *pCamera = GetEntitySkybox();
if ( pCamera )
{
float flSkyboxScale = pCamera->m_skyboxData.scale;
if ( flSkyboxScale == 0.0f )
{
flSkyboxScale = 1.0f;
}
m_flSequenceScale = flSkyboxScale;
}
else
{
m_flSequenceScale = 1.0f;
}
m_flPlaybackRate = 1.0f;
}
//-----------------------------------------------------------------------------
// Should we transmit it to the client?
//-----------------------------------------------------------------------------
int CEnvParticleScript::UpdateTransmitState()
{
if ( IsEffectActive( EF_NODRAW ) )
{
return SetTransmitState( FL_EDICT_DONTSEND );
}
if ( IsEFlagSet( EFL_IN_SKYBOX ) )
{
return SetTransmitState( FL_EDICT_ALWAYS );
}
return SetTransmitState( FL_EDICT_PVSCHECK );
}
//-----------------------------------------------------------------------------
// Purpose: Input that sets the sequence of the entity
//-----------------------------------------------------------------------------
void CEnvParticleScript::InputSetSequence( inputdata_t &inputdata )
{
if ( inputdata.value.StringID() != NULL_STRING )
{
int nSequence = LookupSequence( STRING( inputdata.value.StringID() ) );
if ( nSequence != ACT_INVALID )
{
SetSequence( nSequence );
}
}
}
|