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.

153 lines
4.7 KiB

  1. //--------------------------------------------------------------------------------------------------------
  2. // Copyright (c) 2007 Turtle Rock Studios, Inc. - All Rights Reserved
  3. #include "cbase.h"
  4. #include "fogvolume.h"
  5. #include "collisionutils.h"
  6. // memdbgon must be the last include file in a .cpp file!!!
  7. #include "tier0/memdbgon.h"
  8. CUtlVector< CFogVolume * > TheFogVolumes;
  9. ConVar fog_volume_debug( "fog_volume_debug", "0", 0, "If enabled, prints diagnostic information about the current fog volume" );
  10. //--------------------------------------------------------------------------------------------------------
  11. LINK_ENTITY_TO_CLASS(fog_volume, CFogVolume);
  12. BEGIN_DATADESC( CFogVolume )
  13. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  14. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  15. DEFINE_KEYFIELD( m_fogName, FIELD_STRING, "FogName" ),
  16. DEFINE_KEYFIELD( m_postProcessName, FIELD_STRING, "PostProcessName" ),
  17. DEFINE_KEYFIELD( m_colorCorrectionName, FIELD_STRING, "ColorCorrectionName" ),
  18. DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "StartDisabled" ),
  19. DEFINE_FIELD( m_hFogController, FIELD_EHANDLE ),
  20. DEFINE_FIELD( m_hPostProcessController, FIELD_EHANDLE ),
  21. DEFINE_FIELD( m_hColorCorrectionController, FIELD_EHANDLE ),
  22. END_DATADESC()
  23. //--------------------------------------------------------------------------------------------------------
  24. CFogVolume *CFogVolume::FindFogVolumeForPosition( const Vector &position )
  25. {
  26. CFogVolume *fogVolume = NULL;
  27. for ( int i=0; i<TheFogVolumes.Count(); ++i )
  28. {
  29. fogVolume = TheFogVolumes[i];
  30. Vector vecRelativeCenter;
  31. fogVolume->CollisionProp()->WorldToCollisionSpace( position, &vecRelativeCenter );
  32. if ( IsBoxIntersectingSphere( fogVolume->CollisionProp()->OBBMins(), fogVolume->CollisionProp()->OBBMaxs(), vecRelativeCenter, 1.0f ) )
  33. {
  34. break;
  35. }
  36. fogVolume = NULL;
  37. }
  38. // This doesn't work well if there are multiple players or multiple fog volume queries per frame; might want to relocate this if that's the case
  39. if ( fog_volume_debug.GetBool() )
  40. {
  41. if ( fogVolume )
  42. {
  43. char fogVolumeName[256];
  44. fogVolume->GetKeyValue( "targetname", fogVolumeName, 256 );
  45. engine->Con_NPrintf( 0, "Fog Volume ""%s"" found at position (%f %f %f)", fogVolumeName, position.x, position.y, position.z );
  46. engine->Con_NPrintf( 1, "Fog: %s, post process: %s, color correct: %s", fogVolume->m_fogName.ToCStr(), fogVolume->m_postProcessName.ToCStr(), fogVolume->m_colorCorrectionName.ToCStr() );
  47. }
  48. else
  49. {
  50. engine->Con_NPrintf( 0, "No Fog Volume found at given position (%f %f %f)", position.x, position.y, position.z );
  51. }
  52. }
  53. return fogVolume;
  54. }
  55. //--------------------------------------------------------------------------------------------------------
  56. CFogVolume::CFogVolume() :
  57. BaseClass(),
  58. m_bDisabled( false ),
  59. m_bInFogVolumesList( false )
  60. {
  61. }
  62. //--------------------------------------------------------------------------------------------------------
  63. CFogVolume::~CFogVolume()
  64. {
  65. RemoveFromGlobalList();
  66. }
  67. //--------------------------------------------------------------------------------------------------------
  68. void CFogVolume::Spawn( void )
  69. {
  70. BaseClass::Spawn();
  71. SetSolid( SOLID_BSP );
  72. SetSolidFlags( FSOLID_NOT_SOLID );
  73. SetModel( STRING( GetModelName() ) );
  74. }
  75. //--------------------------------------------------------------------------------------------------------
  76. void CFogVolume::AddToGlobalList()
  77. {
  78. if ( !m_bInFogVolumesList )
  79. {
  80. TheFogVolumes.AddToTail( this );
  81. m_bInFogVolumesList = true;
  82. }
  83. }
  84. //--------------------------------------------------------------------------------------------------------
  85. void CFogVolume::RemoveFromGlobalList()
  86. {
  87. if ( m_bInFogVolumesList )
  88. {
  89. TheFogVolumes.FindAndRemove( this );
  90. m_bInFogVolumesList = false;
  91. }
  92. }
  93. //----------------------------------------------------------------------------
  94. void CFogVolume::InputEnable( inputdata_t &data )
  95. {
  96. m_bDisabled = false;
  97. AddToGlobalList();
  98. }
  99. //----------------------------------------------------------------------------
  100. void CFogVolume::InputDisable( inputdata_t &data )
  101. {
  102. m_bDisabled = true;
  103. RemoveFromGlobalList();
  104. }
  105. //----------------------------------------------------------------------------
  106. // Called when the level loads or is restored
  107. //----------------------------------------------------------------------------
  108. void CFogVolume::Activate()
  109. {
  110. BaseClass::Activate();
  111. m_hFogController = dynamic_cast< CFogController* >( gEntList.FindEntityByName( NULL, m_fogName ) );
  112. m_hPostProcessController = dynamic_cast< CPostProcessController* >( gEntList.FindEntityByName( NULL, m_postProcessName ) );
  113. m_hColorCorrectionController = dynamic_cast< CColorCorrection* >( gEntList.FindEntityByName( NULL, m_colorCorrectionName ) );
  114. if ( !m_bDisabled )
  115. {
  116. AddToGlobalList();
  117. }
  118. }