Runs in a desktop browser with WebGPU (recent Chrome or Edge). On Linux, Chrome needs the enable-unsafe-webgpu flag. Phones are not supported.
This game was written as an early experiment in complex gameplay. At the time, a wave of serious protests started in Europe (France, Spain, …). But Ljubljana, where I live, has seen its share as well, especially during the COVID period. In this game, I wanted to recreate some historic scenarios and transfer some seen in foreign capitals as a what-if here.
You can play the police command or the protest coordinator. Naturally, the police has many more tactical options at their disposal: gas, water cannon, kettling, snatching of protest leaders, etc. As a protest leader, you can move the crowds and form basic walls, but not much else. I started the development without being strictly aware of this asymmetry, so the missions lean more towards playing as police.
WebGPU proved to be a good match, if you can enable it in the browser. It runs smoothly even in a crowded map, so try it out. The development is not strictly over – I plan to add some scenarios in Paris and Belgrade as well.
The game
Cordon Bleu is a real-time strategy game about crowds. Twelve standalone missions of 10 to 20 minutes put you in command of police squads or of protest groups: escort a VIP convoy to the National Assembly, keep a march and a counter-protest apart, carry a banner up Miklošičeva to the court before the verdict, get a speaker out of a kettled square. Some missions are based on real events in Ljubljana, others are fiction. Each has its own win and lose conditions and a score of one to three stars.
Two gauges run through every mission. Public opinion moves with what you do: police violence costs you, violence against the police earns you some back. The escalation ladder (force, tear gas, water cannon, firearms) only goes up. Every step makes the next order easier to give and the crowd harder to calm. The violence itself is abstract: dots, counters and a feed of events. The tone is serious.

The game is written in TypeScript with three.js and its WebGPU renderer, with Tone.js for sound and Vite for the build. There is no game engine and no server: the build is a static site. The code is on GitHub under the MIT licence.
A city from open data
The map of central Ljubljana is a 3.2 × 2.9 km rectangle around Prešernov trg, built by a Python script from the PostGIS database behind bloki.si. Building footprints come from the GURS building cadastre. The cadastre misses roughly half of the old-town footprints, so OpenStreetMap buildings fill the gaps. Streets, water, parks, railways and CCTV cameras come from OpenStreetMap, bus stops from LPP, and the convoy route from pgRouting on the car network. Everything is projected to D96/TM and stored in local metres around a fixed origin.
The script writes a city.json with the vector geometry for drawing, plus three small rasters that the simulation reads:
- A signed distance field at 1 m: for every square metre, the distance to the nearest wall or the river, in decimetres, in one signed byte. People slide along walls instead of snagging on them, and a GPU texture lookup tells each agent how far the nearest facade is.
- A walking cost grid at 4 m: streets and pedestrian zones are cheap, courtyards and railway lines expensive, buildings blocked. Crowds plan their routes on this grid.
- A CCTV grid at 4 m: which cells each camera from OpenStreetMap can see within 35 m, with line of sight tested against the buildings. A protest leader who walks into a covered cell is identified, and the police player can send a snatch squad after them.

Thousands of people on the GPU
Every person in the game is simulated individually, and all of it runs in WebGPU compute shaders, written in three.js’s shading language TSL. The buffers have room for 98,304 agents. Each agent is a few vectors: position and velocity; faction, group, agitation and health; and a few more numbers such as resolve, role and arrest progress. Five kernels run in order 60 times per simulated second:
- clear and clearDens zero the counters.
- insert puts every agent into a spatial hash of 1.25 m cells (262,144 buckets of up to 16 people, claimed with atomic adds), and adds it to a coarse 4 m density grid that counts each faction, the agitation and the injured.
- update is the big one. Each agent steers by its group’s flow field or police formation, keeps close to its group leader, and pushes against the people in the 3 × 3 neighbouring cells through damped springs, so dense crowds compress and transmit pressure. It also reacts to walls, vehicles, tear gas and water cannon, and updates agitation, resolve, injuries and arrests.
- commit integrates the positions, pushes anyone left inside a wall back out and gathers statistics.
There is no central decision-maker for the crowd. Each person’s agitation rises with crush (but only past the normal compression of a dense crowd, so a packed square stays calm while a kettle boils), with blows, tear gas and soaking, and with the agitation of the people around them. A group leader sets the mood, and an attacked leader sets the group off. Resolve is how committed someone is to staying: it falls with gas, water, injuries and time, rises with numbers around them, and once it drops below zero the person walks to the nearest map exit and goes home. That is how most crowds in the game end: not beaten, just thinned out.

