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 /game/client/tf2/ObjectBuildAlphaProxy.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/client/tf2/ObjectBuildAlphaProxy.cpp')
| -rw-r--r-- | game/client/tf2/ObjectBuildAlphaProxy.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/game/client/tf2/ObjectBuildAlphaProxy.cpp b/game/client/tf2/ObjectBuildAlphaProxy.cpp new file mode 100644 index 0000000..a25add8 --- /dev/null +++ b/game/client/tf2/ObjectBuildAlphaProxy.cpp @@ -0,0 +1,117 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// +#include "cbase.h" +#include "proxyentity.h" +#include "materialsystem/imaterial.h" +#include "materialsystem/imaterialvar.h" +#include "c_baseobject.h" +#include <KeyValues.h> + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +class CObjectBuildAlphaProxy : public CEntityMaterialProxy +{ +public: + CObjectBuildAlphaProxy(); + virtual ~CObjectBuildAlphaProxy(); + virtual bool Init( IMaterial *pMaterial, KeyValues* pKeyValues ); + virtual void OnBind( C_BaseEntity *pC_BaseEntity ); + +private: + IMaterialVar* m_pAlphaVar; + + float buildstart; + float buildend; +}; + + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- + +CObjectBuildAlphaProxy::CObjectBuildAlphaProxy() +{ + m_pAlphaVar = 0; +} + +CObjectBuildAlphaProxy::~CObjectBuildAlphaProxy() +{ +} + +//----------------------------------------------------------------------------- +// Init baby... +//----------------------------------------------------------------------------- +bool CObjectBuildAlphaProxy::Init( IMaterial *pMaterial, KeyValues* pKeyValues ) +{ + + bool foundVar; + m_pAlphaVar = pMaterial->FindVar( "$alpha", &foundVar, false ); + if( !foundVar ) + { + m_pAlphaVar = 0; + } + + buildstart = pKeyValues->GetFloat( "buildstart", 1.0f ); + buildend = pKeyValues->GetFloat( "buildfinish", 1.0f ); + + return true; +} + + +//----------------------------------------------------------------------------- +// Set the appropriate texture... +//----------------------------------------------------------------------------- +void CObjectBuildAlphaProxy::OnBind( C_BaseEntity *pEntity ) +{ + if( !m_pAlphaVar ) + return; + + // It needs to be a TF2 C_BaseObject to have this proxy applied + C_BaseObject *pObject = dynamic_cast< C_BaseObject * >( pEntity ); + if ( !pObject ) + return; + + float build_amount = pObject->GetCycle(); //pObject->GetPercentageConstructed(); + float frac; + + if ( build_amount <= buildstart ) + { + frac = 0.0f; + } + else if ( build_amount >= buildend ) + { + frac = 1.0f; + } + else + { + // Avoid div by zero + if ( buildend == buildstart ) + { + frac = 1.0f; + } + else + { + frac = ( build_amount - buildstart ) / ( buildend - buildstart ); + frac = clamp( frac, 0.0f, 1.0f ); + } + } + + if ( !pObject->IsBuilding() ) + { + frac = 1.0f; + } + + m_pAlphaVar->SetFloatValue( frac ); +} + +EXPOSE_INTERFACE( CObjectBuildAlphaProxy, IMaterialProxy, "TFObjectBuildAlpha" IMATERIAL_PROXY_INTERFACE_VERSION ); + + |