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.

179 lines
5.2 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 "tier0/vprof.h"
  15. #include "toolframework_client.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. //-----------------------------------------------------------------------------
  19. // Purpose: Decal TE
  20. //-----------------------------------------------------------------------------
  21. class C_TEDecal : public C_BaseTempEntity
  22. {
  23. public:
  24. DECLARE_CLASS( C_TEDecal, C_BaseTempEntity );
  25. DECLARE_CLIENTCLASS();
  26. C_TEDecal( void );
  27. virtual ~C_TEDecal( void );
  28. virtual void PostDataUpdate( DataUpdateType_t updateType );
  29. virtual void Precache( void );
  30. public:
  31. Vector m_vecOrigin;
  32. Vector m_vecStart;
  33. int m_nEntity;
  34. int m_nHitbox;
  35. int m_nIndex;
  36. };
  37. //-----------------------------------------------------------------------------
  38. // Networking
  39. //-----------------------------------------------------------------------------
  40. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEDecal, DT_TEDecal, CTEDecal)
  41. RecvPropVector( RECVINFO(m_vecOrigin)),
  42. RecvPropVector( RECVINFO(m_vecStart)),
  43. RecvPropInt( RECVINFO(m_nEntity)),
  44. RecvPropInt( RECVINFO(m_nHitbox)),
  45. RecvPropInt( RECVINFO(m_nIndex)),
  46. END_RECV_TABLE()
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. //-----------------------------------------------------------------------------
  50. C_TEDecal::C_TEDecal( void )
  51. {
  52. m_vecOrigin.Init();
  53. m_vecStart.Init();
  54. m_nEntity = 0;
  55. m_nIndex = 0;
  56. m_nHitbox = 0;
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. //-----------------------------------------------------------------------------
  61. C_TEDecal::~C_TEDecal( void )
  62. {
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose:
  66. //-----------------------------------------------------------------------------
  67. void C_TEDecal::Precache( void )
  68. {
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Recording
  72. //-----------------------------------------------------------------------------
  73. static inline void RecordDecal( const Vector &pos, const Vector &start,
  74. int entity, int hitbox, int index )
  75. {
  76. if ( !ToolsEnabled() )
  77. return;
  78. if ( clienttools->IsInRecordingMode() )
  79. {
  80. // FIXME: Can't record on entities yet
  81. if ( entity != 0 )
  82. return;
  83. KeyValues *msg = new KeyValues( "TempEntity" );
  84. msg->SetInt( "te", TE_DECAL );
  85. msg->SetString( "name", "TE_Decal" );
  86. msg->SetFloat( "time", gpGlobals->curtime );
  87. msg->SetFloat( "originx", pos.x );
  88. msg->SetFloat( "originy", pos.y );
  89. msg->SetFloat( "originz", pos.z );
  90. msg->SetFloat( "startx", start.x );
  91. msg->SetFloat( "starty", start.y );
  92. msg->SetFloat( "startz", start.z );
  93. msg->SetInt( "hitbox", hitbox );
  94. msg->SetString( "decalname", effects->Draw_DecalNameFromIndex( index ) );
  95. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  96. msg->deleteThis();
  97. }
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Tempent
  101. //-----------------------------------------------------------------------------
  102. void TE_Decal( IRecipientFilter& filter, float delay,
  103. const Vector* pos, const Vector* start, int entity, int hitbox, int index )
  104. {
  105. RecordDecal( *pos, *start, entity, hitbox, index );
  106. trace_t tr;
  107. // Special case for world entity with hitbox:
  108. if ( (entity == 0) && (hitbox != 0) )
  109. {
  110. Ray_t ray;
  111. ray.Init( *start, *pos );
  112. staticpropmgr->AddDecalToStaticProp( *start, *pos, hitbox - 1, index, false, tr );
  113. }
  114. else
  115. {
  116. // Only decal the world + brush models
  117. // Here we deal with decals on entities.
  118. C_BaseEntity* ent;
  119. if ( ( ent = cl_entitylist->GetEnt( entity ) ) == NULL )
  120. return;
  121. ent->AddDecal( *start, *pos, *pos, hitbox,
  122. index, false, tr );
  123. }
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. //-----------------------------------------------------------------------------
  128. void C_TEDecal::PostDataUpdate( DataUpdateType_t updateType )
  129. {
  130. VPROF( "C_TEDecal::PostDataUpdate" );
  131. CBroadcastRecipientFilter filter;
  132. TE_Decal( filter, 0.0f, &m_vecOrigin, &m_vecStart, m_nEntity, m_nHitbox, m_nIndex );
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Playback
  136. //-----------------------------------------------------------------------------
  137. void TE_Decal( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  138. {
  139. Vector vecOrigin, vecStart;
  140. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  141. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  142. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  143. vecStart.x = pKeyValues->GetFloat( "startx" );
  144. vecStart.y = pKeyValues->GetFloat( "starty" );
  145. vecStart.z = pKeyValues->GetFloat( "startz" );
  146. int nHitbox = pKeyValues->GetInt( "hitbox" );
  147. const char *pDecalName = pKeyValues->GetString( "decalname" );
  148. TE_Decal( filter, 0.0f, &vecOrigin, &vecStart, 0, nHitbox, effects->Draw_DecalIndexFromName( (char*)pDecalName ) );
  149. }