What method do you use to Sync up players?

TobyToby povedal

veľmi dávno | Príspevok #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 povedal

veľmi dávno | Príspevok #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 povedal

veľmi dávno | Príspevok #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.
Naposledy upravené veľmi dávno

KarolinaGamesKarolinaGames povedal

veľmi dávno | Príspevok #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 povedal

veľmi dávno | Príspevok #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 povedal

veľmi dávno | Príspevok #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 povedal

veľmi dávno | Príspevok #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
Naposledy upravené veľmi dávno

rdzrdz povedal

veľmi dávno | Príspevok #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 povedal

veľmi dávno | Príspevok #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.
Naposledy upravené veľmi dávno

ChrisChris povedal

veľmi dávno | Príspevok #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 povedal

veľmi dávno | Príspevok #11 | odpoveď na #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 povedal

veľmi dávno | Príspevok #12
hey, i keep getting this error,


but i have my server running?

ChrisChris povedal

veľmi dávno | Príspevok #13 | odpoveď na #11
The system calculates the offset between the server and the client. Thus what time each have does not matter.

ChrisChris povedal

veľmi dávno | Príspevok #14 | odpoveď na #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 povedal

veľmi dávno | Príspevok #15 | odpoveď na #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 povedal

veľmi dávno | Príspevok #16 | odpoveď na #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

Odpoveď na diskusiu

Zaregistruj sa a zapoj sa do diskusie

Flashky.sk

flashky.sk je herný portál kde môžeš hraj single- aj multiplayerové flashové hry.

Nástroje pre vývojárov

Ak si vývojár flash hier tak pre teba máme skvelé nástroje, ktoré ti pomôžu robiť ešte lepšie hry.

Skvelé hry

Vyskúšaj niektoré z najlepších online flash hier, ktoré tu máme! Samozrejme zadarmo

Copyright ©2007-2012 Flashky.sk™ - All rights reserved.46.8001ms on SERVER34096