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:
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?