dELtaluca Messages: 2228 Registered: July 2010 Location: Malden Rushett, Surrey
Senior Member Administrator
Absolutely 'not' And this is the same for every physics engine, even Box2D in C++ is not 100% deterministic across different machines.
The reason is that floating point maths is not 100% the same on all cpu's, although the IEEE standard exists for floating point maths; the standard has various areas including sizes of intermediate calculations within the fpu which are open to variation which means you cannot guarantee floating point maths will gave the exact same answers on all cpus.
The only way to get around this is to use fixed point arithmetic (which is 'really' slow in comparison, and a 100% 'pita' since it is hugely limited in comparison to floats) or if it's a multiplayer game; to have the server do all the computation (like they would normally) and have clients only interpolate and guess-ahead until the updated positions are thrown back from server etc.
I'm guessing what you're wondering about is setting up a game level that depends on some sequence of physics interactions like a scripted cutscene?
I would suggest that you'd have to ensure that the same sequence still occurs in a reliable fashion after say a very small amount of randomisation to the input; or otherwise use key-frames where say on your computer you run the sequence; but record object parameters ever few frames so that you can sync the user's sequence to it forcefully or something like that.I created nape!
kod1234567 Messages: 14 Registered: January 2012 Location: South East England
Junior Member
Thank you for coming back so quickly. I always wonder if you're online 24/7 or whether you're on mobile constantly or something. ))
Hmm I absolutely forgot we are dealing with floats here... Must be the amount of overtime here at work that made me so dumb.
What I'm doing is a multiplayer game. I'm looking at different solutions to the network side of it. I'd really love to avoid the server/client approach, as I don't plan to invest into a dedicated server. Which leaves P2P. I got the Cirrus key, so this is becoming a reality now. While in a P2P scenario it's true one of the clients can act as a "server", it has its own caveats. Then there is full-mesh P2P, for example the RealtimeLib from Tom Krcha.
Synchronization is the key here. I'm thinking about temporarily disconnecting objects from their current nape space if a network info with a lower timestamp arrives, enforcing the action on all relevant objects then putting the objects back into space for the player to interact. I haven't tried it out in practice yet though.
I'm just trying to brainstorm here how to make the simulation run smoothly for all clients without too much interpolation and guessing.
barliesque Messages: 12 Registered: February 2012 Location: Los Angeles
Junior Member
This is an issue that I'd also like to solve somehow.
As for floats, isn't it possible to use a fixed-point datatype to ensure consistent calculations?
One solution I've been thinking about for reproducing a physics sequence would involve recording "key frames" at regular intervals, or maybe whenever a collision occurs. Then, the client doing the playback would attempt to let the physics engine do its thing, using the key frames to make corrections. The problem I'm anticipating is in applying the key frame data without causing the physics engine to freak out.
I should quickly add that I don't have anything nearly so complex in mind as that Acid Test simulation. ...I'm thinking of a game containing only a handful of dynamic objects.
dELtaluca Messages: 2228 Registered: July 2010 Location: Malden Rushett, Surrey
Senior Member Administrator
Yeh, fixed point can produce consistent calculations.... It's also a complete BITCH to try and fit it into something as complex as a physics engine and requires endless tweaking to ensure values are always as consistently sized as eachother and prevent overflows occuring, it would also make the code be a complete nightmare as every single operation like + - * / would have to be turned into a complex function call, not to mind that it would be ridiculously slow in comparison.
As long as the key frames aren't 'too' different it will be fine, especcialy with a handful of objects (maybe keyframes on a huuuge pyramid would be a bit more of an issue )I created nape!
barliesque Messages: 12 Registered: February 2012 Location: Los Angeles
Junior Member
Quote:
...every single operation like + - * / would have to be turned into a complex function call, not to mind that it would be ridiculously slow in comparison.
Ahhh. Yep, that makes sense.
Quote:
As long as the key frames aren't 'too' different it will be fine...
Excellent. I will proceed with confidence. Thanks.