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.

89 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include "tier0/memdbgon.h"
  9. //-----------------------------------------------------------------------------
  10. class C_TFGlow : public C_BaseEntity
  11. {
  12. public:
  13. DECLARE_CLASS( C_TFGlow, C_BaseEntity );
  14. DECLARE_CLIENTCLASS();
  15. C_TFGlow();
  16. virtual ~C_TFGlow();
  17. virtual void PostDataUpdate( DataUpdateType_t updateType ) OVERRIDE;
  18. private:
  19. void CreateGlow();
  20. CGlowObject *pGlow;
  21. CNetworkVar( int, m_iMode );
  22. CNetworkVar( color32, m_glowColor );
  23. CNetworkVar( bool, m_bDisabled );
  24. CNetworkHandle( CBaseEntity, m_hTarget );
  25. };
  26. //-----------------------------------------------------------------------------
  27. IMPLEMENT_CLIENTCLASS_DT( C_TFGlow, DT_TFGlow, CTFGlow )
  28. RecvPropInt(RECVINFO( m_iMode ) ),
  29. RecvPropInt( RECVINFO( m_glowColor ), 0, RecvProxy_IntToColor32 ),
  30. RecvPropBool( RECVINFO( m_bDisabled ) ),
  31. RecvPropEHandle( RECVINFO( m_hTarget ) ),
  32. END_RECV_TABLE()
  33. //-----------------------------------------------------------------------------
  34. C_TFGlow::C_TFGlow()
  35. {
  36. }
  37. //-----------------------------------------------------------------------------
  38. C_TFGlow::~C_TFGlow()
  39. {
  40. delete pGlow;
  41. }
  42. //-----------------------------------------------------------------------------
  43. void C_TFGlow::CreateGlow()
  44. {
  45. if ( pGlow )
  46. {
  47. delete pGlow;
  48. pGlow = nullptr;
  49. }
  50. if ( m_bDisabled || !m_hTarget )
  51. {
  52. return;
  53. }
  54. Vector cvec;
  55. color32 c = m_glowColor.Get();
  56. cvec[0] = c.r * (1.0f/255.0f);
  57. cvec[1] = c.g * (1.0f/255.0f);
  58. cvec[2] = c.b * (1.0f/255.0f);
  59. float a = c.a * (1.0f/255.0f);
  60. int iMode = m_iMode.Get();
  61. bool bDrawWhenOccluded = ( iMode == 0 ) || ( iMode == 1 );
  62. bool bDrawWhenVisible = ( iMode == 0 ) || ( iMode == 2 );
  63. Assert( bDrawWhenOccluded || bDrawWhenVisible );
  64. pGlow = new CGlowObject( m_hTarget, cvec, a, bDrawWhenOccluded, bDrawWhenVisible );
  65. }
  66. //-----------------------------------------------------------------------------
  67. void C_TFGlow::PostDataUpdate( DataUpdateType_t updateType )
  68. {
  69. BaseClass::PostDataUpdate( updateType );
  70. // this could avoid recreating the glow object on every update, but it
  71. // wouldn't be noticeably more efficient and it would add a ton of code here.
  72. CreateGlow();
  73. }