Anyone know how to sync ODE physics or any physic objects over a network? What are best practices and rules of thumbs for establishing physics computations over a network? I think a pseudo-code approach would be just fine as this is a preliminary venture.
My thought is that, because different CPUs arrive at different compuations that one client’s race car will computed at a different location than what is represented on another client.
I hope my explanation is clear. thanks
Not necessarily. If the same computers are given the same parameters and the same formulas they will arrive at the same answer. I think the “random number generators” with the same seed will also give the same numbers on different computers, but do not quote me on this.
There are a number of games where each client computes its own and the other players’ postions/movements and such. Because they are deterministic they only transmit player changes. In the case of Darwinia on the Xbot the game only sends the actual key presses.
As long as you have a deterministic simulation you only need to transmit player changes, maybe with the occasional game state update to make sure no one is cheating
well darwina and physical simulations are a LOT different.
for physics simulations results can be simmilar. but especially in a racing simulation over network where you have delays and thus different positions for each object results can turn out to be very different.
guess easiest thing is to let the server handle the more important parts of it. (like the player positions). or let each client compute their own cars position and just hope that the physical results dont cause cars to intersect or otherwise cause havok. never worked with cars and physics over network, so i cant tell for sure. either way testing a few different approaches wouldnt hurt.
Here I am quoting you on it, sorry. But I wanted to point out that this is in fact untrue; there is usually no guarantee that a given random-number generator will produce the same results on different machines. The problem is that floating-point calculations themselves may be slightly different on different computers. Usually the difference is only in the lowest digit(s) and don’t matter much, but for a random number generator algorithm, those lowest digits can make a huge difference.
For this reason, Panda provides the direct.showbase.RandomNumGen module, which is implemented on top of the C++ Mersenne class, and which provides a random-number generator implemented with integer arithmetic instead of floating-point arithmetic. This random-number generator is guaranteed to give the same results on different computers, for the same initial seed.
Another reason why this is not true with physics simulations is that the results of all physics engines depend on the size of time steps. Different stepping can lead to slightly different results. Differences might by tiny, but if summed up over a long time they will become large enough to cause different decisions (collision of two nearby objects or not).
So maybe it is best if only one computer computes physics for an object. There are (at least) two top-level concepts to do this:
(1) One server and many clients:
The clients do no physics computations at all. They send input (player controls) to the server, the server does the physics computation for all objects, and then sends back the results (new positions and orientations) to all clients. The clients update their nodes, and just display them.
For such a top-level concept it would not be necessary to have Panda3D on the server. Just the physics simulation would be enough (Python + PyODE e.g., or even a game server written in Java). But running Panda3D on the server makes it more easy of course.
(2) Distributed simulation:
In this case you assign each (dynamic) object to exactly one computer who is “owning” the object. If you have non-player controlled cars than you can have one “AI” computer who owns all the non-player controlled cars. Every computer computes the physics results for the objects it owns, and only these objects. All other objects are unmovable by the physics engine (“kinematic”). Then, each computer publishes the results for it’s objects to all other computers, and they update their scene.
This second top-level concept is used for example by the SISO DIS (distributed interactive simulation) standard and by it predecessor SIMNET. SISO DIS is an industry standard, and thus has good documentation, but I don’t know how much of it is open to the public.