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.

116 lines
3.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #include "cbase.h"
  10. #include "animation.h"
  11. #include "baseviewmodel.h"
  12. #include "player.h"
  13. #include <KeyValues.h>
  14. #include "studio.h"
  15. #include "vguiscreen.h"
  16. #include "saverestore_utlvector.h"
  17. #include "hltvdirector.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. void SendProxy_AnimTime( const void *pStruct, const void *pVarData, DVariant *pOut, int iElement, int objectID );
  21. void SendProxy_SequenceChanged( const void *pStruct, const void *pVarData, DVariant *pOut, int iElement, int objectID );
  22. //-----------------------------------------------------------------------------
  23. // Purpose: Save Data for Base Weapon object
  24. //-----------------------------------------------------------------------------//
  25. BEGIN_DATADESC( CBaseViewModel )
  26. DEFINE_FIELD( m_hOwner, FIELD_EHANDLE ),
  27. // Client only
  28. // DEFINE_FIELD( m_LagAnglesHistory, CInterpolatedVar < QAngle > ),
  29. // DEFINE_FIELD( m_vLagAngles, FIELD_VECTOR ),
  30. DEFINE_FIELD( m_nViewModelIndex, FIELD_INTEGER ),
  31. DEFINE_FIELD( m_flTimeWeaponIdle, FIELD_FLOAT ),
  32. DEFINE_FIELD( m_nAnimationParity, FIELD_INTEGER ),
  33. // Client only
  34. // DEFINE_FIELD( m_nOldAnimationParity, FIELD_INTEGER ),
  35. DEFINE_FIELD( m_vecLastFacing, FIELD_VECTOR ),
  36. DEFINE_FIELD( m_hWeapon, FIELD_EHANDLE ),
  37. DEFINE_UTLVECTOR( m_hScreens, FIELD_EHANDLE ),
  38. // Read from weapons file
  39. // DEFINE_FIELD( m_sVMName, FIELD_STRING ),
  40. // DEFINE_FIELD( m_sAnimationPrefix, FIELD_STRING ),
  41. // ---------------------------------------------------------------------
  42. // Don't save these, init to 0 and regenerate
  43. // DEFINE_FIELD( m_Activity, FIELD_INTEGER ),
  44. END_DATADESC()
  45. int CBaseViewModel::UpdateTransmitState()
  46. {
  47. if ( IsEffectActive( EF_NODRAW ) )
  48. {
  49. return SetTransmitState( FL_EDICT_DONTSEND );
  50. }
  51. return SetTransmitState( FL_EDICT_FULLCHECK );
  52. }
  53. int CBaseViewModel::ShouldTransmit( const CCheckTransmitInfo *pInfo )
  54. {
  55. // check if receipient owns this weapon viewmodel
  56. CBasePlayer *pOwner = ToBasePlayer( m_hOwner );
  57. if ( pOwner && pOwner->edict() == pInfo->m_pClientEnt )
  58. {
  59. return FL_EDICT_ALWAYS;
  60. }
  61. // check if recipient spectates the own of this viewmodel
  62. CBaseEntity *pRecipientEntity = CBaseEntity::Instance( pInfo->m_pClientEnt );
  63. if ( pRecipientEntity->IsPlayer() )
  64. {
  65. CBasePlayer *pPlayer = static_cast<CBasePlayer*>( pRecipientEntity );
  66. #ifndef _XBOX
  67. if ( pPlayer->IsHLTV() || pPlayer->IsReplay() )
  68. {
  69. // if this is the HLTV client, transmit all viewmodels in our PVS
  70. return FL_EDICT_PVSCHECK;
  71. }
  72. #endif
  73. if ( (pPlayer->GetObserverMode() == OBS_MODE_IN_EYE) && (pPlayer->GetObserverTarget() == pOwner) )
  74. {
  75. return FL_EDICT_ALWAYS;
  76. }
  77. }
  78. // Don't send to anyone else except the local player or his spectators
  79. return FL_EDICT_DONTSEND;
  80. }
  81. void CBaseViewModel::SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
  82. {
  83. // Are we already marked for transmission?
  84. if ( pInfo->m_pTransmitEdict->Get( entindex() ) )
  85. return;
  86. BaseClass::SetTransmit( pInfo, bAlways );
  87. // Force our screens to be sent too.
  88. for ( int i=0; i < m_hScreens.Count(); i++ )
  89. {
  90. CVGuiScreen *pScreen = m_hScreens[i].Get();
  91. if ( pScreen )
  92. pScreen->SetTransmit( pInfo, bAlways );
  93. }
  94. }