Networking sync

OvermindDL1

19-04-2006 18:08:02

I've started putting networking in my playground of code, and to network the physics engine I have everything timestamped (which already accounts for lag on the network and different times on computers and adjusts accordingly) and I will be transfering forces and on occasion, position and such. When I get an update of forces and position that is set say 80ms in the past, should I just keep a record of all physics movements for the past, say, quarter second, and reset it back to that point, replaying the forces on it adding those forces (overwriting a force if it would of been the same), or does Newton/OgreNewt have things for that already that I cannot find?

Also, is there any way to timestep up a single object for a few frames to accellerate it back to the present? Yes I know all the issues that can occur, but I just want to keep the client *mostly* synced with objects near it. Objects far away or out of view do not even recieve updates, and the server always has the master, authoritive, and final copy. So I just need the clients to *look* synced, even if they are horribly not.

walaber

19-04-2006 18:54:01

unfortunately there is no way to update a single object safely (what would happen if it collided with other objects during the update?)...

there are also no built-in ways to rewind the simulation, etc.

OvermindDL1

19-04-2006 19:57:23

So do a combonation of manual interpolation and guesstimation for where things should presently go then?

And I don't really care about pure syncronization on the client, just as long as it looks close enough and moves well enough till it gets the next authoritative update.

walaber

19-04-2006 20:23:26

what I have found is that basically you get a packet with the exact position/orientation/vel/omega for a body, and then you set it there manually, and let Newton interpolate until you get another packet.

if you want to make up for lost time, you could apply your own simple integration. for example, if you know the position and velocity, and that the packet is 30ms old, you could apply 30ms of that velocity, and then get a new projected position for the object, and set it there (also setting the velocity). then Newton will handle moving the object until another packet comes in.

you would need to do the same for orientation / omega as well, but it should be pretty simple.

since the server is the authority, the clients will always be "behind" the servers simulation... you would need to run some tests, but I think a technique like this could work.

OvermindDL1

19-04-2006 23:46:17

That is exactly how I was writing it actually, and why I was wondering if there was a way to apply a force at a point and let the engine say where it should be so much time after that so I would not have to do my own, obviously inaccurate calculations. Thanks much.

Project5

20-04-2006 15:25:00

I'm keeping track of every object's state for every physics tick, and know the time between ticks because the timestamp is constant.

So when I get an update in the past, I rewind every object to that time in the past, write the archived states to Newton, and then play the simulation to the present, overwriting the old archived states as necessary.

It avoids the whole mess of trying to compute physics on your own, which is why we're all using Newton in the first place :-)

The downside is that it uses a good bit of memory... about 16 to 18kb per object that needs a history, depending on the number of points to trace back in the past.

www.gaffer.org has a great series of articles on how to put together such a system.

--Ben

OvermindDL1

21-04-2006 01:46:49

Yea, that is what I had been setting up, as per my comment on keeping the history for a good half second or so. Thanks for the link will read through when I get a free moment.

praetor

21-04-2006 21:38:06

You could keep the client "up" with the server by implementing extrapolation instead of interpolation. Might be more work than it's worth, but it's a possibility.