five-on-it / packages/net-client/src/predictor / Predictor
Class: Predictor
Defined in: packages/net-client/src/predictor.ts:320
Drives the local prediction world for the controlled entity.
Constructors
Constructor
new Predictor(
sim):Predictor
Defined in: packages/net-client/src/predictor.ts:352
Parameters
sim
Returns
Predictor
Properties
enabled
enabled:
boolean=true
Defined in: packages/net-client/src/predictor.ts:344
Replay on/off. When off, the controlled entity simply snaps to the server's state.
inputTarget
inputTarget:
number=NO_TARGET
Defined in: packages/net-client/src/predictor.ts:348
Local entity id that receives the player's input: their character (it forwards to the car it drives).
sim
readonlysim:SimWorld
Defined in: packages/net-client/src/predictor.ts:346
The local prediction world.
target
target:
number=NO_TARGET
Defined in: packages/net-client/src/predictor.ts:350
Local entity id whose snapshot is reconciled: the character on foot, the car while driving; else NO_TARGET.
Accessors
stats
Get Signature
get stats():
PredictorStats
Defined in: packages/net-client/src/predictor.ts:775
Current statistics for the HUD.
Returns
Methods
applyLocal()
applyLocal(
raw):InputMessage
Defined in: packages/net-client/src/predictor.ts:374
Applies an input locally for one tick and returns the message to send to the server. The returned input is the quantized one the server will see.
Parameters
raw
Returns
catchUp()
catchUp(
lastSeq):void
Defined in: packages/net-client/src/predictor.ts:457
Before a snapshot acknowledging the client's tick lastSeq is applied: the ticks up to it the local world has not run, the server ran on its guess (none of their inputs had been sent), and they are run here on it too, so the snapshot is held against what the prediction has for its own tick. Only when they are MAX_GUESSED_TICKS or fewer: a longer gap is the snapshot's to put right.
Parameters
lastSeq
number
Returns
void
guess()
guess(
ticks):void
Defined in: packages/net-client/src/predictor.ts:444
Runs ticks of the client's clock that its frame loop dropped (a stall) on the input the server runs them on, its guess: the last input sent held without its presses and, unless the character's grenade is cooking, its trigger (guessedInput). Their inputs are never sent (the server, which runs a client's ticks one per tick of its own, runs them on that guess whatever comes), so the next input is numbered by the clock, the tick it is for. MAX_GUESSED_TICKS of them at most are run, the oldest; the numbers of the rest are skipped, the local world short of them until a snapshot puts it right.
Parameters
ticks
number
Returns
void
pendingAfter()
pendingAfter(
lastSeq):number
Defined in: packages/net-client/src/predictor.ts:768
How many inputs a snapshot acknowledging lastSeq would leave pending: the ticks its reconcile replays, and the local world runs ahead of it (the mirror sizes its horizons by this before the replay).
Parameters
lastSeq
number
Returns
number
reconcile()
reconcile(
mine,lastSeq,trailer?,stands?,driver?):object
Defined in: packages/net-client/src/predictor.ts:683
Reconciles with the server's view of the controlled entity and returns the correction vector (predicted pose minus corrected pose), so the renderer can smooth it away: zero when the server's word agrees with what the prediction had for the acknowledged tick (see the module documentation). With stands (the Mirror's word that the prediction stands as a whole, standing), nothing is rewound nor replayed.
Parameters
mine
lastSeq
number
trailer?
stands?
boolean = false
driver?
Returns
object
dx
dx:
number
dy
dy:
number
dz
dz:
number
resetStats()
resetStats():
void
Defined in: packages/net-client/src/predictor.ts:790
Forgets the correction history (after toggling modes).
Returns
void
retarget()
retarget(
inputEid,reconcileEid?):void
Defined in: packages/net-client/src/predictor.ts:361
Switches the entity that gets the input and the one that is reconciled (the same entity on foot and in tests; the character and its car while driving). Pending inputs were meant for the old one and are dropped.
Parameters
inputEid
number
reconcileEid?
number = inputEid
Returns
void
standing()
standing(
mine,lastSeq,trailer,loose,driver?):Set<number> |undefined
Defined in: packages/net-client/src/predictor.ts:563
Whether the prediction stands on a snapshot acknowledging lastSeq (see the module documentation): the server's word on the controlled entity (mine, its trailer) agrees with what the prediction had for that tick, and so does its word on every light piece within PIECE_SCOPE of it there (loose: the pieces the snapshot lists loose, by placement; one it does not list stands planted), loose or planted alike and where it lies within QUANTIZED_AGREEMENT, and on the hit points of the player's character at its wheel (driver, a wreck's crash hurts it). Returns the placements in that scope, whose local state the Mirror keeps; undefined when it does not stand. The Mirror asks it before it lays the snapshot's pieces, and passes the answer to reconcile; whether anything else near the controlled entity is simulated is the Mirror's to say.
Parameters
mine
lastSeq
number
trailer
EntitySnapshot | undefined
loose
ReadonlyMap<number, BodyPose>
driver?
Returns
Set<number> | undefined
takeFelt()
takeFelt():
FeltCrash[]
Defined in: packages/net-client/src/predictor.ts:428
The crashes felt since the last call, oldest first (see FeltCrash); the list is emptied.