The simulation never waits for the CPU. The game logic needs only aggregates: counters (injuries, arrests, how many people are in a zone) read back every frame, and a fuller snapshot of positions and states every half second. From that snapshot the game works out group centres and leaders, checks the CCTV grid and drives the AI police and crowds. Orders go back to the GPU as uniforms and small batches of edits (spawn, remove, nudge), so the flow of data stays one-directional and asynchronous.
Flow fields
Twenty thousand people can’t each run a path search, so they share them. A goal (a square, a building, the map exits) becomes a flow field: Dijkstra from the goal cells outward over the 4 m cost grid, after which each cell points toward its cheapest neighbour, smoothed over 3 × 3. Three Web Workers compute the fields in the background. The results go into a pool of 32 layers in one half-float array texture, which the crowd shader samples with bilinear filtering. Every group refers to a layer, and a thousand-person march costs the same as a single walker. When a new order needs a field that isn’t ready yet, the group keeps its old one until the worker is done.
Crowds at police lines
For a long time the crowds walked straight into the shields: a march’s flow field ignores the police, so the physics pressed the front rows into the cordon, and the injuries piled up even when nobody meant to fight. Now a crowd that a police line blocks climbs a ladder of four levels. First it walks up to about 10 m from the line and stands there while the rest queue behind. After a minute, small groups of 5 to 15 people break off and lean on the line, then come back. Then the whole group pushes, and finally a militant group storms one point of the line while its leader throws firecrackers.

What moves the crowd up the ladder is the waiting, and above all police action: charges, kettles, arrests, gas and water within about 40 m, or their own people hurt or arrested. A minute and a half of quiet brings it down a level. Agitation only sets the starting level. When it drove the ladder, peaceful marches got angry just squeezing through a narrow street and went for the shields again. The result is the dynamic the game is about: quiet policing calms crowds, and heavy-handed policing unites them against the police. In a test of the Clash mission with the same cordon, injuries caused by police at about five and a half minutes fell from 373 to 81.
Queueing was the hardest part to get right on the GPU. A hard stop behind slow people deadlocked the front row when the flow field ran diagonally, because neighbours in the same row counted as being “ahead”. Stopping at 0.8 m froze crowds whose normal spacing is about 0.6 m. What works now: behind someone slow, creep forward at 0.3 m/s, and stop only when pressed closer than the normal spacing.
Missions as plugins
The first missions were classes that reached into the engine wherever they needed to. As their number grew, I added a Scenario SDK: a mission is a definition with places, a setup that spawns crowds, squads and vehicles, objectives, outcome rules and a scoring policy. A mission is also an ES module that can be loaded from a URL with ?plugin=. It gets only the public builders, never the simulation buffers or the DOM. This is the smallest one:
export const sdkVersion = 1;
export default ( { defineScenario, place, survive } ) => defineScenario( {
id: 'hello-scenario',
title: 'Hello Square',
brief: 'Keep Trg republike calm for one minute.',
goals: [ 'Hold the square for 1:00' ],
locations: { square: place( 'Trg republike' ) },
setup( ctx ) {
ctx.presentation.focus( 'square', 0.5 );
ctx.spawn.crowd( { id: 'demonstrators', at: 'square', people: 300 } );
ctx.spawn.squad( { id: 'squad-east', at: [ -10, 20 ] } );
},
objectives: [ survive( { id: 'hold', seconds: 60, label: 'Hold the square' } ) ],
} );
The built-in missions are moving to the same SDK one by one, each first as a candidate that has to match the old mission’s results. Clash is the first one rewritten entirely on it. The plugin authoring guide describes the whole API.
Other cities
Ljubljana’s maps come from a database that only I have, so other cities needed a different route. A second build tool makes a map of any city from OpenStreetMap alone. A settings file names the centre and size of the play area, the places missions refer to, the convoy route and the buildings to defend. The tool downloads the smallest Geofabrik extract that covers the area, clips it, projects it to a transverse Mercator centred on the map and writes the same files the Ljubljana script writes, so the game needed no changes to load them. The convoy route is now a one-way-aware Dijkstra in SciPy instead of pgRouting. The only requirement is uv, which installs Python and the rest.
A small map editor on Leaflet places the play area, the places and the route, picks the landmarks (parliament, ministries, police stations, hospitals, embassies, TV studios) from OpenStreetMap tags and shows the rasters the game will use. Names are the contract between maps and missions: every build lists the places and landmarks that appeared or disappeared since the previous one, so an edit in OpenStreetMap can’t silently break a mission. Belgrade and Paris are the next cities.
Data
Map data © OpenStreetMap contributors, under the ODbL. Building footprints © Geodetska uprava Republike Slovenije (Kataster stavb, e-prostor), under CC BY 4.0. Bus stops © LPP. Sound effects from Pixabay; the rest of the sound is synthesised in the browser.
