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.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "materialsystem/imaterialproxy.h"
  9. #include "materialsystem/imaterialvar.h"
  10. #include "materialsystem/imaterial.h"
  11. #include "portalrenderable_flatbasic.h"
  12. #include "c_prop_portal.h"
  13. #include "toolframework_client.h"
  14. #include <KeyValues.h>
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. class CPortalStaticProxy : public IMaterialProxy
  18. {
  19. protected:
  20. IMaterialVar *m_StaticOutput;
  21. public:
  22. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  23. virtual void OnBind( void *pBind );
  24. virtual void Release( void ) { delete this; }
  25. virtual IMaterial * GetMaterial() { return ( m_StaticOutput ) ? m_StaticOutput->GetOwningMaterial() : NULL; }
  26. float ComputeStaticAmount( CPortalRenderable_FlatBasic *pPortal );
  27. };
  28. bool CPortalStaticProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  29. {
  30. char const* pszResultVar = pKeyValues->GetString( "resultVar" );
  31. if( !pszResultVar )
  32. return false;
  33. bool foundVar;
  34. m_StaticOutput = pMaterial->FindVar( pszResultVar, &foundVar, false );
  35. if( !foundVar )
  36. return false;
  37. return true;
  38. }
  39. float CPortalStaticProxy::ComputeStaticAmount( CPortalRenderable_FlatBasic *pFlatBasic )
  40. {
  41. float flStaticAmount = pFlatBasic->m_fStaticAmount;
  42. if ( !pFlatBasic->GetLinkedPortal() )
  43. {
  44. flStaticAmount = 1.0f;
  45. }
  46. if ( pFlatBasic->WillUseDepthDoublerThisDraw() )
  47. {
  48. flStaticAmount = 0.0f;
  49. }
  50. else if ( g_pPortalRender->GetRemainingPortalViewDepth() == 0 ) //end of the line, no more views
  51. {
  52. flStaticAmount = 1.0f;
  53. }
  54. else if ( (g_pPortalRender->GetRemainingPortalViewDepth() == 1) && (pFlatBasic->m_fSecondaryStaticAmount > flStaticAmount) ) //fading in from no views to another view (player just walked through it)
  55. {
  56. flStaticAmount = pFlatBasic->m_fSecondaryStaticAmount;
  57. }
  58. return flStaticAmount;
  59. }
  60. void CPortalStaticProxy::OnBind( void *pBind )
  61. {
  62. if ( pBind == NULL )
  63. return;
  64. float flStaticAmount;
  65. IClientRenderable *pRenderable = (IClientRenderable*)pBind;
  66. CPortalRenderable *pRecordedPortal = g_pPortalRender->FindRecordedPortal( pRenderable );
  67. if ( pRecordedPortal )
  68. {
  69. CPortalRenderable_FlatBasic *pRecordedFlatBasic = dynamic_cast<CPortalRenderable_FlatBasic *>(pRecordedPortal);
  70. if ( !pRecordedFlatBasic )
  71. return;
  72. flStaticAmount = ComputeStaticAmount( pRecordedFlatBasic );
  73. }
  74. else
  75. {
  76. CPortalRenderable_FlatBasic *pFlatBasic = dynamic_cast<CPortalRenderable_FlatBasic*>( pRenderable );
  77. if ( !pFlatBasic )
  78. return;
  79. flStaticAmount = ComputeStaticAmount( pFlatBasic );
  80. }
  81. m_StaticOutput->SetFloatValue( flStaticAmount );
  82. if ( ToolsEnabled() )
  83. {
  84. ToolFramework_RecordMaterialParams( GetMaterial() );
  85. }
  86. }
  87. EXPOSE_INTERFACE( CPortalStaticProxy, IMaterialProxy, "PortalStaticModel" IMATERIAL_PROXY_INTERFACE_VERSION );
  88. class CPortalStaticPortalProxy : public CPortalStaticProxy
  89. {
  90. public:
  91. virtual void OnBind( void *pBind );
  92. };
  93. void CPortalStaticPortalProxy::OnBind( void *pBind )
  94. {
  95. if ( pBind == NULL )
  96. return;
  97. IClientRenderable *pRenderable = (IClientRenderable*)( pBind );
  98. C_Prop_Portal *pPortal = (C_Prop_Portal *)pRenderable;
  99. float flStaticAmount = ComputeStaticAmount( pPortal );
  100. m_StaticOutput->SetFloatValue( flStaticAmount );
  101. }
  102. EXPOSE_INTERFACE( CPortalStaticPortalProxy, IMaterialProxy, "PortalStatic" IMATERIAL_PROXY_INTERFACE_VERSION );
  103. class CPortalOpenAmountProxy : public CPortalStaticProxy
  104. {
  105. public:
  106. virtual void OnBind( void *pBind );
  107. };
  108. void CPortalOpenAmountProxy::OnBind( void *pBind )
  109. {
  110. if ( pBind == NULL )
  111. return;
  112. IClientRenderable *pRenderable = (IClientRenderable*)( pBind );
  113. C_Prop_Portal *pPortal = (C_Prop_Portal *)pRenderable;
  114. m_StaticOutput->SetFloatValue( pPortal->m_fOpenAmount );
  115. }
  116. EXPOSE_INTERFACE( CPortalOpenAmountProxy, IMaterialProxy, "PortalOpenAmount" IMATERIAL_PROXY_INTERFACE_VERSION );