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.

46 lines
1.4 KiB

  1. //====== Copyright � 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "imaterialproxydict.h"
  8. #include "materialsystem/imaterialproxy.h"
  9. #include "tier1/UtlStringMap.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. class CMaterialProxyDict : public IMaterialProxyDict
  13. {
  14. public:
  15. IMaterialProxy * CreateProxy( const char *proxyName );
  16. void Add( const char *pMaterialProxyName, MaterialProxyFactory_t *pMaterialProxyFactory );
  17. private:
  18. CUtlStringMap<MaterialProxyFactory_t *> m_StringToProxyFactoryMap;
  19. };
  20. void CMaterialProxyDict::Add( const char *pMaterialProxyName, MaterialProxyFactory_t *pMaterialProxyFactory )
  21. {
  22. Assert( pMaterialProxyName );
  23. m_StringToProxyFactoryMap[pMaterialProxyName] = pMaterialProxyFactory;
  24. }
  25. IMaterialProxyDict &GetMaterialProxyDict()
  26. {
  27. static CMaterialProxyDict g_MaterialProxyDict;
  28. return g_MaterialProxyDict;
  29. }
  30. IMaterialProxy *CMaterialProxyDict::CreateProxy( const char *pMaterialProxyName )
  31. {
  32. UtlSymId_t sym = m_StringToProxyFactoryMap.Find( pMaterialProxyName );
  33. if ( sym == m_StringToProxyFactoryMap.InvalidIndex() )
  34. {
  35. return NULL;
  36. }
  37. MaterialProxyFactory_t *pMaterialProxyFactory = m_StringToProxyFactoryMap[sym];
  38. Assert( pMaterialProxyFactory );
  39. return (*pMaterialProxyFactory)();
  40. }