QtCraft API C++ classes QML types Handbook

QcTerrainGenerator Class

Data-driven terrain: continents and oceans, biomes chosen by a climate map (temperature, humidity, ruggedness and rarity, with bent borders), rolling hills, ridged mountain ranges, terraces and rocky cliffs, winding rivers down to the sea level, connected cave tunnels and caverns, ore veins, liquid pools sunk into cave floors and features (trees, cacti, plants in patches). More...

Header: #include <worldgen/terrain/QcTerrainGenerator.h>
Inherits: QcWorldGenerator

Public Types

Column

Public Functions

QcTerrainGenerator(std::shared_ptr<const QcContentRegistry> content, qint64 seed)
QcTerrainGenerator(const QcTerrainGenerator &)
QcTerrainGenerator(QcTerrainGenerator &&)
int biomeForClimate(const QcTerrainClimate::Point &climate) const
QString biomeName(int index) const
QcTerrainClimate::Point climateAt(int x, int z) const
const QcCoastalTowerGenerator &coastalTowers() const
QcTerrainGenerator::Column column(int x, int z) const
double continentAt(int x, int z) const
std::optional<QcTerrainClimate::Point> dryClimateAt(int x, int z) const
const QcDungeonGenerator &dungeons() const
QcBlockId frozenWaterAt(int x, int z, const QcTerrainGenerator::Column &column) const
const QcGiantTreePlacer &giantTrees() const
int groundBiomeFor(const QcTerrainGenerator::Column &column, int land) const
std::optional<std::pair<int, int>> groundSource(int x, int z, const QcTerrainGenerator::Column &column) const
int groundTop(int x, int z, const QcTerrainGenerator::Column &column) const
bool isCave(int x, int y, int z) const
bool isCave(int x, int y, int z, const QcTerrainGenerator::Column &column) const
bool isDeltaBiome(int biome) const
bool isRiverBiome(int biome) const
std::optional<QcSurfaceLakes::Site> lakeIn(QcChunkPos pos) const
const QcSurfaceLakes &lakes() const
int landBiomeAt(int x, int z) const
bool mineshaftEntranceNear(QcChunkPos pos, QcXzRect footprint) const
const QcMineshaftGenerator &mineshafts() const
double rarityAt(int x, int z) const
QcRiverField::Sample riverAt(int x, int z) const
double riverFreezeShare(const QcTerrainGenerator::Column &column) const
int seaLevel() const
QList<QcXzRect> structureFootprintsNear(QcChunkPos pos, int margin, bool plantsOnBlend) const
QcBlockId surfaceBlockAt(int x, int z) const
QcBlockId surfaceBlockAt(int x, int z, int height) const
const QcSurfaceStructures &surfaceStructures() const
bool touchesDelta(QcXzRect footprint) const
const QcVegetationPatchPlacer &vegetationPatches() const
const QcVillageGenerator &villages() const
QcBlockId waterBlock() const
QcTerrainGenerator::Column withGround(int x, int z, QcTerrainGenerator::Column column) const
QcTerrainGenerator &operator=(QcTerrainGenerator &&)
QcTerrainGenerator &operator=(const QcTerrainGenerator &)

Reimplemented Public Functions

virtual QString biomeAt(int x, int z) const override
virtual QcChunkFurnishing furnishingIn(QcChunkPos pos) const override
virtual std::shared_ptr<QcChunk> generate(QcChunkPos pos) const override
virtual bool isNaturalGround(QcBlockId block) const override
virtual QStringList locatableNames() const override
virtual QcLocateResult locate(QStringView kind, QcBlockPos from, int reach) const override
virtual std::optional<QcStructurePlacement> nearestStructure(const QString &name, QcBlockPos from, int reach) const override
virtual std::shared_ptr<const QcVillagePlan> nearestVillage(QcBlockPos from, int reach) const override
virtual std::optional<QcStructureSites> plannedStructureSitesNear(QcBlockPos from, int reach) const override
virtual void setVersion(int version) override
virtual QcBlockPos spawnPoint() const override
virtual QcStructureSites structureSitesNear(QcBlockPos from, int reach) const override
virtual std::shared_ptr<const QcVillagePlan> villageFor(QcChunkPos pos) const override

Detailed Description

All blocks come from the registry's biome, feature, ore and terrain definitions. Deterministic per seed and thread-safe: generate() only reads immutable state.

Member Type Documentation

[alias] QcTerrainGenerator::Column

The shape and biome of one terrain column.

Member Function Documentation

QcTerrainGenerator::QcTerrainGenerator(std::shared_ptr<const QcContentRegistry> content, qint64 seed)

Builds the terrain of the world seed from the definitions in content. Unresolvable references are replaced by sensible fallbacks with a warning (warnings()); omitted optional blocks (empty names) fall back silently.

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

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

[delete] QcTerrainGenerator::QcTerrainGenerator(QcTerrainGenerator &&)

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

[override virtual] QString QcTerrainGenerator::biomeAt(int x, int z) const

Reimplements: QcWorldGenerator::biomeAt(int x, int z) const.

int QcTerrainGenerator::biomeForClimate(const QcTerrainClimate::Point &climate) const

