Jazz2::Tiles::TileSet class

Represents tile set used by tile map, consists of texture and collision mask.

Holds the source texture and the per-tile collision masks for a single tile set, providing lookups for a tile's mask and texture coordinates. A tile map references one or more of these to render and collide its layers; textures may be true-color or indexed for palette recoloring.

Public static variables

static std::int32_t DefaultTileSize constexpr
Size of a tile.
static std::int32_t MaskBytesPerTile constexpr
Byte size of one tile's packed collision mask (1 bit per pixel, LSB-first, row-major - the cache file format).

Public static functions

static auto GetTileMaskRow(const std::uint8_t* packedMask, std::int32_t y) -> std::uint32_t
Returns one row of a packed tile mask as a 32-bit word (bit x set = column x solid).
static auto IsTileMaskBitSet(const std::uint8_t* packedMask, std::int32_t x, std::int32_t y) -> bool
Returns whether pixel (x, y) of a packed tile mask is solid.

Constructors, destructors, conversion operators

TileSet(StringView path, std::uint16_t tileCount, SmallVector<std::unique_ptr<Texture>, 1>&& textureDiffuse, std::unique_ptr<std::uint8_t[]> mask, std::uint32_t maskSize, std::unique_ptr<Color[]> captionTile, const std::uint8_t* tileDiffuseOpaque = nullptr)
Creates a new instance.

Public functions

auto ResolveTextureDiffuse(std::int32_t& tileId) const -> Texture*
Resolves the diffuse texture chunk containing tileId, rebasing the ID into the chunk's local space (mirrors TileMap::ResolveTileSet).
auto GetTextureCount() const -> std::int32_t
Returns the number of diffuse texture chunks (1 unless the device texture-size limit forced a split).
auto GetTileMask(std::int32_t tileId) const -> const std::uint8_t*
Returns the packed mask (MaskBytesPerTile bytes, 1 bit per pixel) for the specified tile.
auto IsTileMaskEmpty(std::int32_t tileId) const -> bool
Returns true if the mask of a tile is completely empty.
auto IsTileMaskFilled(std::int32_t tileId) const -> bool
Returns true if the mask of a tile is completely filled (non-empty).
auto IsColumnContiguous(std::int32_t tileId) const -> bool
Returns true if every column of the tile's mask is vertically contiguous (no gaps).
auto GetColumnSpans(std::int32_t tileId) const -> const std::uint8_t*
Returns per-column solid spans for a tile.
auto IsTileFilled(std::int32_t tileId) const -> bool
Returns true if the texture of a tile is completely opaque (non-transparent).
auto GetCaptionTile() const -> StaticArrayView<DefaultTileSize*DefaultTileSize, Color>
Returns a caption tile.
auto OverrideTileDiffuse(std::int32_t tileId, StaticArrayView<(DefaultTileSize+2)*(DefaultTileSize+2), std::uint32_t> tileDiffuse) -> bool
Overrides the diffuse texture of the specified tile.
auto OverrideTileMask(std::int32_t tileId, StaticArrayView<DefaultTileSize*DefaultTileSize, std::uint8_t> tileMask) -> bool
Overrides the collision mask of the specified tile.

Public variables

String FilePath
Relative path to source file.
SmallVector<std::unique_ptr<Texture>, 1> TextureDiffuse
Main (diffuse) texture(s): a single texture normally, consecutive row-band chunks when the device texture-size limit forced a split.
std::int32_t TileCount
Total number of tiles.
std::int32_t TilesPerRow
Number of tiles per row.
std::int32_t TilesPerTexture
Number of tiles covered by each diffuse texture chunk (0 when untextured/headless).
bool IsIndexed
Whether TextureDiffuse stores raw palette indices instead of baked colors.

Function documentation

Jazz2::Tiles::TileSet::TileSet(StringView path, std::uint16_t tileCount, SmallVector<std::unique_ptr<Texture>, 1>&& textureDiffuse, std::unique_ptr<std::uint8_t[]> mask, std::uint32_t maskSize, std::unique_ptr<Color[]> captionTile, const std::uint8_t* tileDiffuseOpaque = nullptr)

Creates a new instance.

Parameters
path Relative path to the source file
tileCount Total number of tiles
textureDiffuse Main (diffuse) texture, or several row-band chunks when the device texture-size limit forced a split (see ContentResolver::BuildTilesetDiffuse)
mask Packed collision mask of all tiles (MaskBytesPerTile bytes each)
maskSize Size of the packed collision mask in bytes
captionTile Pixels of the caption tile
tileDiffuseOpaque Optional table marking fully opaque tiles

Texture* Jazz2::Tiles::TileSet::ResolveTextureDiffuse(std::int32_t& tileId) const

Resolves the diffuse texture chunk containing tileId, rebasing the ID into the chunk's local space (mirrors TileMap::ResolveTileSet).

The returned texture's tile grid starts at the rebased tileId 0, so the usual (tileId % TilesPerRow, tileId / TilesPerRow) UV math applies against ITS size. Returns nullptr when untextured (headless) or out of range.

bool Jazz2::Tiles::TileSet::IsColumnContiguous(std::int32_t tileId) const

Returns true if every column of the tile's mask is vertically contiguous (no gaps).

Contiguity allows replacing the per-pixel collision scan with an exact per-column span test.

const std::uint8_t* Jazz2::Tiles::TileSet::GetColumnSpans(std::int32_t tileId) const

Returns per-column solid spans for a tile.

2 bytes per column (first solid row, last solid row); a first row of 0xFF marks an empty column. Only meaningful when IsColumnContiguous() returns true.

Variable documentation

bool Jazz2::Tiles::TileSet::IsIndexed

Whether TextureDiffuse stores raw palette indices instead of baked colors.

Indexed tiles (red channel holds the index) are recolored at draw time through the palette shaders. false for tilesets containing 32-bit true-color tiles.