Skip to content

five-on-it / apps/client/src/renderer/game

apps/client/src/renderer/game ​

The game loop: given the server's welcome (the client id, the clock and the level), keeps a mirror of the server's world and predicts the entity the player controls at a fixed 60 Hz, reconciles on every snapshot, draws every frame interpolated between the last two ticks (and the remotes at the same fractional tick), drives the camera, publishes the HUD to the overlay's store (at most ten times a second), draws the collision wireframe over the level on request, sends the legend's chaser commands (a style with its car tactics and crew, the infinite-health switch) and shows the server's chaser readout (a HUD line, the minimap's marker colours), shows the player's mission (the tracker and the notices in the overlay, the target as a marker in the world and a ring on the minimap), shows the player's Wanted level (the stars, flashing while the police see the player, and the fine of an arrest, in the overlay and the hits log), flashes the light bars of the police, the ambulances and the fire trucks in their patterns and the police's dots on the minimap, sounds the sirens (the player's own, the nearest other's fainter with the distance) and the horn, shows the interaction prompt on foot (what E would do now, worked out from the local world the way the server will: get in, get in as a passenger, carjack, pick up, open a container or a trunk, close it, open or shut a door, or say it is locked) beside the character, the inventory strip and the open container's panel from the server's inventory, the phone from the server's word on it (what the world opens takes it out by itself; ui/phone-view.ts) and its waypoint on the minimap, draws the items on the ground, the containers, the terminals and the doors (items-view.ts), lays what every car's tyres leave behind (marks, smoke, dust, a landing's dust: wheel-effects.ts) and smokes every wreck (wreck-smoke.ts), draws the gunfire (tracers from the shooter's muzzle, muzzle flashes, sparks, blood that follows the person hit: gunfire.ts), animates the people (figure.ts: the player's own from its local world, its phone and its trigger at once, the rest from the snapshots; the room's chat's emotes over their players), lets them go limp when they go down (ragdoll.ts, against the level's ground and, by rays, its walls and cars), seats the riders (riders.ts: behind a car's see-through glass too), swings the cars' doors as people get in and out (car-doors.ts), cracks the windows shots go through (cracks.ts), shows stealth (the glyphs over the guards' and the sleepers' heads, the security cameras and their cones, the player seen or hidden and the room's alert: stealth-view.ts), colours the traffic lights' lamps by the junctions' fixed plan at the tick drawn (signal-lamps.ts; a junction a mission switched by hand as the server's signals frame says), shows the room clock (the server's clock frame, run on from the tick drawn), a race's readout and its next gate's arrow on the minimap, the game's restricted zones and race gates on the minimap, a shop's panel and the player's Cash (the inventory frame's), draws a player back from lying dead see-through while a ghost, keeps the room's parties on the local world's characters (the prompt never offers to carjack a party member), and exposes window.__poc for the end-to-end tests (the social side's state among it: social.ts).

Keys handled here (the rest is input.ts): the mouse aims and its left button fires, its wheel picks the target when several stand on the line of fire at different heights, its right button pops up out of cover and hides again, Q takes cover at the wall ahead or leaves it, 1–9 select the inventory's first nine slots (the weapon held is the selected slot's, the fists for an empty slot or an item that is no weapon; seated, the pistol when the player carries one), a double-tapped and held W boosts, E does what the prompt says (gets in or out of a car, carjacks one, picks up, opens and closes), F uses the selected item, G drops it on foot and is the horn at the wheel (in a car with a siren it switches the siren, which the input carries), X selects the next slot (a click on the strip selects one, a click in the container's panel moves a stack) and V asks for the next vehicle class (one-shot inputs the server validates), T takes the phone out or puts it away, Esc goes back a page of it, and while it is out 1–9 press its numbered buttons instead of selecting a slot (the phone's commands go to the server as text frames it checks), P toggles prediction, L cycles the simulated latency, K the simulated loss (the snapshots and the inputs a transport that loses frames may lose, with some jitter: the server is then asked for the acked snapshots, and the inputs go four to a frame), N toggles correction smoothing, M toggles the music, H hides and shows the HUD. Hits given and taken, and carjacks, go to a short log on the HUD.

Every snapshot frame is read through one SnapshotReader (@foi/protocol: whole, ordered deltas, acked deltas; a stale one dropped), and every tick sends a frame of the last inputs (InputHistory, @foi/net-client) with the newest snapshot tick shown as its acknowledgement; while the room is frozen for the player, the acknowledgement alone goes every quarter of a second.

Interfaces ​

Functions ​