So I first asked this question on the nape forum to no answer so far.
But since this question is larger than just the physic engine, maybe some of you know a bit of the answer.
So I’m making an online multiplayer fighting game, physics are based on Nape (Haxe).
I figured how to make 2 games sync with deterministic lockstep locally. (Nape is already deterministic on the same computer, but I had to change Movieclip frame based)
It’s functionning and I have no desync between two games sending UPD packets, but again, that’s on the same computer.
Now I know it’s not going to work across different machines, but my question is, what would it take to make Nape and Haxe? deterministic between most machines, architecture ?
I’ve heard the problem is about floating points interpretation.
But in this article, developers achieved such a thing with their own engine and they seem to say the problem is not about floating points, could be compilation setup.
https://gafferongames.com/post/floating_point_determinism/
Is there a way to add compilation arguments to make sure it compile with internal precision set to 64 bits and “strict” IEEE 754 compliant mode ?
Here are a few things been said :
During development, we discovered that AMD and Intel processors produced slightly different results for trancendental functions (sin, cos, tan, and their inverses), so we had to wrap them in non-optimized function calls to force the compiler to leave them at single-precision
As long as you stick to a single compiler, and a single CPU instruction set, it is possible to make floating point fully deterministic. The specifics vary by platform (i e, different between x86, x64 and PPC). You have to make sure that the internal precision is set to 64 bits (not 80, because only Intel implements that), and that the rounding mode is consistent.
We did however have problems when using some physics APIs because their code did not have determinism or reproducibility in mind. For example some physics APIS have solvers that take X number of iterations when solving where X can be lower with faster CPUs.
I don’t think Nape has iterations based on cpu speed, that’s up to the “deltaTime, velocityIterations, positionIterations” l right ?
So if someone can help me go to the right direction, I would be grateful.
Thanks for your help.