QtCraft API C++ classes QML types Handbook

QcBlockStateTable Class

Runtime ids are block states: every block owns a contiguous range of ids, one per combination of its property values (the first property varies fastest). More...

Header: #include <common/content/blocks/QcBlockStateTable.h>

Public Functions

void append(const QcBlockDefinition &block, const QcShapeDefinition &shape)
void clear()
quint32 firstState(quint32 type) const
bool fits(std::optional<quint32> type, qsizetype boxes) const
qsizetype size() const
const QcBlockState &state(quint32 id) const
int stateCount(quint32 type) const
qsizetype totalDerivedBoxes() const
qsizetype typeCount() const
void update(quint32 type, const QcBlockDefinition &block, const QcShapeDefinition &shape)

Static Public Members

QcBlockState compute(const QcBlockDefinition &block, const QcShapeDefinition &shape, quint32 index)
qsizetype derivedBoxes(const QcBlockDefinition &block, const QcShapeDefinition &shape)
QString describe(const QcBlockDefinition &block, quint32 index)
const qsizetype maxDerivedBoxes
const qsizetype maxStates
const int maxStatesPerBlock
QString problem(const QcBlockDefinition &block)
qsizetype stateCountOf(const QcBlockDefinition &block)
QString value(const QcBlockDefinition &block, quint32 index, const QString &property)
std::optional<quint32> withValue(const QcBlockDefinition &block, quint32 index, const QString &property, const QString &value)

Detailed Description

The table holds the derived data of every state; it is rebuilt by the registry whenever definitions or shapes change.

Member Function Documentation

void QcBlockStateTable::append(const QcBlockDefinition &block, const QcShapeDefinition &shape)

Adds the states of the next block block with its resolved shape (type index = number of blocks added so far). Callers check fits() first.

void QcBlockStateTable::clear()

Removes all states and blocks.

[static] QcBlockState QcBlockStateTable::compute(const QcBlockDefinition &block, const QcShapeDefinition &shape, quint32 index)

Returns the derived data of state index of block with the resolved shape; exposed for tests.

[static] qsizetype QcBlockStateTable::derivedBoxes(const QcBlockDefinition &block, const QcShapeDefinition &shape)

Returns the number of boxes the distinct variants of the states of block derive from shape.

[static] QString QcBlockStateTable::describe(const QcBlockDefinition &block, quint32 index)

Returns the property values of state index of block as "[a=x,b=y]", or an empty string for blocks without properties.

quint32 QcBlockStateTable::firstState(quint32 type) const

Returns the runtime id of the first state of block type.

bool QcBlockStateTable::fits(std::optional<quint32> type, qsizetype boxes) const

Returns whether the table stays within maxDerivedBoxes when block type (or a new block for std::nullopt) derives boxes.

[static] QString QcBlockStateTable::problem(const QcBlockDefinition &block)

Returns why block cannot be used (too many properties, values or states), or an empty string.

qsizetype QcBlockStateTable::size() const

Returns the number of states of all blocks.

const QcBlockState &QcBlockStateTable::state(quint32 id) const

Returns the derived data of state id. Precondition: id < size().

int QcBlockStateTable::stateCount(quint32 type) const

Returns the number of states of block type.

[static] qsizetype QcBlockStateTable::stateCountOf(const QcBlockDefinition &block)

Returns the number of states of block: the product of its properties' value counts; 0 when a property has no values.

qsizetype QcBlockStateTable::totalDerivedBoxes() const

Returns the total of derivedBoxes() over all blocks in the table.

qsizetype QcBlockStateTable::typeCount() const

Returns the number of blocks in the table.

void QcBlockStateTable::update(quint32 type, const QcBlockDefinition &block, const QcShapeDefinition &shape)

Recomputes the states of the existing block type from block and shape; its state count must not have changed.

[static] QString QcBlockStateTable::value(const QcBlockDefinition &block, quint32 index, const QString &property)

Returns the value of property in state index of block, empty when the block has no such property.

[static] std::optional<quint32> QcBlockStateTable::withValue(const QcBlockDefinition &block, quint32 index, const QString &property, const QString &value)

Returns the state index of block that is state index with property set to value; std::nullopt for unknown properties or values.

Member Variable Documentation

const qsizetype QcBlockStateTable::maxDerivedBoxes

States of a block that turn, flip and select the same parts share their derived data; this limits the boxes of all distinct variants of all blocks together (memory and build time).

const qsizetype QcBlockStateTable::maxStates

Most states of all blocks together (65536).

const int QcBlockStateTable::maxStatesPerBlock

Most states of one block (Signal Dust needs 16 strengths times 81 connection shapes, decision E-334).