Feature Library

Factory flow: belts, pipes, power and production graphs (engine-free)

0.76 CPU ms
A still of the Factory flow: belts, pipes, power and production graphs (engine-free) demo
Still
The live demo starts when it’s in view.Belts Mk1 or Mk2 · the dock busy, slow or closed · the tower’s valve · pass a cloud · flow overlay · drag to look around

The HaTac engine’s four logistics parts, lifted whole and engine-free.

Connector paths route a belt, pipe, cable or rail between two typed ports: an orthogonal plan with filleted bends, standard heights, ramps eased at both ends or vertical risers, supports that stacked runs share, cutting in two, and an arc-length parameterisation that samples bends on their arcs. Item transport moves discrete cargo along belt segments on a fixed tick, event-scheduled so a stalled line costs nothing: sources, input ports with stock, splitters that rotate and filter, mergers that take turns, regrading, cutting and joining in place, and a whole-state save that replays item for item. Network flow solves pipes and vessels (free-surface heads, pumps, valves, one-way valves, sources and sinks, mass kept to 1e-12, components that sleep when settled) and power grids (supply, demand by priority, storage that charges and covers). Production statistics keep every counter in nested rings (1 s to 1 h, 48 hours deep) with minimum and maximum per bucket, answer sums, rates, ratios and top-N over any window, chart at one point per pixel, save in slices while play goes on, and upload a per-entity overlay (saturation, state, stress, headroom) to a GPU buffer only where it changed. No three.js, no dependencies; the overlay is the one WebGPU piece.

What it costs a frame

0.76 ms
GPU
not used
CPU, median
0.76 ms
CPU, 95th pct
1.18 ms
Draw calls
0
Weight
Moderate

Measured 28 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 158, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 0.72–0.77 ms). What ran: The four parts alone: the works simulated at 60 ticks a second (7 belts with a splitter and a merger, 3 machines, 7 fluid vessels and 6 pipes, a power grid of 8 nodes with a battery, 42 statistics series with three group roll-ups) after three warm minutes, drawn as a Canvas 2D plan, with the production panel (four figures, three time bars and a rate chart) read once a second. Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
16.85 ms
1% low ?
55 fps
Varies by ?
±0.50 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.05 ms18.29 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.85 ms
p95 ?
17.82 ms
p99 ?
18.25 ms
Slowest ?
18.66 ms
Mean ?
16.90 ms
Standard deviation ?
0.50 ms
1% low ?
55 fps
0.1% low ?
54 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.1 / 1.5 / 1.5 ms

Input

No input during this run.

Memory

JavaScript heap ?
34.4 → 33.2 MB
Growth ?
-1.19 MB

Browser

JavaScript a frame ?
0.76 ms
All tasks a frame ?
1.33 ms
Layout / style ?
0.08 / 0.02 ms
Main thread busy ?
8%

Garbage collection

Collections ?
8 (6 minor, 2 major)
Pauses ?
17.2 ms in all, longest 1.6

What it needs

Renders with
WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
Your browser
Checking…Looking for WebGPU
Depends on
NothingNo other packages
With an agent
install("factory-flow")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. A factory or automation game: belts that back up when a machine blocks, splitters and mergers, machines that starve, and the numbers that say why
  2. Pipes, tanks, pumps and valves for a city builder, a farm or a ship, with levels and flow rates a player can read and mass that never drifts
  3. A power grid with generators, batteries and consumers by priority: brownouts that hit the least important first, a battery that covers a cloud
  4. Routing a conveyor, pipe, cable or road between two ports with proper bends, ramps or risers and shared supports, and pricing it by length
  5. A production dashboard over a simulation: rates per minute, efficiency, the most blocked machine, charted over a minute or two days without storing every tick
  6. A world overlay that tints belts by how busy they are and machines by state, fed to the GPU only where something changed
  7. A deterministic simulation saved and replayed tick for tick (a lockstep multiplayer game, an undo history, a cloud save)

Pitfalls, in brief

  1. The demo needs WebGPU to draw the yard (and the production overlay is a GPU storage buffer).
  2. Give a run its ground: without ground(x, z) posts stand at y = 0 and are as tall as the run’s height, so on terrain or floors they sink into hills and float over pits.
  3. Sample a run on its arcs with pointAt and tangentAt, never by interpolating its points: the points are a bend’s chords, so items cut 1.3 cm inside a corner and turn in 15° steps.
  4. A ramp’s ends are eased vertical bends (rampBlend, 1.2 m): a ramp is up to that much longer than slope alone says.
  5. Item positions are leading-edge arc lengths in exit-to-entrance order, local to each segment: add the segment’s s0 exactly once when you sample a whole run (conveyor.ts’s writeItemPoses does).
13 more in brief
  1. Edit the transport between ticks, never inside one, and keep segment ids stable through a replay: they set who goes first when two items arrive at a junction in the same tick.
  2. Check a machine’s intake with stored(id) or storedOf(id, type), not stats(id).stored: stats builds an object and sums blocked time on every call (2,000 intakes a tick cost the engine’s game about 0.2 ms).
  3. Save the transport whole with saveState and keep the ids it returns (removed segments included: a junction’s turn cursor may name one).
  4. Budget for bursts: items on a packed line reach their joins together, so a tick can carry many transfers (1.822 ms against a 0.454 ms mean with 10,000 segments all moving).
  5. Fluid heads are free surfaces: a junction or a valve is a small open vessel, and a tiny one fills and stands at its brim, so two at the same height pass almost nothing.
  6. Orient links through pumps and one-way valves in the pumping direction: a reversed inlet blocks circulation.
  7. Reacquire a network’s component views after any edit (a split or join changes the dense indices; ids stay), and batch edits into one edit(): each repacks the touched component.
  8. Read sleeping components’ flows and event flags as steady conditions, not events: a persistent shortage stays flagged.
  9. Power: larger numeric priorities are served first, and within a priority each consumer gets the same fraction.
  10. Add a counter’s delta, never its running total, to production-stats (beltMeter in conveyor.ts turns a lane’s cumulative count into deltas), and call endTick() once per simulation tick after every producer, not from each producer.
  11. Pick the smallest bucket for the dips you need to see (sub-second dips cancel inside a one-second total), and compare rates over the seconds a query actually covered: summary(...).seconds, since old detail expires at the edge of an unaligned window.
  12. Keep retention in proportion to the series count: every series reserves 9,572 bytes in the default rings (191 MB for 20,000).
  13. The overlay uploads only changed records and joins adjacent ones: lay out entities that change often next to each other (600 scattered writes took 0.575 ms through queue completion against 0.085 ms for one run).
18 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Adapted from published work, named below.

Hannes Andersson: The HaTac engine’s connector paths, item transport, network flow and production statistics, their decisions, tests and measurements; the library’s glue and demo.

factoryautomation gameconveyorbeltsitemslogisticssplittermergerfilterthroughputbackpressurefixed tickevent schedulingdeterministicreplaysave statepipesfluidtankspumpvalvehydraulicsmass conservationpower grid

Near it in the frame