Jazz2::Formats::LevelReader class

Reads the body of a level, section by section.

The sections have to be read in the order they are declared in, every one of them, because the body is a single compressed stream. The input is buffered, so reading a value doesn't go through the decompressing stream every time.

Constructors, destructors, conversion operators

LevelReader(Stream& s, const LevelHeader& header)
Starts reading the body, the stream is left after the header by LevelFile::ReadHeader().
LevelReader(const LevelReader&) deleted

Public functions

auto operator=(const LevelReader&) -> LevelReader& deleted
auto IsValid() const -> bool
Returns false if the body is truncated or corrupted.
auto GetError() const -> StringView
Returns why the body couldn't be read, empty if it could.
auto GetHeader() const -> const LevelHeader&
Returns the header the body belongs to.
void ReadProperties(LevelProperties& properties)
Reads the level properties.
auto ReadPalettes(std::uint32_t* levelPalette, SmallVectorImpl<PaletteRecord>* additionalPalettes) -> bool
Reads the level palette and the additional palettes.
void ReadExtraTileSets(SmallVectorImpl<ExtraTileSetRecord>& tileSets)
Reads the extra tile sets.
void ReadTileDiffuseOverrides(SmallVectorImpl<TileDiffuseOverride>* overrides)
Reads the overridden tile diffuse, nullptr skips them.
void ReadTileMaskOverrides(SmallVectorImpl<TileMaskOverride>* overrides)
Reads the overridden tile masks, nullptr skips them.
void ReadTexts(SmallVectorImpl<String>& texts)
Reads the level texts.
void ReadAnimatedTiles(std::uint16_t& animatedTilesOffset, SmallVectorImpl<AnimatedTileRecord>& animatedTiles)
Reads the first animated tile ID and the animated tiles.
auto ReadLayerCount() -> std::int32_t
Reads the number of layers.
void ReadLayerHeader(LayerRecord& layer)
Reads the description of the next layer, its tiles have to be read next.
void ReadLayerTiles(const LayerRecord& layer, Function<void(std::int32_t, ArrayView<const TileRecord>)>&& callback)
Reads the tiles of the layer whose description was read last.
void ReadEvents(std::int32_t width, std::int32_t height, Function<void(std::int32_t, std::int32_t, const EventRecord&)>&& callback)
Reads the event grid.
void ReadOffGridEvents(SmallVectorImpl<OffGridEventRecord>& events)
Reads the off-grid events.
auto SkipToChunks() -> bool
Skips all sections after the level properties, so ReadChunks() can be called next.
void ReadChunks(SmallVectorImpl<ChunkRecord>& chunks, bool includeEditorOnly, ArrayView<const std::uint32_t> knownCriticalChunks = {})
Reads the optional chunks at the end of the body.
void ReadSelectedChunks(SmallVectorImpl<ChunkRecord>& chunks, Function<bool(std::uint32_t, std::uint32_t)>&& select, ArrayView<const std::uint32_t> knownCriticalChunks = {})
Reads only the chunks select returns true for, skipping the others without keeping their payload.
auto SkipChunks(ArrayView<const std::uint32_t> knownCriticalChunks = {}) -> bool
Skips the optional chunks at the end of the body, only checking them.

Function documentation

bool Jazz2::Formats::LevelReader::ReadPalettes(std::uint32_t* levelPalette, SmallVectorImpl<PaletteRecord>* additionalPalettes)

Reads the level palette and the additional palettes.

The level palette is stored only with LevelFlags::UseLevelPalette, so levelPalette (256 entries) is filled only then, which is what the return value tells. Either pointer may be nullptr to skip it.

void Jazz2::Formats::LevelReader::ReadLayerTiles(const LayerRecord& layer, Function<void(std::int32_t, ArrayView<const TileRecord>)>&& callback)

Reads the tiles of the layer whose description was read last.

The tiles are handed over in blocks, the callback gets the index of the first tile of the block (row by row) and the tiles. Without a callback the tiles are skipped.

void Jazz2::Formats::LevelReader::ReadEvents(std::int32_t width, std::int32_t height, Function<void(std::int32_t, std::int32_t, const EventRecord&)>&& callback)

Reads the event grid.

It has the size of the sprite layer. The callback is called for every tile, empty ones included.

bool Jazz2::Formats::LevelReader::SkipToChunks()

Skips all sections after the level properties, so ReadChunks() can be called next.

For a reader that needs only the properties and the chunks, as a preview of the level. The data of embedded tile sets is skipped without being kept. Returns false if the body is truncated or corrupted.

void Jazz2::Formats::LevelReader::ReadChunks(SmallVectorImpl<ChunkRecord>& chunks, bool includeEditorOnly, ArrayView<const std::uint32_t> knownCriticalChunks = {})

Reads the optional chunks at the end of the body.

Editor-only chunks (see LevelFile::IsEditorOnlyChunk()) are skipped unless includeEditorOnly is set. A critical chunk (see LevelFile::IsCriticalChunk()) not listed in knownCriticalChunks makes the body invalid, the level must not be used then.

void Jazz2::Formats::LevelReader::ReadSelectedChunks(SmallVectorImpl<ChunkRecord>& chunks, Function<bool(std::uint32_t, std::uint32_t)>&& select, ArrayView<const std::uint32_t> knownCriticalChunks = {})

Reads only the chunks select returns true for, skipping the others without keeping their payload.

select gets the tag and the size of the payload of each chunk, editor-only ones too. Critical chunks are checked as by ReadChunks().

bool Jazz2::Formats::LevelReader::SkipChunks(ArrayView<const std::uint32_t> knownCriticalChunks = {})

Skips the optional chunks at the end of the body, only checking them.

For a reader that needs none of them. Returns false if the body is truncated or corrupted, or if it has a critical chunk not listed in knownCriticalChunks.