Lag Compensation: Difference between revisions
Jump to navigation
Jump to search
Note:
Tip:In Left 4 Dead 2, prop_physics can lag compensated. Do this sparingly!
TomEdwards (talk | contribs) (corrected headings) |
(→Invocation: Lag Compensation Type) |
||
Line 21: | Line 21: | ||
void CMyPlayer::FireBullets ( const FireBulletsInfo_t &info ) | void CMyPlayer::FireBullets ( const FireBulletsInfo_t &info ) | ||
{ | { | ||
// Source 2007 | |||
lagcompensation->StartLagCompensation( this, this->GetCurrentCommand() ); | lagcompensation->StartLagCompensation( this, this->GetCurrentCommand() ); | ||
// Alien Swarm and later (see also sub-section below) | |||
lagcompensation->StartLagCompensation( this, LAG_COMPENSATE_HITBOXES ); | |||
BaseClass::FireBullets(info); | BaseClass::FireBullets(info); | ||
Line 30: | Line 34: | ||
Time will be wound back on the call to <code>StartLagCompensation()</code>, and wound forward again on the call to <code>FinishLagCompensation()</code>. | Time will be wound back on the call to <code>StartLagCompensation()</code>, and wound forward again on the call to <code>FinishLagCompensation()</code>. | ||
== Lag Compensation Type == | |||
Starting with Alien Swarm, you can optimise lag compensation with these settings: | |||
; <code>LAG_COMPENSATE_BOUNDS</code> | |||
: Rewind the entity's location only, skipping animations. | |||
; <code>LAG_COMPENSATE_HITBOXES</code> | |||
: Rewind both location and [[hitbox]]es. This is the standard setting. | |||
; <code>LAG_COMPENSATE_HITBOXES_ALONG_RAY</code> | |||
: Rewind hitboxes if the target entity is hit by a ray defined by the "weaponPos" <code>StartLagCompensation()</code> overload. Otherwise rewind bounds only. | |||
== Implementation == | == Implementation == |
Revision as of 16:19, 30 June 2011
- You may be looking for Yahn Bernier's 2001 paper on game engine networking.
Lag compensation is the notion of the server calculating as best it can when a usercmd was sent, and rewinding time to that point when processing it. In combination with prediction, lag compensation can help to combat network latency to the point of almost eliminating it.
By default only players are rewound. For a more detailed explanation, see Source Multiplayer Networking.

CBasePlayer
does not use lag compensation; it must be implemented by a derived class. Valve's networked player classes do this already.
Invocation
Simply wrap whatever code you want lag compensated within two calls to the lagcompensation
object:
#ifdef GAME_DLL
#include "..\server\ilagcompensationmanager.h"
void CMyPlayer::FireBullets ( const FireBulletsInfo_t &info )
{
// Source 2007
lagcompensation->StartLagCompensation( this, this->GetCurrentCommand() );
// Alien Swarm and later (see also sub-section below)
lagcompensation->StartLagCompensation( this, LAG_COMPENSATE_HITBOXES );
BaseClass::FireBullets(info);
lagcompensation->FinishLagCompensation( this );
}
#endif
Time will be wound back on the call to StartLagCompensation()
, and wound forward again on the call to FinishLagCompensation()
.
Lag Compensation Type
Starting with Alien Swarm, you can optimise lag compensation with these settings:
LAG_COMPENSATE_BOUNDS
- Rewind the entity's location only, skipping animations.
LAG_COMPENSATE_HITBOXES
- Rewind both location and hitboxes. This is the standard setting.
LAG_COMPENSATE_HITBOXES_ALONG_RAY
- Rewind hitboxes if the target entity is hit by a ray defined by the "weaponPos"
StartLagCompensation()
overload. Otherwise rewind bounds only.
Implementation
[Todo]