How to make Nape deterministic between plateforms

120 views
Skip to first unread message

Jin K

unread,
Aug 1, 2017, 8:53:10 AM8/1/17
to Nape Physics
First I want to say Nape is a blast, I'm super happy with it, thank you Luca !

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 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.

Here are a few things they say :

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.

T1m_

unread,
Aug 23, 2017, 7:12:34 AM8/23/17
to Nape Physics
I think there is no only way to do what you want. Here some:

1. run Nape on server side and send to clients data to visualize
2. run Nape on one of the client and send data to other client (bad approach, I believe)
3. run Nape on server side for gameplay-specifiec calculations. For additional non-gameplay features client can run physic simulation on its own side. Under the additional features I mean particles effects like breakable pieces of stage, opponent's teeth and so on.
4. run Nape on both server and client and periodically sync data.

Jin K

unread,
Sep 1, 2017, 3:01:47 AM9/1/17
to Nape Physics
Yes I know there are different ways to achieve this, but my personnal choice is deterministic lockstep because it just feels better for a fighting game like mine.
Fighting game needs the lowest latency, therefore most of them don't rely on server and just use P2P network model, like in my case.
Lockstep give the consistency needed between local and online gamefeel (no repositionning, no re-sync, consistency over combos)

I found out I can set options for the visual studio compilation and set strict floating point for example, that maybe fixed this issue as I think it would affect Nape Haxe code as well.
I still need to check with different devices to make sure.

Reply all
Reply to author
Forward
0 new messages