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.

152 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "quakedef.h"
  9. #include "server.h"
  10. #include "enginesingleuserfilter.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. void SV_DetermineMulticastRecipients( bool usepas, const Vector& origin, CBitVec< ABSOLUTE_PLAYER_LIMIT >& playerbits );
  14. //-----------------------------------------------------------------------------
  15. // Purpose:
  16. //-----------------------------------------------------------------------------
  17. CEngineRecipientFilter::CEngineRecipientFilter()
  18. {
  19. Reset();
  20. }
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. void CEngineRecipientFilter::Reset( void )
  25. {
  26. m_bReliable = false;
  27. m_bInit = false;
  28. m_Recipients.RemoveAll();
  29. }
  30. void CEngineRecipientFilter::MakeReliable( void )
  31. {
  32. m_bReliable = true;
  33. }
  34. void CEngineRecipientFilter::MakeInitMessage( void )
  35. {
  36. m_bInit = true;
  37. }
  38. int CEngineRecipientFilter::GetRecipientCount( void ) const
  39. {
  40. return m_Recipients.Size();
  41. }
  42. int CEngineRecipientFilter::GetRecipientIndex( int slot ) const
  43. {
  44. if ( slot < 0 || slot >= GetRecipientCount() )
  45. return -1;
  46. return m_Recipients[ slot ];
  47. }
  48. void CEngineRecipientFilter::AddAllPlayers( void )
  49. {
  50. m_Recipients.RemoveAll();
  51. for ( int i = 0; i < sv.GetClientCount(); i++ )
  52. {
  53. IClient *cl = sv.GetClient( i );
  54. if ( !cl->IsActive() )
  55. continue;
  56. m_Recipients.AddToTail( i+1 );
  57. }
  58. }
  59. void CEngineRecipientFilter::AddRecipient( int index )
  60. {
  61. // Already in list
  62. if ( m_Recipients.Find( index ) != m_Recipients.InvalidIndex() )
  63. return;
  64. m_Recipients.AddToTail( index );
  65. }
  66. void CEngineRecipientFilter::RemoveRecipient( int index )
  67. {
  68. // Remove it if it's in the list
  69. m_Recipients.FindAndRemove( index );
  70. }
  71. void CEngineRecipientFilter::AddPlayersFromBitMask( CBitVec< ABSOLUTE_PLAYER_LIMIT >& playerbits )
  72. {
  73. for( int i = 0; i < sv.GetClientCount(); i++ )
  74. {
  75. if ( !playerbits[i] )
  76. continue;
  77. IClient *cl = sv.GetClient( i );
  78. if ( !cl->IsActive() )
  79. continue;
  80. AddRecipient( i + 1 );
  81. }
  82. }
  83. bool CEngineRecipientFilter::IncludesPlayer(int playerindex)
  84. {
  85. for( int i = 0; i < GetRecipientCount(); i++ )
  86. {
  87. if ( playerindex == GetRecipientIndex(i) )
  88. return true;
  89. }
  90. return false;
  91. }
  92. void CEngineRecipientFilter::AddPlayersFromFilter(const IRecipientFilter *filter )
  93. {
  94. for( int i = 0; i < filter->GetRecipientCount(); i++ )
  95. {
  96. AddRecipient( filter->GetRecipientIndex(i) );
  97. }
  98. }
  99. void CEngineRecipientFilter::AddRecipientsByPVS( const Vector& origin )
  100. {
  101. if ( sv.GetMaxClients() == 1 )
  102. {
  103. AddAllPlayers();
  104. }
  105. else
  106. {
  107. CBitVec< ABSOLUTE_PLAYER_LIMIT > playerbits;
  108. SV_DetermineMulticastRecipients( false, origin, playerbits );
  109. AddPlayersFromBitMask( playerbits );
  110. }
  111. }
  112. void CEngineRecipientFilter::AddRecipientsByPAS( const Vector& origin )
  113. {
  114. if ( sv.GetMaxClients() == 1 )
  115. {
  116. AddAllPlayers();
  117. }
  118. else
  119. {
  120. CBitVec< ABSOLUTE_PLAYER_LIMIT > playerbits;
  121. SV_DetermineMulticastRecipients( true, origin, playerbits );
  122. AddPlayersFromBitMask( playerbits );
  123. }
  124. }