five-on-it / packages/net-client/src/mirror / Mirror
Class: Mirror
Defined in: packages/net-client/src/mirror.ts:183
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:221
Parameters
sim
clientId
number
Returns
Mirror
Properties
clientId
readonlyclientId:number
Defined in: packages/net-client/src/mirror.ts:189
This player's client id.
predictor
readonlypredictor:Predictor
Defined in: packages/net-client/src/mirror.ts:187
Prediction of the controlled entity.
sim
readonlysim:SimWorld
Defined in: packages/net-client/src/mirror.ts:185
The local world.
Accessors
character
Get Signature
get character():
number
Defined in: packages/net-client/src/mirror.ts:233
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:228
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:328
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:243
How far the player has picked a car's lock, 0..1, as the last snapshot says (0 when not picking).
Returns
number
presentTick
Get Signature
get presentTick():
number
Defined in: packages/net-client/src/mirror.ts:333
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:238
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:342
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" | "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:354
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:485
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
reconcile?
boolean = true
Returns
localOf()
localOf(
serverEid):number|undefined
Defined in: packages/net-client/src/mirror.ts:248
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:273
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:286
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:297
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