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.

260 lines
6.5 KiB

  1. //========= Copyright � 1996-2006, 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. #include "imaterialproxydict.h"
  13. // NOTE: This has to be the last file included!
  14. #include "tier0/memdbgon.h"
  15. #include "c_cs_player.h" // for grenades
  16. class CEntityOriginMaterialProxy : public CEntityMaterialProxy
  17. {
  18. public:
  19. CEntityOriginMaterialProxy()
  20. {
  21. m_pMaterial = NULL;
  22. m_pOriginVar = NULL;
  23. }
  24. virtual ~CEntityOriginMaterialProxy()
  25. {
  26. }
  27. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  28. {
  29. m_pMaterial = pMaterial;
  30. bool found;
  31. m_pOriginVar = m_pMaterial->FindVar( "$entityorigin", &found );
  32. if( !found )
  33. {
  34. m_pOriginVar = NULL;
  35. return false;
  36. }
  37. return true;
  38. }
  39. virtual void OnBind( C_BaseEntity *pC_BaseEntity )
  40. {
  41. const Vector &origin = pC_BaseEntity->GetAbsOrigin();
  42. m_pOriginVar->SetVecValue( origin.x, origin.y, origin.z );
  43. }
  44. virtual IMaterial *GetMaterial()
  45. {
  46. return m_pMaterial;
  47. }
  48. protected:
  49. IMaterial *m_pMaterial;
  50. IMaterialVar *m_pOriginVar;
  51. };
  52. EXPOSE_MATERIAL_PROXY( CEntityOriginMaterialProxy, EntityOrigin );
  53. /*
  54. extern CUtlVector<EHANDLE> g_SmokeGrenadeHandles;
  55. #define SMOKE_PROXY_RADIUS_SQUARED 30000 //approx smoke radius ^2
  56. ConVar cl_debug_smoke_proxy( "cl_debug_smoke_proxy", "0", FCVAR_CHEAT );
  57. class CSmokeOriginMaterialProxy : public CEntityMaterialProxy
  58. {
  59. public:
  60. CSmokeOriginMaterialProxy()
  61. {
  62. m_pMaterial = NULL;
  63. m_pOriginVar = NULL;
  64. }
  65. virtual ~CSmokeOriginMaterialProxy()
  66. {
  67. }
  68. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  69. {
  70. m_pMaterial = pMaterial;
  71. bool found;
  72. m_pOriginVar = m_pMaterial->FindVar( "$BlendWithSmokeGrenadePosEntity", &found );
  73. if( !found )
  74. {
  75. m_pOriginVar = NULL;
  76. return false;
  77. }
  78. m_pSmokeOriginVar = m_pMaterial->FindVar( "$BlendWithSmokeGrenadePosSmoke", &found );
  79. if( !found )
  80. {
  81. m_pSmokeOriginVar = NULL;
  82. return false;
  83. }
  84. return true;
  85. }
  86. virtual void OnBind( C_BaseEntity *pC_BaseEntity )
  87. {
  88. if ( !g_SmokeGrenadeHandles.Count() )
  89. {
  90. m_pSmokeOriginVar->SetVecValue( 0, 0, 0 );
  91. return;
  92. }
  93. C_BaseAnimating *pBaseAnimating = pC_BaseEntity ? pC_BaseEntity->GetBaseAnimating() : NULL;
  94. if ( pBaseAnimating )
  95. {
  96. CStudioHdr *pHdr = pBaseAnimating->GetModelPtr();
  97. if ( pHdr )
  98. {
  99. matrix3x4_t matTemp;
  100. AngleMatrix( pC_BaseEntity->GetAbsAngles(), matTemp );
  101. Vector vecWorldRelativeIllumPos;
  102. VectorRotate( pHdr->illumposition(), matTemp, vecWorldRelativeIllumPos );
  103. Vector origin = pC_BaseEntity->GetAbsOrigin() + vecWorldRelativeIllumPos;
  104. m_pOriginVar->SetVecValue( origin.x, origin.y, origin.z );
  105. Vector vecClosestGrenadePos;
  106. vecClosestGrenadePos.Init();
  107. //find closest smoke grenade
  108. float flClosestDist = SMOKE_PROXY_RADIUS_SQUARED;
  109. for ( int i = 0; i < g_SmokeGrenadeHandles.Count(); i++ )
  110. {
  111. CBaseCSGrenadeProjectile *pGrenade = static_cast< CBaseCSGrenadeProjectile* >( g_SmokeGrenadeHandles[i].Get() );
  112. if ( !pGrenade )
  113. continue;
  114. float flTemp = pGrenade->GetAbsOrigin().DistToSqr( origin - Vector(0,0,69) );
  115. if ( flTemp < flClosestDist )
  116. {
  117. flClosestDist = flTemp;
  118. vecClosestGrenadePos = pGrenade->GetAbsOrigin() + Vector(0,0,69);
  119. }
  120. }
  121. m_pSmokeOriginVar->SetVecValue( vecClosestGrenadePos.x, vecClosestGrenadePos.y, vecClosestGrenadePos.z );
  122. if ( cl_debug_smoke_proxy.GetBool() )
  123. {
  124. debugoverlay->AddBoxOverlay( origin, Vector(-1,-1,-1), Vector(1,1,1), QAngle(0,0,0), 255,0,0,0, 0 );
  125. if ( flClosestDist < SMOKE_PROXY_RADIUS_SQUARED )
  126. {
  127. debugoverlay->AddLineOverlay( origin, vecClosestGrenadePos, 255,0,0, true, 0 );
  128. }
  129. }
  130. }
  131. }
  132. }
  133. virtual IMaterial *GetMaterial()
  134. {
  135. return m_pMaterial;
  136. }
  137. protected:
  138. IMaterial *m_pMaterial;
  139. IMaterialVar *m_pOriginVar;
  140. IMaterialVar *m_pSmokeOriginVar;
  141. };
  142. EXPOSE_MATERIAL_PROXY( CSmokeOriginMaterialProxy, SmokeOrigin );
  143. */
  144. //=================================================================================================================
  145. // This is a last-minute hack to ship Orange Box on the 360!
  146. //=================================================================================================================
  147. class CEntityOriginAlyxMaterialProxy : public CEntityMaterialProxy
  148. {
  149. public:
  150. CEntityOriginAlyxMaterialProxy()
  151. {
  152. m_pMaterial = NULL;
  153. m_pOriginVar = NULL;
  154. }
  155. virtual ~CEntityOriginAlyxMaterialProxy()
  156. {
  157. }
  158. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  159. {
  160. m_pMaterial = pMaterial;
  161. bool found;
  162. m_pOriginVar = m_pMaterial->FindVar( "$entityorigin", &found );
  163. if( !found )
  164. {
  165. m_pOriginVar = NULL;
  166. return false;
  167. }
  168. return true;
  169. }
  170. virtual void OnBind( C_BaseEntity *pC_BaseEntity )
  171. {
  172. const Vector &origin = pC_BaseEntity->GetAbsOrigin();
  173. m_pOriginVar->SetVecValue( origin.x - 15.0f, origin.y, origin.z );
  174. }
  175. virtual IMaterial *GetMaterial()
  176. {
  177. return m_pMaterial;
  178. }
  179. protected:
  180. IMaterial *m_pMaterial;
  181. IMaterialVar *m_pOriginVar;
  182. };
  183. EXPOSE_MATERIAL_PROXY( CEntityOriginAlyxMaterialProxy, EntityOriginAlyx );
  184. //=================================================================================================================
  185. // This is a last-minute hack to ship Orange Box on the 360!
  186. //=================================================================================================================
  187. class CEp1IntroVortRefractMaterialProxy : public CEntityMaterialProxy
  188. {
  189. public:
  190. CEp1IntroVortRefractMaterialProxy()
  191. {
  192. m_pMaterial = NULL;
  193. m_pOriginVar = NULL;
  194. }
  195. virtual ~CEp1IntroVortRefractMaterialProxy()
  196. {
  197. }
  198. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  199. {
  200. m_pMaterial = pMaterial;
  201. bool found;
  202. m_pOriginVar = m_pMaterial->FindVar( "$refractamount", &found );
  203. if( !found )
  204. {
  205. m_pOriginVar = NULL;
  206. return false;
  207. }
  208. return true;
  209. }
  210. virtual void OnBind( C_BaseEntity *pC_BaseEntity )
  211. {
  212. if ( m_pOriginVar != NULL)
  213. {
  214. float flTmp = ( 1.0f - m_pOriginVar->GetFloatValue() );
  215. flTmp *= flTmp;
  216. flTmp *= flTmp;
  217. flTmp = ( 1.0f - flTmp ) * 0.25f;
  218. m_pOriginVar->SetFloatValue( flTmp );
  219. }
  220. }
  221. virtual IMaterial *GetMaterial()
  222. {
  223. return m_pMaterial;
  224. }
  225. protected:
  226. IMaterial *m_pMaterial;
  227. IMaterialVar *m_pOriginVar;
  228. };
  229. EXPOSE_MATERIAL_PROXY( CEp1IntroVortRefractMaterialProxy, Ep1IntroVortRefract );