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.

199 lines
7.5 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "baseentity.h"
  8. #include "entityoutput.h"
  9. //#include "convar.h"
  10. #include "env_dof_controller.h"
  11. #include "ai_utils.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. LINK_ENTITY_TO_CLASS( env_dof_controller, CEnvDOFController );
  15. BEGIN_DATADESC( CEnvDOFController )
  16. DEFINE_KEYFIELD( m_bDOFEnabled, FIELD_BOOLEAN, "enabled" ),
  17. DEFINE_KEYFIELD( m_flNearBlurDepth, FIELD_FLOAT, "near_blur" ),
  18. DEFINE_KEYFIELD( m_flNearFocusDepth, FIELD_FLOAT, "near_focus" ),
  19. DEFINE_KEYFIELD( m_flFarFocusDepth, FIELD_FLOAT, "far_focus" ),
  20. DEFINE_KEYFIELD( m_flFarBlurDepth, FIELD_FLOAT, "far_blur" ),
  21. DEFINE_KEYFIELD( m_flNearBlurRadius, FIELD_FLOAT, "near_radius" ),
  22. DEFINE_KEYFIELD( m_flFarBlurRadius, FIELD_FLOAT, "far_radius" ),
  23. DEFINE_KEYFIELD( m_strFocusTargetName, FIELD_STRING, "focus_target" ),
  24. DEFINE_KEYFIELD( m_flFocusTargetRange, FIELD_FLOAT, "focus_range" ),
  25. DEFINE_FIELD( m_hFocusTarget, FIELD_EHANDLE ),
  26. DEFINE_THINKFUNC( UpdateParamBlend ),
  27. // Inputs
  28. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetNearBlurDepth", InputSetNearBlurDepth ),
  29. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetNearFocusDepth", InputSetNearFocusDepth ),
  30. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFarFocusDepth", InputSetFarFocusDepth ),
  31. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFarBlurDepth", InputSetFarBlurDepth ),
  32. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetNearBlurRadius", InputSetNearBlurRadius ),
  33. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFarBlurRadius", InputSetFarBlurRadius ),
  34. DEFINE_INPUTFUNC( FIELD_STRING, "SetFocusTarget", InputSetFocusTarget ),
  35. DEFINE_INPUTFUNC( FIELD_STRING, "SetFocusTargetRange", InputSetFocusTargetRange ),
  36. END_DATADESC()
  37. IMPLEMENT_SERVERCLASS_ST( CEnvDOFController, DT_EnvDOFController )
  38. SendPropInt( SENDINFO(m_bDOFEnabled), 1, SPROP_UNSIGNED ),
  39. SendPropFloat( SENDINFO(m_flNearBlurDepth), 0, SPROP_NOSCALE),
  40. SendPropFloat( SENDINFO(m_flNearFocusDepth), 0, SPROP_NOSCALE),
  41. SendPropFloat( SENDINFO(m_flFarFocusDepth), 0, SPROP_NOSCALE),
  42. SendPropFloat( SENDINFO(m_flFarBlurDepth), 0, SPROP_NOSCALE),
  43. SendPropFloat( SENDINFO(m_flNearBlurRadius), 0, SPROP_NOSCALE),
  44. SendPropFloat( SENDINFO(m_flFarBlurRadius), 0, SPROP_NOSCALE),
  45. END_SEND_TABLE()
  46. //-----------------------------------------------------------------------------
  47. // Purpose:
  48. //-----------------------------------------------------------------------------
  49. void CEnvDOFController::Spawn( void )
  50. {
  51. SetSolid( SOLID_NONE );
  52. SetMoveType( MOVETYPE_NONE );
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose:
  56. //-----------------------------------------------------------------------------
  57. void CEnvDOFController::Activate( void )
  58. {
  59. BaseClass::Activate();
  60. // Find our target entity and hold on to it
  61. m_hFocusTarget = gEntList.FindEntityByName( NULL, m_strFocusTargetName );
  62. // Update if we have a focal target
  63. if ( m_hFocusTarget )
  64. {
  65. SetThink( &CEnvDOFController::UpdateParamBlend );
  66. SetNextThink( gpGlobals->curtime + 0.1f );
  67. }
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. int CEnvDOFController::UpdateTransmitState()
  73. {
  74. return SetTransmitState( FL_EDICT_ALWAYS );
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Purpose:
  78. //-----------------------------------------------------------------------------
  79. void CEnvDOFController::InputSetNearBlurDepth( inputdata_t &inputdata )
  80. {
  81. m_flNearBlurDepth = inputdata.value.Float();
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. //-----------------------------------------------------------------------------
  86. void CEnvDOFController::InputSetNearFocusDepth( inputdata_t &inputdata )
  87. {
  88. m_flNearFocusDepth = inputdata.value.Float();
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. //-----------------------------------------------------------------------------
  93. void CEnvDOFController::InputSetFarFocusDepth( inputdata_t &inputdata )
  94. {
  95. m_flFarFocusDepth = inputdata.value.Float();
  96. }
  97. //-----------------------------------------------------------------------------
  98. // Purpose:
  99. //-----------------------------------------------------------------------------
  100. void CEnvDOFController::InputSetFarBlurDepth( inputdata_t &inputdata )
  101. {
  102. m_flFarBlurDepth = inputdata.value.Float();
  103. }
  104. //-----------------------------------------------------------------------------
  105. // Purpose:
  106. //-----------------------------------------------------------------------------
  107. void CEnvDOFController::InputSetNearBlurRadius( inputdata_t &inputdata )
  108. {
  109. m_flNearBlurRadius = inputdata.value.Float();
  110. m_bDOFEnabled = ( m_flNearBlurRadius > 0.0f ) || ( m_flFarBlurRadius > 0.0f );
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose:
  114. //-----------------------------------------------------------------------------
  115. void CEnvDOFController::InputSetFarBlurRadius( inputdata_t &inputdata )
  116. {
  117. m_flFarBlurRadius = inputdata.value.Float();
  118. m_bDOFEnabled = ( m_flNearBlurRadius > 0.0f ) || ( m_flFarBlurRadius > 0.0f );
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. //-----------------------------------------------------------------------------
  123. void CEnvDOFController::SetControllerState( DOFControlSettings_t setting )
  124. {
  125. m_flNearBlurDepth = setting.flNearBlurDepth;
  126. m_flNearBlurRadius = setting.flNearBlurRadius;
  127. m_flNearFocusDepth = setting.flNearFocusDistance;
  128. m_flFarBlurDepth = setting.flFarBlurDepth;
  129. m_flFarBlurRadius = setting.flFarBlurRadius;
  130. m_flFarFocusDepth = setting.flFarFocusDistance;
  131. m_bDOFEnabled = ( m_flNearBlurRadius > 0.0f ) || ( m_flFarBlurRadius > 0.0f );
  132. }
  133. const float BLUR_DEPTH = 500.0f;
  134. //-----------------------------------------------------------------------------
  135. // Purpose: Blend the parameters to the specified value
  136. //-----------------------------------------------------------------------------
  137. void CEnvDOFController::UpdateParamBlend( void )
  138. {
  139. // Update our focal target if we have one
  140. if ( m_hFocusTarget )
  141. {
  142. CBasePlayer *pPlayer = AI_GetSinglePlayer();
  143. float flDistToFocus = ( m_hFocusTarget->GetAbsOrigin() - pPlayer->GetAbsOrigin() ).Length();
  144. m_flFarFocusDepth.GetForModify() = flDistToFocus + m_flFocusTargetRange;
  145. m_flFarBlurDepth.GetForModify() = m_flFarFocusDepth + BLUR_DEPTH;
  146. }
  147. SetThink( &CEnvDOFController::UpdateParamBlend );
  148. SetNextThink( gpGlobals->curtime + 0.1f );
  149. }
  150. //-----------------------------------------------------------------------------
  151. // Purpose: Set the "focus" target entity
  152. //-----------------------------------------------------------------------------
  153. void CEnvDOFController::InputSetFocusTarget( inputdata_t &inputdata )
  154. {
  155. m_hFocusTarget = gEntList.FindEntityByName( NULL, inputdata.value.String() );
  156. // Update if we have a focal target
  157. if ( m_hFocusTarget )
  158. {
  159. SetThink( &CEnvDOFController::UpdateParamBlend );
  160. SetNextThink( gpGlobals->curtime + 0.1f );
  161. }
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Purpose: Set the range behind the focus entity that we'll blur (in units)
  165. //-----------------------------------------------------------------------------
  166. void CEnvDOFController::InputSetFocusTargetRange( inputdata_t &inputdata )
  167. {
  168. m_flFocusTargetRange = inputdata.value.Float();
  169. }