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.

113 lines
3.0 KiB

  1. //========= Copyright 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. };
  23. CMaterialProxyFactory g_MaterialProxyFactory;
  24. IMaterialProxy *CMaterialProxyFactory::CreateProxy( const char *proxyName )
  25. {
  26. // assumes that the client.dll is already LoadLibraried
  27. CreateInterfaceFn clientFactory = Sys_GetFactoryThis();
  28. // allocate exactly enough memory for the versioned name on the stack.
  29. char proxyVersionedName[512];
  30. Q_snprintf( proxyVersionedName, sizeof( proxyVersionedName ), "%s%s", proxyName, IMATERIAL_PROXY_INTERFACE_VERSION );
  31. return ( IMaterialProxy * )clientFactory( proxyVersionedName, NULL );
  32. }
  33. void CMaterialProxyFactory::DeleteProxy( IMaterialProxy *pProxy )
  34. {
  35. if ( pProxy )
  36. {
  37. pProxy->Release();
  38. }
  39. }
  40. IMaterialProxyFactory* GetHammerMaterialProxyFactory()
  41. {
  42. return &g_MaterialProxyFactory;
  43. }
  44. // ------------------------------------------------------------------------------------- //
  45. // Specific material proxies.
  46. // ------------------------------------------------------------------------------------- //
  47. class CWorldDimsProxy : public IMaterialProxy
  48. {
  49. public:
  50. CWorldDimsProxy();
  51. virtual ~CWorldDimsProxy();
  52. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  53. virtual void OnBind( void *pC_BaseEntity );
  54. virtual void Release( void ) { delete this; }
  55. virtual IMaterial *GetMaterial();
  56. public:
  57. IMaterialVar *m_pMinsVar;
  58. IMaterialVar *m_pMaxsVar;
  59. };
  60. CWorldDimsProxy::CWorldDimsProxy()
  61. {
  62. m_pMinsVar = m_pMaxsVar = NULL;
  63. }
  64. CWorldDimsProxy::~CWorldDimsProxy()
  65. {
  66. }
  67. bool CWorldDimsProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  68. {
  69. m_pMinsVar = pMaterial->FindVar( "$world_mins", NULL, false );
  70. m_pMaxsVar = pMaterial->FindVar( "$world_maxs", NULL, false );
  71. return true;
  72. }
  73. void CWorldDimsProxy::OnBind( void *pC_BaseEntity )
  74. {
  75. if ( m_pMinsVar && m_pMaxsVar )
  76. {
  77. float mins[3] = {-500,-500,-500};
  78. float maxs[3] = {+500,+500,+500};
  79. m_pMinsVar->SetVecValue( (const float*)mins, 3 );
  80. m_pMaxsVar->SetVecValue( (const float*)maxs, 3 );
  81. }
  82. }
  83. IMaterial *CWorldDimsProxy::GetMaterial()
  84. {
  85. if ( m_pMinsVar && m_pMaxsVar )
  86. return m_pMinsVar->GetOwningMaterial();
  87. return NULL;
  88. }
  89. EXPOSE_INTERFACE( CWorldDimsProxy, IMaterialProxy, "WorldDims" IMATERIAL_PROXY_INTERFACE_VERSION );