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.

118 lines
3.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "stdafx.h"
  7. #include "tier1/strtools.h"
  8. #include "materialsystem/IMaterialProxy.h"
  9. #include "materialsystem/IMaterialProxyFactory.h"
  10. #include "materialsystem/IMaterialVar.h"
  11. #include "materialsystem/IMaterial.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include <tier0/memdbgon.h>
  14. // ------------------------------------------------------------------------------------- //
  15. // The material proxy factory for WC.
  16. // ------------------------------------------------------------------------------------- //
  17. class CMaterialProxyFactory : public IMaterialProxyFactory
  18. {
  19. public:
  20. IMaterialProxy *CreateProxy( const char *proxyName );
  21. void DeleteProxy( IMaterialProxy *pProxy );
  22. CreateInterfaceFn GetFactory();
  23. };
  24. CMaterialProxyFactory g_MaterialProxyFactory;
  25. IMaterialProxy *CMaterialProxyFactory::CreateProxy( const char *proxyName )
  26. {
  27. // assumes that the client.dll is already LoadLibraried
  28. CreateInterfaceFn clientFactory = Sys_GetFactoryThis();
  29. // allocate exactly enough memory for the versioned name on the stack.
  30. char proxyVersionedName[512];
  31. Q_snprintf( proxyVersionedName, sizeof( proxyVersionedName ), "%s%s", proxyName, IMATERIAL_PROXY_INTERFACE_VERSION );
  32. return ( IMaterialProxy * )clientFactory( proxyVersionedName, NULL );
  33. }
  34. void CMaterialProxyFactory::DeleteProxy( IMaterialProxy *pProxy )
  35. {
  36. if ( pProxy )
  37. {
  38. pProxy->Release();
  39. }
  40. }
  41. CreateInterfaceFn CMaterialProxyFactory::GetFactory()
  42. {
  43. return Sys_GetFactoryThis();
  44. }
  45. IMaterialProxyFactory* GetHammerMaterialProxyFactory()
  46. {
  47. return &g_MaterialProxyFactory;
  48. }
  49. // ------------------------------------------------------------------------------------- //
  50. // Specific material proxies.
  51. // ------------------------------------------------------------------------------------- //
  52. class CWorldDimsProxy : public IMaterialProxy
  53. {
  54. public:
  55. CWorldDimsProxy();
  56. virtual ~CWorldDimsProxy();
  57. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  58. virtual void OnBind( void *pC_BaseEntity );
  59. virtual void Release( void ) { delete this; }
  60. virtual IMaterial *GetMaterial();
  61. public:
  62. IMaterialVar *m_pMinsVar;
  63. IMaterialVar *m_pMaxsVar;
  64. };
  65. CWorldDimsProxy::CWorldDimsProxy()
  66. {
  67. m_pMinsVar = m_pMaxsVar = NULL;
  68. }
  69. CWorldDimsProxy::~CWorldDimsProxy()
  70. {
  71. }
  72. bool CWorldDimsProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  73. {
  74. m_pMinsVar = pMaterial->FindVar( "$world_mins", NULL, false );
  75. m_pMaxsVar = pMaterial->FindVar( "$world_maxs", NULL, false );
  76. return true;
  77. }
  78. void CWorldDimsProxy::OnBind( void *pC_BaseEntity )
  79. {
  80. if ( m_pMinsVar && m_pMaxsVar )
  81. {
  82. float mins[3] = {-500,-500,-500};
  83. float maxs[3] = {+500,+500,+500};
  84. m_pMinsVar->SetVecValue( (const float*)mins, 3 );
  85. m_pMaxsVar->SetVecValue( (const float*)maxs, 3 );
  86. }
  87. }
  88. IMaterial *CWorldDimsProxy::GetMaterial()
  89. {
  90. if ( m_pMinsVar && m_pMaxsVar )
  91. return m_pMinsVar->GetOwningMaterial();
  92. return NULL;
  93. }
  94. EXPOSE_INTERFACE( CWorldDimsProxy, IMaterialProxy, "WorldDims" IMATERIAL_PROXY_INTERFACE_VERSION );