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.

157 lines
4.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Shadow control entity.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. //------------------------------------------------------------------------------
  11. // FIXME: This really should inherit from something more lightweight
  12. //------------------------------------------------------------------------------
  13. //------------------------------------------------------------------------------
  14. // Purpose : Shadow control entity
  15. //------------------------------------------------------------------------------
  16. class CShadowControl : public CBaseEntity
  17. {
  18. public:
  19. DECLARE_CLASS( CShadowControl, CBaseEntity );
  20. CShadowControl();
  21. void Spawn( void );
  22. bool KeyValue( const char *szKeyName, const char *szValue );
  23. int UpdateTransmitState();
  24. void InputSetAngles( inputdata_t &inputdata );
  25. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
  26. DECLARE_SERVERCLASS();
  27. DECLARE_DATADESC();
  28. private:
  29. CNetworkVector( m_shadowDirection );
  30. CNetworkColor32( m_shadowColor );
  31. CNetworkVar( float, m_flShadowMaxDist );
  32. CNetworkVar( bool, m_bDisableShadows );
  33. CNetworkVar( bool, m_bEnableLocalLightShadows );
  34. };
  35. LINK_ENTITY_TO_CLASS(shadow_control, CShadowControl);
  36. BEGIN_DATADESC( CShadowControl )
  37. DEFINE_KEYFIELD( m_flShadowMaxDist, FIELD_FLOAT, "distance" ),
  38. DEFINE_KEYFIELD( m_bDisableShadows, FIELD_BOOLEAN, "disableallshadows" ),
  39. DEFINE_KEYFIELD( m_bEnableLocalLightShadows, FIELD_BOOLEAN, "enableshadowsfromlocallights" ),
  40. // Inputs
  41. DEFINE_INPUT( m_shadowColor, FIELD_COLOR32, "color" ),
  42. DEFINE_INPUT( m_shadowDirection, FIELD_VECTOR, "direction" ),
  43. DEFINE_INPUT( m_flShadowMaxDist, FIELD_FLOAT, "SetDistance" ),
  44. DEFINE_INPUT( m_bDisableShadows, FIELD_BOOLEAN, "SetShadowsDisabled" ),
  45. DEFINE_INPUT( m_bEnableLocalLightShadows, FIELD_BOOLEAN, "SetShadowsFromLocalLightsEnabled" ),
  46. DEFINE_INPUTFUNC( FIELD_STRING, "SetAngles", InputSetAngles ),
  47. END_DATADESC()
  48. IMPLEMENT_SERVERCLASS_ST_NOBASE(CShadowControl, DT_ShadowControl)
  49. SendPropVector(SENDINFO(m_shadowDirection), -1, SPROP_NOSCALE ),
  50. SendPropInt(SENDINFO(m_shadowColor), 32, SPROP_UNSIGNED, SendProxy_Color32ToInt32 ),
  51. SendPropFloat(SENDINFO(m_flShadowMaxDist), 0, SPROP_NOSCALE ),
  52. SendPropBool(SENDINFO(m_bDisableShadows)),
  53. SendPropBool(SENDINFO(m_bEnableLocalLightShadows)),
  54. END_SEND_TABLE()
  55. CShadowControl::CShadowControl()
  56. {
  57. m_shadowDirection.Init( 0.2, 0.2, -2 );
  58. m_flShadowMaxDist = 50.0f;
  59. m_shadowColor.Init( 64, 64, 64, 0 );
  60. m_bDisableShadows = false;
  61. m_bEnableLocalLightShadows = false;
  62. }
  63. //------------------------------------------------------------------------------
  64. // Purpose : Send even though we don't have a model
  65. //------------------------------------------------------------------------------
  66. int CShadowControl::UpdateTransmitState()
  67. {
  68. // ALWAYS transmit to all clients.
  69. return SetTransmitState( FL_EDICT_ALWAYS );
  70. }
  71. bool CShadowControl::KeyValue( const char *szKeyName, const char *szValue )
  72. {
  73. if ( FStrEq( szKeyName, "color" ) )
  74. {
  75. color32 tmp;
  76. V_StringToColor32( &tmp, szValue );
  77. m_shadowColor = tmp;
  78. return true;
  79. }
  80. if ( FStrEq( szKeyName, "angles" ) )
  81. {
  82. QAngle angles;
  83. UTIL_StringToVector( angles.Base(), szValue );
  84. if (angles == vec3_angle)
  85. {
  86. angles.Init( 80, 30, 0 );
  87. }
  88. Vector vForward;
  89. AngleVectors( angles, &vForward );
  90. m_shadowDirection = vForward;
  91. return true;
  92. }
  93. // For backward compatibility...
  94. if ( FStrEq( szKeyName, "direction" ) )
  95. {
  96. // Only use this if angles haven't been set...
  97. if ( fabs(m_shadowDirection->LengthSqr() - 1.0f) > 1e-3 )
  98. {
  99. Vector vTemp;
  100. UTIL_StringToVector( vTemp.Base(), szValue );
  101. m_shadowDirection = vTemp;
  102. }
  103. return true;
  104. }
  105. return BaseClass::KeyValue( szKeyName, szValue );
  106. }
  107. //------------------------------------------------------------------------------
  108. // Purpose :
  109. //------------------------------------------------------------------------------
  110. void CShadowControl::Spawn( void )
  111. {
  112. Precache();
  113. SetSolid( SOLID_NONE );
  114. }
  115. //------------------------------------------------------------------------------
  116. // Input values
  117. //------------------------------------------------------------------------------
  118. void CShadowControl::InputSetAngles( inputdata_t &inputdata )
  119. {
  120. const char *pAngles = inputdata.value.String();
  121. QAngle angles;
  122. UTIL_StringToVector( angles.Base(), pAngles );
  123. Vector vTemp;
  124. AngleVectors( angles, &vTemp );
  125. m_shadowDirection = vTemp;
  126. }