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.

184 lines
5.9 KiB

  1. //========= Copyright � 1996-2005, 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. CHandle<CSkyCamera> g_hActiveSkybox = INVALID_EHANDLE;
  16. #ifdef PORTAL2
  17. //------------------------------------------------------------------------------
  18. // Purpose: NPC step trough AI
  19. //------------------------------------------------------------------------------
  20. void CC_SkyboxSwap( void )
  21. {
  22. // Make this cyclical for now!
  23. if ( g_SkyList.m_pClassList->m_pNext )
  24. {
  25. g_SkyList.m_pClassList->m_pNext->m_pNext = g_SkyList.m_pClassList;
  26. }
  27. g_SkyList.m_pClassList = g_SkyList.m_pClassList->m_pNext;
  28. }
  29. static ConCommand skybox_swap("skybox_swap", CC_SkyboxSwap, "Swap through the skyboxes in our queue", FCVAR_CHEAT );
  30. #endif // PORTAL2
  31. //-----------------------------------------------------------------------------
  32. // Retrives the current skycamera
  33. //-----------------------------------------------------------------------------
  34. CSkyCamera* GetCurrentSkyCamera()
  35. {
  36. if (g_hActiveSkybox.Get() == NULL)
  37. {
  38. g_hActiveSkybox = GetSkyCameraList();
  39. }
  40. return g_hActiveSkybox.Get();
  41. }
  42. CSkyCamera* GetSkyCameraList()
  43. {
  44. return g_SkyList.m_pClassList;
  45. }
  46. //=============================================================================
  47. LINK_ENTITY_TO_CLASS( sky_camera, CSkyCamera );
  48. BEGIN_DATADESC( CSkyCamera )
  49. DEFINE_KEYFIELD( m_skyboxData.scale, FIELD_INTEGER, "scale" ),
  50. DEFINE_FIELD( m_skyboxData.origin, FIELD_VECTOR ),
  51. DEFINE_FIELD( m_skyboxData.area, FIELD_INTEGER ),
  52. // Quiet down classcheck
  53. // DEFINE_FIELD( m_skyboxData, sky3dparams_t ),
  54. // This is re-set up in the constructor
  55. // DEFINE_FIELD( m_pNext, CSkyCamera ),
  56. // fog data for 3d skybox
  57. DEFINE_KEYFIELD( m_bUseAngles, FIELD_BOOLEAN, "use_angles" ),
  58. DEFINE_KEYFIELD( m_skyboxData.fog.enable, FIELD_BOOLEAN, "fogenable" ),
  59. DEFINE_KEYFIELD( m_skyboxData.fog.blend, FIELD_BOOLEAN, "fogblend" ),
  60. DEFINE_KEYFIELD( m_skyboxData.fog.dirPrimary, FIELD_VECTOR, "fogdir" ),
  61. DEFINE_KEYFIELD( m_skyboxData.fog.colorPrimary, FIELD_COLOR32, "fogcolor" ),
  62. DEFINE_KEYFIELD( m_skyboxData.fog.colorSecondary, FIELD_COLOR32, "fogcolor2" ),
  63. DEFINE_KEYFIELD( m_skyboxData.fog.start, FIELD_FLOAT, "fogstart" ),
  64. DEFINE_KEYFIELD( m_skyboxData.fog.end, FIELD_FLOAT, "fogend" ),
  65. DEFINE_KEYFIELD( m_skyboxData.fog.maxdensity, FIELD_FLOAT, "fogmaxdensity" ),
  66. DEFINE_KEYFIELD( m_skyboxData.fog.HDRColorScale, FIELD_FLOAT, "HDRColorScale" ),
  67. DEFINE_INPUTFUNC( FIELD_VOID, "ActivateSkybox", InputActivateSkybox ),
  68. END_DATADESC()
  69. //-----------------------------------------------------------------------------
  70. // List of maps in HL2 that we must apply our skybox fog fixup hack to
  71. //-----------------------------------------------------------------------------
  72. static const char *s_pBogusFogMaps[] =
  73. {
  74. "d1_canals_01",
  75. "d1_canals_01a",
  76. "d1_canals_02",
  77. "d1_canals_03",
  78. "d1_canals_09",
  79. "d1_canals_10",
  80. "d1_canals_11",
  81. "d1_canals_12",
  82. "d1_canals_13",
  83. "d1_eli_01",
  84. "d1_trainstation_01",
  85. "d1_trainstation_03",
  86. "d1_trainstation_04",
  87. "d1_trainstation_05",
  88. "d1_trainstation_06",
  89. "d3_c17_04",
  90. "d3_c17_11",
  91. "d3_c17_12",
  92. "d3_citadel_01",
  93. NULL
  94. };
  95. //-----------------------------------------------------------------------------
  96. // Constructor, destructor
  97. //-----------------------------------------------------------------------------
  98. CSkyCamera::CSkyCamera()
  99. {
  100. g_SkyList.Insert( this );
  101. m_skyboxData.fog.maxdensity = 1.0f;
  102. m_skyboxData.fog.HDRColorScale = 1.0f;
  103. }
  104. CSkyCamera::~CSkyCamera()
  105. {
  106. g_SkyList.Remove( this );
  107. }
  108. void CSkyCamera::Spawn( void )
  109. {
  110. m_skyboxData.origin = GetLocalOrigin();
  111. m_skyboxData.area = engine->GetArea( m_skyboxData.origin );
  112. Precache();
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Activate!
  116. //-----------------------------------------------------------------------------
  117. void CSkyCamera::Activate( )
  118. {
  119. BaseClass::Activate();
  120. if ( m_bUseAngles )
  121. {
  122. AngleVectors( GetAbsAngles(), &m_skyboxData.fog.dirPrimary.GetForModify() );
  123. m_skyboxData.fog.dirPrimary.GetForModify() *= -1.0f;
  124. }
  125. #ifdef HL2_DLL
  126. // NOTE! This is a hack. There was a bug in the skybox fog computation
  127. // on the client DLL that caused it to use the average of the primary and
  128. // secondary fog color when blending was enabled. The bug is fixed, but to make
  129. // the maps look the same as before the bug fix without having to download new maps,
  130. // I have to cheat here and slam the primary and secondary colors to be the average of
  131. // the primary and secondary colors.
  132. if ( m_skyboxData.fog.blend )
  133. {
  134. for ( int i = 0; s_pBogusFogMaps[i]; ++i )
  135. {
  136. if ( !Q_stricmp( s_pBogusFogMaps[i], STRING(gpGlobals->mapname) ) )
  137. {
  138. m_skyboxData.fog.colorPrimary.SetR( ( m_skyboxData.fog.colorPrimary.GetR() + m_skyboxData.fog.colorSecondary.GetR() ) * 0.5f );
  139. m_skyboxData.fog.colorPrimary.SetG( ( m_skyboxData.fog.colorPrimary.GetG() + m_skyboxData.fog.colorSecondary.GetG() ) * 0.5f );
  140. m_skyboxData.fog.colorPrimary.SetB( ( m_skyboxData.fog.colorPrimary.GetB() + m_skyboxData.fog.colorSecondary.GetB() ) * 0.5f );
  141. m_skyboxData.fog.colorPrimary.SetA( ( m_skyboxData.fog.colorPrimary.GetA() + m_skyboxData.fog.colorSecondary.GetA() ) * 0.5f );
  142. m_skyboxData.fog.colorSecondary = m_skyboxData.fog.colorPrimary;
  143. }
  144. }
  145. }
  146. #endif
  147. }
  148. //-----------------------------------------------------------------------------
  149. // Activate!
  150. //-----------------------------------------------------------------------------
  151. void CSkyCamera::InputActivateSkybox( inputdata_t &inputdata )
  152. {
  153. g_hActiveSkybox = this;
  154. }