diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /engine/materialproxyfactory.cpp | |
| download | archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip | |
Diffstat (limited to 'engine/materialproxyfactory.cpp')
| -rw-r--r-- | engine/materialproxyfactory.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/engine/materialproxyfactory.cpp b/engine/materialproxyfactory.cpp new file mode 100644 index 0000000..e493619 --- /dev/null +++ b/engine/materialproxyfactory.cpp @@ -0,0 +1,71 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include <stdlib.h> +#include <malloc.h> +#include <string.h> +#include "materialsystem/imaterialproxy.h" +#include "materialproxyfactory.h" +#include "toolframework/itoolframework.h" +#include "toolframework/itoolsystem.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" +extern CSysModule *g_ClientDLLModule; + +IMaterialProxy *CMaterialProxyFactory::CreateProxy( const char *proxyName ) +{ +#if !defined(SWDS) + IMaterialProxy *materialProxy = LookupProxy( proxyName, Sys_GetFactory( g_ClientDLLModule ) ); + + // If the client didn't have it and we're in tool mode, ask the tools... + if ( toolframework->InToolMode() && !materialProxy ) + { + materialProxy = toolframework->LookupProxy( proxyName ); + } + + if( !materialProxy ) + { + ConDMsg( "Can't find material proxy \"%s\"\n", proxyName ); + return NULL; + } + return materialProxy; +#else + return NULL; +#endif +} + +void CMaterialProxyFactory::DeleteProxy( IMaterialProxy *pProxy ) +{ + // how do you delete something generated by an interface.h factory? + if( pProxy ) + { + pProxy->Release(); + } +} + + +//----------------------------------------------------------------------------- +// Look up proxy +//----------------------------------------------------------------------------- +IMaterialProxy *CMaterialProxyFactory::LookupProxy( const char *proxyName, CreateInterfaceFn factory ) +{ + if( !factory ) + return NULL; + + // allocate exactly enough memory for the versioned name on the stack. + char *proxyVersionedName; + int buflen = Q_strlen( proxyName ) + Q_strlen( IMATERIAL_PROXY_INTERFACE_VERSION ) + 1; + + proxyVersionedName = ( char * )_alloca( buflen ); + Q_strncpy( proxyVersionedName, proxyName, buflen ); + Q_strncat( proxyVersionedName, IMATERIAL_PROXY_INTERFACE_VERSION, buflen, COPY_ALL_CHARACTERS ); + return ( IMaterialProxy * )factory( proxyVersionedName, NULL ); +} + + + |