4
\$\begingroup\$

I want to create a multiplayer game with HTML/JavaScript and only send user input between players. I read some articles for C++, saying that I could not expect floating point to get the same results on different binaries/machines. I expect the situation to be no better in JavaScript.

Do I need to use fixed point? Assuming fixed point is the way, can I calculate e.g. (estimated reciprocal) square roots using floating point functions exposed thru JavaScript, and then apply something akin to rounding to get determinism?

\$\endgroup\$

closed as off-topic by Anko, MichaelHouse Mar 12 '14 at 14:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Anko, MichaelHouse
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Not necessarily an exact duplicate, but definitely related: Elegant workaround for JavaScript floating point number problem \$\endgroup\$ – Mario Mar 12 '14 at 9:14
  • \$\begingroup\$ A few considerations: 1) if your users send messages to each other an not through your server, you open a security risk as now your user know stuff about others and 2) if you're sending your data through HTTP, keep in mind that the second T of HTTP stands for Text, in which case your numbers are converted to text before being sent. In c++, this concern is also valid for integer numbers as well and it has to do with endianness, from what I recall. \$\endgroup\$ – Alexandre Vaillancourt Mar 12 '14 at 11:22
0
\$\begingroup\$

JavaScript as a language does not support any number formats but 64 bit floating point numbers so you can't use true integers (integers in the range of -2^53 to 2^53 can be accurately represented).

Most likely it would be possible to make floating point numbers "act" deterministic through proper rounding and other techniques, however this will require a lot of discipline to make and be very hard to debug. Even big game developers like Blizzard struggle with making a game that functions correctly from solely the player inputs.

The problem with floating point differences between computers aren't that big, the problem is they accumulate over time and get worse as play progresses, probably the easiest thing to do would be to send player input every network tick and send the variables (position, orientation, etc) of part of the game objects along with it. That way you keep bandwidth minimal while keeping the game visually consistent.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.