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.

78 lines
1.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "materialsystem/imaterialproxy.h"
  8. #include "materialsystem/imaterial.h"
  9. #include "materialsystem/imaterialvar.h"
  10. #include "c_world.h"
  11. #include "toolframework_client.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. // forward declarations
  15. void ToolFramework_RecordMaterialParams( IMaterial *pMaterial );
  16. class CWorldDimsProxy : public IMaterialProxy
  17. {
  18. public:
  19. CWorldDimsProxy();
  20. virtual ~CWorldDimsProxy();
  21. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  22. virtual void OnBind( void *pC_BaseEntity );
  23. virtual void Release( void ) { delete this; }
  24. virtual IMaterial *GetMaterial();
  25. public:
  26. IMaterialVar *m_pMinsVar;
  27. IMaterialVar *m_pMaxsVar;
  28. };
  29. CWorldDimsProxy::CWorldDimsProxy()
  30. {
  31. m_pMinsVar = m_pMaxsVar = NULL;
  32. }
  33. CWorldDimsProxy::~CWorldDimsProxy()
  34. {
  35. }
  36. bool CWorldDimsProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  37. {
  38. m_pMinsVar = pMaterial->FindVar( "$world_mins", NULL, false );
  39. m_pMaxsVar = pMaterial->FindVar( "$world_maxs", NULL, false );
  40. return true;
  41. }
  42. void CWorldDimsProxy::OnBind( void *pC_BaseEntity )
  43. {
  44. if ( m_pMinsVar && m_pMaxsVar )
  45. {
  46. C_World *pWorld = GetClientWorldEntity();
  47. if ( pWorld )
  48. {
  49. m_pMinsVar->SetVecValue( (const float*)&pWorld->m_WorldMins, 3 );
  50. m_pMaxsVar->SetVecValue( (const float*)&pWorld->m_WorldMaxs, 3 );
  51. }
  52. }
  53. if ( ToolsEnabled() )
  54. {
  55. ToolFramework_RecordMaterialParams( GetMaterial() );
  56. }
  57. }
  58. IMaterial *CWorldDimsProxy::GetMaterial()
  59. {
  60. return m_pMinsVar->GetOwningMaterial();
  61. }
  62. EXPOSE_INTERFACE( CWorldDimsProxy, IMaterialProxy, "WorldDims" IMATERIAL_PROXY_INTERFACE_VERSION );