schteppe / p2.js

JavaScript 2D physics library
Other
2.63k stars 329 forks source link

[QUESTION] multiplayer billiard game, forcing decimals #312

Closed enriqueto closed 6 years ago

enriqueto commented 6 years ago

Hi,

I need to make a multiplayer game and the results need to be exact the same on each client with independence of the floating point used. I know that p2.js is deterministic but the key issue here is decimals. The only possibility I can think of is to force p2.js to work with 4 or 5 decimals.

Is it there a simple way of inserting a function like this:

fixDecimals = function(n) { return isNaN(n) ? 0 : Math.round(1e4 *n)) / 1e4; }

each time a relevant calculation it's done? Where should I use it?

enriqueto commented 6 years ago

it looks like implementing that may be too complicated. I'll code a simple physics engine dealing with ball collisions.