QtCraft API C++ classes QML types Handbook

QcVillagePlanCache Class

The village plans of the regions planned last (decision E-416), shared by the generation threads and the server thread. More...

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

Public Types

Planner

Public Functions

QcVillagePlanCache(qsizetype capacity)
qsizetype capacity() const
std::shared_ptr<const QcVillagePlan> plan(int regionX, int regionZ, const QcVillagePlanCache::Planner &planner) const
quint64 planned() const
std::optional<std::shared_ptr<const QcVillagePlan>> planned(int regionX, int regionZ) const
qsizetype size() const

Detailed Description

When it is full it lets go of the region used least recently; a plan that someone else still holds (QcVillages keeps the plans of the villages with loaded chunks) is found again through a weak reference instead of being planned anew. Regions without a village are cached as null plans. Thread-safe.

Member Type Documentation

[alias] QcVillagePlanCache::Planner

Plans the village of a region; null when the region has none.

Member Function Documentation

[explicit] QcVillagePlanCache::QcVillagePlanCache(qsizetype capacity)

Keeps the plans of at most capacity regions.

qsizetype QcVillagePlanCache::capacity() const

Returns how many regions the cache keeps at most.

std::shared_ptr<const QcVillagePlan> QcVillagePlanCache::plan(int regionX, int regionZ, const QcVillagePlanCache::Planner &planner) const

Returns the plan of region regionX, regionZ: cached, held elsewhere, or planned with planner outside the lock (two threads planning the same region at once both plan it; the first one stored is kept).

quint64 QcVillagePlanCache::planned() const

Returns how often a region was planned so far, repeats included (tests count how often a region is planned again).

std::optional<std::shared_ptr<const QcVillagePlan>> QcVillagePlanCache::planned(int regionX, int regionZ) const

Returns the plan of region regionX, regionZ when it is cached or held elsewhere (a null plan: no village); std::nullopt when it is not planned yet. Never plans.

qsizetype QcVillagePlanCache::size() const

Returns how many regions the cache keeps now (not counting plans only held elsewhere).