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.

149 lines
4.8 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "c_basetempentity.h"
  9. #include "c_te_legacytempents.h"
  10. #include "tempent.h"
  11. #include "tier1/keyvalues.h"
  12. #include "toolframework_client.h"
  13. #include "tier0/vprof.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. //-----------------------------------------------------------------------------
  17. // Purpose: Glow Sprite TE
  18. //-----------------------------------------------------------------------------
  19. class C_TEGlowSprite : public C_BaseTempEntity
  20. {
  21. public:
  22. DECLARE_CLASS( C_TEGlowSprite, C_BaseTempEntity );
  23. DECLARE_CLIENTCLASS();
  24. C_TEGlowSprite( void );
  25. virtual ~C_TEGlowSprite( void );
  26. virtual void PostDataUpdate( DataUpdateType_t updateType );
  27. public:
  28. Vector m_vecOrigin;
  29. int m_nModelIndex;
  30. float m_fScale;
  31. float m_fLife;
  32. int m_nBrightness;
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Networking
  36. //-----------------------------------------------------------------------------
  37. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEGlowSprite, DT_TEGlowSprite, CTEGlowSprite)
  38. RecvPropVector( RECVINFO(m_vecOrigin)),
  39. RecvPropInt( RECVINFO(m_nModelIndex)),
  40. RecvPropFloat( RECVINFO(m_fScale )),
  41. RecvPropFloat( RECVINFO(m_fLife )),
  42. RecvPropInt( RECVINFO(m_nBrightness)),
  43. END_RECV_TABLE()
  44. //-----------------------------------------------------------------------------
  45. // Purpose:
  46. //-----------------------------------------------------------------------------
  47. C_TEGlowSprite::C_TEGlowSprite( void )
  48. {
  49. m_vecOrigin.Init();
  50. m_nModelIndex = 0;
  51. m_fScale = 0;
  52. m_fLife = 0;
  53. m_nBrightness = 0;
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. C_TEGlowSprite::~C_TEGlowSprite( void )
  59. {
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Recording
  63. //-----------------------------------------------------------------------------
  64. static inline void RecordGlowSprite( const Vector &start, int nModelIndex,
  65. float flDuration, float flSize, int nBrightness )
  66. {
  67. if ( !ToolsEnabled() )
  68. return;
  69. if ( clienttools->IsInRecordingMode() )
  70. {
  71. const model_t* pModel = (nModelIndex != 0) ? modelinfo->GetModel( nModelIndex ) : NULL;
  72. const char *pModelName = pModel ? modelinfo->GetModelName( pModel ) : "";
  73. KeyValues *msg = new KeyValues( "TempEntity" );
  74. msg->SetInt( "te", TE_GLOW_SPRITE );
  75. msg->SetString( "name", "TE_GlowSprite" );
  76. msg->SetFloat( "time", gpGlobals->curtime );
  77. msg->SetFloat( "originx", start.x );
  78. msg->SetFloat( "originy", start.y );
  79. msg->SetFloat( "originz", start.z );
  80. msg->SetString( "model", pModelName );
  81. msg->SetFloat( "duration", flDuration );
  82. msg->SetFloat( "size", flSize );
  83. msg->SetInt( "brightness", nBrightness );
  84. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  85. msg->deleteThis();
  86. }
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose:
  90. //-----------------------------------------------------------------------------
  91. void C_TEGlowSprite::PostDataUpdate( DataUpdateType_t updateType )
  92. {
  93. VPROF( "C_TEGlowSprite::PostDataUpdate" );
  94. float a = ( 1.0 / 255.0 ) * m_nBrightness;
  95. C_LocalTempEntity *ent = tempents->TempSprite( m_vecOrigin, vec3_origin, m_fScale, m_nModelIndex, kRenderTransAdd, 0, a, m_fLife, FTENT_SPRANIMATE | FTENT_SPRANIMATELOOP );
  96. if ( ent )
  97. {
  98. ent->bounceFactor = 0.2;
  99. }
  100. RecordGlowSprite( m_vecOrigin, m_nModelIndex, m_fLife, m_fScale, m_nBrightness );
  101. }
  102. void TE_GlowSprite( IRecipientFilter& filter, float delay,
  103. const Vector* pos, int modelindex, float life, float size, int brightness )
  104. {
  105. float a = ( 1.0 / 255.0 ) * brightness;
  106. C_LocalTempEntity *ent = tempents->TempSprite( *pos, vec3_origin, size, modelindex, kRenderTransAdd, 0, a, life, FTENT_SPRANIMATE | FTENT_SPRANIMATELOOP );
  107. if ( ent )
  108. {
  109. ent->bounceFactor = 0.2;
  110. }
  111. RecordGlowSprite( *pos, modelindex, life, size, brightness );
  112. }
  113. void TE_GlowSprite( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  114. {
  115. Vector vecOrigin;
  116. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  117. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  118. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  119. const char *pModelName = pKeyValues->GetString( "model" );
  120. int nModelIndex = pModelName[0] ? modelinfo->GetModelIndex( pModelName ) : 0;
  121. float flDuration = pKeyValues->GetFloat( "duration" );
  122. float flSize = pKeyValues->GetFloat( "size" );
  123. int nBrightness = pKeyValues->GetFloat( "brightness" );
  124. TE_GlowSprite( filter, delay, &vecOrigin, nModelIndex, flDuration, flSize, nBrightness );
  125. }