I am programming a bomberman clone which is basically working, now I want it to have network functionality.
I think p2p would be great, but for now I am using a client/server model, where the server has the actual state of the game and the clients are dumb ( not trusted ) and a bit behind the actual state of the game.
I have read many articles about interpolation, lag compensation and client prediction.
I don't want to talk about the first two, but I have a question about client prediction.
I am implementing reliable UDP on my own.
I don't trust my clients, so they don't send absolute position, they send commands like move up, move right, move down, move left and plant bomb. The bomb always gets planted in the center of the current tile that the player is on ( which is depended on his position of course ).
I have not implemented a way to regard the order of the packets, which of course can lead to errors like:
Player sends move up and move right ( in that order ), the client predicts these commands and moves up and right, now let's say these packets are received in the wrong order, then the player is first moving right and then moving up. Now if things are going really bad then the player may have collided with a wall when going right first and basically his final position is different. I can of course correct this error when the player receives the position from the server ( a possibility is to just ignore packets that are older than the last received packet ) but when the player also send a plant bomb command afterwards and the different final positions lead to him standing on a different tile, then the client predicts the plant bomb on a different tile than the server. I can of course keep history of the last actions and also correct this and when the player receives the bomb planting by the server it gets corrected. But this correction will look pretty ugly, since it will remove the bomb from one tile and have it appear on another.
I know this is a very unusual scenario, but it would have such a deep impact, since the gameplayer will suffer immensely.
I talked about an uncorrect packet order, the same error could also appear when a packet is lost of course... I can resend packets, but to be sure a packet is lost the client checks if an ack hasn't been received in 1 second. The problem is, the bomb timer ( bombs explode after 4 seconds ) is already counting down every since it was planted, when the client predicted it.
And the server has to also send the bomb planting to all its clients and there of course packets might also get lost and becoming aware of that also takes another second.
It's kinda frustrating, a player can also pick up powerups, but I'm not there yet, at this point I just want everything to run great with the move commands and planting a bomb.
What is the best way to implement reliable udp and how do you know if a packet hasn't been received? Basically I am acking the packets with redundancy so you usually receive multiple acks for a packet and you will only not receive an ack if you don't receive any packet for about a second.
In short: What does reliable UDP do or how to make a good implementation of reliable UDP and what about client prediction/error correction?
I have read so many stuff and have a basic idea, but on my specific game I can think of many scenarios that I can't really find a good solution for. Is 1 second too long to make sure a packet wasn't received? Usually an ack should arrive in about 200ms, right? ( when sending a packet to server takes about 100ms and the server sending the ack takes another about 100ms. but that of course is depending on the connection between the client and the server ).
I really appreciate anyone taking the time to read and trying to answer my questions, you guys are the best!
Edited by teremy, 13 March 2014 - 10:16 PM.