wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
wowlib::formats::adt::detail::MapChunk< V > Struct Template Reference

A terrain chunk (MCNK) for one client version. More...

#include <wowlib/formats/adt/map_chunk.hpp>

Inheritance diagram for wowlib::formats::adt::detail::MapChunk< V >:

Public Member Functions

void validateExtra (ValidationReport &report) const
 Validation hook (see formats::detail::validateValue): the terrain chunk's contracts the annotations cannot express — the decoded alpha surfaces' fixed size and the layer/alpha relationship.
Result< void > readFrom (std::span< const std::byte > payload, FileKind kind, AlphaFormat af)
 Decode one physical file's portion of this terrain chunk into the accumulating entity, reflecting over the chunk()-annotated members.
Result< void > writeTo (FileBuffer &out, FileKind kind, AlphaFormat af) const
 Append this chunk's portion for kind to out (the MCNK payload; the caller wraps the fourcc+size).
bool operator== (const MapChunk &) const =default

Public Attributes

SMChunk header {}
 The chunk header (flags, grid position, area, holes, origin).
std::vector< float > heights
 The 9x9 + 8x8 = 145 terrain heights (MCVT), relative to the chunk origin, in the interleaved outer/inner row order.
std::vector< MCNREntry > normals
 The 145 terrain normals (MCNR), X Z Y signed bytes.
std::vector< SMLayer > layers
 The texture layers (MCLY); layer 0 is opaque, later layers blend through their alpha map.
