What method do you use to Sync up players?

TobyToby

很久以前 | 帖子#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

很久以前 | 帖子#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

很久以前 | 帖子#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.
最后编辑很久以前

KarolinaGamesKarolinaGames

很久以前 | 帖子#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

很久以前 | 帖子#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

很久以前 | 帖子#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

很久以前 | 帖子#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
最后编辑很久以前

rdzrdz

很久以前 | 帖子#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

很久以前 | 帖子#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.
最后编辑很久以前

ChrisChris

很久以前 | 帖子#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

很久以前 | 帖子#11 | 回复#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

很久以前 | 帖子#12
hey, i keep getting this error,


but i have my server running?

ChrisChris

很久以前 | 帖子#13 | 回复#11
The system calculates the offset between the server and the client. Thus what time each have does not matter.

ChrisChris

很久以前 | 帖子#14 | 回复#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

很久以前 | 帖子#15 | 回复#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

很久以前 | 帖子#16 | 回复#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

回复主题

现在就注册以回复主题

5dyouxi

5dyouxi.com是一个独立的游戏网站,在这里你将可以免费玩到各种好玩的单人和多人游戏。

开发者工具

如果你是一位flash游戏开发者,我们有一些非常强大的工具来帮助你开发更加优秀的游戏。

经典游戏

为什么不试试我们这里的一些最为优秀的在线flash游戏呢?这可是完全免费的!

Copyright ©2007-2012 5dyouxi™ - All rights reserved.48.0028ms on SERVER34097
注册 或者