Danielv123 / gridworld

Automatic creation of distributed factorio gridworlds connected using edge_transports
4 stars 0 forks source link

Optimize sending map data by using binary strings #33

Open Danielv123 opened 4 months ago

Danielv123 commented 4 months ago

Currently the colors for map data is sent as hexadecimal strings where 8 bytes are used to represent color: AABBCCDD for rgba. Lua and factorio supports putting binary data in strings using string.char(0-255) which allows us to compress it to 4 bytes.

For additional compression we could also take advantage of the actual color palette in use being far more restricted by finding all relevant map colors, transferring them to the controller once and then using a single byte to index the color. This would give us a nice and compact 1 byte per tile for dump_mapview.

Similar reductions can also be done to the position coordinates. Currently the position is sent as a string, but sending long decimal numbers as strings takes a lot of space. The position could be sent losslessly as 2x8 bytes or truncated as 2x4 bytes, bringing us to a worst case of 9 bytes per tile before compression.