CRecipientFilter: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
m (Robot: fixing template case.)
 
(9 intermediate revisions by one other user not shown)
Line 1: Line 1:
The <code>[[CRecipientFilter]]</code> class enables the server to pick and choose which clients it passes an item of data to. Most server-to-client communication supports it.
The <code>[[CRecipientFilter]]</code> class enables the server to pick and choose which clients it passes an item of data to. Most server-to-client communication supports it.


Alongside adding/removing clients individually or all at once, it can filter by:
Alongside adding/removing clients individually or all at once, it can filter by [[Potentially Audible Set]], [[Potentially Visible Set]] and [[Team]].
 
*[[PAS]]
*[[PVS]]
*[[Team]]


== Examples ==
== Examples ==


  '''CRecipientFilter''' MyFilter;
  '''CRecipientFilter''' MyFilter;
  MyFilter.AddRecipientsByPVS( [[GetAbsOrigin()]] ); ''// Origin of the host entity; clients within its PVS will be added.''
  MyFilter.AddRecipientsByPVS( [[GetAbsOrigin()]] ); ''// Clients within the entity's PVS will be added.''
  MyFilter.MakeReliable(); ''// All this does is make m_bReliable true! Best to use it anyway.''
  MyFilter.MakeReliable();


  '''CRecipientFilter''' MyInverseFilter;
  '''CRecipientFilter''' MyInverseFilter;
  MyInverseFilter.AddAllPlayers();
  MyInverseFilter.AddAllPlayers();
  MyInverseFilter.RemoveRecipientsByPVS( GetAbsOrigin() ); ''// Only players '''outside''' the PVS''
  MyInverseFilter.RemoveRecipientsByPVS( GetAbsOrigin() ); ''// Leaving only players '''outside''' the PVS''
  MyInverseFilter.MakeReliable();
  MyInverseFilter.MakeReliable();
== Reliable vs. Unreliable ==
<code>[[MakeReliable()]]</code> gives any command using the filter instance a higher network transmission priority. It causes the data to be sent early on in the next network update, and to be queued if it can't be sent immediately. Data with an unreliable filter is sent at the end of the next packet if there is any room left, and is dropped and forgotten about if not transmitted immediately.
This is useful for prioritising [[:Category:Networking|network data]] at times of heavy traffic. {{TODO|Confirm/expand this.}}


== Derived classes ==
== Derived classes ==


Several derived classes exist to automate the creation of common filters, with constructors set up to directly return an appropriately-configured filter.
Several derived classes exist to automate the creation of common filters, with constructors set up to directly return an appropriately-configured instance.
 
{{warning|These are unreliable unless otherwise noted!}}


;<code>CBroadcastRecipientFilter()</code>
;<code>CBroadcastRecipientFilter()</code>
;<code>CReliableBroadcastRecipientFilter()</code>
:All players.
:All players.
;<code>CLocalPlayerFilter()</code>
:The local player. Client-side only, needless to say! {{todo|Useful how?}}
;<code>CPASFilter([[origin]])</code>
;<code>CPASFilter([[origin]])</code>
:All players in the origin's [[PAS]].
;<code>CPASAttenuationFilter(<various constructors>)</code>
:All players in the origin's [[PAS]]. <code>CPASAttenuationFilter</code> will additionally remove those too far away to hear the sound.
;<code>CPVSFilter([[origin]])</code>
;<code>CPVSFilter([[origin]])</code>
:All players in the origin's [[PVS]].
:All players in the origin's [[PVS]].
;<code>CSingleUserRecipientFilter([[CBasePlayer]])</code>
;<code>CSingleUserRecipientFilter([[CBasePlayer]])</code>
:A specific player.
:A specific player.
;<code>CTeamRecipientFilter([[int]] team, [[bool]] isReliable = false)</code>
:A multiplayer [[team]].
;<code>CLocalPlayerFilter()</code>
:The local player. Used as a dummy filter when calling functions requiring one on the client. Reliability is irrelevant.


=== Example ===
=== Example ===
Line 37: Line 45:
To make an entity produce a sound from another location:
To make an entity produce a sound from another location:


  [[EmitSound()|EmitSound]]( CPASFilter(pPuppet->[[GetAbsOrigin()]]),pPuppet->[[entindex()]],"Ventriloquist.Hello" );
  [[EmitSound()|EmitSound]]( '''CPASFilter(pPuppet->[[GetAbsOrigin()]])''',pPuppet->[[entindex()]],"Ventriloquist.Hello" );


== See also ==
== See also ==

Latest revision as of 19:17, 19 January 2009

The CRecipientFilter class enables the server to pick and choose which clients it passes an item of data to. Most server-to-client communication supports it.

Alongside adding/removing clients individually or all at once, it can filter by Potentially Audible Set, Potentially Visible Set and Team.

Examples

CRecipientFilter MyFilter;
	MyFilter.AddRecipientsByPVS( GetAbsOrigin() );	// Clients within the entity's PVS will be added.
	MyFilter.MakeReliable();
CRecipientFilter MyInverseFilter;
	MyInverseFilter.AddAllPlayers();
	MyInverseFilter.RemoveRecipientsByPVS( GetAbsOrigin() );	// Leaving only players outside the PVS
	MyInverseFilter.MakeReliable();

Reliable vs. Unreliable

MakeReliable() gives any command using the filter instance a higher network transmission priority. It causes the data to be sent early on in the next network update, and to be queued if it can't be sent immediately. Data with an unreliable filter is sent at the end of the next packet if there is any room left, and is dropped and forgotten about if not transmitted immediately.

This is useful for prioritising network data at times of heavy traffic.

Todo: Confirm/expand this.

Derived classes

Several derived classes exist to automate the creation of common filters, with constructors set up to directly return an appropriately-configured instance.

Warning.pngWarning:These are unreliable unless otherwise noted!
CBroadcastRecipientFilter()
CReliableBroadcastRecipientFilter()
All players.
CPASFilter(origin)
CPASAttenuationFilter(<various constructors>)
All players in the origin's PAS. CPASAttenuationFilter will additionally remove those too far away to hear the sound.
CPVSFilter(origin)
All players in the origin's PVS.
CSingleUserRecipientFilter(CBasePlayer)
A specific player.
CTeamRecipientFilter(int team, bool isReliable = false)
A multiplayer team.
CLocalPlayerFilter()
The local player. Used as a dummy filter when calling functions requiring one on the client. Reliability is irrelevant.

Example

To make an entity produce a sound from another location:

EmitSound( CPASFilter(pPuppet->GetAbsOrigin()),pPuppet->entindex(),"Ventriloquist.Hello" );

See also

Tip.pngTip:You don't need to use the filter entities as a programmer - you already have direct access to the relevant data.