summaryrefslogtreecommitdiff
path: root/game/client/hl2/c_basehelicopter.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/hl2/c_basehelicopter.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/client/hl2/c_basehelicopter.cpp')
-rw-r--r--game/client/hl2/c_basehelicopter.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/game/client/hl2/c_basehelicopter.cpp b/game/client/hl2/c_basehelicopter.cpp
new file mode 100644
index 0000000..abc3728
--- /dev/null
+++ b/game/client/hl2/c_basehelicopter.cpp
@@ -0,0 +1,91 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================//
+
+#include "cbase.h"
+#include "c_basehelicopter.h"
+#include "proxyentity.h"
+#include "materialsystem/imaterial.h"
+#include "materialsystem/imaterialvar.h"
+#include "KeyValues.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+IMPLEMENT_CLIENTCLASS_DT( C_BaseHelicopter, DT_BaseHelicopter, CBaseHelicopter )
+ RecvPropTime( RECVINFO( m_flStartupTime ) ),
+END_RECV_TABLE()
+
+
+C_BaseHelicopter::C_BaseHelicopter()
+{
+}
+
+
+//-----------------------------------------------------------------------------
+// Chopper blade fade-in time
+//-----------------------------------------------------------------------------
+#define FADE_IN_TIME 2.0f
+
+
+//-----------------------------------------------------------------------------
+// Sets the fade of the blades when the chopper starts up
+//-----------------------------------------------------------------------------
+class CHeliBladeMaterialProxy : public CEntityMaterialProxy
+{
+public:
+ CHeliBladeMaterialProxy() { m_AlphaVar = NULL; }
+ virtual ~CHeliBladeMaterialProxy() {}
+ virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
+ virtual void OnBind( C_BaseEntity *pEntity );
+ virtual IMaterial *GetMaterial();
+
+private:
+ IMaterialVar *m_AlphaVar;
+ bool m_bFadeOut;
+};
+
+bool CHeliBladeMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
+{
+ bool foundVar;
+ m_AlphaVar = pMaterial->FindVar( "$alpha", &foundVar, false );
+ m_bFadeOut = pKeyValues->GetInt( "$fadeout", 0 ) != 0;
+ return foundVar;
+}
+
+void CHeliBladeMaterialProxy::OnBind( C_BaseEntity *pEnt )
+{
+ if (!m_AlphaVar)
+ return;
+
+ C_BaseHelicopter *pHeli = dynamic_cast<C_BaseHelicopter*>( pEnt );
+ if ( pHeli )
+ {
+ float dt = gpGlobals->curtime - pHeli->StartupTime();
+ dt /= FADE_IN_TIME;
+ dt = clamp( dt, 0.0f, 1.0f );
+ if ( m_bFadeOut )
+ {
+ dt = 1.0f - dt;
+ }
+
+ m_AlphaVar->SetFloatValue( dt );
+ }
+ else
+ {
+ m_AlphaVar->SetFloatValue( 1.0f );
+ }
+}
+
+IMaterial *CHeliBladeMaterialProxy::GetMaterial()
+{
+ if ( !m_AlphaVar )
+ return NULL;
+
+ return m_AlphaVar->GetOwningMaterial();
+}
+
+EXPOSE_INTERFACE( CHeliBladeMaterialProxy, IMaterialProxy, "HeliBlade" IMATERIAL_PROXY_INTERFACE_VERSION );
+