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.
What method do you use to Sync up players?
rdz说
很久以前 | 帖子#2
Chris说
很久以前 | 帖子#3Here 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.
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.
最后编辑很久以前
KarolinaGames说
很久以前 | 帖子#4ive 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?
Chris说
很久以前 | 帖子#5Karolina,
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
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
rdz说
很久以前 | 帖子#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) ;-)
"...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) ;-)
Chris说
很久以前 | 帖子#7Nothing 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
But I created this as an example of similar techniques.
http://nonoba.com/chris/asteroids-lite/
Source can be had here
最后编辑很久以前
rdz说
很久以前 | 帖子#8Thanks 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. ;-)
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. ;-)
Chris说
很久以前 | 帖子#9Well 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.
最后编辑很久以前
Chris说
很久以前 | 帖子#10While 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.
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.
torskmunken说
很久以前 | 帖子#11 | 回复#10but 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
Just wondering o.O
craigbeswetherick说
很久以前 | 帖子#12hey, i keep getting this error,
but i have my server running?
but i have my server running?
The system calculates the offset between the server and the client. Thus what time each have does not matter.
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?
torskmunken说
很久以前 | 帖子#15 | 回复#13hmm :/
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?
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?
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
A much more complex example can be seen here http://nonoba.com/chris/mpa2/
Source can be had here
回复主题
现在就注册以回复主题
Toby说
很久以前 | 帖子#1I 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.