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.

158 lines
4.4 KiB

  1. //========= Copyright 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 "decals.h"
  13. #include "tier0/vprof.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. //-----------------------------------------------------------------------------
  17. // Purpose: World Decal TE
  18. //-----------------------------------------------------------------------------
  19. class C_TEWorldDecal : public C_BaseTempEntity
  20. {
  21. public:
  22. DECLARE_CLASS( C_TEWorldDecal, C_BaseTempEntity );
  23. DECLARE_CLIENTCLASS();
  24. C_TEWorldDecal( void );
  25. virtual ~C_TEWorldDecal( void );
  26. virtual void PostDataUpdate( DataUpdateType_t updateType );
  27. virtual void Precache( void );
  28. public:
  29. Vector m_vecOrigin;
  30. int m_nIndex;
  31. };
  32. //-----------------------------------------------------------------------------
  33. // Networking
  34. //-----------------------------------------------------------------------------
  35. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEWorldDecal, DT_TEWorldDecal, CTEWorldDecal)
  36. RecvPropVector( RECVINFO(m_vecOrigin)),
  37. RecvPropInt( RECVINFO(m_nIndex)),
  38. END_RECV_TABLE()
  39. //-----------------------------------------------------------------------------
  40. // Constructor, destructor
  41. //-----------------------------------------------------------------------------
  42. C_TEWorldDecal::C_TEWorldDecal( void )
  43. {
  44. m_vecOrigin.Init();
  45. m_nIndex = 0;
  46. }
  47. C_TEWorldDecal::~C_TEWorldDecal( void )
  48. {
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. void C_TEWorldDecal::Precache( void )
  54. {
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Shared code
  58. //-----------------------------------------------------------------------------
  59. static inline void RecordWorldDecal( const Vector *pos, int index )
  60. {
  61. if ( !ToolsEnabled() )
  62. return;
  63. if ( clienttools->IsInRecordingMode() )
  64. {
  65. KeyValues *msg = new KeyValues( "TempEntity" );
  66. msg->SetInt( "te", TE_WORLD_DECAL );
  67. msg->SetString( "name", "TE_WorldDecal" );
  68. msg->SetFloat( "time", gpGlobals->curtime );
  69. msg->SetFloat( "originx", pos->x );
  70. msg->SetFloat( "originy", pos->y );
  71. msg->SetFloat( "originz", pos->z );
  72. msg->SetString( "decalname", effects->Draw_DecalNameFromIndex( index ) );
  73. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  74. msg->deleteThis();
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. void C_TEWorldDecal::PostDataUpdate( DataUpdateType_t updateType )
  81. {
  82. VPROF( "C_TEWorldDecal::PostDataUpdate" );
  83. if ( r_decals.GetInt() )
  84. {
  85. C_BaseEntity *ent = cl_entitylist->GetEnt( 0 );
  86. if ( ent )
  87. {
  88. bool bNoBlood = UTIL_IsLowViolence();
  89. bool bIsBlood = false;
  90. if ( bNoBlood )
  91. {
  92. const char *pchDecalName = decalsystem->GetDecalNameForIndex( m_nIndex );
  93. if ( pchDecalName && V_stristr( pchDecalName, "blood" ) )
  94. {
  95. bIsBlood = true;
  96. }
  97. }
  98. if ( !( bNoBlood && bIsBlood ) )
  99. {
  100. effects->DecalShoot( m_nIndex, 0, ent->GetModel(), ent->GetAbsOrigin(), ent->GetAbsAngles(), m_vecOrigin, 0, 0 );
  101. }
  102. }
  103. }
  104. RecordWorldDecal( &m_vecOrigin, m_nIndex );
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Client-side effects
  108. //-----------------------------------------------------------------------------
  109. void TE_WorldDecal( IRecipientFilter& filter, float delay, const Vector* pos, int index )
  110. {
  111. if ( r_decals.GetInt() )
  112. {
  113. C_BaseEntity *ent = cl_entitylist->GetEnt( 0 );
  114. if ( ent )
  115. {
  116. effects->DecalShoot( index, 0, ent->GetModel(), ent->GetAbsOrigin(), ent->GetAbsAngles(), *pos, 0, 0 );
  117. }
  118. }
  119. RecordWorldDecal( pos, index );
  120. }
  121. void TE_WorldDecal( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  122. {
  123. Vector vecOrigin;
  124. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  125. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  126. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  127. const char *pDecalName = pKeyValues->GetString( "decalname" );
  128. TE_WorldDecal( filter, 0.0f, &vecOrigin, effects->Draw_DecalIndexFromName( (char*)pDecalName ) );
  129. }