QtCraft API C++ classes QML types Handbook

QcMeshScheduler Class

Keeps section meshes in sync with the client world. More...

Header: #include <clientcore/meshing/QcMeshScheduler.h>
Inherits: QObject

Public Types

struct Stats
enum class Priority { Normal, Player }

Public Functions

QcMeshScheduler(const QcMeshScheduler &)
QcMeshScheduler(QcMeshScheduler &&)
void blockChanged(const QcClientWorld &world, QcBlockPos pos, QcBlockId previous, QcMeshScheduler::Priority priority = Priority::Normal)
int blockLight(QcBlockPos pos) const
void chunkLoaded(const QcClientWorld &world, QcChunkPos pos)
bool chunkMeshed(QcChunkPos pos) const
void chunkUnloaded(QcChunkPos pos)
void clear()
qsizetype dirtyCount() const
qsizetype jobsInFlight() const
qint64 lightBytes() const
int lightJobsPending() const
void pump(const QcClientWorld &world)
void remeshAll()
void resetStats()
void setFocus(const QcVec3 &position)
void setRenderTable(std::shared_ptr<const QcBlockRenderTable> table)
void setSectionLight(bool on)
QcMeshScheduler::Stats stats() const
void waitForJobs()
QcMeshScheduler &operator=(QcMeshScheduler &&)
QcMeshScheduler &operator=(const QcMeshScheduler &)

Signals

void meshReady(quint64 key, std::shared_ptr<const QcChunkMesh> mesh)
void meshRemoved(quint64 key)

Detailed Description

Dirty sections are meshed on private worker threads from immutable chunk snapshots, nearest to the camera first; results come back to the owning thread as signals. A section is only meshed once its four side neighbours are loaded and the block light of its chunk is known. Block light is updated incrementally by a QcBlockLightEngine on a thread of its own; only sections whose light changed are meshed again. The local player's own block changes go first (decision E-853).

Member Type Documentation

enum class QcMeshScheduler::Priority

Who changed a block, and so how soon it is meshed.

ConstantValueDescription
QcMeshScheduler::Priority::Normal0The server's changes and the streaming: in the order of pump(), nearest first.
QcMeshScheduler::Priority::Player1The local player's predicted change or its rollback: the sections holding its faces are meshed when the event loop comes back (each section once for all changes of that pass, e.g. both halves of a door), before every waiting job and beyond maxJobsInFlight, with the block light known so far; a change of the block light follows with the light job.

Member Function Documentation

[delete] QcMeshScheduler::QcMeshScheduler(const QcMeshScheduler &)

Copy-constructs an instance of QcMeshScheduler. This function is deleted.

[delete] QcMeshScheduler::QcMeshScheduler(QcMeshScheduler &&)

Move-constructs an instance of QcMeshScheduler. This function is deleted.

void QcMeshScheduler::blockChanged(const QcClientWorld &world, QcBlockPos pos, QcBlockId previous, QcMeshScheduler::Priority priority = Priority::Normal)

The block at pos changed from previous to what world holds now, with priority. Light changes of the block changes of one pass of the event loop go to the light engine together, as one job (an explosion's hundreds of blocks, decision E-604). A change between two states drawn alike (equal render table entries) meshes nothing.

int QcMeshScheduler::blockLight(QcBlockPos pos) const

Returns the block light (0..15) at pos as the meshes show it; 0 where it is not known yet.

void QcMeshScheduler::chunkLoaded(const QcClientWorld &world, QcChunkPos pos)

Notes that the chunk at pos of world is loaded: its sections and those of its neighbours are meshed once its block light is known.

bool QcMeshScheduler::chunkMeshed(QcChunkPos pos) const

Returns whether the loaded chunk at pos has its light and no section waiting for or in a mesh job (the loading screen, decision E-943). A section whose side neighbour is missing is not marked, so the caller checks the neighbours.

void QcMeshScheduler::chunkUnloaded(QcChunkPos pos)

Forgets the chunk at pos: drops its dirty sections and light and emits meshRemoved() for each of its sections.

void QcMeshScheduler::clear()

Forgets every chunk, dirty section and light and drops the waiting jobs (another world).

qsizetype QcMeshScheduler::dirtyCount() const

Returns the number of sections waiting for a mesh job.

qsizetype QcMeshScheduler::jobsInFlight() const

Returns the number of mesh jobs running or queued.

qint64 QcMeshScheduler::lightBytes() const

Returns the bytes of the block light sections handed to the mesher (memory statistics, decision E-813); the light engine on its own thread holds about as many again. Walks every section: for occasional statistics, not per frame.

int QcMeshScheduler::lightJobsPending() const

Returns the light jobs submitted or gathered and not yet back.

[signal] void QcMeshScheduler::meshReady(quint64 key, std::shared_ptr<const QcChunkMesh> mesh)

Emitted when the section key (qcSectionKey()) has a new mesh.

[signal] void QcMeshScheduler::meshRemoved(quint64 key)

Emitted when the section key is gone (its chunk unloaded).

void QcMeshScheduler::pump(const QcClientWorld &world)

Starts jobs for dirty sections of world, at most maxJobsInFlight at a time.

void QcMeshScheduler::remeshAll()

Marks every section of the loaded chunks dirty, so each is meshed and delivered again (the renderer lost its GPU copies, QcWorldView::meshesLost).

void QcMeshScheduler::resetStats()

Starts the statistics over.

void QcMeshScheduler::setFocus(const QcVec3 &position)

Sets the camera position: dirty sections nearest to it are meshed first.

void QcMeshScheduler::setRenderTable(std::shared_ptr<const QcBlockRenderTable> table)

Sets the render data of the block states table and starts a new light engine for it; the block light of all chunks is computed again.

void QcMeshScheduler::setSectionLight(bool on)

Sets whether meshes carry the light of their cells (on; QcMeshInput::sectionLight); for the sections meshed from then on.

QcMeshScheduler::Stats QcMeshScheduler::stats() const

Returns the statistics since the last resetStats().

void QcMeshScheduler::waitForJobs()

Submits the gathered light changes and blocks until all queued jobs finished; their results are delivered through the event loop.

[delete] QcMeshScheduler &QcMeshScheduler::operator=(QcMeshScheduler &&)

Move-assigns other to this QcMeshScheduler instance. This function is deleted.

[delete] QcMeshScheduler &QcMeshScheduler::operator=(const QcMeshScheduler &)

Copy-assigns other to this QcMeshScheduler instance. This function is deleted.