TileAtlas

Maps a block type to the UV rectangle of its texture icon in object-m.png, either as the sheet is or as the terrain's padded copy.

Headersrc/GalaxyEggbert/Game/TileAtlas.hpp
Sourcesrc/GalaxyEggbert/Game/TileAtlas.cpp
NamespaceGalaxyEggbert::Game
Former nameGETileAtlas

Purpose

Every terrain block is textured with one icon of the original's tile sheet Content/icons/object-m.png: 1301 × 1431 pixels, 64-pixel tiles with a 1-pixel gap before each, 20 columns by 22 rows (icons 0-439). TileAtlas is data only: it loads no pixels and draws nothing. GetTileUv() looks the block up in the BlockDefinitionRegistry, takes its textureIcon (which may differ from the block type) and returns that icon's rectangle.

Two layouts:

Collaborators

Public API

MemberWhat it does
enum class Layout { Sheet, Padded }Which texture the UVs are for.
TileAtlas(), explicit TileAtlas(Layout layout, int scale = 1)Default is Sheet at scale 1; a scale below 1 counts as 1.
CnaEngine::Graphics::UvRect GetTileUv(int blockType) constThe rectangle, or all zeros for air, negative or out-of-sheet types, unsupported types and types not textured from object-m.png.
int Scale() constThe texture scale given.
PaddedLayout Padded() const, static constexpr PaddedLayout PaddedLayoutFor(int scale)Tile, border, pitch, width and height of the padded sheet at a scale.
kPaddedBorder = 16, kPaddedPitch = 96, kPaddedColumns = 20, kPaddedRows = 22, kPaddedWidth, kPaddedHeightThe 1x padded layout's constants.

Free functions in the same header:

FunctionWhat it does
std::vector<std::uint8_t> BuildPaddedSheet(const std::uint8_t* sheetRgba, int width, int height, int scale = 1)The padded RGBA sheet from object-m.png's texels.
std::vector<std::uint8_t> DownsampleHalf(const std::vector<std::uint8_t>& rgba, int width, int height)The next mip level: each texel the mean of a 2 × 2 block.

How it is used

The game keeps two atlases (src/GalaxyEggbertCNA/GalaxyEggbertGame.hpp):

// Maps block types to object-m.png UV rects (plan.md E3D-MIG-053).
GalaxyEggbert::Game::TileAtlas tileAtlas_;
// The terrain's own padded, mipmapped copy of object-m.png and its UVs (TileAtlas.hpp Layout::Padded).
GalaxyEggbert::Game::TileAtlas terrainTileAtlas_{GalaxyEggbert::Game::TileAtlas::Layout::Padded};

At load it builds the padded texture with BuildPaddedSheet() and its mip chain with DownsampleHalf(), and hands terrainTileAtlas_ to every TerrainRenderer. A UV from one layout is only valid on that layout's texture; mixing them shows the wrong part of the sheet.

Icon 440. The block registry has entries 0-440, but the sheet holds 440 icons (0-439). Icon 440 has no rectangle; VerifyTileUvBounds keeps this as an explicit, tracked exception.

Tests

Related pages