TD file format

Hello,

here is the structure of the TD-file as far as it is known to me:

A TD-file (*.td,*.tdl) is connected with a tile-definition of 512×512 length. The position of this tile is shown within the filename.

The file starts with a header of 54 bytes, which contain:
– the file-id (+cr/lf)
– 3 length-values (datalength at pos 50, datalength+5 at pos. 45, datalength+14 at pos. 36)
– some (for me) unknown values

The next byte represents the 4 sub-tiles of this tile (length: 256×256). It shows, if the tile is ‘divided’ (first 4 bits) or populated (second 4 bits).
If none of the first 4 bits is set, the file ends here. Then it describes 4 tiles of length 256×256, which may be populated.

If one (or more) of the first 4 bits is set, this tile is divided and the next byte represents, the FIRST of these sub-tiles. It shows, if this tile is divided into subtiles of length 128×128 or if it is populated. The above scheme is used to signal this.

This procedure continues until sub-tiles of length 1×1 are reached, which cannot be further divided, or until a controlbyte is reached, where none of the first 4 bits is set.

Then, the second of the sub-tiles is processed in the same way. (one level higher)

This continues until all defined sub-tiles of various length are processed. Then, all bytes of the file should be processed, too.

I hope this will help you.

regards
CarlosHR

PS.
The 4 subtiles are processed (from-> to): upper/left, lower/left, lower/right, upper/right

Using the Simis Editor at http://jgrmsts.codeplex.com/ I was able to complete the format of TD files.

/* File format information */
FILE = :terrain_desc .
FILE_NAME = “Tile Definition” .
FILE_EXT = “td” .
FILE_TYPE = “d” .
FILE_TYPE_VER = “1” .

/* Base types */
terrain_desc_tiles ==> :uint {:byte} .

/* Format types */
terrain_desc ==> :terrain_desc_tiles .

EOF /* End of file */

The following are defined in coreids.tok:
SIDDEF(SID_TERRAIN_DESC, “terrain_desc”)
SIDDEF(SID_TERRAIN_DESC_FLAGS, “terrain_desc_flags”)
SIDDEF(SID_TERRAIN_DESC_SIZE, “terrain_desc_size”)
SIDDEF(SID_TERRAIN_DESC_TILES, “terrain_desc_tiles”)

SID_TERRAIN_DESC = 0x84
SID_TERRAIN_DESC_TILES = 0x87

Using the documentation for the binary format at http://twpol.dyndns.org/weblog/2010/05/10/01

32 byte header
4 byte identifier for SID_TERRAIN_DESC
4 byte length
1 byte length for null string
4 byte identifier for SID_TERRAIN_DESC_TILES
4 byte length
1 byte length for null string
4 byte :uint count of bytes
variable number of bytes describing division and population of tiles

Source: TD file – TrainSim.Com

Leave a Reply