Skip to content

Interface: PredictorOptions<View, Command> ​

Defined in: client/predict.ts:5

How a Predictor works out what the room will do with this player's commands.

Type Parameters ​

Type Parameter
View
Command

Methods ​

apply() ​

ts
apply(
   state, 
   command, 
   you
): void;

Defined in: client/predict.ts:13

What one of this player's commands does to the state, written the way the room's onCommand is: change state in place. It is given a draft of the room's state, so the room's state itself is never touched, and you is this player's id. If the room would refuse the command, change nothing.

Parameters ​

ParameterType
stateView
commandCommand
youstring

Returns ​

void


tick()? ​

ts
tick?(state, you): void;

Defined in: client/predict.ts:23

What one tick does to what this player controls, written the way the room's onTick is. Give it for a game in which a command sets something in motion that the simulation then carries on with, such as a unit that walks to where it was sent: the prediction then runs as far ahead of the room's state as a command takes to come back, and the player's own unit moves the moment they act. Leave the other players' units alone: where they will be is not this player's to know.

Parameters ​

ParameterType
stateView
youstring

Returns ​

void


onState()? ​

ts
onState?(state): void;

Defined in: client/predict.ts:29

The room's state changed, or a command was sent, applied or refused. With tick the prediction also moves on with time: read state when you draw, rather than wait for this.

Parameters ​

ParameterType
stateView

Returns ​

void


now()? ​

ts
now?(): number;

Defined in: client/predict.ts:31

The clock, in milliseconds. Defaults to Date.now.

Returns ​

number

MIT licence. Tickflare is an independent project and is not affiliated with Cloudflare.