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.

152 lines
4.4 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 "dlight.h"
  12. #include "iefx.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. //-----------------------------------------------------------------------------
  19. // Purpose: Dynamic Light
  20. //-----------------------------------------------------------------------------
  21. class C_TEDynamicLight : public C_BaseTempEntity
  22. {
  23. public:
  24. DECLARE_CLASS( C_TEDynamicLight, C_BaseTempEntity );
  25. DECLARE_CLIENTCLASS();
  26. C_TEDynamicLight( void );
  27. virtual ~C_TEDynamicLight( void );
  28. virtual void PostDataUpdate( DataUpdateType_t updateType );
  29. public:
  30. Vector m_vecOrigin;
  31. float m_fRadius;
  32. int r;
  33. int g;
  34. int b;
  35. int exponent;
  36. float m_fTime;
  37. float m_fDecay;
  38. };
  39. //-----------------------------------------------------------------------------
  40. // Networking
  41. //-----------------------------------------------------------------------------
  42. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEDynamicLight, DT_TEDynamicLight, CTEDynamicLight)
  43. RecvPropVector( RECVINFO(m_vecOrigin)),
  44. RecvPropInt( RECVINFO(r)),
  45. RecvPropInt( RECVINFO(g)),
  46. RecvPropInt( RECVINFO(b)),
  47. RecvPropInt( RECVINFO(exponent)),
  48. RecvPropFloat( RECVINFO(m_fRadius)),
  49. RecvPropFloat( RECVINFO(m_fTime)),
  50. RecvPropFloat( RECVINFO(m_fDecay)),
  51. END_RECV_TABLE()
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. C_TEDynamicLight::C_TEDynamicLight( void )
  56. {
  57. m_vecOrigin.Init();
  58. r = 0;
  59. g = 0;
  60. b = 0;
  61. exponent = 0;
  62. m_fRadius = 0.0;
  63. m_fTime = 0.0;
  64. m_fDecay = 0.0;
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. C_TEDynamicLight::~C_TEDynamicLight( void )
  70. {
  71. }
  72. void TE_DynamicLight( IRecipientFilter& filter, float delay,
  73. const Vector* org, int r, int g, int b, int exponent, float radius, float time, float decay, int nLightIndex )
  74. {
  75. dlight_t *dl = effects->CL_AllocDlight( nLightIndex );
  76. if ( !dl )
  77. return;
  78. dl->origin = *org;
  79. dl->radius = radius;
  80. dl->color.r = r;
  81. dl->color.g = g;
  82. dl->color.b = b;
  83. dl->color.exponent = exponent;
  84. dl->die = gpGlobals->curtime + time;
  85. dl->decay = decay;
  86. if ( ToolsEnabled() && clienttools->IsInRecordingMode() )
  87. {
  88. Color clr( r, g, b, 255 );
  89. KeyValues *msg = new KeyValues( "TempEntity" );
  90. msg->SetInt( "te", TE_DYNAMIC_LIGHT );
  91. msg->SetString( "name", "TE_DynamicLight" );
  92. msg->SetFloat( "time", gpGlobals->curtime );
  93. msg->SetFloat( "duration", time );
  94. msg->SetFloat( "originx", org->x );
  95. msg->SetFloat( "originy", org->y );
  96. msg->SetFloat( "originz", org->z );
  97. msg->SetFloat( "radius", radius );
  98. msg->SetFloat( "decay", decay );
  99. msg->SetColor( "color", clr );
  100. msg->SetInt( "exponent", exponent );
  101. msg->SetInt( "lightindex", nLightIndex );
  102. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  103. msg->deleteThis();
  104. }
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Purpose:
  108. // Input : bool -
  109. //-----------------------------------------------------------------------------
  110. void C_TEDynamicLight::PostDataUpdate( DataUpdateType_t updateType )
  111. {
  112. VPROF( "C_TEDynamicLight::PostDataUpdate" );
  113. CBroadcastRecipientFilter filter;
  114. TE_DynamicLight( filter, 0.0f, &m_vecOrigin, r, g, b, exponent, m_fRadius, m_fTime, m_fDecay, LIGHT_INDEX_TE_DYNAMIC );
  115. }
  116. void TE_DynamicLight( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  117. {
  118. Vector vecOrigin;
  119. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  120. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  121. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  122. float flDuration = pKeyValues->GetFloat( "duration" );
  123. Color c = pKeyValues->GetColor( "color" );
  124. int nExponent = pKeyValues->GetInt( "exponent" );
  125. float flRadius = pKeyValues->GetFloat( "radius" );
  126. float flDecay = pKeyValues->GetFloat( "decay" );
  127. int nLightIndex = pKeyValues->GetInt( "lightindex", LIGHT_INDEX_TE_DYNAMIC );
  128. TE_DynamicLight( filter, 0.0f, &vecOrigin, c.r(), c.g(), c.b(), nExponent,
  129. flRadius, flDuration, flDecay, nLightIndex );
  130. }