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.

147 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "view.h"
  10. #include "model_types.h"
  11. #include "ivrenderview.h"
  12. #include "engine/ivmodelinfo.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. #define VIEWER_PADDING 80.0f
  16. class C_FuncAreaPortalWindow : public C_BaseEntity
  17. {
  18. public:
  19. DECLARE_CLIENTCLASS();
  20. DECLARE_CLASS( C_FuncAreaPortalWindow, C_BaseEntity );
  21. // Overrides.
  22. public:
  23. virtual void ComputeFxBlend();
  24. virtual bool IsTransparent();
  25. virtual int DrawModel( int flags );
  26. virtual bool ShouldReceiveProjectedTextures( int flags );
  27. private:
  28. float GetDistanceBlend();
  29. public:
  30. float m_flFadeStartDist; // Distance at which it starts fading (when <= this, alpha=m_flTranslucencyLimit).
  31. float m_flFadeDist; // Distance at which it becomes solid.
  32. // 0-1 value - minimum translucency it's allowed to get to.
  33. float m_flTranslucencyLimit;
  34. int m_iBackgroundModelIndex;
  35. };
  36. IMPLEMENT_CLIENTCLASS_DT( C_FuncAreaPortalWindow, DT_FuncAreaPortalWindow, CFuncAreaPortalWindow )
  37. RecvPropFloat( RECVINFO( m_flFadeStartDist ) ),
  38. RecvPropFloat( RECVINFO( m_flFadeDist ) ),
  39. RecvPropFloat( RECVINFO( m_flTranslucencyLimit ) ),
  40. RecvPropInt( RECVINFO( m_iBackgroundModelIndex ) )
  41. END_RECV_TABLE()
  42. void C_FuncAreaPortalWindow::ComputeFxBlend()
  43. {
  44. // We reset our blend down below so pass anything except 0 to the renderer.
  45. m_nRenderFXBlend = 255;
  46. #ifdef _DEBUG
  47. m_nFXComputeFrame = gpGlobals->framecount;
  48. #endif
  49. }
  50. bool C_FuncAreaPortalWindow::IsTransparent()
  51. {
  52. return true;
  53. }
  54. int C_FuncAreaPortalWindow::DrawModel( int flags )
  55. {
  56. if ( !m_bReadyToDraw )
  57. return 0;
  58. if( !GetModel() )
  59. return 0;
  60. // Make sure we're a brush model.
  61. int modelType = modelinfo->GetModelType( GetModel() );
  62. if( modelType != mod_brush )
  63. return 0;
  64. // Draw the fading version.
  65. render->SetBlend( GetDistanceBlend() );
  66. DrawBrushModelMode_t mode = DBM_DRAW_ALL;
  67. if ( flags & STUDIO_TWOPASS )
  68. {
  69. mode = ( flags & STUDIO_TRANSPARENCY ) ? DBM_DRAW_TRANSLUCENT_ONLY : DBM_DRAW_OPAQUE_ONLY;
  70. }
  71. render->DrawBrushModelEx(
  72. this,
  73. (model_t *)GetModel(),
  74. GetAbsOrigin(),
  75. GetAbsAngles(),
  76. mode );
  77. // Draw the optional foreground model next.
  78. // Only use the alpha in the texture from the thing in the front.
  79. if (m_iBackgroundModelIndex >= 0)
  80. {
  81. render->SetBlend( 1 );
  82. model_t *pBackground = ( model_t * )modelinfo->GetModel( m_iBackgroundModelIndex );
  83. if( pBackground && modelinfo->GetModelType( pBackground ) == mod_brush )
  84. {
  85. render->DrawBrushModelEx(
  86. this,
  87. pBackground,
  88. GetAbsOrigin(),
  89. GetAbsAngles(),
  90. mode );
  91. }
  92. }
  93. return 1;
  94. }
  95. float C_FuncAreaPortalWindow::GetDistanceBlend()
  96. {
  97. // Get the viewer's distance to us.
  98. float flDist = CollisionProp()->CalcDistanceFromPoint( CurrentViewOrigin() );
  99. C_BasePlayer *local = C_BasePlayer::GetLocalPlayer();
  100. if ( local )
  101. {
  102. flDist *= local->GetFOVDistanceAdjustFactor();
  103. }
  104. return RemapValClamped( flDist, m_flFadeStartDist, m_flFadeDist, m_flTranslucencyLimit, 1 );
  105. }
  106. bool C_FuncAreaPortalWindow::ShouldReceiveProjectedTextures( int flags )
  107. {
  108. return false;
  109. }