Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Box2D perfectly deterministic?

I'm writing an Android game using LibGDX and Box2D. I'm planning on adding a turn-based multiplayer feature to it.

Now, if on both clients I step the Box2D world at the same rate with the same time steps and I start a simulation on both clients with the exact same initial parameters, when the simulations are over, will the final state of both simulations be exactly the same? In other words, is a Box2D simulation perfectly deterministic?

If it's not, then that means every time a simulation is over, one client acting as a host will have to tell the other to throw away its final simulation's results and use its instead.

like image 959
AxiomaticNexus Avatar asked Jun 05 '15 19:06

AxiomaticNexus


1 Answers

Official FAQ quote

The official FAQ had a quote that confirms what you deduced http://web.archive.org/web/20160131050402/https://github.com/erincatto/Box2D/wiki/FAQ#is-box2d-deterministic:

Is Box2D deterministic?

For the same input, and same binary, Box2D will reproduce any simulation. Box2D does not use any random numbers nor base any computation on random events (such as timers, etc).

However, people often want more stringent determinism. People often want to know if Box2D can produce identical results on different binaries and on different platforms. The answer is no. The reason for this answer has to do with how floating point math is implemented in many compilers and processors. I recommend reading this article if you are curious: http://www.yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html

Or in other words: Fixed-size floating point types

Why the wiki was deleted, I do not know. Humans. I'm glad he lowercased the project name though.