diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /engine/enginesingleuserfilter.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'engine/enginesingleuserfilter.cpp')
| -rw-r--r-- | engine/enginesingleuserfilter.cpp | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/engine/enginesingleuserfilter.cpp b/engine/enginesingleuserfilter.cpp new file mode 100644 index 0000000..28c6b1d --- /dev/null +++ b/engine/enginesingleuserfilter.cpp @@ -0,0 +1,152 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#include "quakedef.h" +#include "server.h" +#include "enginesingleuserfilter.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +void SV_DetermineMulticastRecipients( bool usepas, const Vector& origin, CBitVec< ABSOLUTE_PLAYER_LIMIT >& playerbits ); + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +CEngineRecipientFilter::CEngineRecipientFilter() +{ + Reset(); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CEngineRecipientFilter::Reset( void ) +{ + m_bReliable = false; + m_bInit = false; + m_Recipients.RemoveAll(); +} + +void CEngineRecipientFilter::MakeReliable( void ) +{ + m_bReliable = true; +} + + +void CEngineRecipientFilter::MakeInitMessage( void ) +{ + m_bInit = true; +} + +int CEngineRecipientFilter::GetRecipientCount( void ) const +{ + return m_Recipients.Size(); +} + +int CEngineRecipientFilter::GetRecipientIndex( int slot ) const +{ + if ( slot < 0 || slot >= GetRecipientCount() ) + return -1; + + return m_Recipients[ slot ]; +} + +void CEngineRecipientFilter::AddAllPlayers( void ) +{ + m_Recipients.RemoveAll(); + + for ( int i = 0; i < sv.GetClientCount(); i++ ) + { + IClient *cl = sv.GetClient( i ); + + if ( !cl->IsActive() ) + continue; + + m_Recipients.AddToTail( i+1 ); + } +} + + +void CEngineRecipientFilter::AddRecipient( int index ) +{ + // Already in list + if ( m_Recipients.Find( index ) != m_Recipients.InvalidIndex() ) + return; + + m_Recipients.AddToTail( index ); +} + +void CEngineRecipientFilter::RemoveRecipient( int index ) +{ + // Remove it if it's in the list + m_Recipients.FindAndRemove( index ); +} + +void CEngineRecipientFilter::AddPlayersFromBitMask( CBitVec< ABSOLUTE_PLAYER_LIMIT >& playerbits ) +{ + for( int i = 0; i < sv.GetClientCount(); i++ ) + { + if ( !playerbits[i] ) + continue; + + IClient *cl = sv.GetClient( i ); + if ( !cl->IsActive() ) + continue; + + AddRecipient( i + 1 ); + } +} + +bool CEngineRecipientFilter::IncludesPlayer(int playerindex) +{ + for( int i = 0; i < GetRecipientCount(); i++ ) + { + if ( playerindex == GetRecipientIndex(i) ) + return true; + } + + return false; +} + +void CEngineRecipientFilter::AddPlayersFromFilter(const IRecipientFilter *filter ) +{ + for( int i = 0; i < filter->GetRecipientCount(); i++ ) + { + AddRecipient( filter->GetRecipientIndex(i) ); + } +} + +void CEngineRecipientFilter::AddRecipientsByPVS( const Vector& origin ) +{ + if ( sv.GetMaxClients() == 1 ) + { + AddAllPlayers(); + } + else + { + CBitVec< ABSOLUTE_PLAYER_LIMIT > playerbits; + SV_DetermineMulticastRecipients( false, origin, playerbits ); + AddPlayersFromBitMask( playerbits ); + } +} + +void CEngineRecipientFilter::AddRecipientsByPAS( const Vector& origin ) +{ + if ( sv.GetMaxClients() == 1 ) + { + AddAllPlayers(); + } + else + { + CBitVec< ABSOLUTE_PLAYER_LIMIT > playerbits; + SV_DetermineMulticastRecipients( true, origin, playerbits ); + AddPlayersFromBitMask( playerbits ); + } +} + + |