QtCraft API C++ classes QML types Handbook

QcRiverPieces Class

Whether a river leads anywhere (decision E-851): the middle line of a river is followed both ways from a point on it until it reaches the sea, runs dry (a desert, the fading ring of a small hill of the noise) or comes back round to the point. More...

Header: #include <worldgen/terrain/QcRiverPieces.h>

Public Types

struct Walk
enum class End { Sea, Dry, Round, Far, Lost }

Public Functions

QcRiverPieces(const QcRiverField &rivers)
bool cellLeadsOn(qint32 cellX, qint32 cellZ, const QcRiverField::Land &land) const
bool leadsOn(const QcRiverField::Sample &sample, const QcRiverField::Land &land) const
double longest() const
void setVersion(int version)
std::optional<QcRiverPieces::Walk> walkFrom(QcRiverField::Point near, double side, const QcRiverField::Land &land) const

Static Public Members

const double cellSize
const double longestVersion1
const double longestVersion2

Detailed Description

A piece that ends on land at both ends or runs round in a loop, all of it within longest() blocks, is closed: the terrain does not build it. Longer pieces count as open, whichever point they are followed from, so every column of a piece gets the same answer. Deterministic per seed and thread-safe; the answers are remembered per thread by cells of 32 blocks along the rivers.

Member Type Documentation

enum class QcRiverPieces::End

How a walk along the middle line ended: in the sea, where the river runs dry, back at its start, after the walk's length, or off the line (the steps did not settle on it).

ConstantValueDescription
QcRiverPieces::End::Sea0At a crossing whose ground is not dry land (the sea, a lake).
QcRiverPieces::End::Dry1Where the river runs dry.
QcRiverPieces::End::Round2Back at its first crossing: a loop.
QcRiverPieces::End::Far3After the walk's length, nothing ended.
QcRiverPieces::End::Lost4Off the line.

Member Function Documentation

[explicit] QcRiverPieces::QcRiverPieces(const QcRiverField &rivers)

rivers must outlive the pieces (the terrain generator owns both). The pieces start with the length of the current generator version (longestVersion2).

bool QcRiverPieces::cellLeadsOn(qint32 cellX, qint32 cellZ, const QcRiverField::Land &land) const

Returns the answer for the cell (cellX, cellZ) of cellSize blocks on land, remembered per thread.

bool QcRiverPieces::leadsOn(const QcRiverField::Sample &sample, const QcRiverField::Land &land) const

Returns whether the river of sample (a column within its reach, QcRiverField::at()) reaches the sea or runs on for more than longest() blocks; land gives the terrain's maps.

double QcRiverPieces::longest() const

Returns the length in blocks along the middle line up to which a piece ending on land at both ends (or a loop) is closed.

void QcRiverPieces::setVersion(int version)

Sets longest() for generator version version (longestVersion1 for version 1, longestVersion2 from version 2 on); set before the pieces are read, by the generator's version. Answers found before are not used again.

std::optional<QcRiverPieces::Walk> QcRiverPieces::walkFrom(QcRiverField::Point near, double side, const QcRiverField::Land &land) const

Returns the walk the answer of a point near a middle line (bent coordinates) reads way side (1 or -1 times the line's direction there), started as for a cell (at the first crossing ahead) and given longest() blocks; none where no walk starts (the river stays). near is the point, land the terrain's maps. For tests (E-935).

Member Variable Documentation

const double QcRiverPieces::cellSize

The answers are found from the middle of cells of this many blocks (bent coordinates; a column of a river finds the cell of the nearest point of its middle line, Sample::lineX/lineZ).

const double QcRiverPieces::longestVersion1

longest() of generator version 1: a piece that ends on land at both ends within this many blocks along its middle line is closed.

const double QcRiverPieces::longestVersion2

longest() from generator version 2 on (decision E-976).