Ad

Is It Possible To Limit A JavaScript Variable Size In Bits?

- 1 answer

I am working on a networked game. Thus, I have to send information to clients many times a second. One of these pieces of information is position that is limited to a 500x500 field. It would be great if I could simply send 2.25 bytes (1.25 bytes per x/y). However, as far as I am aware, I am going to end up sending a massive floating point number.

So is there any to limit the numbers to a certain bit count?

Ad

Answer

There is not. As @Pointy states in the comments, your best simple bet is to send a typed Array to clients via WebSockets. You could also make some significant improvements to transmitted payload size using a custom compression algorithm if you know that the position matrix/Array will be very sparse.

Ad
source: stackoverflow.com
Ad