QtCraft API C++ classes QML types Handbook

QcFireQueue Class

The burning fires of the loaded world and when each takes its next step (decision E-392): one entry per fire block, ordered by due tick, so a tick only looks at the fires that are due and costs the same in a world of any size. More...

Header: #include <server/blocks/QcFireQueue.h>

Public Types

struct Fire
struct Limits
struct Saved

Public Functions

QcFireQueue()
QcFireQueue(std::vector<bool> fire, std::vector<bool> eternalGround)
bool add(const QcFireQueue::Fire &fire)
bool contains(QcBlockPos pos) const
qsizetype countIn(QcChunkPos chunk) const
qsizetype counted() const
void drop(QcBlockPos pos)
qsizetype dueCount(quint64 now) const
std::optional<QcFireQueue::Fire> entry(QcBlockPos pos) const
QList<QcFireQueue::Fire> fires() const
void forgetChunk(QcChunkPos pos)
bool hasDue(quint64 now) const
bool hasRoom(QcChunkPos chunk) const
bool isEternalGround(QcBlockId block) const
bool isFire(QcBlockId block) const
const QcFireQueue::Limits &limits() const
void noteBlock(QcBlockPos pos, QcBlockId before, QcBlockId block)
void noteChunk(QcChunkPos pos, const QcChunk &chunk, quint32 sections)
bool plan(const QcFireQueue::Fire &fire)
qsizetype refusedCount() const
void restore(const QList<QcFireQueue::Saved> &fires, quint64 now, const QcChunk &chunk)
QList<QcFireQueue::Saved> savedOf(QcChunkPos chunk, quint64 now) const
void setLimits(QcFireQueue::Limits limits)
qsizetype size() const
QList<QcFireQueue::Saved> takeChunk(QcChunkPos chunk, quint64 now)
std::optional<QcFireQueue::Fire> takeDue(quint64 now)
QList<QcBlockPos> takeRefused()
QList<QcBlockPos> takeUnplanned()
qsizetype unplannedCount() const

Static Public Members

const int maxAge

Detailed Description

Kept in step with every block set (QcServerWorld::setBlock): a fire block that goes away loses its entry, a fire block set without one (a command, a player, a chunk whose entries were lost) waits in a list until QcServerFire adopts or puts it out. Entries leave and come back with their chunk (decision E-374), with the ticks left to their step. A fire on eternal ground (a block with "eternalFire") never ages and never spreads; it does not count toward the caps per chunk and world (decision E-394).

Member Function Documentation

[noexcept default] QcFireQueue::QcFireQueue()

Default-constructs an instance of QcFireQueue.

QcFireQueue::QcFireQueue(std::vector<bool> fire, std::vector<bool> eternalGround)

Both indexed by block state id: which states are fire, and on which fire burns for ever.

bool QcFireQueue::add(const QcFireQueue::Fire &fire)

Plans the next step of fire at fire.due. Returns false when the position has an entry already.

bool QcFireQueue::contains(QcBlockPos pos) const

Returns whether pos has an entry.

qsizetype QcFireQueue::countIn(QcChunkPos chunk) const

Returns the number of fires in chunk that count toward the caps.

qsizetype QcFireQueue::counted() const

Returns the fires that count toward the caps: all but those on eternal ground.

void QcFireQueue::drop(QcBlockPos pos)

Drops the entry of pos, whose block is no fire any more.

qsizetype QcFireQueue::dueCount(quint64 now) const

Returns the number of fires due at now.

std::optional<QcFireQueue::Fire> QcFireQueue::entry(QcBlockPos pos) const

Returns the entry of pos, if it has one.

QList<QcFireQueue::Fire> QcFireQueue::fires() const

Returns every fire, sorted by position (tests, checks).

void QcFireQueue::forgetChunk(QcChunkPos pos)

Drops the entries and waiting fires of the chunk at pos that left the world or was generated again.

bool QcFireQueue::hasDue(quint64 now) const

Returns whether a fire is due at now.

bool QcFireQueue::hasRoom(QcChunkPos chunk) const

Returns whether one more fire fits into chunk and the world (fires on eternal ground always fit).

bool QcFireQueue::isEternalGround(QcBlockId block) const

Returns whether fire burns for ever on block.

bool QcFireQueue::isFire(QcBlockId block) const

Returns whether block is a fire state.

const QcFireQueue::Limits &QcFireQueue::limits() const

Returns the caps.

See also setLimits().

void QcFireQueue::noteBlock(QcBlockPos pos, QcBlockId before, QcBlockId block)

The block at pos was set from before to block (QcServerWorld::setBlock). When the ground of a fire turns eternal, the fire leaves the caps; when it stops being eternal, the fire takes a place again or, without room, waits in takeRefused() to be put out.

void QcFireQueue::noteChunk(QcChunkPos pos, const QcChunk &chunk, quint32 sections)

The chunk at pos entered the world: its fire blocks without an entry wait for adoption. Only the sections in sections (bit n: section n, QcSectionMarks) are scanned.

bool QcFireQueue::plan(const QcFireQueue::Fire &fire)

Plans the next step of fire, which has an entry, at fire.due, with its new age. Returns false without an entry. The entry keeps its own eternal.

qsizetype QcFireQueue::refusedCount() const

Returns the number of fire blocks waiting in takeRefused().

void QcFireQueue::restore(const QList<QcFireQueue::Saved> &fires, quint64 now, const QcChunk &chunk)

Puts back the fires of chunk, which entered the world, their steps counted from now. Fires whose block is no fire any more are left out; those that find no room wait in takeRefused(); a fire block without an entry waits for adoption.

QList<QcFireQueue::Saved> QcFireQueue::savedOf(QcChunkPos chunk, quint64 now) const

Returns the fires of chunk as takeChunk() does, ticks left counted from now, but leaves them in the queue (a save).

void QcFireQueue::setLimits(QcFireQueue::Limits limits)

Sets the caps to limits.

See also limits().

qsizetype QcFireQueue::size() const

Returns the number of fires with an entry, eternal ones included.

QList<QcFireQueue::Saved> QcFireQueue::takeChunk(QcChunkPos chunk, quint64 now)

Returns the fires of chunk as it keeps them, ticks left counted from now, in the order of their steps, and takes them out of the queue.

std::optional<QcFireQueue::Fire> QcFireQueue::takeDue(quint64 now)

Returns the fire due first and takes it out of the order of steps if it is due at now; it keeps its entry (and counts for the caps) until its block goes away or plan() gives it its next step.

QList<QcBlockPos> QcFireQueue::takeRefused()

Returns the fire blocks that lost their entry for want of room (a restored fire, a fire whose eternal ground went away) since the last call, sorted: QcServerFire puts them out. They are never adopted as new sparks, so a fire cannot come back with a new budget.

QList<QcBlockPos> QcFireQueue::takeUnplanned()

Returns the fire blocks set without an entry since the last call, sorted.

qsizetype QcFireQueue::unplannedCount() const

Returns the number of fire blocks waiting in takeUnplanned().

Member Variable Documentation

const int QcFireQueue::maxAge

Steps a fire lives at most; every fire but an eternal one is out after them. The chances of the rules take a third of the age, the reference game's age of 0 to 15 (it ages by one in about three steps there).