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.

122 lines
3.2 KiB

  1. //===== Copyright � 1996-2005, 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 <KeyValues.h>
  14. #include "imaterialproxydict.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. };
  27. bool CPortalStaticProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  28. {
  29. char const* pszResultVar = pKeyValues->GetString( "resultVar" );
  30. if( !pszResultVar )
  31. return false;
  32. bool foundVar;
  33. m_StaticOutput = pMaterial->FindVar( pszResultVar, &foundVar, false );
  34. if( !foundVar )
  35. return false;
  36. if ( !Q_stricmp( pszResultVar, "$alpha" ) )
  37. {
  38. pMaterial->SetMaterialVarFlag( MATERIAL_VAR_ALPHA_MODIFIED_BY_PROXY, true );
  39. }
  40. return true;
  41. }
  42. void CPortalStaticProxy::OnBind( void *pBind )
  43. {
  44. if ( pBind == NULL )
  45. return;
  46. float flStaticAmount;
  47. IClientRenderable *pRenderable = (IClientRenderable*)pBind;
  48. CPortalRenderable *pRecordedPortal = g_pPortalRender->FindRecordedPortal( pRenderable );
  49. if ( pRecordedPortal )
  50. {
  51. C_Prop_Portal *pRecordedFlatBasic = dynamic_cast<C_Prop_Portal *>(pRecordedPortal);
  52. if ( !pRecordedFlatBasic )
  53. return;
  54. flStaticAmount = pRecordedFlatBasic->ComputeStaticAmountForRendering();
  55. }
  56. else
  57. {
  58. C_Prop_Portal *pFlatBasic = dynamic_cast<C_Prop_Portal*>( pRenderable );
  59. if ( !pFlatBasic )
  60. return;
  61. flStaticAmount = pFlatBasic->ComputeStaticAmountForRendering();
  62. }
  63. m_StaticOutput->SetFloatValue( flStaticAmount );
  64. }
  65. EXPOSE_MATERIAL_PROXY( CPortalStaticProxy, PortalStaticModel );
  66. class CPortalStaticPortalProxy : public CPortalStaticProxy
  67. {
  68. public:
  69. virtual void OnBind( void *pBind );
  70. };
  71. void CPortalStaticPortalProxy::OnBind( void *pBind )
  72. {
  73. if ( pBind == NULL )
  74. return;
  75. IClientRenderable *pRenderable = (IClientRenderable*)( pBind );
  76. C_Prop_Portal *pPortal = (C_Prop_Portal *)pRenderable;
  77. float flStaticAmount = pPortal->ComputeStaticAmountForRendering();
  78. m_StaticOutput->SetFloatValue( flStaticAmount );
  79. }
  80. EXPOSE_MATERIAL_PROXY( CPortalStaticPortalProxy, PortalStatic );
  81. class CPortalOpenAmountProxy : public CPortalStaticProxy
  82. {
  83. public:
  84. virtual void OnBind( void *pBind );
  85. };
  86. void CPortalOpenAmountProxy::OnBind( void *pBind )
  87. {
  88. if ( pBind == NULL )
  89. return;
  90. IClientRenderable *pRenderable = (IClientRenderable*)( pBind );
  91. C_Prop_Portal *pPortal = (C_Prop_Portal *)pRenderable;
  92. m_StaticOutput->SetFloatValue( pPortal->m_fOpenAmount );
  93. }
  94. EXPOSE_MATERIAL_PROXY( CPortalOpenAmountProxy, PortalOpenAmount );