3.6 KiB
3.6 KiB
Map file format
Overview
Format is little endian. It has following structure:
| Section |
|---|
| Header |
| Chunks data |
| Chunk headers |
Information about data types used in format:
| Name | Description |
|---|---|
| char string | Unterminated non-prefixed static size array of bytes |
| uint16 | Unsigned 16-bit integer |
| uint32 | Unsigned 32-bit integer |
| uint64 | Unsigned 64-bit integer |
Header
File header consists of following fields:
| Name | Size (bytes) | Type | Offset | Remarks |
|---|---|---|---|---|
| File magic | 7 | char string | 0 | It always has value polymap |
| Format version number | 2 | uint16 | 7 | For development version 0xFFFF number should be used |
| Chunk count | 4 | uint32 | 9 | |
| Chunk headers array offset | 8 | uint64 | 13 | Offset from beginning of file |
Single chunk data entry
Immediately after header chunk data array is located. Each entry has following structure:
| Name | Size (bytes) | Type | Offset | Remarks |
|---|---|---|---|---|
| Data | varying | uint8 array | 0 | Compressed chunk data of size specified earlier |
Single chunk header
| Name | Size (bytes) | Type | Offset | Remarks |
|---|---|---|---|---|
| Chunk X position | 4 | int32 | 0 | |
| Chunk Y position | 4 | int32 | 4 | |
| Chunk Z position | 4 | int32 | 8 | |
| Compression mode | 1 | uint8 | 12 | See Compression modes for possible values |
| Data size | 2 | uint16 | 13 | Size of compressed chunk data |
| Data offset | 8 | uint64 | 15 | Offset of chunk data in Chunk data file section |
Compression modes
0: No compression. Every node is stored using it's 16-bit ID1: Efficient Huffman coding. Node count is stored first then node ID, however following encoding is used to decrease size: node count is stored in first 7 bits in byte. Last bit is used to denote if count spans to next byte, if this is a case then that bit is high (1), else it's low (0). Because there are only 7 bits available maximum value that can be stored is127. Situation repeats for next bytes if last bit was1. Same applies to node ID.2: Fill. If chunk is filled with just one node type then the only thing that is stored is node ID as regular uint16.
Compression mode will be selected depending on which mode gives best result in particular case.