Jump to content

Tile map file: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 13: Line 13:
<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
struct TilemapHeader {
struct TilemapHeader {
   /* offset 0x00 */ char magic[2]; // Always the two ASCII characters "MP"
   /* offset 0x00 */ char magic[2];     // Always the two ASCII characters "MP"
   /* offset 0x02 */ u16 unknown_0x02;
   /* offset 0x02 */ u16 unknown_0x02;
   /* offset 0x04 */ u16 layerCount; // Number of layers in this file
   /* offset 0x04 */ u16 layerCount;   // Number of layers in this file
   /* offset 0x06 */ u16 tileCount; // Number of tiles in this file's tileset (if it exists)
   /* offset 0x06 */ u16 tileCount;     // Number of tiles in this file's tileset (if it exists)
   /* offset 0x08 */ u32 unknown_0x08;
   /* offset 0x08 */ u32 metatileCount; // Number of metatiles in this file


   // Byte offset from start of this struct to the layerDefinitions[] array
   // Byte offset from start of this struct to the layerDefinitions[] array
Line 29: Line 29:
   /* offset 0x14 */ u32 offsetToMetatiles;
   /* offset 0x14 */ u32 offsetToMetatiles;


   // TODO: how are these ordered?
   TilemapLayer layerDefintions[layerCount];


   TilemapLayer layerDefintions[layerCount];
   // Only if offsetToTiles != 0. Array of 8x8 px 4 bpp GBA tiles to use.
  u8 tileset[][32];


   // Each metatile contains four GBA BG screen entries:
   // Each metatile contains four GBA BG screen entries:
Line 38: Line 39:
   // For each metatile, element 0=top left, 1=top right, 2=bottom left, 3=bottom right.
   // For each metatile, element 0=top left, 1=top right, 2=bottom left, 3=bottom right.
   u16 metatiles[][4];
   u16 metatiles[][4];
  // Only if offsetToTiles != 0. Array of 8x8 px 4 bpp GBA tiles to use.
  u8 tileset[][32];


   // Each layer is an array of TilemapLayer.width * TilemapLayer.height metatile numbers,
   // Each layer is an array of TilemapLayer.width * TilemapLayer.height metatile numbers,
   // in row-major order.
   // in a specific order (see "Layer data order" section below).
   // Each individual u16 in this array references a metatile, which is 16x16 px in size.
   // Each individual u16 in this array references a metatile, which is 16x16 px in size.
   u16 layerData[][];
   u16 layerData[];
};
};


Line 57: Line 55:
};
};
</syntaxhighlight>
</syntaxhighlight>
= Layer data order =
The metatile data of each layer is stored in a particular order:
# First, the entire layer is divided into blocks of 16x16 metatiles (= 256x256 px).
# Each of those blocks is stored sequentially in the layer data, in row major order.
# ''Within each 16x16 block'', the individual metatiles are also laid out in row major order.
This implies that the width and the height of each layer must be evenly divisible by 16 metatiles.
As an example, let's look at a layer that's 32x32 metatiles in size. There are 4 blocks in this layer. First, the top left quarter of the layer is stored in its entirety in the tile map file, followed by the top right quarter, followed by the bottom left quarter, and finally the bottom right quarter.


[[Category:Documentation]] [[Category:File formats]]
[[Category:Documentation]] [[Category:File formats]]
[[Category:Boktai 1]] [[Category:Boktai 2]] [[Category:Boktai 3]]
[[Category:Boktai 1]] [[Category:Boktai 2]] [[Category:Boktai 3]]