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.

143 lines
3.7 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Spatial entity with simple radial falloff
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef C_SPATIALENTITY_H
  8. #define C_SPATIALENTITY_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #define SPATIAL_ENTITY_FORCED_VALUE_BLEND_DISTANCE 128.0f
  13. //------------------------------------------------------------------------------
  14. // Purpose : Spatial entity with radial falloff
  15. //------------------------------------------------------------------------------
  16. class C_SpatialEntity : public C_BaseEntity
  17. {
  18. public:
  19. DECLARE_CLASS( C_SpatialEntity, C_BaseEntity );
  20. DECLARE_CLIENTCLASS();
  21. virtual void OnDataChanged(DataUpdateType_t updateType);
  22. virtual void UpdateOnRemove( void );
  23. virtual bool ShouldDraw();
  24. virtual void ClientThink();
  25. virtual void InitSpatialEntity();
  26. virtual void ResetAccumulation( void ) {};
  27. virtual void Accumulate( void ) {};
  28. virtual void ApplyAccumulation( void ) {};
  29. float GetMinFalloff( void ) { return m_minFalloff; }
  30. float GetMaxFalloff( void ) { return m_maxFalloff; }
  31. void SetFalloff( float flMinFalloff, float flMaxFalloff ) { m_minFalloff = flMinFalloff; m_maxFalloff = flMaxFalloff; }
  32. void SetEnabled( bool bEnabled ) { m_bEnabled = bEnabled; }
  33. void SetCurWeight( float flWeight ) { m_flCurWeight = flWeight; }
  34. protected:
  35. virtual void AddToPersonalSpatialEntityMgr( void ) {};
  36. virtual void RemoveFromPersonalSpatialEntityMgr( void ) {};
  37. private:
  38. Vector m_vecOrigin;
  39. float m_minFalloff;
  40. float m_maxFalloff;
  41. float m_flCurWeight;
  42. char m_netLookupFilename[MAX_PATH];
  43. bool m_bEnabled;
  44. protected:
  45. float m_flWeight; // Interpolator for how much it's value adds to the total
  46. float m_flInfluence; // Distance within the inner radius
  47. };
  48. template <class T>
  49. class C_SpatialEntityTemplate : public C_SpatialEntity
  50. {
  51. DECLARE_CLASS( C_SpatialEntityTemplate, C_SpatialEntity );
  52. public:
  53. virtual void ResetAccumulation( void )
  54. {
  55. m_AccumulatedValue = 0;
  56. m_ForcedValue = 0;
  57. m_ForcedMinFalloff = GetMinFalloff();
  58. m_ForcedInfluence = 0.0f;
  59. }
  60. virtual void Accumulate( void )
  61. {
  62. if ( m_flInfluence > m_ForcedInfluence )
  63. {
  64. // This value is in control unless a stronger influence is accumulated
  65. m_ForcedValue = m_Value;
  66. m_ForcedMinFalloff = GetMinFalloff();
  67. m_ForcedInfluence = m_flInfluence;
  68. }
  69. // Contribute to the total
  70. m_AccumulatedValue += m_Value * m_flWeight;
  71. }
  72. T BlendedValue( void )
  73. {
  74. if ( m_ForcedInfluence <= 0.0f )
  75. {
  76. // No forced value
  77. return m_AccumulatedValue;
  78. }
  79. // Check if we're fully inside the forced area
  80. if ( m_ForcedInfluence >= SPATIAL_ENTITY_FORCED_VALUE_BLEND_DISTANCE )
  81. {
  82. // Fully inside the forced area
  83. return m_ForcedValue;
  84. }
  85. // Blend between the accumulated value and the forced value
  86. float flInterp = ( SPATIAL_ENTITY_FORCED_VALUE_BLEND_DISTANCE - m_ForcedInfluence ) / SPATIAL_ENTITY_FORCED_VALUE_BLEND_DISTANCE;
  87. return ( m_AccumulatedValue * flInterp ) + ( m_ForcedValue * ( 1.0f - flInterp ) );
  88. }
  89. protected:
  90. T m_Value;
  91. private:
  92. static T m_AccumulatedValue;
  93. static T m_ForcedValue;
  94. static float m_ForcedMinFalloff;
  95. static float m_ForcedInfluence;
  96. };
  97. template <class T>
  98. T C_SpatialEntityTemplate<T>::m_AccumulatedValue;
  99. template <class T>
  100. T C_SpatialEntityTemplate<T>::m_ForcedValue;
  101. template <class T>
  102. float C_SpatialEntityTemplate<T>::m_ForcedMinFalloff;
  103. template <class T>
  104. float C_SpatialEntityTemplate<T>::m_ForcedInfluence;
  105. template <>
  106. inline void C_SpatialEntityTemplate<Vector>::ResetAccumulation( void )
  107. {
  108. m_AccumulatedValue.Init();
  109. m_ForcedValue.Init();
  110. m_ForcedMinFalloff = GetMinFalloff();
  111. m_ForcedInfluence = 0.0f;
  112. }
  113. #endif // C_SPATIALENTITY_H