forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeam_shared.h
476 lines (388 loc) · 11.9 KB
/
beam_shared.h
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef BEAM_H
#define BEAM_H
#ifdef _WIN32
#pragma once
#endif
#include "baseentity_shared.h"
#include "baseplayer_shared.h"
#if !defined( CLIENT_DLL )
#include "entityoutput.h"
#endif
#include "beam_flags.h"
#define MAX_BEAM_WIDTH 102.3f
#define MAX_BEAM_SCROLLSPEED 100.0f
#define MAX_BEAM_NOISEAMPLITUDE 64
#define SF_BEAM_STARTON 0x0001
#define SF_BEAM_TOGGLE 0x0002
#define SF_BEAM_RANDOM 0x0004
#define SF_BEAM_RING 0x0008
#define SF_BEAM_SPARKSTART 0x0010
#define SF_BEAM_SPARKEND 0x0020
#define SF_BEAM_DECALS 0x0040
#define SF_BEAM_SHADEIN 0x0080
#define SF_BEAM_SHADEOUT 0x0100
#define SF_BEAM_TAPEROUT 0x0200 // Tapers to zero
#define SF_BEAM_TEMPORARY 0x8000
#define ATTACHMENT_INDEX_BITS 5
#define ATTACHMENT_INDEX_MASK ((1 << ATTACHMENT_INDEX_BITS) - 1)
#if defined( CLIENT_DLL )
#define CBeam C_Beam
#include "c_pixel_visibility.h"
#endif
class CBeam : public CBaseEntity
{
DECLARE_CLASS( CBeam, CBaseEntity );
public:
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
#if !defined( CLIENT_DLL )
DECLARE_DATADESC();
#endif
CBeam();
virtual void SetModel( const char *szModelName );
void Spawn( void );
void Precache( void );
#if !defined( CLIENT_DLL )
int ObjectCaps( void );
void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
int UpdateTransmitState( void );
int ShouldTransmit( const CCheckTransmitInfo *pInfo );
#endif
virtual int DrawDebugTextOverlays(void);
// These functions are here to show the way beams are encoded as entities.
// Encoding beams as entities simplifies their management in the client/server architecture
void SetType( int type );
void SetBeamFlags( int flags );
void SetBeamFlag( int flag );
// NOTE: Start + End Pos are specified in *relative* coordinates
void SetStartPos( const Vector &pos );
void SetEndPos( const Vector &pos );
// This will change things so the abs position matches the requested spot
void SetAbsStartPos( const Vector &pos );
void SetAbsEndPos( const Vector &pos );
const Vector &GetAbsStartPos( void ) const;
const Vector &GetAbsEndPos( void ) const;
void SetStartEntity( CBaseEntity *pEntity );
void SetEndEntity( CBaseEntity *pEntity );
void SetStartAttachment( int attachment );
void SetEndAttachment( int attachment );
void SetTexture( int spriteIndex );
void SetHaloTexture( int spriteIndex );
void SetHaloScale( float haloScale );
void SetWidth( float width );
void SetEndWidth( float endWidth );
void SetFadeLength( float fadeLength );
void SetNoise( float amplitude );
void SetColor( int r, int g, int b );
void SetBrightness( int brightness );
void SetFrame( float frame );
void SetScrollRate( int speed );
void SetFireTime( float flFireTime );
void SetFrameRate( float flFrameRate ) { m_flFrameRate = flFrameRate; }
void SetMinDXLevel( int nMinDXLevel ) { m_nMinDXLevel = nMinDXLevel; }
void TurnOn( void );
void TurnOff( void );
int GetType( void ) const;
int GetBeamFlags( void ) const;
CBaseEntity* GetStartEntityPtr( void ) const;
int GetStartEntity( void ) const;
CBaseEntity* GetEndEntityPtr( void ) const;
int GetEndEntity( void ) const;
int GetStartAttachment() const;
int GetEndAttachment() const;
virtual const Vector &WorldSpaceCenter( void ) const;
int GetTexture( void );
float GetWidth( void ) const;
float GetEndWidth( void ) const;
float GetFadeLength( void ) const;
float GetNoise( void ) const;
int GetBrightness( void ) const;
float GetFrame( void ) const;
float GetScrollRate( void ) const;
float GetHDRColorScale( void ) const;
void SetHDRColorScale( float flScale ) { m_flHDRColorScale = flScale; }
// Call after you change start/end positions
void RelinkBeam( void );
void DoSparks( const Vector &start, const Vector &end );
CBaseEntity *RandomTargetname( const char *szName );
void BeamDamage( trace_t *ptr );
// Init after BeamCreate()
void BeamInit( const char *pSpriteName, float width );
void PointsInit( const Vector &start, const Vector &end );
void PointEntInit( const Vector &start, CBaseEntity *pEndEntity );
void EntsInit( CBaseEntity *pStartEntity, CBaseEntity *pEndEntity );
void LaserInit( CBaseEntity *pStartEntity, CBaseEntity *pEndEntity );
void HoseInit( const Vector &start, const Vector &direction );
void SplineInit( int nNumEnts, CBaseEntity** pEntList, int *attachment );
// Input handlers
static CBeam *BeamCreate( const char *pSpriteName, float width );
static CBeam *BeamCreatePredictable( const char *module, int line, bool persist, const char *pSpriteName, float width, CBasePlayer *pOwner );
void LiveForTime( float time );
void BeamDamageInstant( trace_t *ptr, float damage );
// Only supported in TF2 right now
#if defined( INVASION_CLIENT_DLL )
virtual bool ShouldPredict( void )
{
return true;
}
#endif
virtual const char *GetDecalName( void ) { return "BigShot"; }
#if defined( CLIENT_DLL )
// IClientEntity overrides.
public:
virtual int DrawModel( int flags );
virtual bool IsTransparent( void );
virtual bool ShouldDraw();
virtual bool IgnoresZBuffer( void ) const { return true; }
virtual void OnDataChanged( DataUpdateType_t updateType );
virtual bool OnPredictedEntityRemove( bool isbeingremoved, C_BaseEntity *predicted );
// Add beam to visible entities list?
virtual void AddEntity( void );
virtual bool ShouldReceiveProjectedTextures( int flags )
{
return false;
}
// Beam Data Elements
private:
// Computes the bounding box of a beam local to the origin of the beam
void ComputeBounds( Vector& mins, Vector& maxs );
friend void RecvProxy_Beam_ScrollSpeed( const CRecvProxyData *pData, void *pStruct, void *pOut );
friend class CViewRenderBeams;
#endif
protected:
CNetworkVar( float, m_flFrameRate );
CNetworkVar( float, m_flHDRColorScale );
float m_flFireTime;
float m_flDamage; // Damage per second to touchers.
CNetworkVar( int, m_nNumBeamEnts );
#if defined( CLIENT_DLL )
pixelvis_handle_t m_queryHandleHalo;
#endif
private:
#if !defined( CLIENT_DLL )
void InputNoise( inputdata_t &inputdata );
void InputWidth( inputdata_t &inputdata );
void InputColorRedValue( inputdata_t &inputdata );
void InputColorBlueValue( inputdata_t &inputdata );
void InputColorGreenValue( inputdata_t &inputdata );
#endif
// Beam Data Elements
CNetworkVar( int, m_nHaloIndex );
CNetworkVar( int, m_nBeamType );
CNetworkVar( int, m_nBeamFlags );
CNetworkArray( EHANDLE, m_hAttachEntity, MAX_BEAM_ENTS );
CNetworkArray( int, m_nAttachIndex, MAX_BEAM_ENTS );
CNetworkVar( float, m_fWidth );
CNetworkVar( float, m_fEndWidth );
CNetworkVar( float, m_fFadeLength );
CNetworkVar( float, m_fHaloScale );
CNetworkVar( float, m_fAmplitude );
CNetworkVar( float, m_fStartFrame );
CNetworkVar( float, m_fSpeed );
CNetworkVar( int, m_nMinDXLevel );
CNetworkVar( float, m_flFrame );
CNetworkVector( m_vecEndPos );
EHANDLE m_hEndEntity;
#if !defined( CLIENT_DLL )
int m_nDissolveType;
#endif
public:
#ifdef PORTAL
CNetworkVar( bool, m_bDrawInMainRender );
CNetworkVar( bool, m_bDrawInPortalRender );
#endif //#ifdef PORTAL
};
#if !defined( CLIENT_DLL )
//-----------------------------------------------------------------------------
// Inline methods
//-----------------------------------------------------------------------------
inline int CBeam::ObjectCaps( void )
{
int flags = 0;
if ( HasSpawnFlags( SF_BEAM_TEMPORARY ) )
flags = FCAP_DONT_SAVE;
return (BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | flags;
}
#endif
inline void CBeam::SetFireTime( float flFireTime )
{
m_flFireTime = flFireTime;
}
//-----------------------------------------------------------------------------
// NOTE: Start + End Pos are specified in *relative* coordinates
//-----------------------------------------------------------------------------
inline void CBeam::SetStartPos( const Vector &pos )
{
#if defined( CLIENT_DLL )
SetNetworkOrigin( pos );
#endif
SetLocalOrigin( pos );
}
inline void CBeam::SetEndPos( const Vector &pos )
{
m_vecEndPos = pos;
}
// center point of beam
inline const Vector &CBeam::WorldSpaceCenter( void ) const
{
Vector &vecResult = AllocTempVector();
VectorAdd( GetAbsStartPos(), GetAbsEndPos(), vecResult );
vecResult *= 0.5f;
return vecResult;
}
inline void CBeam::SetStartAttachment( int attachment )
{
Assert( (attachment & ~ATTACHMENT_INDEX_MASK) == 0 );
m_nAttachIndex.Set( 0, attachment );
}
inline void CBeam::SetEndAttachment( int attachment )
{
Assert( (attachment & ~ATTACHMENT_INDEX_MASK) == 0 );
m_nAttachIndex.Set( m_nNumBeamEnts-1, attachment );
}
inline void CBeam::SetTexture( int spriteIndex )
{
SetModelIndex( spriteIndex );
}
inline void CBeam::SetHaloTexture( int spriteIndex )
{
m_nHaloIndex = spriteIndex;
}
inline void CBeam::SetHaloScale( float haloScale )
{
m_fHaloScale = haloScale;
}
inline void CBeam::SetWidth( float width )
{
Assert( width <= MAX_BEAM_WIDTH );
m_fWidth = MIN( MAX_BEAM_WIDTH, width );
}
inline void CBeam::SetEndWidth( float endWidth )
{
Assert( endWidth <= MAX_BEAM_WIDTH );
m_fEndWidth = MIN( MAX_BEAM_WIDTH, endWidth );
}
inline void CBeam::SetFadeLength( float fadeLength )
{
m_fFadeLength = fadeLength;
}
inline void CBeam::SetNoise( float amplitude )
{
m_fAmplitude = amplitude;
}
inline void CBeam::SetColor( int r, int g, int b )
{
SetRenderColor( r, g, b, GetRenderColor().a );
}
inline void CBeam::SetBrightness( int brightness )
{
SetRenderColorA( brightness );
}
inline void CBeam::SetFrame( float frame )
{
m_fStartFrame = frame;
}
inline void CBeam::SetScrollRate( int speed )
{
m_fSpeed = speed;
}
inline CBaseEntity* CBeam::GetStartEntityPtr( void ) const
{
return m_hAttachEntity[0].Get();
}
inline int CBeam::GetStartEntity( void ) const
{
CBaseEntity *pEntity = m_hAttachEntity[0].Get();
return pEntity ? pEntity->entindex() : 0;
}
inline CBaseEntity* CBeam::GetEndEntityPtr( void ) const
{
return m_hAttachEntity[1].Get();
}
inline int CBeam::GetEndEntity( void ) const
{
CBaseEntity *pEntity = m_hAttachEntity[m_nNumBeamEnts-1].Get();
return pEntity ? pEntity->entindex() : 0;
}
inline int CBeam::GetStartAttachment() const
{
return m_nAttachIndex[0] & ATTACHMENT_INDEX_MASK;
}
inline int CBeam::GetEndAttachment() const
{
return m_nAttachIndex[m_nNumBeamEnts-1] & ATTACHMENT_INDEX_MASK;
}
inline int CBeam::GetTexture( void )
{
return GetModelIndex();
}
inline float CBeam::GetWidth( void ) const
{
return m_fWidth;
}
inline float CBeam::GetEndWidth( void ) const
{
return m_fEndWidth;
}
inline float CBeam::GetFadeLength( void ) const
{
return m_fFadeLength;
}
inline float CBeam::GetNoise( void ) const
{
return m_fAmplitude;
}
inline int CBeam::GetBrightness( void ) const
{
return GetRenderColor().a;
}
inline float CBeam::GetFrame( void ) const
{
return m_fStartFrame;
}
inline float CBeam::GetScrollRate( void ) const
{
return m_fSpeed;
}
inline float CBeam::GetHDRColorScale( void ) const
{
return m_flHDRColorScale;
}
inline void CBeam::LiveForTime( float time )
{
SetThink(&CBeam::SUB_Remove);
SetNextThink( gpGlobals->curtime + time );
}
inline void CBeam::BeamDamageInstant( trace_t *ptr, float damage )
{
m_flDamage = damage;
m_flFireTime = gpGlobals->curtime - 1;
BeamDamage(ptr);
}
bool IsStaticPointEntity( CBaseEntity *pEnt );
// Macro to wrap creation
#define BEAM_CREATE_PREDICTABLE( name, width, player ) \
CBeam::BeamCreatePredictable( __FILE__, __LINE__, false, name, width, player )
#define BEAM_CREATE_PREDICTABLE_PERSIST( name, width, player ) \
CBeam::BeamCreatePredictable( __FILE__, __LINE__, true, name, width, player )
// Start/End Entity is encoded as 12 bits of entity index, and 4 bits of attachment (4:12)
#define BEAMENT_ENTITY(x) ((x)&0xFFF)
#define BEAMENT_ATTACHMENT(x) (((x)>>12)&0xF)
// Beam types, encoded as a byte
enum
{
BEAM_POINTS = 0,
BEAM_ENTPOINT,
BEAM_ENTS,
BEAM_HOSE,
BEAM_SPLINE,
BEAM_LASER,
NUM_BEAM_TYPES
};
#endif // BEAM_H