Sign in to follow this  
Zomis

Synchronizing Realtime Multiplayer games

Recommended Posts

After having made a turn-based Multiplayer implementation of Minesweeper Flags at my site, I want to go into real-time Multiplayer development. The turn-based Minesweeper Flags game can be found here: http://www.zomis.net/games/flags The easiest real-time multiplayer thing that came to my mind was to have two squares travel around the playfield. I've made it working, but it isn't synchronized. When player1's x-position is 110 for Player1, Player1's x-position might be 104 for Player2. Only 6 pixels difference, but in realtime Multiplayer it must be perfect. All players move 10 times per second - a local timer controls this movement. I'm working in Flash (ActionScript 3.0) and using a PHP script as the server. I've implemented it so that any command that a player executes (change speed or change direction) is first sent to the server, then being sent back to all clients. And then all clients execute the action for the correct player. So what techniques should I use to make my games synchronized? I don't want to send too much data back and forth all the time, there has to be a better way, right?

Share this post


Link to post
Share on other sites
The Forum FAQ mentions that you either delay the local user, or forward predict (extrapolate, dead reckon) the other user. It also links to the Entity Position Interpolation Code code sample. Although it's in C++, it does show the math involved, and has a sample test program.

Share this post


Link to post
Share on other sites
How you synchronize also depends greatly on what is being synchronized and how important time-critical it is. If it is a slower-paced game, you can often get away with event-based updates - that is, when player X moves, you send the information stating they have moved. You can also use TCP for this since resends are actually wanted (nearly) every time. If it is faster-paced, though, like a shooter, you will probably want to use UDP so you don't have to resend dropped packets, and constantly dish out information on the state of every entity. Information that is lost from dropped packets is just replaced shortly later by newer information instead of waiting around for the old information to be received before making use of the new information. This will result in a lot more bandwidth but a lot better synchronization.

The FAQ also goes into great detail about "TCP vs UDP", when to use each, etc.

When you say the positions are not equal in your second paragraph, is this after they have finished moving? Or while they are moving? If the latter, it is something you should expect for any networked game and can't be "fixed" but rather just "covered up" by using techniques like hplus mentioned. If its not synchronized when they are not moving, simply include that information. Include their current position, velocity, and any other relevant information to properly simulate the movement.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this