← CloverleafA city builder played like Satisfactory
Development notes · October 17, 2026
How Cloverleaf's traffic works
In Cloverleaf, roads are the conveyors, and every truck on them is real: it drives there and back, and it never vanishes out of a jam. Doing that for a city of 400,000 people means thinking hard about how traffic is simulated. This is a look at the research behind it: the ideas we're building on, the math behind each one, and what's still open. Every picture in section 04 is interactive.
Cloverleaf is early in development. Numbers are targets or estimates unless marked as measured.
M measured on our test bench
P measured in a published paper
E our estimate or derivation
01The goal
Cloverleaf's traffic has to hold these targets on a 2020-class 6-core PC:
The reference city: 400,000 people, about 4,100 buildings and 20,000 freight trucks, at full speed in under 4 ms of simulation per frame.
The stress city: four times that (about 16,000 buildings and 80,000 vehicles) in the same budget.
A stretch city at eight times the reference, which we measure as we go.
Steady while you survey: a city you aren't editing runs rock solid, and after a burst of building it recovers by itself.
None of this is allowed to cheat. Every truck is real, nothing despawns, there's no hidden capacity, and the simulation gives exactly the same result on every PC, which co-op needs. If a PC can't keep up, the simulation runs slower and the frame rate holds, the way Factorio does it. We never quietly drop work.
02The core approach
Simulate in full detail only what someone is looking at, and do work only when something changes.
One model at two resolutions. Up close, cars are particles (agents). Far away, traffic is a wave (queues). Both obey one traffic law, so a car can switch between them exactly.
Free-flowing trucks are booked once on departure and cost nothing until they arrive.
Settled supply lines go to sleep with a certificate saying when to wake them.
Routing reacts only to events, and the math proves which events it can skip.
Building bursts: all long work is capped and sliced, so pasting a blueprint can never spike a frame.
The particles-close, waves-far picture is Brad-Lee Nichols's idea.
Picture 0 · The bubble
Detail only where someone is looking
This is a city seen from above, with you (the Mayor) at the center. Cars inside the yellow bubble are full agents: each one steers, brakes and keeps its distance on its own. Out to the dashed 1.5 km ring, cars are still drawn, but their positions come from the cheaper queue model (the meso), so nothing pops in when you turn around. Past the ring, nothing is drawn: each street is just a queue with a color for how busy it is. Every car is still simulated there, only more cheaply.
The bubble leans the way you face, and when you turn it swings round after a short delay.
Schematic. The real bubble's size, lean and delay are still being tuned.
Most of the city runs as queues, which are far cheaper than steering every car. We expect about 25× fewer full agents E. The handover can't be seen, because the agents and the queues follow the same traffic law (Picture 1).
03The ideas
Ranked by how much we expect each to help.
#
Idea
What it buys
Expected gain
1
Bounded edit work
Capped, sliced rebuilds: no frame spikes while you build, and recovery by itself
Removes a 1.75 ms spike per edit burst M
2
Particles close, waves far
One traffic law for agents and queues, with a bubble of detail around each viewer
About 25× fewer full agents E
3
Cost only on change
Booked free-flow trucks and routing that proves which updates it can skip
Most per-tick truck work vanishes in a healthy city E
4
Settled lines sleep sooner
Max-plus algebra spots a supply line's rhythm exactly
Up to about 3× sooner E
5
Sharp route search while you build
A repair for A*'s landmark hint when new roads open
Avoids a 7.5× slower fallback M
6
Proved recovery times
Network calculus says in advance how fast a burst clears
Turns "is it solid?" into a formula
7
Commuters as flows
Commuters travel as flows between real homes and jobs, and become individual cars when you look
Keeps commuting bounded at large city sizes E
8
Multi-core
Fixed work partitions, so the result never depends on thread count
About 3× on routing with 4 workers E
9
Per-lane queues
One slow truck no longer blocks a four-lane road
Correctness
10
Exact gridlock detection
A "blocked by" forest that finds a gridlock loop the moment it closes
Constant cost per event E
11
Event-driven signals
Traffic lights cost only when they change
No per-tick scanning of every junction
04The math, shown
Each idea below has a picture you can play with. Read the plain words first, then try the picture. The formula comes last, for anyone who wants it. Where a picture uses example numbers rather than the game's data, it says so.
Picture 1 · The triangular fundamental diagram
How many cars a road can carry
Add cars to an empty road and, at first, everyone drives at the speed limit, so each extra car adds to the flow. Past a certain density, cars are too close to keep the speed limit. Everyone slows down, and fewer cars get through per minute even though more are on the road. Draw flow against density and you get a triangle. Its peak is the road's capacity.
q is the flow (cars per hour), k the density (cars per km), vf the free speed, kj the density of a stopped queue, δ the spacing in a stopped queue, and τ the time gap a driver keeps. Lane capacity vf/(vfτ + δ) equals the road table's number exactly.
Example numbers: 50 km/h, δ = 7.5 m, τ = 1.5 s. The game uses one triangle per road type × vehicle, from the road table.
For Cloverleaf: both levels of detail are built on this one curve, so they agree by construction. The within-10% match is a test that should pass, not a tuning job.
Picture 2 · Newell car-following
Every driver copies the car ahead, a moment late
Newell's rule is short: drive at the speed limit, unless that would bring you closer than a set gap to where the car ahead was a moment ago. Watch a queue at a light that turns green. The front car pulls away, and each car behind starts one reaction time later. The "go" signal travels backward through the queue at a steady speed, the slope −w of the triangle in Picture 1.
The lower chart is a time–space diagram: each line is one car, with time going right and distance going up. A flat line is a stopped car, and a steep line a fast one.
xi(t+Δt) = max( xi, min( xi + Δt·min(vf, vi + aΔt), xi−1(t + Δt − τ) − δ ) )
Car i's next position is the smaller of two limits: where speeding up toward the speed limit vf at acceleration a would take it, and where its leader i−1 was τ seconds ago, less the gap δ. The outer max means it never reverses.
For Cloverleaf: on a long, steady road, Newell's rule settles exactly onto the triangle. So the agents up close and the queues far away agree with no tuning. That's why it replaced IDM, a popular car-following model that, with our road data, missed the capacity by as much as 2× E.
Picture 3 · Ballistic arrival
Book the arrival, then stop thinking about it
If the road ahead is clear, a truck's arrival time is just distance over speed, added up edge by edge. So on departure, write the arrival in the calendar once and do nothing more until it's due. The truck still drives, and you still see it. Only when an edge on its route changes congestion band (a band event) do the trucks that still have to cross that edge work their times out again.
Both rows below move the same trucks the same way. The counters show the work each method does. Try jamming an edge.
tarrive = tdepart + Σe ∈ routeLe / vf,e
Le is each edge's length, and vf,e its free speed. Recompute only when an edge on the route changes congestion band.
One work unit = updating one truck for one tick, or booking one route. Example road and speeds, shown 10× faster than real time.
For Cloverleaf: in a healthy city most trucks are free-flowing, so most per-tick truck work disappears E. This is still a lead: the gain hasn't been measured yet.
Picture 4 · Max-plus periodicity
Supply lines fall into a rhythm, and then they can sleep
In a supply line, each event waits for the last of the things it depends on, then takes a fixed time. Example: a truck leaves once it's loaded and the dock is free. "Wait for the latest" is a max, and "then add a fixed time" is a plus. Mathematicians call a system built only from max and plus max-plus algebra, and it has a lovely property: after a short settling-in, it repeats exactly, step after step.
The chart plots three event times, with the steady pace removed. While the system settles, the lines wobble. Once they repeat, the line has found its rhythm. It can then sleep with a certificate, a guarantee of exactly when every future event happens, at the cost of one calendar check.
x(k+1) = A ⊗ x(k), (A ⊗ x)i = maxj (Aij + xj), x(k+c) = x(k) + cλ
x(k) holds the times of the kth round of events, and Aij is the fixed time event i waits after event j. After a finite transient, the sequence repeats every c rounds, advancing by λ per round, where λ is the slowest loop's average time (the maximum cycle mean, found by Karp's algorithm). That gives an exact settling test, so there's no need to wait three round trips.
Example matrix, times in minutes. Here the slowest loop alternates two events, so the rhythm repeats every 2 rounds.
For Cloverleaf: settled lines sleep up to about 3× sooner E. The same algebra also tells the city's Problems page which loop sets the pace: the exact "why" behind a slow line.
Picture 5 · The landmark overlay
Keeping route search sharp when the player builds a bridge
To find a truck's route, A* search explores outward from the start, guided by a hint: a guess of the time left to the goal. A better hint means less exploring. The one rule is that the hint must never overstate the time, or the search can skip past the true best route.
Landmarks make an excellent hint. We measure the time from a few far-off reference points (the black diamonds; switch on a landmark hint to see them) to everywhere, ahead of time. If the depot is 10 minutes from a landmark and you're 25 minutes from it, you must be at least 15 minutes from the depot. But a new road makes those measured times out of date, and then the hint can overstate. Build the bridge below and try plain landmarks: the search misses the bridge. The old fix was to fall back to the straight-line hint, which is safe but slow (7.5× slower on our bench M). The overlay repairs the hint: either the route avoids the new bridge, and the old hint still holds, or it uses the bridge, and then it's at least the time to reach the bridge, plus the crossing, plus the rest. The smaller of the two is always safe and still sharp.
hALT is the landmark hint, and hEuclid the straight-line hint. Each new road ei runs from ui to vi with time c(ei), and LB is a lower bound on the time to reach it. Any shortest path either avoids every new road or uses one first, so this stays a true lower bound after roads are added.
Example map. Off-road cells cost 1 and road cells cost 0.3. The numbers in the table are this map's real search results.
For Cloverleaf: routes stay correct and fast while the player builds, avoiding the 7.5× fallback M, at about 1.5–2× the cost per explored node while the overlay is active E. We haven't found this repair rule published anywhere.
Picture 6 · Network calculus
How long a city takes to recover from a blueprint paste
Pasting a big blueprint dumps a pile of work on the sim at once: routes to re-check, queues to rebuild. Meanwhile ordinary building keeps adding a trickle. The sim clears a fixed amount per tick and no more, so no frame ever spikes. While the trickle is slower than the clearing rate, the pile shrinks at the difference, and we can say in advance exactly when it's gone.
In the chart, the yellow line is all the work that has arrived so far, and the green line is all the work cleared so far. The gap between them is the pile. Where they meet, the city has recovered.
D ≤ T + σ / (R − ρ), stable only if ρ < R
σ is the burst: the pile waiting when clearing starts (the paste plus whatever trickled in during the delay T). ρ is the steady rate, and R the per-tick drain. The ρ/R ratio is the early warning: the closer it gets to 1, the slower a city recovers while you keep building.
Example numbers, in work units per tick.
For Cloverleaf: this turns "is it solid?" into a formula before any playtest. It's math from guaranteeing internet routers, reused to prove that a city recovers from a pasted blueprint.
Picture 7 · Junction yield (Siegloch) and start-up lag
How many cars can slip into a busy road
A car waiting to join a priority road needs a big enough gap in the traffic: it goes if the next car is at least tc seconds away, and the cars queued behind it can follow every tf seconds. The busier the main road, the rarer the big gaps, so side-road capacity falls away smoothly, as an exponential. The animation runs the gap rule and counts the cars that get in. Over time the count should settle near the formula's curve.
c = s·e−qp(tc − tf/2)
c is the side-road capacity, qp the priority flow and s = 1/tf the rate if the main road were empty. Our constant 0.07 means tc − tf/2 = 4.2 s, a realistic gap (here tc = 5.8 s and tf = 3.2 s).
The start-up lag
A car pulling away from a stop takes a while to reach speed, so it falls behind a car that was already moving. The shaded triangle is the distance it loses. Divide by the speed and you get the time it loses, ℓ, which is owed once per platoon start at a junction, not once per car.
ℓ = vf / (2a)
For Cloverleaf: junction rates come straight from these two formulas and each vehicle's acceleration in the game data, with no hand-tuned "lost time".
Picture 8 · Bounded edit work
Why a blueprint paste never hitches the game
Each bar is one sim tick, and the line is the 4 ms budget. Paste a blueprint with "all at once" and the work lands in a single tick, blowing the budget: you'd feel a hitch. With "capped and sliced", the same work waits in a queue and each tick takes only a capped slice, so every bar stays under the line. Picture 6 is the math that says how long the queue takes to drain.
Example tick times. The spike we measured on the bench was 1.75 ms for a single edit burst M, an estimated 3.5 ms at 8× E.
Picture 9 · The blocking forest
Spotting gridlock the instant it happens
Every stuck car points at the car blocking it. Usually the arrows form trees, which all lead back to a car that will move eventually (a root). Gridlock is the one case where the arrows go round in a loop and nobody can ever move. Each car remembers its root, so when a new arrow is added, one look tells you whether it points back to its own chain. If it does, that's a loop, found the moment it closes, with no "stuck for 60 seconds" timer.
For Cloverleaf: exact gridlock detection at about O(1) per event and 2.6 MB E. The same arrows give the city's Problems page its "blocked by" chain for free: it shows what is wrong and where, never the fix.
05What's new
As far as we've found, these ideas are new to city builders, and a couple may be new anywhere.
Repairing A*'s landmarks after roads are addedWe haven't found this repair rule published anywhere.
One traffic law for both levels of detailUp-close agents and far-away queues follow the same curve, so the switch between them is exact rather than tuned.
Max-plus certificates for a sleeping factoryA settled supply line costs one calendar check, and the same algebra tells the city's Problems page exactly which loop sets a line's pace.
The observer ruleA commuter is part of a flow until a player looks at it. It then gets a real, deterministic identity and stays detailed while you track it, so you can follow one person home.
Network calculus for building burstsMath designed to guarantee internet routers, reused to prove a city recovers from a pasted blueprint.
Exact gridlock detectionA loop in a "blocked by" forest, with no timeouts.
06What's still open
Sharing the PC with the renderer. How many cores the simulation gets beside the game engine. We plan for 3–4 until we can measure it.
Long trips across the map. Whether landmark search with the repair stays fast on 5–15 km trips. If not, we have a heavier technique (customizable contraction hierarchies) in reserve.
The bubble's numbers. Its radius at each eye height and zoom, how far it leans and how quickly it catches up are all still to be tuned.
Rain. When a shower starts, every dirt track slows at once. The per-tick cap bounds that burst, but we haven't measured it yet.
Pathological layouts. A single 5,000-truck corridor or a spaghetti junction must cost no more than the same amount of normal traffic. Per-road queue work should guarantee it, but it isn't benchmarked yet.
Booked trucks are still a lead. The gain from booking free-flowing trucks hasn't been measured.
07What we draw from
Cities: Skylines with TM:PE for the depth of traffic tools: lane arrows, junction rules and priority roads, with traffic as the main late-game puzzle.
Satisfactory for first-person building where the factory is the game.
Factorio for a simulation that slows instead of dropping frames, gives the same result on every PC, and is talked about openly in its Friday Facts.
Navigation apps for route choice: each truck takes its own quickest route and switches only when it clearly pays.
Brad-Lee Nichols for the particles-close, waves-far idea at the heart of it all.