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.

182 lines
5.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 "iefx.h"
  12. #include "engine/IStaticPropMgr.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. // UNDONE: Get rid of this?
  19. #define FDECAL_PERMANENT 0x01
  20. //-----------------------------------------------------------------------------
  21. // Purpose: Projected Decal TE
  22. //-----------------------------------------------------------------------------
  23. class C_TEProjectedDecal : public C_BaseTempEntity
  24. {
  25. public:
  26. DECLARE_CLASS( C_TEProjectedDecal, C_BaseTempEntity );
  27. DECLARE_CLIENTCLASS();
  28. C_TEProjectedDecal( void );
  29. virtual ~C_TEProjectedDecal( void );
  30. virtual void PostDataUpdate( DataUpdateType_t updateType );
  31. virtual void Precache( void );
  32. public:
  33. Vector m_vecOrigin;
  34. QAngle m_angRotation;
  35. float m_flDistance;
  36. int m_nIndex;
  37. };
  38. //-----------------------------------------------------------------------------
  39. // Networking
  40. //-----------------------------------------------------------------------------
  41. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEProjectedDecal, DT_TEProjectedDecal, CTEProjectedDecal)
  42. RecvPropVector( RECVINFO(m_vecOrigin)),
  43. RecvPropQAngles( RECVINFO( m_angRotation )),
  44. RecvPropFloat( RECVINFO(m_flDistance)),
  45. RecvPropInt( RECVINFO(m_nIndex)),
  46. END_RECV_TABLE()
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. //-----------------------------------------------------------------------------
  50. C_TEProjectedDecal::C_TEProjectedDecal( void )
  51. {
  52. m_vecOrigin.Init();
  53. m_angRotation.Init();
  54. m_flDistance = 0.0f;
  55. m_nIndex = 0;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. C_TEProjectedDecal::~C_TEProjectedDecal( void )
  61. {
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose:
  65. //-----------------------------------------------------------------------------
  66. void C_TEProjectedDecal::Precache( void )
  67. {
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Recording
  71. //-----------------------------------------------------------------------------
  72. static inline void RecordProjectDecal( const Vector &pos, const QAngle &angles,
  73. float flDistance, int index )
  74. {
  75. if ( !ToolsEnabled() )
  76. return;
  77. if ( clienttools->IsInRecordingMode() )
  78. {
  79. KeyValues *msg = new KeyValues( "TempEntity" );
  80. msg->SetInt( "te", TE_PROJECT_DECAL );
  81. msg->SetString( "name", "TE_ProjectDecal" );
  82. msg->SetFloat( "time", gpGlobals->curtime );
  83. msg->SetFloat( "originx", pos.x );
  84. msg->SetFloat( "originy", pos.y );
  85. msg->SetFloat( "originz", pos.z );
  86. msg->SetFloat( "anglesx", angles.x );
  87. msg->SetFloat( "anglesy", angles.y );
  88. msg->SetFloat( "anglesz", angles.z );
  89. msg->SetFloat( "distance", flDistance );
  90. msg->SetString( "decalname", effects->Draw_DecalNameFromIndex( index ) );
  91. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  92. msg->deleteThis();
  93. }
  94. }
  95. void TE_ProjectDecal( IRecipientFilter& filter, float delay,
  96. const Vector* pos, const QAngle *angles, float distance, int index )
  97. {
  98. RecordProjectDecal( *pos, *angles, distance, index );
  99. trace_t tr;
  100. Vector fwd;
  101. AngleVectors( *angles, &fwd );
  102. Vector endpos;
  103. VectorMA( *pos, distance, fwd, endpos );
  104. CTraceFilterHitAll traceFilter;
  105. UTIL_TraceLine( *pos, endpos, MASK_ALL, &traceFilter, &tr );
  106. if ( tr.fraction == 1.0f )
  107. {
  108. return;
  109. }
  110. C_BaseEntity* ent = tr.m_pEnt;
  111. Assert( ent );
  112. int hitbox = tr.hitbox;
  113. if ( tr.hitbox != 0 )
  114. {
  115. staticpropmgr->AddDecalToStaticProp( *pos, endpos, hitbox - 1, index, false, tr );
  116. }
  117. else
  118. {
  119. // Only decal the world + brush models
  120. ent->AddDecal( *pos, endpos, endpos, hitbox,
  121. index, false, tr );
  122. }
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose:
  126. //-----------------------------------------------------------------------------
  127. void C_TEProjectedDecal::PostDataUpdate( DataUpdateType_t updateType )
  128. {
  129. VPROF( "C_TEProjectedDecal::PostDataUpdate" );
  130. CBroadcastRecipientFilter filter;
  131. TE_ProjectDecal( filter, 0.0f, &m_vecOrigin, &m_angRotation, m_flDistance, m_nIndex );
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Playback
  135. //-----------------------------------------------------------------------------
  136. void TE_ProjectDecal( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  137. {
  138. Vector vecOrigin;
  139. QAngle angles;
  140. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  141. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  142. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  143. angles.x = pKeyValues->GetFloat( "anglesx" );
  144. angles.y = pKeyValues->GetFloat( "anglesy" );
  145. angles.z = pKeyValues->GetFloat( "anglesz" );
  146. float flDistance = pKeyValues->GetFloat( "distance" );
  147. const char *pDecalName = pKeyValues->GetString( "decalname" );
  148. TE_ProjectDecal( filter, 0.0f, &vecOrigin, &angles, flDistance, effects->Draw_DecalIndexFromName( (char*)pDecalName ) );
  149. }