QtCraft API C++ classes QML types Handbook

QcGeneratedChunks Class

The index of the generated chunks of a world (decision E-946): every chunk that was ever in the world, whether its blocks changed or not, so a later generator change knows the explored area. More...

Header: #include <server/storage/QcGeneratedChunks.h>

Public Types

struct Opened

Public Functions

QByteArray bytes() const
QSet<QcChunkPos> chunks() const
bool contains(QcChunkPos chunk) const
bool isUnsaved() const
void note(QcChunkPos chunk)
qsizetype regionCount() const
void setUnsaved(bool unsaved)

Static Public Members

const QStringView fileName
const quint16 formatVersion
const QByteArrayView magic
const QStringView olderFileName
QcGeneratedChunks::Opened open(const QString &directory)
QcResult<QcGeneratedChunks> parse(const QByteArray &payload, const QString &path)

Detailed Description

It lives in the file generated.qcg of the world directory, written whole with a commit of QcChunkStore (and so through its journal):

QcSaveFile container (magic, formatVersion), payload: [quint32 region count] per region, sorted by z then x: [qint32 x][qint32 z][128 bytes, one bit per chunk slot (x + 32 * z within the region, lowest bit first)]

In memory it keeps the same bitmap per region. A world without the file starts with an empty index. Entries are only ever added.

Member Function Documentation

QByteArray QcGeneratedChunks::bytes() const

Returns the bytes of the file.

QSet<QcChunkPos> QcGeneratedChunks::chunks() const

Returns every chunk in the index (built from the bitmaps).

bool QcGeneratedChunks::contains(QcChunkPos chunk) const

Returns whether chunk is in the index.

bool QcGeneratedChunks::isUnsaved() const

Returns whether chunks were added since the index was last written or read.

void QcGeneratedChunks::note(QcChunkPos chunk)

Adds chunk; a chunk not in the index yet makes it unsaved.

[static] QcGeneratedChunks::Opened QcGeneratedChunks::open(const QString &directory)

Returns the index of the world directory directory (decision E-946): none without the file; a damaged file is kept aside (and removed once the copy exists) and the index starts empty; while generated.qcg has a newer format version it stays untouched, and the index is the one this build keeps in olderFileName.

[static] QcResult<QcGeneratedChunks> QcGeneratedChunks::parse(const QByteArray &payload, const QString &path)

Returns the index read from payload, the payload of the file path (named in messages); an error when it is damaged or names a region beyond the world.

qsizetype QcGeneratedChunks::regionCount() const

Returns the number of regions with chunks in the index.

void QcGeneratedChunks::setUnsaved(bool unsaved)

Sets whether chunks were added since the index was last written (unsaved).

See also isUnsaved().

Member Variable Documentation

const QStringView QcGeneratedChunks::fileName

Name of the file in the world directory.

const quint16 QcGeneratedChunks::formatVersion

The format version this build reads and writes.

const QByteArrayView QcGeneratedChunks::magic

The magic of the file.

const QStringView QcGeneratedChunks::olderFileName

Name of the file this build writes instead while generated.qcg has a newer format version, which it leaves alone (decision E-946).