Team Fortress 2 Source Code as on 22/4/2020
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.

112 lines
3.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Muzzle flash temp ent
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "c_basetempentity.h"
  9. #include "IEffects.h"
  10. #include "tier1/KeyValues.h"
  11. #include "toolframework_client.h"
  12. #include "tier0/vprof.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: User Tracer TE
  17. //-----------------------------------------------------------------------------
  18. class C_TEMuzzleFlash : public C_BaseTempEntity
  19. {
  20. public:
  21. DECLARE_CLASS( C_TEMuzzleFlash, C_BaseTempEntity );
  22. DECLARE_CLIENTCLASS();
  23. C_TEMuzzleFlash( void );
  24. virtual ~C_TEMuzzleFlash( void );
  25. virtual void PostDataUpdate( DataUpdateType_t updateType );
  26. public:
  27. Vector m_vecOrigin;
  28. QAngle m_vecAngles;
  29. float m_flScale;
  30. int m_nType;
  31. };
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. //-----------------------------------------------------------------------------
  35. C_TEMuzzleFlash::C_TEMuzzleFlash( void )
  36. {
  37. m_vecOrigin.Init();
  38. m_vecAngles.Init();
  39. m_flScale = 1.0f;
  40. m_nType = 0;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. C_TEMuzzleFlash::~C_TEMuzzleFlash( void )
  46. {
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Recording
  50. //-----------------------------------------------------------------------------
  51. static inline void RecordMuzzleFlash( const Vector &start, const QAngle &angles, float scale, int type )
  52. {
  53. if ( !ToolsEnabled() )
  54. return;
  55. if ( clienttools->IsInRecordingMode() )
  56. {
  57. KeyValues *msg = new KeyValues( "TempEntity" );
  58. msg->SetInt( "te", TE_MUZZLE_FLASH );
  59. msg->SetString( "name", "TE_MuzzleFlash" );
  60. msg->SetFloat( "time", gpGlobals->curtime );
  61. msg->SetFloat( "originx", start.x );
  62. msg->SetFloat( "originy", start.y );
  63. msg->SetFloat( "originz", start.z );
  64. msg->SetFloat( "anglesx", angles.x );
  65. msg->SetFloat( "anglesy", angles.y );
  66. msg->SetFloat( "anglesz", angles.z );
  67. msg->SetFloat( "scale", scale );
  68. msg->SetInt( "type", type );
  69. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  70. msg->deleteThis();
  71. }
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose:
  75. //-----------------------------------------------------------------------------
  76. void C_TEMuzzleFlash::PostDataUpdate( DataUpdateType_t updateType )
  77. {
  78. VPROF( "C_TEMuzzleFlash::PostDataUpdate" );
  79. //FIXME: Index is incorrect
  80. g_pEffects->MuzzleFlash( m_vecOrigin, m_vecAngles, m_flScale, m_nType );
  81. RecordMuzzleFlash( m_vecOrigin, m_vecAngles, m_flScale, m_nType );
  82. }
  83. void TE_MuzzleFlash( IRecipientFilter& filter, float delay,
  84. const Vector &start, const QAngle &angles, float scale, int type )
  85. {
  86. g_pEffects->MuzzleFlash( start, angles, scale, 0 );
  87. RecordMuzzleFlash( start, angles, scale, 0 );
  88. }
  89. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEMuzzleFlash, DT_TEMuzzleFlash, CTEMuzzleFlash)
  90. RecvPropVector( RECVINFO(m_vecOrigin)),
  91. RecvPropVector( RECVINFO(m_vecAngles)),
  92. RecvPropFloat( RECVINFO(m_flScale)),
  93. RecvPropInt( RECVINFO(m_nType)),
  94. END_RECV_TABLE()