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.

75 lines
1.9 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "func_areaportalbase.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. // A sphere around the player used for backface culling of areaportals.
  12. #define VIEWER_PADDING 80
  13. CUtlLinkedList<CFuncAreaPortalBase*, unsigned short> g_AreaPortals;
  14. //---------------------------------------------------------
  15. // Save/Restore
  16. //---------------------------------------------------------
  17. BEGIN_DATADESC( CFuncAreaPortalBase )
  18. DEFINE_FIELD( m_portalNumber, FIELD_INTEGER ),
  19. DEFINE_KEYFIELD( m_iPortalVersion, FIELD_INTEGER, "PortalVersion" )
  20. // DEFINE_FIELD( m_AreaPortalsElement, FIELD_SHORT ),
  21. END_DATADESC()
  22. CFuncAreaPortalBase::CFuncAreaPortalBase()
  23. {
  24. m_portalNumber = -1;
  25. m_AreaPortalsElement = g_AreaPortals.AddToTail( this );
  26. m_iPortalVersion = 0;
  27. }
  28. CFuncAreaPortalBase::~CFuncAreaPortalBase()
  29. {
  30. g_AreaPortals.Remove( m_AreaPortalsElement );
  31. }
  32. bool CFuncAreaPortalBase::UpdateVisibility( const CUtlVector< Vector > &vecOrigins, float fovDistanceAdjustFactor, bool &bIsOpenOnClient )
  33. {
  34. // NOTE: We leave bIsOpenOnClient alone on purpose here. See the header for a description of why.
  35. if( m_portalNumber == -1 )
  36. return false;
  37. // See if the viewer is on the backside.
  38. for ( int i = 0; i < vecOrigins.Count(); ++i )
  39. {
  40. const Vector &vOrigin = vecOrigins[ i ];
  41. VPlane plane;
  42. if( !engine->GetAreaPortalPlane( vOrigin, m_portalNumber, &plane ) )
  43. return true; // leave it open if there's an error here for some reason
  44. // If either players' origin is on the front, the areaportal is considered opened...
  45. if( plane.DistTo( vOrigin ) + VIEWER_PADDING > 0 )
  46. return true;
  47. }
  48. return false;
  49. }