# Delta compressed world state when networking in JavaScript

Lets say we send a snapshot from the server to the clients about world details, containing object positions, velocities etc, every second. We should send only delta-data based on the previous snapshot that was sent.

For example, if the player moved from (x:50, y:0) to (x:100, y:0), then the snapshot will only contain (move_x:50: move_y:0), and the clients will add the previous position and move_x. We should sending delta values, as it is less data to send.

How do I achieve this in Javascript?

My objects already have data stored in Float32 (by TypedArray) and there is no Float16 data type in JavaScript.

For example:

delta = currentPos - prevPos
20 = 100 - 80


okey, now I have 20 instead of 80, but this isn't less data to send.. still both will be send as Float32.

data.writeFloat32(delta); //for simplesness


there is no Float16 and I am afraid that even if JS will has Float16 TypedArrays, then it still would be not enough, because for example 20.3454356 from Float32 to Float16 will lose precision to lets say sth like 20.34, or I'm wrong?

How to send delta data in JS and gain the benefits of this technique in JS?

• Please note that I have removed the component requesting additional explanation of the floating precision of float32. You can ask multiple questions as multiple questions, or in direct relation to the core question. I see no relation when you specifically say you dont have access to float16, regardless of the additional understanding. Jan 16 '17 at 3:00
• It also occurs to me that, as its own question, you should ask about floating precision at StackOverflow. Jan 16 '17 at 3:06
• What exactly are you having trouble with? This question seems kind of broad at the moment. Jan 16 '17 at 10:55