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.

136 lines
4.3 KiB

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