Skip to content

five-on-it / packages/net-client/src/mirror / Mirror

Class: Mirror ​

Defined in: packages/net-client/src/mirror.ts:194

Keeps the local world in step with the snapshots and drives prediction.

Constructors ​

Constructor ​

new Mirror(sim, clientId): Mirror

Defined in: packages/net-client/src/mirror.ts:232

Parameters ​

sim ​

SimWorld

clientId ​

number

Returns ​

Mirror

Properties ​

clientId ​

readonly clientId: number

Defined in: packages/net-client/src/mirror.ts:200

This player's client id.


predictor ​

readonly predictor: Predictor

Defined in: packages/net-client/src/mirror.ts:198

Prediction of the controlled entity.


sim ​

readonly sim: SimWorld

Defined in: packages/net-client/src/mirror.ts:196

The local world.

Accessors ​

character ​

Get Signature ​

get character(): number

Defined in: packages/net-client/src/mirror.ts:244

Server entity id of the player's character, or -1 before the first snapshot.

Returns ​

number


controlled ​

Get Signature ​

get controlled(): number

Defined in: packages/net-client/src/mirror.ts:239

Server entity id of what the player controls, or -1 (passenger, or nothing yet).

Returns ​

number


lead ​

Get Signature ​

get lead(): number

Defined in: packages/net-client/src/mirror.ts:339

How many ticks the local world runs ahead of the latest snapshot: the inputs the server has not applied yet, each a tick the prediction took past it.

Returns ​

number


picking ​

Get Signature ​

get picking(): number

Defined in: packages/net-client/src/mirror.ts:254

How far the player's hold is along (a lock picked, a device worked), 0..1, as the last snapshot says (0 when holding nothing).

Returns ​

number


presentTick ​

Get Signature ​

get presentTick(): number

Defined in: packages/net-client/src/mirror.ts:344

The server tick the local world stands at: the latest snapshot's and the lead; -1 before the first snapshot.

Returns ​

number


vehicle ​

Get Signature ​

get vehicle(): number

Defined in: packages/net-client/src/mirror.ts:249

Server entity id of the car the player sits in (driving or riding), or -1.

Returns ​

number

Methods ​

applyInventory() ​

applyInventory(message): void

Defined in: packages/net-client/src/mirror.ts:353

Takes what the server says the player holds and has open, applied to the player's twin now and after every snapshot, and the cars they keep in the garages (the local world's stored cars, so the interaction rule offers to take one out).

Parameters ​

message ​
bank? ​

number = ...

cash? ​

number = ...

container ​

{ eid: number; kind: "crate" | "locker" | "shop" | "trunk" | "safe" | "pockets"; prices?: number[]; slots: object[]; } | null = ...

slots ​

object[] = ...

stored? ​

object[] = ...

type ​

"inventory" = ...

Returns ​

void


applyKeys() ​

applyKeys(message): void

Defined in: packages/net-client/src/mirror.ts:365

Takes the tags the room's cars' keys answer to; put on their twins now and after every snapshot.

Parameters ​

message ​
keys ​

object[] = ...

type ​

"keys" = ...

Returns ​

void


applySnapshot() ​

applySnapshot(s, reconcile?): MirrorUpdate

Defined in: packages/net-client/src/mirror.ts:535

Applies a snapshot: twins are created, updated or removed, and the controlled one reconciled. With reconcile false the controlled entity is left alone (no replay): when several snapshots arrive at once only the newest needs the replay, and replaying every one of them is what lets a slow page fall further and further behind. A snapshot older than the last applied changes nothing (a frame that came late, over a transport that reorders them).

Parameters ​

s ​

SnapshotMessage

reconcile? ​

boolean = true

Returns ​

MirrorUpdate


localOf() ​

localOf(serverEid): number | undefined

Defined in: packages/net-client/src/mirror.ts:259

The local twin of a server entity, if it exists.

Parameters ​

serverEid ​

number

Returns ​

number | undefined


predicts() ​

predicts(serverEid): boolean

Defined in: packages/net-client/src/mirror.ts:284

Whether a remote vehicle, trailer or person is on the predicted timeline: the player controls something and the remote could touch it within its blend's length, the replay and the next snapshot's wait (assignProxies, at every snapshot), or could until less than a blend's length ago (the hold: one hovering at the edge goes on and off once, never back and forth with the jitter of its measured place). Such a remote is drawn where it stands at the local time (PredictedRemotes, presentPose), not interpolated in the past; a trailer goes with its tractor.

Parameters ​

serverEid ​

number

Returns ​

boolean


predictsDown() ​

predictsDown(serverEid): boolean

Defined in: packages/net-client/src/mirror.ts:297

Whether a remote person the prediction simulates (see predicts) lies knocked down at the local time: the player's car has just hit it here, before any snapshot says so (the replay of every snapshot hits it again, car-hits.ts being the same here as on the server), so its figure goes limp at the hit and not a trip across the network later.

Parameters ​

serverEid ​

number

Returns ​

boolean


presentPose() ​

presentPose(serverEid): BodyPose | undefined

Defined in: packages/net-client/src/mirror.ts:308

Where the twin of a remote vehicle, trailer or person stands at the local time: a simulated one where the prediction has it, a proxy (left where its snapshot put it) carried on by its velocity and its spin for the lead; undefined without a twin.

Parameters ​

serverEid ​

number

Returns ​

BodyPose | undefined