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.

152 lines
4.2 KiB

  1. //========= Copyright 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. };
  34. LINK_ENTITY_TO_CLASS(shadow_control, CShadowControl);
  35. BEGIN_DATADESC( CShadowControl )
  36. DEFINE_KEYFIELD( m_flShadowMaxDist, FIELD_FLOAT, "distance" ),
  37. DEFINE_KEYFIELD( m_bDisableShadows, FIELD_BOOLEAN, "disableallshadows" ),
  38. // Inputs
  39. DEFINE_INPUT( m_shadowColor, FIELD_COLOR32, "color" ),
  40. DEFINE_INPUT( m_shadowDirection, FIELD_VECTOR, "direction" ),
  41. DEFINE_INPUT( m_flShadowMaxDist, FIELD_FLOAT, "SetDistance" ),
  42. DEFINE_INPUT( m_bDisableShadows, FIELD_BOOLEAN, "SetShadowsDisabled" ),
  43. DEFINE_INPUTFUNC( FIELD_STRING, "SetAngles", InputSetAngles ),
  44. END_DATADESC()
  45. IMPLEMENT_SERVERCLASS_ST_NOBASE(CShadowControl, DT_ShadowControl)
  46. SendPropVector(SENDINFO(m_shadowDirection), -1, SPROP_NOSCALE ),
  47. SendPropInt(SENDINFO(m_shadowColor), 32, SPROP_UNSIGNED),
  48. SendPropFloat(SENDINFO(m_flShadowMaxDist), 0, SPROP_NOSCALE ),
  49. SendPropBool(SENDINFO(m_bDisableShadows)),
  50. END_SEND_TABLE()
  51. CShadowControl::CShadowControl()
  52. {
  53. m_shadowDirection.Init( 0.2, 0.2, -2 );
  54. m_flShadowMaxDist = 50.0f;
  55. m_shadowColor.Init( 64, 64, 64, 0 );
  56. m_bDisableShadows = false;
  57. }
  58. //------------------------------------------------------------------------------
  59. // Purpose : Send even though we don't have a model
  60. //------------------------------------------------------------------------------
  61. int CShadowControl::UpdateTransmitState()
  62. {
  63. // ALWAYS transmit to all clients.
  64. return SetTransmitState( FL_EDICT_ALWAYS );
  65. }
  66. bool CShadowControl::KeyValue( const char *szKeyName, const char *szValue )
  67. {
  68. if ( FStrEq( szKeyName, "color" ) )
  69. {
  70. color32 tmp;
  71. UTIL_StringToColor32( &tmp, szValue );
  72. m_shadowColor = tmp;
  73. return true;
  74. }
  75. if ( FStrEq( szKeyName, "angles" ) )
  76. {
  77. QAngle angles;
  78. UTIL_StringToVector( angles.Base(), szValue );
  79. if (angles == vec3_angle)
  80. {
  81. angles.Init( 80, 30, 0 );
  82. }
  83. Vector vForward;
  84. AngleVectors( angles, &vForward );
  85. m_shadowDirection = vForward;
  86. return true;
  87. }
  88. // For backward compatibility...
  89. if ( FStrEq( szKeyName, "direction" ) )
  90. {
  91. // Only use this if angles haven't been set...
  92. if ( fabs(m_shadowDirection->LengthSqr() - 1.0f) > 1e-3 )
  93. {
  94. Vector vTemp;
  95. UTIL_StringToVector( vTemp.Base(), szValue );
  96. m_shadowDirection = vTemp;
  97. }
  98. return true;
  99. }
  100. return BaseClass::KeyValue( szKeyName, szValue );
  101. }
  102. //------------------------------------------------------------------------------
  103. // Purpose :
  104. //------------------------------------------------------------------------------
  105. void CShadowControl::Spawn( void )
  106. {
  107. Precache();
  108. SetSolid( SOLID_NONE );
  109. }
  110. //------------------------------------------------------------------------------
  111. // Input values
  112. //------------------------------------------------------------------------------
  113. void CShadowControl::InputSetAngles( inputdata_t &inputdata )
  114. {
  115. const char *pAngles = inputdata.value.String();
  116. QAngle angles;
  117. UTIL_StringToVector( angles.Base(), pAngles );
  118. Vector vTemp;
  119. AngleVectors( angles, &vTemp );
  120. m_shadowDirection = vTemp;
  121. }