Jazz2::Formats::TileSetFile struct

Layout of the game's own tile set format.

A tile set is converted once from the original .j2t (see Compatibility::JJ2Tileset::Convert()), or saved by the tile set editor, and then read by the game in this form. The game reads it through ContentResolver::RequestTileSet(), which builds the atlas a band of tiles at a time, the editor and the converter through Read() and Write().

Public static variables

static std::uint64_t Signature constexpr
First part of the signature.
static std::uint16_t Signature2 constexpr
Second part of the signature.
static std::uint8_t CurrentVersion constexpr
Version this build writes, and the only one it reads.
static std::uint8_t HasMask constexpr
The masks are stored.
static std::uint8_t HasPalette constexpr
The palette is stored.
static std::uint8_t ImageLz4 constexpr
The image content is in LZ4 blocks, see Compatibility::JJ2Anims::ImageContentLz4Flag.
static std::int32_t TileSize constexpr
Size of a tile in pixels.
static std::int32_t MaskBytesPerTile constexpr
Size of the collision mask of a tile in bytes.
static std::uint32_t MaxImageWidth constexpr
Largest width of the image content in pixels.

Public static functions

static auto ReadHeader(Stream& s, TileSetHeader& header) -> bool
Reads the uncompressed header of a tile set.
static auto Validate(const TileSetHeader& header, std::int64_t remainingBytes = -1) -> bool
Returns true if a header describes a tile set every reader can take.
static auto GetBestColumnCount(std::int32_t tileCount) -> std::int32_t
Returns how many tiles a row of the image content should hold.
static auto Read(Stream& s, TileSetData& data) -> bool
Reads a whole tile set, including the pixels of all tiles.
static auto ReadPalette(Stream& s, std::uint32_t* palette) -> bool
Reads only the palette of a tile set, as TileSetData::Palette, returns false if the stream doesn't hold a tile set.
static auto Write(Stream& s, const TileSetData& data, bool lz4 = false) -> bool
Writes a whole tile set.

Function documentation

static bool Jazz2::Formats::TileSetFile::ReadHeader(Stream& s, TileSetHeader& header)

Reads the uncompressed header of a tile set.

Leaves the stream at the start of the deflated block. Returns false if the stream doesn't hold a tile set of CurrentVersion, or if the header isn't valid (see Validate()).

static bool Jazz2::Formats::TileSetFile::Validate(const TileSetHeader& header, std::int64_t remainingBytes = -1)

Returns true if a header describes a tile set every reader can take.

One or four channels, the image a whole number of tiles in both directions and not wider than MaxImageWidth, at least one tile with a cell for every tile and not much more than the tiles the count can hold. With remainingBytes not negative, the deflated block also has to fit into them. Everything that reads a tile set relies on it, a tile set can come from a level, which can come from anywhere.

static std::int32_t Jazz2::Formats::TileSetFile::GetBestColumnCount(std::int32_t tileCount)

Returns how many tiles a row of the image content should hold.

Chooses the layout whose image wastes the least space once rounded up to power-of-two dimensions, within 1024x1024 where the tiles fit into it. No texture is decided by it, the game copies every tile into an atlas of its own, so it only keeps the file small.

static bool Jazz2::Formats::TileSetFile::Read(Stream& s, TileSetData& data)

Reads a whole tile set, including the pixels of all tiles.

Returns false if the stream doesn't hold a tile set, or holds one in LZ4 and this build can't decode it.

static bool Jazz2::Formats::TileSetFile::Write(Stream& s, const TileSetData& data, bool lz4 = false)

Writes a whole tile set.

The image content has a single index channel if no tile is a true color one, RGBA otherwise. With lz4, which requires LZ4 support in the build, it's written in LZ4 blocks.