Skip to content

five-on-it / apps/client/src/renderer/level-batches

apps/client/src/renderer/level-batches ​

The level's static pieces drawn in batches (static batching): every placement that never moves on its own is baked once, at load, into a few big meshes, one per cell of BATCH_CELL metres and per surface (what the weather and the night do to a colour), its colours carried by its vertices. A city drawn as one instance per placement cost a draw call per piece kind and colour in view (300 over Riverbend's Old Town from a raised camera) and a copy of every visible instance's matrix to the GPU every frame, which kept the browser's GPU process busy for a whole frame on the reference machine; batched, the same view is a few dozen draws of buffers that never change.

  • Surfaces. A colour's surface is what the weather does to it (wet and snowed when paved, muddy and snowed when loose ground, weather-view.ts) and what the night does (glass glows with its own colour, a lamp-like face shines, night-view.ts): one material per surface, shared by every batch, which those views change as they changed the per-colour materials. Its shader takes each vertex's colour as its diffuse colour (BatchSurfacePlugin), so a face is lit exactly as with a material of its own.
  • Light pieces. A piece a car knocks loose (breakable) is baked too, and keeps its own instance, hidden: when it comes loose its triangles in the batch are folded to a point and its instance shown, moving as the snapshots say; planted again, the other way.
  • Left out: a street lamp (its head lit lamp by lamp at night), a piece painted lava (its own glowing material), a roof that fades over the player (overhead.ts); they keep their instances.

Classes ​

Interfaces ​

Variables ​

Functions ​