Returns the biome the point climate belongs to (the heaviest after the rarity gate), as the terrain picks it; tests check the layout of the biomes in climate space with it (decision E-824).

QString QcTerrainGenerator::biomeName(int index) const

Returns the name of the biome at index; empty for an index out of range.

QcTerrainClimate::Point QcTerrainGenerator::climateAt(int x, int z) const

Returns the climate point of the column x, z (decisions E-014, E-821, E-824), for tests and tools.

const QcCoastalTowerGenerator &QcTerrainGenerator::coastalTowers() const

Returns the coastal towers (decision E-605): their chests' loot, and the plans for tools and tests.

QcTerrainGenerator::Column QcTerrainGenerator::column(int x, int z) const

Returns the shape and biome of the column x, z. Near a biome border its ground biome is left unresolvedGround (a second climate evaluation): withGround() or QcTerrainColumnGrid look it up.

double QcTerrainGenerator::continentAt(int x, int z) const

Returns the continent value of the column x, z (below about -0.15 the sea; river deltas read it, decision E-850).

std::optional<QcTerrainClimate::Point> QcTerrainGenerator::dryClimateAt(int x, int z) const

Returns the climate at the column x, z if its ground lies above the sea level before rivers cut it, or at most a block under it (the river pieces, decisions E-851 and E-907); std::nullopt in the sea and lakes at least two blocks deep.

const QcDungeonGenerator &QcTerrainGenerator::dungeons() const

Returns the dungeons (decision E-522).

QcBlockId QcTerrainGenerator::frozenWaterAt(int x, int z, const QcTerrainGenerator::Column &column) const

Returns the block of the top water layer of column at x, z under the sea level (decision E-858): the biome's frozenWater, with freezing by temperature only where the column is cold enough (else water); with a frozenDepth only where the water is that shallow (decision E-850).

[override virtual] QcChunkFurnishing QcTerrainGenerator::furnishingIn(QcChunkPos pos) const

Reimplements: QcWorldGenerator::furnishingIn(QcChunkPos pos) const.

Returns what the dungeons (decision E-522) and mine shafts (decision E-570) put into the chunk at pos: their loot, spawner kinds and carts, and the plans for tools and tests.

[override virtual] std::shared_ptr<QcChunk> QcTerrainGenerator::generate(QcChunkPos pos) const

Reimplements: QcWorldGenerator::generate(QcChunkPos pos) const.

const QcGiantTreePlacer &QcTerrainGenerator::giantTrees() const

Returns the giant trees on a 2×2 trunk (decision E-822).

int QcTerrainGenerator::groundBiomeFor(const QcTerrainGenerator::Column &column, int land) const

Returns the ground biome of column when the land biome at its ground source is land (for a river channel the river biome of that land); -1 for its own.

std::optional<std::pair<int, int>> QcTerrainGenerator::groundSource(int x, int z, const QcTerrainGenerator::Column &column) const

Returns the column whose land biome decides the ground of the unresolved column at x, z: the jittered one of QcColdEdges::groundOffset(); none for a looked-up column.

int QcTerrainGenerator::groundTop(int x, int z, const QcTerrainGenerator::Column &column) const

Returns the highest solid block of the unmodified terrain in column at x, z (overhangs included, caves not).

bool QcTerrainGenerator::isCave(int x, int y, int z) const

Returns true where a cave carves the block x, y, z (the column computed anew).

bool QcTerrainGenerator::isCave(int x, int y, int z, const QcTerrainGenerator::Column &column) const

Returns the same for x, y, z with the terrain column at x, z known already.

bool QcTerrainGenerator::isDeltaBiome(int biome) const

Returns whether biome is a delta biome (the arms and islands of a river delta, decision E-850).

[override virtual] bool QcTerrainGenerator::isNaturalGround(QcBlockId block) const

Reimplements: QcWorldGenerator::isNaturalGround(QcBlockId block) const.

bool QcTerrainGenerator::isRiverBiome(int biome) const

Returns whether biome is a river biome (the water of river channels, decision E-840).

std::optional<QcSurfaceLakes::Site> QcTerrainGenerator::lakeIn(QcChunkPos pos) const

Returns the lake of the chunk at pos; none in or near a village, near a surface structure or coastal tower, or near a mine shaft's entrance.

const QcSurfaceLakes &QcTerrainGenerator::lakes() const

Returns the surface lakes (decision E-856).

int QcTerrainGenerator::landBiomeAt(int x, int z) const

Returns the land biome of the climate at the column x, z.

[override virtual] QStringList QcTerrainGenerator::locatableNames() const

Reimplements: QcWorldGenerator::locatableNames() const.

Returns the villages, mine shafts, dungeons, coastal towers and the surface structures (decision E-911).

[override virtual] QcLocateResult QcTerrainGenerator::locate(QStringView kind, QcBlockPos from, int reach) const

Reimplements: QcWorldGenerator::locate(QStringView kind, QcBlockPos from, int reach) const.

