QcPrediction Class
Prediction of the local player: the movement intent, the inputs the server has not acknowledged yet, the predicted motion one tick ago and now, and the reconciliation with the authoritative state (corrections, decision E-257). More...
| Header: | #include <clientcore/player/QcPrediction.h> |
Public Types
| enum class | Reconciled { Ignored, Placed, Applied } |
Public Functions
| const std::optional<QcBoatState> & | boat() const |
| bool | crouches() const |
| double | eyeHeight() const |
| void | followCart(const QcClientEntities &entities) |
| bool | hasServerState() const |
| const QcPlayerInput & | intent() const |
| double | largestCorrection() const |
| quint32 | lastAcknowledged() const |
| double | lastCorrection() const |
| quint32 | lastSequence() const |
| void | mirror(const QcPrediction &core, bool current) |
| const QcEntityMotion & | motion() const |
| qsizetype | pendingInputCount() const |
| QcPlayerInput | predict(const QcBlockAccess &world, bool flying, QcMovement movement, const QcVec3 &push = {}) |
| const std::optional<QcBoatState> & | previousBoat() const |
| const QcEntityMotion & | previousMotion() const |
| QcPrediction::Reconciled | reconcile(const QcMsg::PlayerState &state, const QcBlockAccess *world, QcMovement movement) |
| void | resetCorrections() |
| void | rest() |
| const QcClientRiding & | riding() const |
| void | setIntent(const QcPlayerInput &intent) |
| void | setSpeedFactor(float factor) |
| void | setUsingItem(bool usingItem) |
| bool | usingItemRefused(const QcMsg::PlayerState &state) const |
Static Public Members
| const qsizetype | maxPendingInputs |
Detailed Description
While the player rides a minecart nothing is predicted, the player follows the cart (QcClientRiding, decision E-382). While they drive a boat the boat is predicted by the shared boat physics (QcBoatState, decision E-920) from the server's state of it and the player sits on its seat. Plain data without Qt objects or signals: it reads the world and the entity mirror only during predict() and reconcile().
Member Type Documentation
enum class QcPrediction::Reconciled
What a server state did to the prediction.
| Constant | Value | Description |
|---|---|---|
QcPrediction::Reconciled::Ignored | 0 | Older than a state already applied; nothing changed. |
QcPrediction::Reconciled::Placed | 1 | The first state: it placed the player in the world. |
QcPrediction::Reconciled::Applied | 2 | A later state: the pending inputs were replayed on top of it. |
Member Function Documentation
const std::optional<QcBoatState> &QcPrediction::boat() const
Returns the predicted boat the player drives after the latest tick; none when they drive none.
bool QcPrediction::crouches() const
Returns whether the player crouches: he sneaks on foot, not flying (sneak descends then, decision E-284) and not riding.
double QcPrediction::eyeHeight() const
Returns the height of the player's eyes above the feet after the latest tick: lower while he crouches (QcPhysics::eyeHeight, decision E-961).
void QcPrediction::followCart(const QcClientEntities &entities)
While riding, after predict(): the player moves onto the seat of the cart as the entity mirror entities shows it this tick.
bool QcPrediction::hasServerState() const
Returns whether a state of the server placed the player.
const QcPlayerInput &QcPrediction::intent() const
Returns the movement intent as last set.
See also setIntent().
double QcPrediction::largestCorrection() const
Returns the most metres the server moved the predicted player since resetCorrections().
quint32 QcPrediction::lastAcknowledged() const
Returns the sequence number of the latest input the server acknowledged.
double QcPrediction::lastCorrection() const
Returns the metres the server moved the predicted player in the latest reconcile (E-257).
quint32 QcPrediction::lastSequence() const
Returns the sequence number of the latest input predicted; 0 before the first.
void QcPrediction::mirror(const QcPrediction &core, bool current)
Takes over the prediction of the session's tick core (decision E-560), keeping the own intent (the session writes it) and, while riding, the own motion (the session follows the cart). With current false the core has not seen all of the session's commands yet: the own largest correction stays (it may just have been reset).
const QcEntityMotion &QcPrediction::motion() const
Returns the predicted state after the latest tick.
qsizetype QcPrediction::pendingInputCount() const
Returns the number of inputs the server has not acknowledged yet.
QcPlayerInput QcPrediction::predict(const QcBlockAccess &world, bool flying, QcMovement movement, const QcVec3 &push = {})
Predicts one tick in world from the intent: on foot or flying (with flying as the wish sent and movement from the game mode) through the shared physics, pushed by the creatures with push (QcPushBodies, decision E-882; kept with the input, so a replay pushes alike: after a correction the replayed steps keep the pushes of the places predicted before, not of the corrected ones, and the next correction takes up the difference); riding a cart the motion stays (followCart moves it); driving a boat the input steps the boat and the player sits in it. Returns the input to send; it carries the next sequence number and is kept until acknowledged.
const std::optional<QcBoatState> &QcPrediction::previousBoat() const
Returns the predicted boat one tick earlier.
const QcEntityMotion &QcPrediction::previousMotion() const
Returns the predicted state one tick earlier, for interpolation.
QcPrediction::Reconciled QcPrediction::reconcile(const QcMsg::PlayerState &state, const QcBlockAccess *world, QcMovement movement)
Applies the server's state of the player and replays the pending inputs on top of it (with world once it exists, moving by movement). Returns what the state did.
void QcPrediction::resetCorrections()
Forgets the largest correction so far.
void QcPrediction::rest()
A tick without a step (the server paused or the player dead, decision E-960): the state one tick earlier becomes the current one, so the interpolation between them stands still instead of swinging back over the last step with every tick.
const QcClientRiding &QcPrediction::riding() const
Returns the minecart the player rides or the boat they drive.
void QcPrediction::setIntent(const QcPlayerInput &intent)
Sets the movement intent applied on every tick until changed. Non-finite values are replaced, ranges (also the flight speed) clamped and yaw wrapped into [0, 360).
See also intent().
void QcPrediction::setSpeedFactor(float factor)
Sets factor, the factor of the player's status effects on their speed (slowness, decision E-838), as the server told them; the next inputs carry it, so replaying them moves as predicted.
void QcPrediction::setUsingItem(bool usingItem)
Sets usingItem, whether the next inputs hold an item in use (draw a bow, decision E-986). The inputs keep it, so replaying them moves as predicted.
bool QcPrediction::usingItemRefused(const QcMsg::PlayerState &state) const
Returns whether state shows that the server does not know of the running draw: it acknowledged an input of this draw and does not draw.
Member Variable Documentation
const qsizetype QcPrediction::maxPendingInputs
Unacknowledged inputs beyond this are dropped; the server would reject them anyway.