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.

147 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "igamesystem.h"
  8. #include "entitylist.h"
  9. #include "SkyCamera.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. // automatically hooks in the system's callbacks
  13. CEntityClassList<CSkyCamera> g_SkyList;
  14. template <> CSkyCamera *CEntityClassList<CSkyCamera>::m_pClassList = NULL;
  15. //-----------------------------------------------------------------------------
  16. // Retrives the current skycamera
  17. //-----------------------------------------------------------------------------
  18. CSkyCamera* GetCurrentSkyCamera()
  19. {
  20. return g_SkyList.m_pClassList;
  21. }
  22. CSkyCamera* GetSkyCameraList()
  23. {
  24. return g_SkyList.m_pClassList;
  25. }
  26. //=============================================================================
  27. LINK_ENTITY_TO_CLASS( sky_camera, CSkyCamera );
  28. BEGIN_DATADESC( CSkyCamera )
  29. DEFINE_KEYFIELD( m_skyboxData.scale, FIELD_INTEGER, "scale" ),
  30. DEFINE_FIELD( m_skyboxData.origin, FIELD_VECTOR ),
  31. DEFINE_FIELD( m_skyboxData.area, FIELD_INTEGER ),
  32. // Quiet down classcheck
  33. // DEFINE_FIELD( m_skyboxData, sky3dparams_t ),
  34. // This is re-set up in the constructor
  35. // DEFINE_FIELD( m_pNext, CSkyCamera ),
  36. // fog data for 3d skybox
  37. DEFINE_KEYFIELD( m_bUseAngles, FIELD_BOOLEAN, "use_angles" ),
  38. DEFINE_KEYFIELD( m_skyboxData.fog.enable, FIELD_BOOLEAN, "fogenable" ),
  39. DEFINE_KEYFIELD( m_skyboxData.fog.blend, FIELD_BOOLEAN, "fogblend" ),
  40. DEFINE_KEYFIELD( m_skyboxData.fog.dirPrimary, FIELD_VECTOR, "fogdir" ),
  41. DEFINE_KEYFIELD( m_skyboxData.fog.colorPrimary, FIELD_COLOR32, "fogcolor" ),
  42. DEFINE_KEYFIELD( m_skyboxData.fog.colorSecondary, FIELD_COLOR32, "fogcolor2" ),
  43. DEFINE_KEYFIELD( m_skyboxData.fog.start, FIELD_FLOAT, "fogstart" ),
  44. DEFINE_KEYFIELD( m_skyboxData.fog.end, FIELD_FLOAT, "fogend" ),
  45. DEFINE_KEYFIELD( m_skyboxData.fog.maxdensity, FIELD_FLOAT, "fogmaxdensity" ),
  46. END_DATADESC()
  47. //-----------------------------------------------------------------------------
  48. // List of maps in HL2 that we must apply our skybox fog fixup hack to
  49. //-----------------------------------------------------------------------------
  50. static const char *s_pBogusFogMaps[] =
  51. {
  52. "d1_canals_01",
  53. "d1_canals_01a",
  54. "d1_canals_02",
  55. "d1_canals_03",
  56. "d1_canals_09",
  57. "d1_canals_10",
  58. "d1_canals_11",
  59. "d1_canals_12",
  60. "d1_canals_13",
  61. "d1_eli_01",
  62. "d1_trainstation_01",
  63. "d1_trainstation_03",
  64. "d1_trainstation_04",
  65. "d1_trainstation_05",
  66. "d1_trainstation_06",
  67. "d3_c17_04",
  68. "d3_c17_11",
  69. "d3_c17_12",
  70. "d3_citadel_01",
  71. NULL
  72. };
  73. //-----------------------------------------------------------------------------
  74. // Constructor, destructor
  75. //-----------------------------------------------------------------------------
  76. CSkyCamera::CSkyCamera()
  77. {
  78. g_SkyList.Insert( this );
  79. m_skyboxData.fog.maxdensity = 1.0f;
  80. }
  81. CSkyCamera::~CSkyCamera()
  82. {
  83. g_SkyList.Remove( this );
  84. }
  85. void CSkyCamera::Spawn( void )
  86. {
  87. m_skyboxData.origin = GetLocalOrigin();
  88. m_skyboxData.area = engine->GetArea( m_skyboxData.origin );
  89. Precache();
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Activate!
  93. //-----------------------------------------------------------------------------
  94. void CSkyCamera::Activate( )
  95. {
  96. BaseClass::Activate();
  97. if ( m_bUseAngles )
  98. {
  99. AngleVectors( GetAbsAngles(), &m_skyboxData.fog.dirPrimary.GetForModify() );
  100. m_skyboxData.fog.dirPrimary.GetForModify() *= -1.0f;
  101. }
  102. #ifdef HL2_DLL
  103. // NOTE! This is a hack. There was a bug in the skybox fog computation
  104. // on the client DLL that caused it to use the average of the primary and
  105. // secondary fog color when blending was enabled. The bug is fixed, but to make
  106. // the maps look the same as before the bug fix without having to download new maps,
  107. // I have to cheat here and slam the primary and secondary colors to be the average of
  108. // the primary and secondary colors.
  109. if ( m_skyboxData.fog.blend )
  110. {
  111. for ( int i = 0; s_pBogusFogMaps[i]; ++i )
  112. {
  113. if ( !Q_stricmp( s_pBogusFogMaps[i], STRING(gpGlobals->mapname) ) )
  114. {
  115. m_skyboxData.fog.colorPrimary.SetR( ( m_skyboxData.fog.colorPrimary.GetR() + m_skyboxData.fog.colorSecondary.GetR() ) * 0.5f );
  116. m_skyboxData.fog.colorPrimary.SetG( ( m_skyboxData.fog.colorPrimary.GetG() + m_skyboxData.fog.colorSecondary.GetG() ) * 0.5f );
  117. m_skyboxData.fog.colorPrimary.SetB( ( m_skyboxData.fog.colorPrimary.GetB() + m_skyboxData.fog.colorSecondary.GetB() ) * 0.5f );
  118. m_skyboxData.fog.colorPrimary.SetA( ( m_skyboxData.fog.colorPrimary.GetA() + m_skyboxData.fog.colorSecondary.GetA() ) * 0.5f );
  119. m_skyboxData.fog.colorSecondary = m_skyboxData.fog.colorPrimary;
  120. }
  121. }
  122. }
  123. #endif
  124. }