1681-engine / index / PredictedMover
Class: PredictedMover ​
Defined in: src/net/PredictedMover.ts:15
Client-side prediction for the local player's body. Every input step is applied at once (the player sees their own move with no lag) and kept until the server acknowledges it. When a snapshot says where the server has the body as of step ack, the body is put there and every step after ack is replayed on top.
Movement is deterministic (stepMover), so with the same steps, params and grid the replay lands exactly where the prediction was and nothing moves. When it does not (the server refused a step, a collision only it knew of), the difference is correction: draw the body at drawX/drawY, which ease that jump out over a few frames instead of snapping.
Constructors ​
Constructor ​
new PredictedMover(
x,
y,
params,
grid
): PredictedMover;Defined in: src/net/PredictedMover.ts:27
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
params | MovementParams |
grid | CollisionGrid |
Returns ​
PredictedMover
Properties ​
correction ​
correction: number = 0;Defined in: src/net/PredictedMover.ts:23
How big the last correction was (0 when the prediction was right).
mover ​
readonly mover: MoverState;Defined in: src/net/PredictedMover.ts:16
smoothing ​
smoothing: number = 0.8;Defined in: src/net/PredictedMover.ts:25
Share of a visual correction left after each 60th of a second (default 0.8).
Accessors ​
drawX ​
Get Signature ​
get drawX(): number;Defined in: src/net/PredictedMover.ts:80
Where to draw the body: the predicted place plus the correction still being eased out.
Returns ​
number
drawY ​
Get Signature ​
get drawY(): number;Defined in: src/net/PredictedMover.ts:84
Returns ​
number
unacknowledged ​
Get Signature ​
get unacknowledged(): number;Defined in: src/net/PredictedMover.ts:45
Steps sent but not yet acknowledged.
Returns ​
number
Methods ​
reconcile() ​
reconcile(ack, server): void;Defined in: src/net/PredictedMover.ts:50
The server's word: the body as of step ack. Rewinds there and replays the rest.
Parameters ​
| Parameter | Type |
|---|---|
ack | number |
server | MoverWire |
Returns ​
void
setGrid() ​
setGrid(grid): void;Defined in: src/net/PredictedMover.ts:93
Parameters ​
| Parameter | Type |
|---|---|
grid | CollisionGrid |
Returns ​
void
setParams() ​
setParams(params): void;Defined in: src/net/PredictedMover.ts:89
New movement rules (a buff, a slow): applied to future steps and to replays.
Parameters ​
| Parameter | Type |
|---|---|
params | MovementParams |
Returns ​
void
smooth() ​
smooth(dt): void;Defined in: src/net/PredictedMover.ts:71
Eases the visual correction out; call once a frame with its length in seconds.
Parameters ​
| Parameter | Type |
|---|---|
dt | number |
Returns ​
void
step() ​
step(step): number;Defined in: src/net/PredictedMover.ts:37
Applies one input step now and keeps it for replay; returns its sequence number (send it with the step).
Parameters ​
| Parameter | Type |
|---|---|
step | InputStep |
Returns ​
number