Skip to content

five-on-it / packages/sim/src/dormant

packages/sim/src/dormant ​

Dormant cars: the parked cars of a level's dormant vehicle spawners (spawners.ts: the car parks, the drives, the loading docks and the dealers' yards the generators fill) are real vehicles, got into, carjacked, picked open, shoved, shot to pieces and set alight like any other, yet they cost the step almost nothing while nobody bothers them. A dormant car is held (proxy.ts): a kinematic body that stands where it came to rest, no controller update, no wheel raycasts, no contacts with the level, passed over by the vehicle, fire and sinking systems and by the search for fast pairs (substeps.ts); solid to everything simulated, and found by rays and shots.

  • Waking. A dormant car is simulated again from where it stands, its parking brake on:
    • before a car, a trailer or a person on foot (moving faster than DORMANT.walker) touches it: every simulated mover looks the dormant cars within its reach up on a grid of the ground (cells of 8 m, as the light pieces' in breakables.ts) and asks Rapier whether its collider comes within what it covers in DORMANT.lookahead ticks of theirs, plus a margin, so a slow push wakes one as surely as a ram, and the step that follows shoves it;
    • when somebody is at it: in it, getting in, carjacking it, picking its lock or repairing it, its trunk open (a character's inside, boardCar, jackCar, holdOn or opened);
    • when it is hurt or a blast shoves it (damage.ts' hurt, weapons.ts' blast: they call wakeVehicle first), so a shot, a rocket and a neighbour's fire reach it.
  • Dozing. A car that dozes (VehicleState.dozes: its spawner's) dozes off once it has been left alone for DORMANT.dozeSeconds: standing still (slower than .still across the ground and .settle up or down, turning slower than .spin), nobody at it, not burning, and no player within .playerRange of it; freshly parked, as soon as it has stood still for .settleSeconds, on its springs where it came to rest. A car dozes with its velocities at rest and its wheels' contact as it last was.

Deterministic: the cars in ascending id order, the clocks in ticks, the state hashed. The same system runs in a client's world, where the snapshots say which twins doze (Mirror) and none dozes off by itself (a twin's dozes is 0): the predicted car wakes one as the server's does.

Variables ​

Functions ​