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.

71 lines
1.7 KiB

  1. //========= Copyright 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 Vector &vOrigin, 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. VPlane plane;
  39. if( !engine->GetAreaPortalPlane( vOrigin, m_portalNumber, &plane ) )
  40. return true; // leave it open if there's an error here for some reason
  41. bool bOpen = false;
  42. if( plane.DistTo( vOrigin ) + VIEWER_PADDING > 0 )
  43. bOpen = true;
  44. return bOpen;
  45. }