What method do you use to Sync up players?

TobyToby said

a long time ago | Post #1
I've been trying to figure this out, first I tried sending the coordinate, which was extremely laggy and required almost frame by frame updates, stupid idea. Next I tried sending updates every time the player hit a new key which sent across their speed, keys pressed and coordinates but this eventually lead to the two screens becomes slightly desynchronised, I'm going to assume this is because of the latency between the two clients so how do you guys keep two players in sync?

I won't be able to use this advice for a while because my visual studio is fubar but it will be good to know after i've finished up some things.

rdzrdz said

a long time ago | Post #2
I only recently gave this a go myself. And to be honoust i am not fully satisfied with the result i got.

But i did get it to be completely in sync as follows.

Any movement updates (like 'turnLeft') go via the server side, into a broadcast to all. This is including yourself, so you click a button and your local movement is only when you get the broadcast back. Downside is that with a really slow connection you can not steer properly, because of the big delays.

To keep the frame-rate evened out for the different players, i send out 'ticks' from the server code. Currently i have a tick per 33ms, which might be a lot of strain on the server.

I started with sending 1 tick per every 100ms which triggered 4 frame updates at every 25ms. This endend up looking not smooth at all.
For some reason delays and framerates are not at all precise in flash. I have seen a more then 10% speed difference, when i started a game twice on the same machine without syncing. :-S


I am also very curious how others implement this. I know that some of the more popular games here just accept some unprecise behaviour, when framerates are not exact. So you see some other players slightly at a different position then they see themselves.

ChrisChris said

a long time ago | Post #3
Here is an example using syncronised timestamps for client to client synchronization.

http://nonoba.com/chris/timesynchtest/

The source can be had here:

http://chrisbenjaminsen.com/temp/TimeSynchedMovement.zip

There is no interpolation nor smoothing, but those are rather simple to add on later.
Last edited a long time ago

KarolinaGamesKarolinaGames said

a long time ago | Post #4
ive just found this neat API and it looks great, but what about realtime performance when it comes down to it? Can it hadle say, 30 objects x, y and rotation (floored to ints) in a realtime action scenario?

ChrisChris said

a long time ago | Post #5
Karolina,

As long as you are clever about it it should handle pretty much anything :) Say bullets don't typically change direction so you don't have to recalculate them ever if everything is based on timestamps

rdzrdz said

a long time ago | Post #6
@Chris
"...interpolation nor smoothing, but those are rather simple to add on later."

I guess you wouldn't have also a nice example for that as well? O-)


(Yes i know it is probably too lazy & google is my friend) ;-)

ChrisChris said

a long time ago | Post #7
Nothing that would work out of the box with this.

But I created this as an example of similar techniques.
http://nonoba.com/chris/asteroids-lite/

Source can be had here
Last edited a long time ago

rdzrdz said

a long time ago | Post #8
Thanks a lot. :-)
There's much rather interesting learning material for me in that code. (besides also the actual smoothing)


but... :-S

The actual smoothing does not seem to work very well on my side.
Which i think is caused by my rather slow internet connection.
At the higher speeds i get to see double (or triple?), where it looks like the new position is drawn and only at the next tick the old one is removed.



How easy it was to trick the eye & brain into the perception of smoothness with a c64 connected to an old fashioned glass tube television. ;-)

ChrisChris said

a long time ago | Post #9
Well if your game mechanic can survive that everything is not as close in synch as possible its no problem. This is why world of warcraft can handle lag much much better than, say, Counter Strike.
Last edited a long time ago

ChrisChris said

5 months ago | Post #10
While discussing hit-maps and movable terrain with Toby, I extended the Synchronized time-stamps example to have both.

The result can be seen here: http://nonoba.com/chris/timestamp-and-movable-hitmap/

And the source code here:http://chrisbenjaminsen.com/temp/WithMovableMapsAndHittest.zip

The system still does not have any interpolation. I might however write this as a extended example if people would like such.

torskmunkentorskmunken said

5 weeks ago | Post #11 | in reply to #10
but what if the computer a user is running on has a very offset time compared to the server? Or does the nonoba server do something weird with the date?

Just wondering o.O

craigbeswetherickcraigbeswetherick said

3 weeks ago | Post #12
hey, i keep getting this error,


but i have my server running?

ChrisChris said

3 weeks ago | Post #13 | in reply to #11
The system calculates the offset between the server and the client. Thus what time each have does not matter.

ChrisChris said

3 weeks ago | Post #14 | in reply to #12
Looks like you are trying to connect to an IP that does not have the server running. Are you sure your server is running at 10.0.0.12?

torskmunkentorskmunken said

2 weeks ago | Post #15 | in reply to #13
hmm :/
I'll have to overlook the code again.
But as far as I remember, the server gets its date and then sends it off to the peer, who then just gets a delta of the server date and the peer date. Or did I see something wrong there? Because the server and user date cant be exactly the same, eh?

ChrisChris said

2 weeks ago | Post #16 | in reply to #15
The client calculates an offset to the server time. And what's send in is the estimated server time, thus it should be fairly in synch.

A much more complex example can be seen here http://nonoba.com/chris/mpa2/

Source can be had here

Reply to thread

Sign up now to reply to threads

Nonoba

nonoba.com is an independent gaming site where you can play both single- and multiplayer games for free.

Developer Tools

If you're a flash game developer, we've got some awesome tools to help you make even better games.

Great Games

Why not try some of the very best online flash games we've got, completely free?

Copyright ©2007-2009 Nonoba™ - All rights reserved.15,6001ms on NONOBA-WEB1