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.

109 lines
2.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "point_camera.h"
  8. #include "modelentities.h"
  9. #include "info_camera_link.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. class CFuncMonitor : public CFuncBrush
  13. {
  14. DECLARE_DATADESC();
  15. DECLARE_CLASS( CFuncMonitor, CFuncBrush );
  16. DECLARE_SERVERCLASS();
  17. public:
  18. virtual void Activate();
  19. virtual void UpdateOnRemove();
  20. private:
  21. void InputSetCamera(inputdata_t &inputdata);
  22. void SetCameraByName(const char *szName);
  23. void ReleaseCameraLink();
  24. EHANDLE m_hInfoCameraLink;
  25. };
  26. // automatically hooks in the system's callbacks
  27. BEGIN_DATADESC( CFuncMonitor )
  28. DEFINE_FIELD( m_hInfoCameraLink, FIELD_EHANDLE ),
  29. // Outputs
  30. DEFINE_INPUTFUNC( FIELD_STRING, "SetCamera", InputSetCamera ),
  31. END_DATADESC()
  32. LINK_ENTITY_TO_CLASS( func_monitor, CFuncMonitor );
  33. IMPLEMENT_SERVERCLASS_ST( CFuncMonitor, DT_FuncMonitor )
  34. END_SEND_TABLE()
  35. //-----------------------------------------------------------------------------
  36. // Purpose: Called after all entities have spawned and after a load game.
  37. //-----------------------------------------------------------------------------
  38. void CFuncMonitor::Activate()
  39. {
  40. BaseClass::Activate();
  41. SetCameraByName(STRING(m_target));
  42. }
  43. void CFuncMonitor::UpdateOnRemove()
  44. {
  45. ReleaseCameraLink();
  46. BaseClass::UpdateOnRemove();
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Frees the camera.
  50. //-----------------------------------------------------------------------------
  51. void CFuncMonitor::ReleaseCameraLink()
  52. {
  53. if ( m_hInfoCameraLink )
  54. {
  55. UTIL_Remove( m_hInfoCameraLink );
  56. m_hInfoCameraLink = NULL;
  57. // Keep the target up-to-date for save/load
  58. m_target = NULL_STRING;
  59. }
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Sets camera
  63. //-----------------------------------------------------------------------------
  64. void CFuncMonitor::SetCameraByName(const char *szName)
  65. {
  66. ReleaseCameraLink();
  67. CBaseEntity *pBaseEnt = gEntList.FindEntityByName( NULL, szName );
  68. if( pBaseEnt )
  69. {
  70. CPointCamera *pCamera = dynamic_cast<CPointCamera *>( pBaseEnt );
  71. if( pCamera )
  72. {
  73. // Keep the target up-to-date for save/load
  74. m_target = MAKE_STRING( szName );
  75. m_hInfoCameraLink = CreateInfoCameraLink( this, pCamera );
  76. }
  77. }
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. //-----------------------------------------------------------------------------
  82. void CFuncMonitor::InputSetCamera(inputdata_t &inputdata)
  83. {
  84. SetCameraByName( inputdata.value.String() );
  85. }