Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
8.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SPRITE_H
  8. #define SPRITE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "predictable_entity.h"
  13. #include "baseentity_shared.h"
  14. #define SF_SPRITE_STARTON 0x0001
  15. #define SF_SPRITE_ONCE 0x0002
  16. #define SF_SPRITE_TEMPORARY 0x8000
  17. class CBasePlayer;
  18. #if defined( CLIENT_DLL )
  19. #define CSprite C_Sprite
  20. #define CSpriteOriented C_SpriteOriented
  21. #include "c_pixel_visibility.h"
  22. class CEngineSprite;
  23. class C_SpriteRenderer
  24. {
  25. public:
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Sprite orientations
  28. // WARNING! Change these in common/MaterialSystem/Sprite.cpp if you change them here!
  29. //-----------------------------------------------------------------------------
  30. typedef enum
  31. {
  32. SPR_VP_PARALLEL_UPRIGHT = 0,
  33. SPR_FACING_UPRIGHT = 1,
  34. SPR_VP_PARALLEL = 2,
  35. SPR_ORIENTED = 3,
  36. SPR_VP_PARALLEL_ORIENTED = 4
  37. } SPRITETYPE;
  38. // Determine sprite orientation
  39. static void GetSpriteAxes( SPRITETYPE type,
  40. const Vector& origin,
  41. const QAngle& angles,
  42. Vector& forward,
  43. Vector& right,
  44. Vector& up );
  45. // Sprites can alter blending amount
  46. virtual float GlowBlend( CEngineSprite *psprite, const Vector& entorigin, int rendermode, int renderfx, int alpha, float *scale );
  47. // Draws tempent as a sprite
  48. int DrawSprite(
  49. IClientEntity *entity,
  50. const model_t *model,
  51. const Vector& origin,
  52. const QAngle& angles,
  53. float frame,
  54. IClientEntity *attachedto,
  55. int attachmentindex,
  56. int rendermode,
  57. int renderfx,
  58. int alpha,
  59. int r,
  60. int g,
  61. int b,
  62. float scale,
  63. float flHDRColorScale = 1.0f
  64. );
  65. protected:
  66. pixelvis_handle_t m_queryHandle;
  67. float m_flGlowProxySize;
  68. float m_flHDRColorScale;
  69. };
  70. #endif
  71. class CSprite : public CBaseEntity
  72. #if defined( CLIENT_DLL )
  73. , public C_SpriteRenderer
  74. #endif
  75. {
  76. DECLARE_CLASS( CSprite, CBaseEntity );
  77. public:
  78. DECLARE_PREDICTABLE();
  79. DECLARE_NETWORKCLASS();
  80. CSprite();
  81. virtual ~CSprite();
  82. virtual void SetModel( const char *szModelName );
  83. #if defined( CLIENT_DLL )
  84. virtual bool IsSprite( void ) const
  85. {
  86. return true;
  87. };
  88. bool IsClientOnly() const { return m_bClientOnly; }
  89. #endif
  90. void Spawn( void );
  91. void Precache( void );
  92. virtual void ComputeWorldSpaceSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );
  93. void SetGlowProxySize( float flSize ) { m_flGlowProxySize = flSize; }
  94. #if !defined( CLIENT_DLL )
  95. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  96. virtual int UpdateTransmitState( void );
  97. void SetAsTemporary( void ) { AddSpawnFlags( SF_SPRITE_TEMPORARY ); }
  98. bool IsTemporary( void ) { return ( HasSpawnFlags( SF_SPRITE_TEMPORARY ) ); }
  99. int ObjectCaps( void )
  100. {
  101. int flags = 0;
  102. if ( IsTemporary() )
  103. {
  104. flags = FCAP_DONT_SAVE;
  105. }
  106. return (BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | flags;
  107. }
  108. void OnRestore();
  109. #endif
  110. void AnimateThink( void );
  111. void ExpandThink( void );
  112. void Animate( float frames );
  113. void Expand( float scaleSpeed, float fadeSpeed );
  114. void SpriteInit( const char *pSpriteName, const Vector &origin );
  115. #if !defined( CLIENT_DLL )
  116. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  117. // Input handlers
  118. void InputHideSprite( inputdata_t &inputdata );
  119. void InputShowSprite( inputdata_t &inputdata );
  120. void InputToggleSprite( inputdata_t &inputdata );
  121. void InputColorRedValue( inputdata_t &inputdata );
  122. void InputColorBlueValue( inputdata_t &inputdata );
  123. void InputColorGreenValue( inputdata_t &inputdata );
  124. #endif
  125. inline void SetAttachment( CBaseEntity *pEntity, int attachment )
  126. {
  127. if ( pEntity )
  128. {
  129. m_hAttachedToEntity = pEntity;
  130. m_nAttachment = attachment;
  131. FollowEntity( pEntity );
  132. }
  133. }
  134. void TurnOff( void );
  135. void TurnOn( void );
  136. bool IsOn() { return !IsEffectActive( EF_NODRAW ); }
  137. inline float Frames( void ) { return m_flMaxFrame; }
  138. inline void SetTransparency( int rendermode, int r, int g, int b, int a, int fx )
  139. {
  140. SetRenderMode( (RenderMode_t)rendermode );
  141. SetColor( r, g, b );
  142. SetBrightness( a );
  143. SetRenderFX( (RenderFx_t)fx );
  144. }
  145. inline void SetTexture( int spriteIndex ) { SetModelIndex( spriteIndex ); }
  146. inline void SetColor( int r, int g, int b ) { SetRenderColor( r, g, b ); }
  147. void SetBrightness( int brightness, float duration = 0.0f );
  148. void SetScale( float scale, float duration = 0.0f );
  149. void SetSpriteScale( float scale );
  150. void EnableWorldSpaceScale( bool bEnable );
  151. float GetScale( void ) { return m_flSpriteScale; }
  152. int GetBrightness( void ) { return m_nBrightness; }
  153. float GetHDRColorScale( void ) { return m_flHDRColorScale; }
  154. inline void FadeAndDie( float duration )
  155. {
  156. SetBrightness( 0, duration );
  157. SetThink(&CSprite::AnimateUntilDead);
  158. m_flDieTime = gpGlobals->curtime + duration;
  159. SetNextThink( gpGlobals->curtime );
  160. }
  161. inline void AnimateAndDie( float framerate )
  162. {
  163. SetThink(&CSprite::AnimateUntilDead);
  164. m_flSpriteFramerate = framerate;
  165. m_flDieTime = gpGlobals->curtime + (m_flMaxFrame / m_flSpriteFramerate);
  166. SetNextThink( gpGlobals->curtime );
  167. }
  168. inline void AnimateForTime( float framerate, float time )
  169. {
  170. SetThink(&CSprite::AnimateUntilDead);
  171. m_flSpriteFramerate = framerate;
  172. m_flDieTime = gpGlobals->curtime + time;
  173. SetNextThink( gpGlobals->curtime );
  174. }
  175. // FIXME: This completely blows.
  176. // Surely there's gotta be a better way.
  177. void FadeOutFromSpawn( )
  178. {
  179. SetThink(&CSprite::BeginFadeOutThink);
  180. SetNextThink( gpGlobals->curtime + 0.01f );
  181. }
  182. void BeginFadeOutThink( )
  183. {
  184. FadeAndDie( 0.25f );
  185. }
  186. void AnimateUntilDead( void );
  187. #if !defined( CLIENT_DLL )
  188. DECLARE_DATADESC();
  189. static CSprite *SpriteCreate( const char *pSpriteName, const Vector &origin, bool animate );
  190. #endif
  191. static CSprite *SpriteCreatePredictable( const char *module, int line, const char *pSpriteName, const Vector &origin, bool animate );
  192. #if defined( CLIENT_DLL )
  193. float GetRenderScale( void );
  194. float GetMaxRenderScale( void );
  195. int GetRenderBrightness( void );
  196. virtual int DrawModel( int flags, const RenderableInstance_t &instance );
  197. virtual const Vector& GetRenderOrigin();
  198. virtual void GetRenderBounds( Vector &vecMins, Vector &vecMaxs );
  199. virtual float GlowBlend( CEngineSprite *psprite, const Vector& entorigin, int rendermode, int renderfx, int alpha, float *scale );
  200. virtual void GetToolRecordingState( KeyValues *msg );
  201. virtual void ClientThink( void );
  202. virtual void OnDataChanged( DataUpdateType_t updateType );
  203. static void RecreateAllClientside();
  204. static void DestroyAllClientside();
  205. static void ParseAllClientsideEntities(const char *pMapData);
  206. static const char *ParseClientsideEntity( const char *pEntData );
  207. bool InitializeClientside();
  208. virtual bool KeyValue( const char *szKeyName, const char *szValue ) ;
  209. #endif // CLIENT_DLL
  210. public:
  211. CNetworkHandle( CBaseEntity, m_hAttachedToEntity );
  212. CNetworkVar( int, m_nAttachment );
  213. CNetworkVar( float, m_flSpriteFramerate );
  214. CNetworkVar( float, m_flFrame );
  215. float m_flDieTime;
  216. private:
  217. CNetworkVar( int, m_nBrightness );
  218. CNetworkVar( float, m_flBrightnessTime );
  219. CNetworkVar( float, m_flSpriteScale );
  220. CNetworkVar( float, m_flScaleTime );
  221. CNetworkVar( bool, m_bWorldSpaceScale );
  222. CNetworkVar( float, m_flGlowProxySize );
  223. CNetworkVar( float, m_flHDRColorScale );
  224. float m_flLastTime;
  225. float m_flMaxFrame;
  226. float m_flStartScale;
  227. float m_flDestScale; //Destination scale
  228. float m_flScaleTimeStart; //Real time for start of scale
  229. int m_nStartBrightness;
  230. int m_nDestBrightness; //Destination brightness
  231. float m_flBrightnessTimeStart;//Real time for brightness
  232. #ifdef CLIENT_DLL
  233. bool m_bClientOnly;
  234. #endif // CLIENT_DLL
  235. };
  236. class CSpriteOriented : public CSprite
  237. {
  238. public:
  239. DECLARE_CLASS( CSpriteOriented, CSprite );
  240. #if !defined( CLIENT_DLL )
  241. DECLARE_SERVERCLASS();
  242. void Spawn( void );
  243. #else
  244. DECLARE_CLIENTCLASS();
  245. virtual RenderableTranslucencyType_t ComputeTranslucencyType();
  246. #endif
  247. };
  248. // Macro to wrap creation
  249. #define SPRITE_CREATE_PREDICTABLE( name, origin, animate ) \
  250. CSprite::SpriteCreatePredictable( __FILE__, __LINE__, name, origin, animate )
  251. #endif // SPRITE_H