std::vector< std::vector< std::uint8_t > > alphaMaps
 One decoded 64x64 (4096-byte) alpha map per layer, aligned with layers (layer 0's is empty); 0 = base texture, 255 = this layer.
std::vector< std::uint8_t > shadowMap
 The decoded 64x64 (4096-byte) shadow map (MCSH), 0/1 per texel; empty when the chunk casts no baked shadow.
std::vector< std::uint32_t > doodadRefs
 Doodad references (MCRF doodad part pre-Cata, MCRD Cata+): indices into the tile's MDDF placements drawn in this chunk.
std::vector< std::uint32_t > objectRefs
 Object references (MCRF object part pre-Cata, MCRW Cata+): indices into the tile's MODF placements drawn in this chunk.
std::vector< std::conditional_t<(V< builds::WotLK), CWSoundEmitterVanilla, CWSoundEmitter > > soundEmitters
 Sound emitters placed in this chunk (MCSE): pre-WotLK versions carry the full 52-byte inline emitter (CWSoundEmitterVanilla), WotLK+ the 28-byte SoundEntriesAdvanced reference (CWSoundEmitter).
ChunkBlob mcseRaw
 A malformed MCSE payload (not a whole number of entries), preserved verbatim — see detail::SoundEmitterCodec; empty whenever soundEmitters parsed.
std::array< std::uint8_t, 13 > mcnrPadding {}
 The 13 undeclared trailing bytes after the MCNR normals (a near-constant client pattern, not derived from the normals); preserved for the semantic round-trip.

Static Public Attributes

static constexpr ClientVersion Version = V
static constexpr std::array SubChunkOrder
 The canonical sub-chunk write order (excluding the references, which are the MCRF-vs-MCRD/MCRW special case, emitted last).

Detailed Description

template<ClientVersion V>
struct wowlib::formats::adt::detail::MapChunk< V >

A terrain chunk (MCNK) for one client version.

Instantiate through the canonicalizing adt::MapChunk alias.

Definition at line 374 of file map_chunk.hpp.

Member Function Documentation

◆ operator==()

template<ClientVersion V>
bool wowlib::formats::adt::detail::MapChunk< V >::operator== ( const MapChunk< V > & ) const
default

◆ readFrom()

template<ClientVersion V>
Result< void > wowlib::formats::adt::detail::MapChunk< V >::readFrom ( std::span< const std::byte > payload,
FileKind kind,
AlphaFormat af )

Decode one physical file's portion of this terrain chunk into the accumulating entity, reflecting over the chunk()-annotated members.

Parameters
payloadthe MCNK chunk payload from this file.
kindwhich physical file the portion came from.
afthe tile's alpha-map bit depth (supplied externally).
Returns
a structural error or success.

Definition at line 680 of file map_chunk.hpp.

References wowlib::formats::detail::annotation(), wowlib::ChunkTruncated, wowlib::formats::adt::chunks::DoNotFixAlphaMap, wowlib::formats::adt::fileHasHeader(), wowlib::formats::fourcc(), wowlib::formats::fourccToString(), wowlib::formats::hasFlag(), header, layers, wowlib::makeError(), wowlib::formats::detail::membersOf(), and wowlib::formats::detail::readValue().

◆ validateExtra()

template<ClientVersion V>
void wowlib::formats::adt::detail::MapChunk< V >::validateExtra ( ValidationReport & report) const
inline

Validation hook (see formats::detail::validateValue): the terrain chunk's contracts the annotations cannot express — the decoded alpha surfaces' fixed size and the layer/alpha relationship.

Contracts reaching into the TILE (layer texture ids, doodad and object references) belong to the ADT's validate(), which is where the texture and placement tables live.

Parameters
reportthe report findings land in.

Definition at line 449 of file map_chunk.hpp.

◆ writeTo()

template<ClientVersion V>
Result< void > wowlib::formats::adt::detail::MapChunk< V >::writeTo ( FileBuffer & out,
FileKind kind,
AlphaFormat af ) const

Append this chunk's portion for kind to out (the MCNK payload; the caller wraps the fourcc+size).

Header-bearing files emit the 128-byte header with every offset/size/count field freshly stamped.

Parameters
outthe destination buffer.
kindwhich physical file's portion to write.
afthe tile's alpha-map bit depth (supplied externally).
Returns
a structural error or success.

Definition at line 749 of file map_chunk.hpp.

References wowlib::formats::detail::annotation(), wowlib::formats::adt::detail::appendBytes(), wowlib::formats::adt::fileHasHeader(), header, wowlib::formats::detail::membersOf(), wowlib::formats::adt::Obj, wowlib::formats::adt::detail::AlphaCodec::prepare(), wowlib::formats::adt::routesTo(), SubChunkOrder, wowlib::formats::adt::Tex, and wowlib::formats::detail::writeValue().

Member Data Documentation

◆ alphaMaps

template<ClientVersion V>
std::vector<std::vector<std::uint8_t> > wowlib::formats::adt::detail::MapChunk< V >::alphaMaps

One decoded 64x64 (4096-byte) alpha map per layer, aligned with layers (layer 0's is empty); 0 = base texture, 255 = this layer.

Definition at line 414 of file map_chunk.hpp.

◆ doodadRefs

template<ClientVersion V>
std::vector<std::uint32_t> wowlib::formats::adt::detail::MapChunk< V >::doodadRefs

Doodad references (MCRF doodad part pre-Cata, MCRD Cata+): indices into the tile's MDDF placements drawn in this chunk.

Definition at line 422 of file map_chunk.hpp.

◆ header

The chunk header (flags, grid position, area, holes, origin).

Definition at line 398 of file map_chunk.hpp.

Referenced by readFrom(), and writeTo().

◆ heights

template<ClientVersion V>
std::vector<float> wowlib::formats::adt::detail::MapChunk< V >::heights

The 9x9 + 8x8 = 145 terrain heights (MCVT), relative to the chunk origin, in the interleaved outer/inner row order.

Definition at line 402 of file map_chunk.hpp.

◆ layers

template<ClientVersion V>
std::vector<SMLayer> wowlib::formats::adt::detail::MapChunk< V >::layers

The texture layers (MCLY); layer 0 is opaque, later layers blend through their alpha map.

Definition at line 410 of file map_chunk.hpp.

Referenced by readFrom().

◆ mcnrPadding

template<ClientVersion V>
std::array<std::uint8_t, 13> wowlib::formats::adt::detail::MapChunk< V >::mcnrPadding {}

The 13 undeclared trailing bytes after the MCNR normals (a near-constant client pattern, not derived from the normals); preserved for the semantic round-trip.

Read/written as part of MCNR by NormalCodec.

Definition at line 440 of file map_chunk.hpp.

◆ mcseRaw

A malformed MCSE payload (not a whole number of entries), preserved verbatim — see detail::SoundEmitterCodec; empty whenever soundEmitters parsed.

Definition at line 435 of file map_chunk.hpp.

◆ normals

template<ClientVersion V>
std::vector<MCNREntry> wowlib::formats::adt::detail::MapChunk< V >::normals

The 145 terrain normals (MCNR), X Z Y signed bytes.

Definition at line 406 of file map_chunk.hpp.

◆ objectRefs

template<ClientVersion V>
std::vector<std::uint32_t> wowlib::formats::adt::detail::MapChunk< V >::objectRefs

Object references (MCRF object part pre-Cata, MCRW Cata+): indices into the tile's MODF placements drawn in this chunk.

Definition at line 426 of file map_chunk.hpp.

◆ shadowMap

template<ClientVersion V>
std::vector<std::uint8_t> wowlib::formats::adt::detail::MapChunk< V >::shadowMap

The decoded 64x64 (4096-byte) shadow map (MCSH), 0/1 per texel; empty when the chunk casts no baked shadow.

Definition at line 418 of file map_chunk.hpp.

◆ soundEmitters

template<ClientVersion V>
std::vector<std::conditional_t<(V < builds::WotLK), CWSoundEmitterVanilla, CWSoundEmitter> > wowlib::formats::adt::detail::MapChunk< V >::soundEmitters

Sound emitters placed in this chunk (MCSE): pre-WotLK versions carry the full 52-byte inline emitter (CWSoundEmitterVanilla), WotLK+ the 28-byte SoundEntriesAdvanced reference (CWSoundEmitter).

Definition at line 430 of file map_chunk.hpp.

◆ SubChunkOrder

template<ClientVersion V>
std::array wowlib::formats::adt::detail::MapChunk< V >::SubChunkOrder
staticconstexpr
Initial value:
{
fourcc("MCVT"),
fourcc("MCCV"),
fourcc("MCLV"),
fourcc("MCNR"),
fourcc("MCLQ"),
fourcc("MCSE"),
fourcc("MCLY"),
fourcc("MCSH"),
fourcc("MCAL"),
fourcc("MCMT")
}
constexpr std::uint32_t fourcc(const char(&cc)[5], FourCCEndian endian=FourCCEndian::Reversed)
The host integer a scanned chunk id compares equal to for code cc.
Definition fourcc.hpp:33

The canonical sub-chunk write order (excluding the references, which are the MCRF-vs-MCRD/MCRW special case, emitted last).

Each physical file emits the subset routed to it, in this order — see writeTo.

Definition at line 384 of file map_chunk.hpp.

Referenced by writeTo().

◆ Version

template<ClientVersion V>
ClientVersion wowlib::formats::adt::detail::MapChunk< V >::Version = V
staticconstexpr

Definition at line 379 of file map_chunk.hpp.


The documentation for this struct was generated from the following file: