QcMapStore Class
The maps of a world (decision E-799) by map id: kept in memory while used, read from the save when first needed (the loader), written with the next save only when changed since, and dropped from memory when nobody used them for idleTicks and they are written (tick). More...
| Header: | #include <server/maps/QcMapStore.h> |
Public Types
Public Functions
| bool | countMade(const QString &player, quint64 now, int perMinute) |
| std::optional<quint32> | create(QcMapData map) |
| const QcMapData * | find(quint32 id) |
| void | finishSave(const QList<quint32> &ids, bool written) |
| void | forget(quint32 client) |
| const QcMapData * | loaded(quint32 id) const |
| qsizetype | loadedCount() const |
| quint32 | nextId() const |
| void | open(QcMapStore::Loader loader, quint32 nextId) |
| void | resend(quint32 id, quint32 client) |
| void | reserveIdsBelow(quint32 next) |
| bool | set(quint32 id, QPoint pixel, quint16 value) |
| void | setWatched(quint32 client, const QList<quint32> &ids) |
| QRect | takePending(quint32 id, quint32 client, int budget) |
| QList<quint32> | takeUnsaved() |
| void | tick(quint64 now) |
| void | touch(quint32 id, quint64 now) |
| void | unwatch(quint32 id, quint32 client) |
| void | watch(quint32 id, quint32 client) |
| QList<quint32> | watched(quint32 client) const |
| bool | watches(quint32 id, quint32 client) const |
Static Public Members
| const quint64 | evictionInterval |
| const quint64 | idleTicks |
| const quint32 | maxId |
Detailed Description
It also keeps, per player that holds a map or stands near a frame showing it, the rectangle of pixels that player has not received yet (decisions E-802, E-807), so a revealed pixel goes out once to everyone who sees the map.
Member Type Documentation
[alias] QcMapStore::Loader
Reads the stored map id; std::nullopt when there is none or it is damaged.
Member Function Documentation
bool QcMapStore::countMade(const QString &player, quint64 now, int perMinute)
Counts a new map of player at tick now (decision E-810). Returns false when it made perMinute maps in its current minute already. Kept by player name, so reconnecting starts no new minute.
std::optional<quint32> QcMapStore::create(QcMapData map)
Keeps map under a new id. Returns the id; std::nullopt when the ids are used up.
const QcMapData *QcMapStore::find(quint32 id)
Returns the map id, read from the save when it is not in memory; nullptr for an unknown id.
void QcMapStore::finishSave(const QList<quint32> &ids, bool written)
The save of the maps ids (from takeUnsaved) is done; when it failed (written false), they are written again with the next one.
void QcMapStore::forget(quint32 client)
The player client left: nothing is kept for it.
const QcMapData *QcMapStore::loaded(quint32 id) const
Returns the map id when it is in memory (never reads the save); nullptr otherwise.
qsizetype QcMapStore::loadedCount() const
Returns the number of maps in memory.
quint32 QcMapStore::nextId() const
Returns the id the next new map gets (saved with the world).
void QcMapStore::open(QcMapStore::Loader loader, quint32 nextId)
Sets loader and the next free id nextId of an opened world.
void QcMapStore::resend(quint32 id, quint32 client)
client gets map id whole again with the next takePending (it took the map into the hand).
void QcMapStore::reserveIdsBelow(quint32 next)
Ids below next are used (the next id saved with the world): new maps get larger ones.
bool QcMapStore::set(quint32 id, QPoint pixel, quint16 value)
Sets pixel of map id in memory to value. Returns whether it changed.
void QcMapStore::setWatched(quint32 client, const QList<quint32> &ids)
Sets ids as the maps client watched in this tick.
See also watched().
QRect QcMapStore::takePending(quint32 id, quint32 client, int budget)
Returns at most budget pixels of what client has not received of map id (QcMapPending::take); the rest stays for later; an empty rectangle when nothing waits.
QList<quint32> QcMapStore::takeUnsaved()
Returns the ids of the maps changed since the last call (for a save); they stay in memory until finishSave.
void QcMapStore::tick(quint64 now)
Tick now of the world: every evictionInterval ticks the maps unused for idleTicks leave memory, unless they wait for a save or the world has no save to read them from again.
void QcMapStore::touch(quint32 id, quint64 now)
Map id is shown somewhere (an item frame in a loaded chunk, decision E-807): it counts as used at tick now, if it is in memory. Never reads the save.
void QcMapStore::unwatch(quint32 id, quint32 client)
client no longer holds map id nor stands near a frame showing it: nothing is kept for it (a later watch sends the map whole again). Never reads the save.
void QcMapStore::watch(quint32 id, quint32 client)
client holds map id now: a map it never had comes out whole (every pixel shown so far).
QList<quint32> QcMapStore::watched(quint32 client) const
Returns the maps client watched in the last tick (QcServerMaps).
See also setWatched().
bool QcMapStore::watches(quint32 id, quint32 client) const
Returns whether client got map id before (since it joined).
Member Variable Documentation
const quint64 QcMapStore::evictionInterval
Ticks between two looks for idle maps.
const quint64 QcMapStore::idleTicks
A map nobody looked at, changed or held for this many ticks (five minutes) leaves memory.
const quint32 QcMapStore::maxId
Map ids are handed out from 1 up to this; a world with more maps makes no new ones.