aboutsummaryrefslogtreecommitdiff
path: root/sp/src/game/shared/SpriteTrail.h
blob: 3e4fb763159da915035beb8a7e38f6ffb1caa754 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef SPRITETRAIL_H
#define SPRITETRAIL_H
#ifdef _WIN32
#pragma once
#endif

#include "Sprite.h"

#if defined( CLIENT_DLL )
#define CSpriteTrail C_SpriteTrail
#endif


//-----------------------------------------------------------------------------
// Sprite trail
//-----------------------------------------------------------------------------
struct TrailPoint_t
{
	DECLARE_SIMPLE_DATADESC();

	Vector	m_vecScreenPos;
	float	m_flDieTime;
	float	m_flTexCoord;
	float	m_flWidthVariance;
};

class CSpriteTrail : public CSprite
{
	DECLARE_CLASS( CSpriteTrail, CSprite );
	DECLARE_DATADESC();
	DECLARE_NETWORKCLASS();
	DECLARE_PREDICTABLE();

public:
	CSpriteTrail( void );

	// Sets parameters of the sprite trail
	void SetLifeTime( float time );
	void SetStartWidth( float flStartWidth );
	void SetEndWidth( float flEndWidth );
	void SetStartWidthVariance( float flStartWidthVariance );
	void SetTextureResolution( float flTexelsPerInch );
	void SetMinFadeLength( float flMinFadeLength );
	void SetSkybox( const Vector &vecSkyboxOrigin, float flSkyboxScale );

	// Is the trail in the skybox?
	bool IsInSkybox() const;
	void Spawn( void );
	void Precache( void );
	void SetTransmit( bool bTransmit = true ) { m_bDrawForMoveParent = bTransmit; }

#if defined( CLIENT_DLL ) 
	// Client only code
	virtual int DrawModel( int flags );
	virtual const Vector &GetRenderOrigin( void );
	virtual const QAngle &GetRenderAngles( void );

	// On data update
	virtual void OnPreDataChanged( DataUpdateType_t updateType );
	virtual void OnDataChanged( DataUpdateType_t updateType );
	virtual void GetRenderBounds( Vector& mins, Vector& maxs );
	virtual void ClientThink();

	virtual bool ValidateEntityAttachedToPlayer( bool &bShouldRetry );

#else
	// Server only code

	virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
	static CSpriteTrail *SpriteTrailCreate( const char *pSpriteName, const Vector &origin, bool animate );

#endif

private:
#if defined( CLIENT_DLL )
	enum
	{
		// NOTE: # of points max must be a power of two!
		MAX_SPRITE_TRAIL_POINTS	= 64,
		MAX_SPRITE_TRAIL_MASK = 0x3F,
	};

	TrailPoint_t *GetTrailPoint( int n );
	void	UpdateTrail( void );
	void	ComputeScreenPosition( Vector *pScreenPos );
	void	ConvertSkybox();
	void	UpdateBoundingBox( void );

	TrailPoint_t	m_vecSteps[MAX_SPRITE_TRAIL_POINTS];
	int	m_nFirstStep;
	int m_nStepCount;
	float m_flUpdateTime;
	Vector m_vecPrevSkyboxOrigin;
	float m_flPrevSkyboxScale;
	Vector m_vecRenderMins;
	Vector m_vecRenderMaxs;
#endif

	CNetworkVar( float, m_flLifeTime );	// Amount of time before a new trail segment fades away
	CNetworkVar( float, m_flStartWidth );	// The starting scale
	CNetworkVar( float, m_flEndWidth );	// The ending scale
	CNetworkVar( float, m_flStartWidthVariance );	// The starting scale
	CNetworkVar( float, m_flTextureRes );	// Texture resolution along the trail
	CNetworkVar( float, m_flMinFadeLength );	// The end of the trail must fade out for this many units
	CNetworkVector( m_vecSkyboxOrigin );	// What's our skybox origin?
	CNetworkVar( float, m_flSkyboxScale );	// What's our skybox scale?

	string_t m_iszSpriteName;
	bool	m_bAnimate;
	bool	m_bDrawForMoveParent;
};

#endif // SPRITETRAIL_H