QtCraft API C++ classes QML types Handbook

QcVillageGenerator Class

The villages of a terrain world (decision E-403): plans each region's village once (cached, shared by the generation threads and the server thread, decision E-416) and writes the part of it that lies in a chunk. More...

Header: #include <worldgen/villages/QcVillageGenerator.h>

Public Functions

QcVillageGenerator(const QcTerrainGenerator &terrain, std::shared_ptr<const QcContentRegistry> content, quint64 seed)
void build(QcChunk &chunk, const QcVillagePlan &plan) const
const QcVillagePlanCache &cache() const
std::shared_ptr<const QcVillagePlan> nearest(QcBlockPos from, int reach) const
std::optional<QcStructurePlacement> nearestPiece(const QString &name, QcBlockPos from, int reach) const
std::shared_ptr<const QcVillagePlan> planFor(QcChunkPos chunk) const
std::optional<QcStructureSites> plannedSitesNear(QcBlockPos from, int reach) const
std::shared_ptr<const QcVillagePlan> regionPlan(int regionX, int regionZ) const
QcStructureSites sitesNear(QcBlockPos from, int reach) const
int spacing() const
const QcVillageStyles &styles() const
const QcWetlandShaper &wetland() const

Static Public Members

const qsizetype cachedPlans
QcChunkFurnishing furnishingIn(QcChunkPos pos, const QcVillagePlan &plan)
QcStructureSites sitesOf(const QcVillagePlan &plan)

Detailed Description

A chunk lies in exactly one region and a village never leaves its region, so a chunk needs only its own region's plan. Thread-safe.

Member Function Documentation

QcVillageGenerator::QcVillageGenerator(const QcTerrainGenerator &terrain, std::shared_ptr<const QcContentRegistry> content, quint64 seed)

Plans villages over terrain with the styles of content, drawing from seed. What the styles leave out is in styles().warnings().

void QcVillageGenerator::build(QcChunk &chunk, const QcVillagePlan &plan) const

Writes the parts of plan that lie in chunk: over water the wetland first (QcWetlandShaper), the blended ground around the centre, the doorsteps, roads into the ground's top block and their steps, jetties, boardwalks and bridges, then the pieces after clearing the terrain above their footprint and filling the ground below it.

const QcVillagePlanCache &QcVillageGenerator::cache() const

Returns the cache of the region plans.

[static] QcChunkFurnishing QcVillageGenerator::furnishingIn(QcChunkPos pos, const QcVillagePlan &plan)

Returns the loot of the chests of plan's pieces in the chunk at pos (decision E-590: the temple at the centre of a desert village).

std::shared_ptr<const QcVillagePlan> QcVillageGenerator::nearest(QcBlockPos from, int reach) const

Returns the village whose centre lies nearest to from within reach blocks (whole regions), if any.

std::optional<QcStructurePlacement> QcVillageGenerator::nearestPiece(const QString &name, QcBlockPos from, int reach) const

Returns the village piece of structure name (the temple at a desert village's centre) whose middle lies nearest to from within reach blocks (whole regions), if any.

std::shared_ptr<const QcVillagePlan> QcVillageGenerator::planFor(QcChunkPos chunk) const

Returns the village of the region that holds chunk; null when it has none.

std::optional<QcStructureSites> QcVillageGenerator::plannedSitesNear(QcBlockPos from, int reach) const

Returns the same as sitesNear() for from and reach from the regions planned so far, never planning (the server's tick thread); std::nullopt when a region within reach is not planned yet.

std::shared_ptr<const QcVillagePlan> QcVillageGenerator::regionPlan(int regionX, int regionZ) const

Returns the village of the region regionX, regionZ from the cache, planning it there first if needed; null when the region has none.

QcStructureSites QcVillageGenerator::sitesNear(QcBlockPos from, int reach) const

Returns the guardian zones (decision E-591) and spawn areas (decision E-871) of the pieces of the villages in the regions within reach of from.

[static] QcStructureSites QcVillageGenerator::sitesOf(const QcVillagePlan &plan)

Returns the guardian zones and spawn areas of the pieces of the village plan.

int QcVillageGenerator::spacing() const

Returns the edge of a village region in blocks (QcVillagePlanner::spacing()).

const QcVillageStyles &QcVillageGenerator::styles() const

Returns the village styles read from the content.

const QcWetlandShaper &QcVillageGenerator::wetland() const

Returns the shaper of the ground of villages over water.

Member Variable Documentation

const qsizetype QcVillageGenerator::cachedPlans

Regions the cache keeps (least recently used go first). A village's plan holds about 33 KB (the largest about 55 KB: the structures of its varied buildings, its road cells) and about one region in six has one, so a full cache holds about 3 MB, at most about 28 MB (test_village_measure). It keeps the 13 x 13 regions /locate village searches and those around the players generating.