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.

94 lines
2.2 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Ambient light controller entity with simple radial falloff
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "c_spatialentity.h"
  9. #include "spatialentitymgr.h"
  10. #include "c_env_ambient_light.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. static ConVar cl_ambient_light_disableentities( "cl_ambient_light_disableentities", "0", FCVAR_NONE, "Disable map ambient light entities." );
  14. static CSpatialEntityMgr s_EnvAmbientLightMgr;
  15. IMPLEMENT_CLIENTCLASS_DT( C_EnvAmbientLight, DT_EnvAmbientLight, CEnvAmbientLight )
  16. RecvPropVector( RECVINFO_NAME( m_Value, m_vecColor ) ),
  17. END_RECV_TABLE()
  18. void C_EnvAmbientLight::ApplyAccumulation( void )
  19. {
  20. Vector rgbVal = BlendedValue();
  21. static ConVarRef mat_ambient_light_r( "mat_ambient_light_r" );
  22. static ConVarRef mat_ambient_light_g( "mat_ambient_light_g" );
  23. static ConVarRef mat_ambient_light_b( "mat_ambient_light_b" );
  24. if ( mat_ambient_light_r.IsValid() )
  25. {
  26. mat_ambient_light_r.SetValue( rgbVal.x );
  27. }
  28. if ( mat_ambient_light_g.IsValid() )
  29. {
  30. mat_ambient_light_g.SetValue( rgbVal.y );
  31. }
  32. if ( mat_ambient_light_b.IsValid() )
  33. {
  34. mat_ambient_light_b.SetValue( rgbVal.z );
  35. }
  36. }
  37. void C_EnvAmbientLight::AddToPersonalSpatialEntityMgr( void )
  38. {
  39. s_EnvAmbientLightMgr.AddSpatialEntity( this );
  40. }
  41. void C_EnvAmbientLight::RemoveFromPersonalSpatialEntityMgr( void )
  42. {
  43. s_EnvAmbientLightMgr.RemoveSpatialEntity( this );
  44. }
  45. void C_EnvAmbientLight::SetColor( const Vector &vecColor, float flLerpTime )
  46. {
  47. if ( flLerpTime <= 0 )
  48. {
  49. m_Value = vecColor / 255.0f;
  50. m_colorTimer.Invalidate();
  51. return;
  52. }
  53. m_vecStartColor = m_Value;
  54. m_vecTargetColor = vecColor / 255.0f;
  55. m_colorTimer.Start( flLerpTime );
  56. }
  57. void C_EnvAmbientLight::ClientThink( void )
  58. {
  59. BaseClass::ClientThink();
  60. if ( m_colorTimer.HasStarted() )
  61. {
  62. if ( m_colorTimer.IsElapsed() )
  63. {
  64. m_Value = m_vecTargetColor;
  65. m_colorTimer.Invalidate();
  66. }
  67. else
  68. {
  69. m_Value = m_vecTargetColor - ( m_vecTargetColor - m_vecStartColor ) * m_colorTimer.GetRemainingRatio();
  70. }
  71. }
  72. }