Skip to content
aspadm edited this page Sep 24, 2018 · 6 revisions

На русском

Format: SEC

Description

Map chunk (section)

Structure

File contain one header:

struct header
{
    uint magic; // 74 F7 4B CF

    byte water;
};

After header lay data arrays:

struct vertex
{
    signed byte x_offset;
    signed byte y_offset;
    ushort altitude; // z coord

    uint packed_normal;
};

struct vertex land_vertex_array[33][33];

If water != 0 there are additional vertex table:

struct vertex water_vertex_array[33][33];

After that lay texture information:

ushort land_textures[16][16];

If water != 0 there are additional textures table:

ushort water_textures[16][16];

After that if water != 0:

uint water_visible[16][16]; // 1 if visible

Additional information

Normal unpacking

10 bits for z, 11 for x and y

uint packed_normal;

float x = ((float)((packed_normal >> 11) & 0x7FF) - 1000.0f) / 1000.0f;
float y = ((float)(packed_normal & 0x7FF) - 1000.0f) / 1000.0f;
float z = (float)(packed_normal >> 22) / 1000.0f;

Texture information

6 bits for tile index, 8 for texture number, 2 for rotation

ushort texture;

byte tile_index = f & 63;
byte texture_index = (f >> 6) & 255;
byte rotation = (f >> 14) & 3;

Getting landscape

Vertices are stored as 33 elements in each of 33 rows, i.e. forms 32x32 cells. Length of cell by side is 1 meter.
Vertex position:
x = x_index + x_offset / 254
y = y_index + y_offset / 254
z = altitude / 65535 * max_altitude (from .mp file)

Vertices are joined in polygons with saw-like pattern; 4 vertices forms 2 triangle polygons:

 0   1 2
   *-*-*
   |/|/| ~
33 *-*-*
   |/|/| ~
66 *-*-*
    ~ ~  ~

Texture lay on 4 cells, i.e. 16x16 tiles on map. Length of tile by side - 2 meters. Tile can be rotated by 0, 90, 180 or 270 degrees.

Clone this wiki locally