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.

142 lines
4.0 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "cbase.h"
  7. #include "c_basetempentity.h"
  8. #include "iefx.h"
  9. #include "tier1/keyvalues.h"
  10. #include "toolframework_client.h"
  11. #include "fx.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: World Decal TE
  17. //-----------------------------------------------------------------------------
  18. class C_TEWorldDecal : public C_BaseTempEntity
  19. {
  20. public:
  21. DECLARE_CLASS( C_TEWorldDecal, C_BaseTempEntity );
  22. DECLARE_CLIENTCLASS();
  23. C_TEWorldDecal( void );
  24. virtual ~C_TEWorldDecal( void );
  25. virtual void PostDataUpdate( DataUpdateType_t updateType );
  26. virtual void Precache( void );
  27. public:
  28. Vector m_vecOrigin;
  29. int m_nIndex;
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Networking
  33. //-----------------------------------------------------------------------------
  34. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEWorldDecal, DT_TEWorldDecal, CTEWorldDecal)
  35. RecvPropVector( RECVINFO(m_vecOrigin)),
  36. RecvPropInt( RECVINFO(m_nIndex)),
  37. END_RECV_TABLE()
  38. //-----------------------------------------------------------------------------
  39. // Constructor, destructor
  40. //-----------------------------------------------------------------------------
  41. C_TEWorldDecal::C_TEWorldDecal( void )
  42. {
  43. m_vecOrigin.Init();
  44. m_nIndex = 0;
  45. }
  46. C_TEWorldDecal::~C_TEWorldDecal( void )
  47. {
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. //-----------------------------------------------------------------------------
  52. void C_TEWorldDecal::Precache( void )
  53. {
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Shared code
  57. //-----------------------------------------------------------------------------
  58. static inline void RecordWorldDecal( const Vector *pos, int index )
  59. {
  60. if ( !ToolsEnabled() )
  61. return;
  62. if ( clienttools->IsInRecordingMode() )
  63. {
  64. KeyValues *msg = new KeyValues( "TempEntity" );
  65. msg->SetInt( "te", TE_WORLD_DECAL );
  66. msg->SetString( "name", "TE_WorldDecal" );
  67. msg->SetFloat( "time", gpGlobals->curtime );
  68. msg->SetFloat( "originx", pos->x );
  69. msg->SetFloat( "originy", pos->y );
  70. msg->SetFloat( "originz", pos->z );
  71. msg->SetString( "decalname", effects->Draw_DecalNameFromIndex( index ) );
  72. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  73. msg->deleteThis();
  74. }
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Purpose:
  78. //-----------------------------------------------------------------------------
  79. void C_TEWorldDecal::PostDataUpdate( DataUpdateType_t updateType )
  80. {
  81. VPROF( "C_TEWorldDecal::PostDataUpdate" );
  82. if ( r_decals.GetInt() )
  83. {
  84. C_BaseEntity *ent = cl_entitylist->GetEnt( 0 );
  85. if ( ent )
  86. {
  87. effects->DecalShoot( m_nIndex, 0, ent->GetModel(), ent->GetAbsOrigin(), ent->GetAbsAngles(), m_vecOrigin, 0, 0 );
  88. }
  89. }
  90. RecordWorldDecal( &m_vecOrigin, m_nIndex );
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Client-side effects
  94. //-----------------------------------------------------------------------------
  95. void TE_WorldDecal( IRecipientFilter& filter, float delay, const Vector* pos, int index )
  96. {
  97. if ( r_decals.GetInt() )
  98. {
  99. C_BaseEntity *ent = cl_entitylist->GetEnt( 0 );
  100. if ( ent )
  101. {
  102. effects->DecalShoot( index, 0, ent->GetModel(), ent->GetAbsOrigin(), ent->GetAbsAngles(), *pos, 0, 0 );
  103. }
  104. }
  105. RecordWorldDecal( pos, index );
  106. }
  107. void TE_WorldDecal( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  108. {
  109. Vector vecOrigin;
  110. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  111. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  112. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  113. const char *pDecalName = pKeyValues->GetString( "decalname" );
  114. TE_WorldDecal( filter, 0.0f, &vecOrigin, effects->Draw_DecalIndexFromName( (char*)pDecalName ) );
  115. }