Hi all monkeys!!!
I’m posting here after a really hard search of resources about multiplayer game programming like many of you said me. The research results in a lot of questions that need some programming guru to be answered. I explain myself:
I’m trying to do a basic multiplayer FPS like UrbanTerror and many others and after some good lecture what I have to do is to implement an algorithm like this
Client
Handle user input and send it to the server
process all update messages arriving from server
render the new game state
repeat
Server
receives input from clients
process all inputs and update the game state
broadcasts all updates
repeat
Substantially this architecture is made of an authorative server that runs a physical simulation and sends the updates to the client, and those have only to render the game state and sample user input. The animations are executed on the server (because the simulation need to verify the position and collisions of every body part of a character, so i need to maintain the position of every anim-bone on the server) and together with special attivation effect and sound, are sent over the net with the update messagges.
This system have to include some other hard stuff like client side prediction and lag compensation. In many resources it is explained how to do some kind of lag compensation and the most used workaround is to interpolate the game state to make it be rendered abount 50 – 100 ms before the actual state, but the client side prediction is never (almost for what i’ve found) explained becuase all it is said is to assume that the client input is correct and instantly rendered. In a second moment all errors have to be fixed when the correct game state is received from the server but it is not explained how to do it. Another point that I’m not sure about is the input sampling, because i don’t know how to send it to the server and how to process it to instantly render the new game state to implement the client side prediction.
To clarify what i said i give some example:
CLIENT INPUT HANDLING
When a user press a button to move, for example, if I send it immediatly to the server (IMHO in TCP) i risk to not consider some bandwith and delay issues because in a second it is possible to send nearly 20 inputs that in tcp are obviously subject to delays. Another way to do it is to store a buffer of the buttun pressed and to send it to the server at a predefined rate, which results in an additional delay of the simulation.
Based on the above considerations, what is the best way to sample users input?
SERVER INPUT HANDLING
I think that the best way to process all users inputs is to store it in a buffer and process it at a fixed rate instead of enqueue every input and process it instantly in order to reduce the game state updating. The idea is: store input and update it just one time instead of update it multiple times.
What do you think about it?
CLIENT SIDE PREDICTION
Assum that I process all inputs like it is a local game, this can be true only for the local player, and what about enemies? The conseguence is that the local player is “forward” in the simulation time respect the other players resulting in an inconsistency of the game state.. However, without considering the inconsistency, some kind of client side prediction requires the server to send a correct state of the game that fix the errors on clients. But i really don’t know how to do this because if i treat every message arriving from the server in a way that lets me do the lag compensation through entity interpolation, the fixing requires a special treatment for the update messages that made the entity be smoothed-position-fixed in a different way. Based on this i should have i cycle that interpolate the entity backword in the time, and a cycle that blends the position of an entity… I wonder what you would see in this case 0,o
Maybe i could assume that every update message simply correct the entity prediction only updating it’s state and doing the interpoltion but maybe in this way may happens some glitches..
What do you think about it??
Another thing that i don’t know how to implement is the interpolation:
Assuming that i have a system that include a SyncAppState that every update takes the most up-to-date message and interpolate it, i need a way to correct the case in which a syncmessage does not arrive (messages that update the game state are sent in UDP) otherwise when another message arrives it will interpolate the state in a way that causes a glitch of the before position to after position..
Those are really enough question so i’ll stop here for now
.
I hope someone of you GAME-DEV-GURU can help me. Thanks a lot for your time monkeys!!!
PS sorry my horrible english ahahahahahahhaha