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.

91 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "c_basehelicopter.h"
  8. #include "proxyentity.h"
  9. #include "materialsystem/imaterial.h"
  10. #include "materialsystem/imaterialvar.h"
  11. #include "KeyValues.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. IMPLEMENT_CLIENTCLASS_DT( C_BaseHelicopter, DT_BaseHelicopter, CBaseHelicopter )
  15. RecvPropTime( RECVINFO( m_flStartupTime ) ),
  16. END_RECV_TABLE()
  17. C_BaseHelicopter::C_BaseHelicopter()
  18. {
  19. }
  20. //-----------------------------------------------------------------------------
  21. // Chopper blade fade-in time
  22. //-----------------------------------------------------------------------------
  23. #define FADE_IN_TIME 2.0f
  24. //-----------------------------------------------------------------------------
  25. // Sets the fade of the blades when the chopper starts up
  26. //-----------------------------------------------------------------------------
  27. class CHeliBladeMaterialProxy : public CEntityMaterialProxy
  28. {
  29. public:
  30. CHeliBladeMaterialProxy() { m_AlphaVar = NULL; }
  31. virtual ~CHeliBladeMaterialProxy() {}
  32. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  33. virtual void OnBind( C_BaseEntity *pEntity );
  34. virtual IMaterial *GetMaterial();
  35. private:
  36. IMaterialVar *m_AlphaVar;
  37. bool m_bFadeOut;
  38. };
  39. bool CHeliBladeMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  40. {
  41. bool foundVar;
  42. m_AlphaVar = pMaterial->FindVar( "$alpha", &foundVar, false );
  43. m_bFadeOut = pKeyValues->GetInt( "$fadeout", 0 ) != 0;
  44. return foundVar;
  45. }
  46. void CHeliBladeMaterialProxy::OnBind( C_BaseEntity *pEnt )
  47. {
  48. if (!m_AlphaVar)
  49. return;
  50. C_BaseHelicopter *pHeli = dynamic_cast<C_BaseHelicopter*>( pEnt );
  51. if ( pHeli )
  52. {
  53. float dt = gpGlobals->curtime - pHeli->StartupTime();
  54. dt /= FADE_IN_TIME;
  55. dt = clamp( dt, 0.0f, 1.0f );
  56. if ( m_bFadeOut )
  57. {
  58. dt = 1.0f - dt;
  59. }
  60. m_AlphaVar->SetFloatValue( dt );
  61. }
  62. else
  63. {
  64. m_AlphaVar->SetFloatValue( 1.0f );
  65. }
  66. }
  67. IMaterial *CHeliBladeMaterialProxy::GetMaterial()
  68. {
  69. if ( !m_AlphaVar )
  70. return NULL;
  71. return m_AlphaVar->GetOwningMaterial();
  72. }
  73. EXPOSE_INTERFACE( CHeliBladeMaterialProxy, IMaterialProxy, "HeliBlade" IMATERIAL_PROXY_INTERFACE_VERSION );