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) (l4d2 prop_physics compensation) |
TomEdwards (talk | contribs) (caption now makes sense) |
||
Line 1: | Line 1: | ||
: ''You may be looking for [[Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization|Yahn Bernier's 2001 paper on game engine networking]].'' | : ''You may be looking for [[Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization|Yahn Bernier's 2001 paper on game engine networking]].'' | ||
[[File:Lag compensation.jpg|thumb| | [[File:Lag compensation.jpg|thumb|Historic client hitboxes (red) versus rewound server hitboxes (blue).]] | ||
'''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. | '''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. |
Revision as of 07:20, 14 February 2010
- 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.
Implementation
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 )
{
lagcompensation->StartLagCompensation( this, this->GetCurrentCommand() );
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()
.