Page 1 of 2

Time synchronization, Server/Client

Posted: Sat Nov 18, 2017 11:06 pm
by personwithhat2
Hey there,

Huge problem. Despite my plans on paper, I'm getting serious out of sync issues on the client.

After some minor bug fixes (ok not that minor, I'm bad ok, pointers to deleted objects XD) I've hit a huge hurdle that no amount of googlin/book-readin/etc. is solving.


Here's the flow:

Client presses button "Spacebar" , saves time.

Server gets button press, does the exact same code as the client and saves time.

Client releases "Spacebar", Jumping (physics impulse up at an angle) based on charge time. (Start time - End time)

Server gets button press, again 100% same code as client and triggers jump.

Positions are sync'd from server -> remote actors. Positions differ from local client!


Sample charge times in seconds:
Client = 0.06705 (released fast) Server = 0.00 (Looks like it was released in the same frame??)
Client = 0.250870 Server = 0.235150
Client = 0.150350 Server = 0.178260

Obviously they differ. I've attempted to do this:
{ "name": "t_FixedStep", "value": "0.016667" }

But that breaks a ton and server-client times differ even more. (e.g. client = ~3 times as much as server)

Some issues I dunno how to fix:
Packets may arrive at different times (relative to each other) compared to how they were triggered on the client.
Differing tickrates. Input could be parsed at slightly different times.

Any help is appreciated. Sorry for bothering but again, no resources I've found assist with this problem (other than identifying it and stating generics e.g. 'just sync inputs')

Re: Time synchronization, Server/Client

Posted: Sat Nov 18, 2017 11:27 pm
by mknmknmknjk
just calculate acceleration and velocity according delayed time. just newton law, some planet time run slow, some fast, how do you sync. change gravity is not possible. but you can change accelerate or speed.

Re: Time synchronization, Server/Client

Posted: Sun Nov 19, 2017 12:07 am
by personwithhat2
I don't follow.

I'm syncing inputs via RMI , press W send message to server. This maintains order etc.

Not sure what velocity or anything like that has to do with this. You do realize I'm saying the total charge time differs between server/client because of differing time-steps/packet lag?

Re: Time synchronization, Server/Client

Posted: Sun Nov 19, 2017 2:04 am
by mknmknmknjk
networking documentation already cover order aspect. rmi is used to remote call not used to sync variable all the time.
http://docs.cryengine.com/plugins/servl ... ew/1605719

http://docs.cryengine.com/plugins/servl ... w/23306593

the doc is not easy followed.

Re: Time synchronization, Server/Client

Posted: Sun Nov 19, 2017 2:18 am
by personwithhat2
I know how RMI's/aspects work (mostly)

Press W -> RMI to Server "Player X has pressed W, simulate this please" ONCE (when pressed/released) and that's it.

As much as I appreciate your help, I prefer when it's actually related to what I'm saying. e.g. inputs out of sync time wise and what not.

Re: Time synchronization, Server/Client

Posted: Sun Nov 19, 2017 6:30 am
by fury22uk
It's just obvious that the time will be different for server and client. It will be even waaay more different for clients connected remotely and even more out of sync if they're far away. Let me understand what you're trying to achieve. You want to have jump strength based on how long you hold spacebar right ? So in this case you won't be able to calculate it on the server. Delay for remote clients might be too huge and therefore their jump will be way bigger than they requested. What I would do is.. When you press spacebar, send RMI with current time value and when it gets to the server, save it there. Then when you release spacebar, also send RMI with current time value, and when it gets to the server, server will calculate difference between start and end time, and apply impulse.

Re: Time synchronization, Server/Client

Posted: Sun Nov 19, 2017 6:40 am
by personwithhat2
Unfortunately that method doesn't solve the root of the problem, which is that input's can have different times relevant to each other due to non-uniform packet delay/lag etc......which is the issue that absolutely has to be solved otherwise desync would be too common.

Re: Time synchronization, Server/Client

Posted: Sun Nov 19, 2017 8:38 am
by fury22uk
I think it does solve the issue. You send start time with rmi, server saves it, then you send rmi that spacebar is released with time of release. Server applies impulse. You filter this action with IsOnGround on both sides. Anyways it takes just a few lines of code. Just try it out.

Re: Time synchronization, Server/Client

Posted: Sun Nov 19, 2017 9:39 am
by namenotfound
From what I understand you're executing the whole spacebar charge logic on client and server? Why not just execute it only on the server? Obviously that would cause a delay, namely the time the RMIs take to travel to and from the server, but that's just the usual ping delay.

Re: Time synchronization, Server/Client

Posted: Sun Nov 19, 2017 10:00 am
by fury22uk
He did not do charge on both. He did charge on server, but what he did test charge time on both to see how much difference there would be.
And this is almost what I suggested. I just suggested sending time from client to server to make it feel more responsive, but yeah. You're perfectly right. The delay will not be bad, it will be usual ping delay.