Jazz2::Editor::LevelThumbnail class

Draws a level small, a pixel for a tile in the average color of the tile.

The colors of the tiles are remembered, so a level is drawn again quickly. Indexed tiles are in the palette the level is shown in.

Public types

using TilePixels = Formats::LevelPreview::TilePixels
Pixels of a tile as stored in its tile set.

Public static functions

static auto GetSourceHash(const LevelDocument& document, TileSetDataCache& tileSets) -> std::uint64_t
Returns a hash of everything the colors of the tiles of a level depend on.
static void MakePreview(const LevelDocument& document, Tiles::TileMap* tileMap, TileSetDataCache& tileSets, SmallVectorImpl<std::uint8_t>& data)
Makes the preview of a level shown in the list of custom levels, see Formats::LevelFile::PreviewChunk.
static auto GetTilePixels(const LevelDocument& document, TileSetDataCache& tileSets, TileRef tile, TilePixels& result) -> bool
Finds the pixels of a tile, the first frame of an animated one, returns false for an empty or unknown one.

Constructors, destructors, conversion operators

LevelThumbnail(const LevelDocument& document, TileSetDataCache& tileSets)
Creates a new instance for a level, the tiles of its tile sets are read whole from tileSets.

Public functions

auto GetTileColor(TileRef tile) -> std::uint32_t
Returns the average color of a tile as R | G << 8 | B << 16 | A << 24, its alpha is how much of it is covered.
void DrawLayer(std::int32_t layer, SmallVectorImpl<std::uint32_t>& pixels)
Draws a layer, a pixel for each of its tiles, row by row.
void Clear()
Forgets the colors of the tiles, when the palette or the tile sets change.
auto Revalidate() -> bool
Forgets the colors of the tiles if what they're made of changed since the last call, returns true then.

Function documentation

static std::uint64_t Jazz2::Editor::LevelThumbnail::GetSourceHash(const LevelDocument& document, TileSetDataCache& tileSets)

Returns a hash of everything the colors of the tiles of a level depend on.

That's the palette the level is shown in, the tile sets and the data tileSets has for them — a tile set read again from its file is new data — their offsets, flags and remapping, the tiles stored in the level itself and the first frames of the animations. Hashing the tiles stored in the level takes a moment for a large set of them, so it's meant for once per change of the level, not for every frame.

static void Jazz2::Editor::LevelThumbnail::MakePreview(const LevelDocument& document, Tiles::TileMap* tileMap, TileSetDataCache& tileSets, SmallVectorImpl<std::uint8_t>& data)

Makes the preview of a level shown in the list of custom levels, see Formats::LevelFile::PreviewChunk.

What the game shows around the start of the level, see Formats::LevelPreview. The layers are placed as tileMap has them, if it's given, the indexed tiles are in the palette the level is shown in.

bool Jazz2::Editor::LevelThumbnail::Revalidate()

Forgets the colors of the tiles if what they're made of changed since the last call, returns true then.

Compares GetSourceHash() with the one of the last call. Meant to be called whenever the level changed, before it's drawn again; the colors of the tiles that stay the same are kept.