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.

80 lines
2.4 KiB

  1. //=========== Copyright (c) Valve Corporation, All rights reserved. ===========
  2. //
  3. // Simple entity to switch the map's 2D skybox texture when triggered.
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include "tier0/memdbgon.h"
  9. //-----------------------------------------------------------------------------
  10. // CSkyboxSwapper
  11. //-----------------------------------------------------------------------------
  12. class CSkyboxSwapper : public CServerOnlyPointEntity
  13. {
  14. DECLARE_CLASS( CSkyboxSwapper, CServerOnlyPointEntity );
  15. public:
  16. DECLARE_DATADESC();
  17. virtual void Spawn( void );
  18. virtual void Precache( void );
  19. void InputTrigger( inputdata_t &inputdata );
  20. protected:
  21. string_t m_iszSkyboxName;
  22. };
  23. LINK_ENTITY_TO_CLASS(skybox_swapper, CSkyboxSwapper);
  24. BEGIN_DATADESC( CSkyboxSwapper )
  25. DEFINE_KEYFIELD( m_iszSkyboxName, FIELD_STRING, "SkyboxName" ),
  26. // Inputs
  27. DEFINE_INPUTFUNC(FIELD_VOID, "Trigger", InputTrigger),
  28. END_DATADESC()
  29. //-----------------------------------------------------------------------------
  30. // Purpose: not much
  31. //-----------------------------------------------------------------------------
  32. void CSkyboxSwapper::Spawn( void )
  33. {
  34. Precache();
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Precache the skybox materials.
  38. //-----------------------------------------------------------------------------
  39. void CSkyboxSwapper::Precache( void )
  40. {
  41. if ( Q_strlen( m_iszSkyboxName.ToCStr() ) == 0 )
  42. {
  43. Warning( "skybox_swapper (%s) has no skybox specified!\n", GetEntityName().ToCStr() );
  44. return;
  45. }
  46. char name[ MAX_PATH ];
  47. char *skyboxsuffix[ 6 ] = { "rt", "bk", "lf", "ft", "up", "dn" };
  48. for ( int i = 0; i < 6; i++ )
  49. {
  50. Q_snprintf( name, sizeof( name ), "skybox/%s%s", m_iszSkyboxName.ToCStr(), skyboxsuffix[i] );
  51. PrecacheMaterial( name );
  52. }
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose: Input handler that triggers the skybox swap.
  56. //-----------------------------------------------------------------------------
  57. void CSkyboxSwapper::InputTrigger( inputdata_t &inputdata )
  58. {
  59. static ConVarRef skyname( "sv_skyname", false );
  60. if ( !skyname.IsValid() )
  61. {
  62. Warning( "skybox_swapper (%s) trigger input failed - cannot find 'sv_skyname' convar!\n", GetEntityName().ToCStr() );
  63. return;
  64. }
  65. skyname.SetValue( m_iszSkyboxName.ToCStr() );
  66. }