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.

71 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <string.h>
  10. #include "materialsystem/imaterialproxy.h"
  11. #include "materialproxyfactory.h"
  12. #include "toolframework/itoolframework.h"
  13. #include "toolframework/itoolsystem.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. extern CSysModule *g_ClientDLLModule;
  17. IMaterialProxy *CMaterialProxyFactory::CreateProxy( const char *proxyName )
  18. {
  19. #if !defined(SWDS)
  20. IMaterialProxy *materialProxy = LookupProxy( proxyName, Sys_GetFactory( g_ClientDLLModule ) );
  21. // If the client didn't have it and we're in tool mode, ask the tools...
  22. if ( toolframework->InToolMode() && !materialProxy )
  23. {
  24. materialProxy = toolframework->LookupProxy( proxyName );
  25. }
  26. if( !materialProxy )
  27. {
  28. ConDMsg( "Can't find material proxy \"%s\"\n", proxyName );
  29. return NULL;
  30. }
  31. return materialProxy;
  32. #else
  33. return NULL;
  34. #endif
  35. }
  36. void CMaterialProxyFactory::DeleteProxy( IMaterialProxy *pProxy )
  37. {
  38. // how do you delete something generated by an interface.h factory?
  39. if( pProxy )
  40. {
  41. pProxy->Release();
  42. }
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Look up proxy
  46. //-----------------------------------------------------------------------------
  47. IMaterialProxy *CMaterialProxyFactory::LookupProxy( const char *proxyName, CreateInterfaceFn factory )
  48. {
  49. if( !factory )
  50. return NULL;
  51. // allocate exactly enough memory for the versioned name on the stack.
  52. char *proxyVersionedName;
  53. int buflen = Q_strlen( proxyName ) + Q_strlen( IMATERIAL_PROXY_INTERFACE_VERSION ) + 1;
  54. proxyVersionedName = ( char * )_alloca( buflen );
  55. Q_strncpy( proxyVersionedName, proxyName, buflen );
  56. Q_strncat( proxyVersionedName, IMATERIAL_PROXY_INTERFACE_VERSION, buflen, COPY_ALL_CHARACTERS );
  57. return ( IMaterialProxy * )factory( proxyVersionedName, NULL );
  58. }