Returns the mine shaft, dungeon or coastal tower of kind nearest to from within about reach blocks (as QcWorldGenerator::locate(); no place for other kinds): mine shafts by their central room and entrance, dungeons by their room's middle, coastal towers by their doorstep (QcTerrainLocate.cpp).

bool QcTerrainGenerator::mineshaftEntranceNear(QcChunkPos pos, QcXzRect footprint) const

Returns whether the entrance of a mine shaft touching the chunk at pos lies within featureMargin of footprint (world).

const QcMineshaftGenerator &QcTerrainGenerator::mineshafts() const

Returns the mine shafts (decision E-570).

[override virtual] std::optional<QcStructurePlacement> QcTerrainGenerator::nearestStructure(const QString &name, QcBlockPos from, int reach) const

Reimplements: QcWorldGenerator::nearestStructure(const QString &name, QcBlockPos from, int reach) const.

[override virtual] std::shared_ptr<const QcVillagePlan> QcTerrainGenerator::nearestVillage(QcBlockPos from, int reach) const

Reimplements: QcWorldGenerator::nearestVillage(QcBlockPos from, int reach) const.

[override virtual] std::optional<QcStructureSites> QcTerrainGenerator::plannedStructureSitesNear(QcBlockPos from, int reach) const

Reimplements: QcWorldGenerator::plannedStructureSitesNear(QcBlockPos from, int reach) const.

double QcTerrainGenerator::rarityAt(int x, int z) const

Returns the world's rarity at the column x, z in [0, 1] (decision E-821): 0 outside the spots where rare biomes may appear, and everywhere when no biome is rare.

QcRiverField::Sample QcTerrainGenerator::riverAt(int x, int z) const

Returns the river near the column x, z (decision E-840): distance to its middle line, width and depth there, for tools, tests and the river deltas; far away without rivers and where the ground before the river lies more than 8 blocks under the sea level (the sea, deep lakes), as in column(). Costs a column(); column() itself gives the distance and the half width.

double QcTerrainGenerator::riverFreezeShare(const QcTerrainGenerator::Column &column) const

Returns how far the freezing of the water of column follows a river's lower threshold (0 to 1, QcColdEdges::freezes): 1 in a river channel, falling off in still water along a river.

int QcTerrainGenerator::seaLevel() const

Returns the sea level: the sea is filled with water up to the block below it (the water surface, seaLevel() - 1), the first air above the sea.

[override virtual] void QcTerrainGenerator::setVersion(int version)

Reimplements: QcWorldGenerator::setVersion(int version).

Sets the world generator version to version, also for the rivers (version 2 on fades small rings smoothly, QcRiverField::smoothRings(), decision E-969, and closes pieces up to QcRiverPieces::longestVersion2 blocks long, decision E-976).

[override virtual] QcBlockPos QcTerrainGenerator::spawnPoint() const

Reimplements: QcWorldGenerator::spawnPoint() const.

QList<QcXzRect> QcTerrainGenerator::structureFootprintsNear(QcChunkPos pos, int margin, bool plantsOnBlend) const

Returns the footprints of surface structures, coastal towers and surface lakes within margin columns of the chunk at pos: no trees grow there. With plantsOnBlend the blended ground of kinds with blendVegetation is left out but for the ring beside their walls (the generator's trees and plants stand on the ground as built; giant trees are planned on the terrain and keep off).

[override virtual] QcStructureSites QcTerrainGenerator::structureSitesNear(QcBlockPos from, int reach) const

Reimplements: QcWorldGenerator::structureSitesNear(QcBlockPos from, int reach) const.

QcBlockId QcTerrainGenerator::surfaceBlockAt(int x, int z) const

Returns the top block of the unmodified terrain at the column x, z (before caves and features).

QcBlockId QcTerrainGenerator::surfaceBlockAt(int x, int z, int height) const

Returns the top block of the column x, z with its ground moved to height (its top block one below; the blend around a surface structure, decision E-889): the block the features of the column check.

const QcSurfaceStructures &QcTerrainGenerator::surfaceStructures() const

Returns the structures it places by itself (decision E-590): the desert temple.

bool QcTerrainGenerator::touchesDelta(QcXzRect footprint) const

Returns whether any column of footprint (world, corners inclusive) lies in a river delta (decision E-850): every column is read, since an arm narrower than the samples of a placement may cross it between them. Only near a delta: away from the band along the coasts it reads the continent on a grid of a few blocks, near it the remembered delta of each cell of sites.

const QcVegetationPatchPlacer &QcTerrainGenerator::vegetationPatches() const

Returns the patches of one kind of grass or flower (decision E-814), for tests.

[override virtual] std::shared_ptr<const QcVillagePlan> QcTerrainGenerator::villageFor(QcChunkPos pos) const

Reimplements: QcWorldGenerator::villageFor(QcChunkPos pos) const.

const QcVillageGenerator &QcTerrainGenerator::villages() const

Returns the villages of the terrain.

QcBlockId QcTerrainGenerator::waterBlock() const

Returns the block the sea and lakes are filled with.

QcTerrainGenerator::Column QcTerrainGenerator::withGround(int x, int z, QcTerrainGenerator::Column column) const

Returns column at x, z with its ground biome looked up (decision E-858).

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

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

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

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