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.

148 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A base class for all material proxies in the client dll
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. // identifier was truncated to '255' characters in the debug information
  9. //#pragma warning(disable: 4786)
  10. #include "proxyentity.h"
  11. #include "materialsystem/imaterialvar.h"
  12. class CEntityOriginMaterialProxy : public CEntityMaterialProxy
  13. {
  14. public:
  15. CEntityOriginMaterialProxy()
  16. {
  17. m_pMaterial = NULL;
  18. m_pOriginVar = NULL;
  19. }
  20. virtual ~CEntityOriginMaterialProxy()
  21. {
  22. }
  23. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  24. {
  25. m_pMaterial = pMaterial;
  26. bool found;
  27. m_pOriginVar = m_pMaterial->FindVar( "$entityorigin", &found );
  28. if( !found )
  29. {
  30. m_pOriginVar = NULL;
  31. return false;
  32. }
  33. return true;
  34. }
  35. virtual void OnBind( C_BaseEntity *pC_BaseEntity )
  36. {
  37. const Vector &origin = pC_BaseEntity->GetAbsOrigin();
  38. m_pOriginVar->SetVecValue( origin.x, origin.y, origin.z );
  39. }
  40. virtual IMaterial *GetMaterial()
  41. {
  42. return m_pMaterial;
  43. }
  44. protected:
  45. IMaterial *m_pMaterial;
  46. IMaterialVar *m_pOriginVar;
  47. };
  48. EXPOSE_INTERFACE( CEntityOriginMaterialProxy, IMaterialProxy, "EntityOrigin" IMATERIAL_PROXY_INTERFACE_VERSION );
  49. //=================================================================================================================
  50. // This is a last-minute hack to ship Orange Box on the 360!
  51. //=================================================================================================================
  52. class CEntityOriginAlyxMaterialProxy : public CEntityMaterialProxy
  53. {
  54. public:
  55. CEntityOriginAlyxMaterialProxy()
  56. {
  57. m_pMaterial = NULL;
  58. m_pOriginVar = NULL;
  59. }
  60. virtual ~CEntityOriginAlyxMaterialProxy()
  61. {
  62. }
  63. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  64. {
  65. m_pMaterial = pMaterial;
  66. bool found;
  67. m_pOriginVar = m_pMaterial->FindVar( "$entityorigin", &found );
  68. if( !found )
  69. {
  70. m_pOriginVar = NULL;
  71. return false;
  72. }
  73. return true;
  74. }
  75. virtual void OnBind( C_BaseEntity *pC_BaseEntity )
  76. {
  77. const Vector &origin = pC_BaseEntity->GetAbsOrigin();
  78. m_pOriginVar->SetVecValue( origin.x - 15.0f, origin.y, origin.z );
  79. }
  80. virtual IMaterial *GetMaterial()
  81. {
  82. return m_pMaterial;
  83. }
  84. protected:
  85. IMaterial *m_pMaterial;
  86. IMaterialVar *m_pOriginVar;
  87. };
  88. EXPOSE_INTERFACE( CEntityOriginAlyxMaterialProxy, IMaterialProxy, "EntityOriginAlyx" IMATERIAL_PROXY_INTERFACE_VERSION );
  89. //=================================================================================================================
  90. // This is a last-minute hack to ship Orange Box on the 360!
  91. //=================================================================================================================
  92. class CEp1IntroVortRefractMaterialProxy : public CEntityMaterialProxy
  93. {
  94. public:
  95. CEp1IntroVortRefractMaterialProxy()
  96. {
  97. m_pMaterial = NULL;
  98. m_pOriginVar = NULL;
  99. }
  100. virtual ~CEp1IntroVortRefractMaterialProxy()
  101. {
  102. }
  103. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  104. {
  105. m_pMaterial = pMaterial;
  106. bool found;
  107. m_pOriginVar = m_pMaterial->FindVar( "$refractamount", &found );
  108. if( !found )
  109. {
  110. m_pOriginVar = NULL;
  111. return false;
  112. }
  113. return true;
  114. }
  115. virtual void OnBind( C_BaseEntity *pC_BaseEntity )
  116. {
  117. if ( m_pOriginVar != NULL)
  118. {
  119. float flTmp = ( 1.0f - m_pOriginVar->GetFloatValue() );
  120. flTmp *= flTmp;
  121. flTmp *= flTmp;
  122. flTmp = ( 1.0f - flTmp ) * 0.25f;
  123. m_pOriginVar->SetFloatValue( flTmp );
  124. }
  125. }
  126. virtual IMaterial *GetMaterial()
  127. {
  128. return m_pMaterial;
  129. }
  130. protected:
  131. IMaterial *m_pMaterial;
  132. IMaterialVar *m_pOriginVar;
  133. };
  134. EXPOSE_INTERFACE( CEp1IntroVortRefractMaterialProxy, IMaterialProxy, "Ep1IntroVortRefract" IMATERIAL_PROXY_INTERFACE_VERSION );