Sunday, December 19, 2010

prediction

The topic of prediction along with closely related lag compensation and distant topic, interpolation are equally disputed as causes of 'problems' in counter-strike: source game play. This couldn't be farther from the truth, this post aims at explaining prediction.

In the context of the source engine The Valve Developer Wiki's article on prediction states:

Prediction is the notion of the client predicting the effects of the local player's actions without waiting for the server to confirm them. An entity's predicted state is tested against server commands as they arrive until either a match or a mis-match is detected.
In the vast majority of cases the client's prediction is confirmed by the server and it continues happily as if there was no latency. If there is a mis-match, which is rare if the prediction code is written correctly, then the client goes back and re-simulates all of the commands it ran with bad data. Depending on the severity of the error this can cause a noticeable hitch in the player's position and state, and possibly the state of the world too.

 In a nut shell, prediction happens client side so that the client can perform an action such as pressing the W key to move forward without waiting for the server to say it was 'ok' and update your position on the sever. why? because it takes time for the command to be received by the server and for it to respond. This would make the game appear laggy. What happens is: the client predicts your position on your key-press, instantly follows through and sends that command to the server. The server then responds with the new position and if it is different from the clients prediction then a mis-match is detected (prediction error) and the client is corrected by going back and re-simulating the commands it ran with the incorrectly predicted data.

TL;DR? Data mis-match or a prediction error is rare to begin with so it's nothing to fret over.

No comments:

Post a Comment