The Battlefield Remembers: Persistent Decals in a 2D Game
In Iron Sector nothing on the ground ever disappears: every track, crater, body and gun wreck stays for the whole battle, more than a hundred thousand of them on the largest map. This lesson shows how the game keeps them all and pays almost nothing for it, from the list the simulation writes to the pixels painted into the ground, with the game's real numbers.
- decal records on the largest map after ten minutes
- 116,645decal records on the largest map after ten minutes
- kinds of record, appended and never removed
- 11kinds of record, appended and never removed
- per frame for off-screen chunks to catch up
- 1.5 msper frame for off-screen chunks to catch up
- to repaint all 5,772 records of a 20-minute battle
- ≈ 30 msto repaint all 5,772 records of a 20-minute battle
Nothing disappears
Iron Sector was built on one rule: nothing on the ground ever disappears. A tank drives across a field and its tracks stay there for the rest of the mission. A shell lands and the crater stays. A man falls and his body stays where he fell. At the end of a battle the field is a record of everything that happened on it, and you can read the fight from the marks.
Most games fade such marks out after a few seconds, or keep the last fifty and drop the oldest. The reason is cost. If every mark were a sprite drawn every frame, the field would cost more than the army on it. On the Kursk map after twenty minutes there are 5,772 marks on the ground and 128 men and vehicles still alive: drawn as sprites, the marks alone would be 45 times more draws than the army.
The answer is an old one: paint it once, and keep the paint. Every mark is painted a single time into the picture of the ground, and from then on it costs nothing to show.
Kursk, 20:00: 5 772 marks / 128 men and vehicles alive ≈ 45 ×


The simulation only writes a list
The simulation never draws anything. When a shell lands, it appends one record to a list called the decals. A record is small: a kind, a position in model units, a size or a heading and a width, and, for the marks that need some randomness, a seed. Craters, tracks and pivots also carry a number for the kind of ground under them, which the simulation already knows.
There are eleven kinds. Craters and scorch marks from explosions. Tracks from tracked vehicles and tyre prints from wheeled ones. Pivot rings where a tank turned on the spot. Brass casings, mine lanes marked with tape, flattened wire, bodies, baked wrecks, and the empty tubes of anti-tank launchers.
The list is append only: nothing is ever removed from it, and nothing is changed. The seed is drawn from the simulation's own random stream at the moment of the event. That matters, because the same battle replayed from the same seed produces the same list, record for record. The renderer's only job is to turn that list into paint.
{ k: "crater", u: -440.11, v: 343.35, r: 8.06, seed: 470178, g: 2 }
{ k: "track", u: -769.47, v: -307.46, a: -17.04, w: 3.29, g: 0 }
{ k: "body", id: 121, u: -482.18, v: 321.74 }
Stamping into the ground
The ground is not one picture. It is a grid of canvases of at most 1024 × 1024 pixels, called chunks, and the renderer owns them. The Kursk map is 21 of them, in three rows of seven, the last column only 576 pixels wide. How those pictures are made is the subject of the previous lesson; here what matters is that they can be drawn on.
When a new record appears in the list, the renderer computes its bounding box, finds every chunk that box touches, and paints the mark into each of them once. A crater that sits on a chunk border is painted twice, into both chunks. Each chunk translates the drawing by its own origin, a whole multiple of 1024 pixels, so the second copy is the same paint shifted by an exact number of whole pixels, and the two halves meet with no seam.
Every chunk keeps a counter, called upto, of how far down the list it has painted. A chunk that is on screen paints the new records in the same frame, so the crater is already there under the smoke of the shell that made it. A chunk that is off screen can wait.
ctx.translate(−X0, −Y0), X0 = 1024 · column 152 mm crater at map x = 2048: chunk 1 (x 1024–2048) and chunk 2 (x 2048–3072) chunk 1: x − 1024 = 1024 (its right edge), chunk 2: x − 2048 = 0 (its left edge)

Catching up off screen
While you watch one corner of the map, the rest of the battle goes on, and the chunks you cannot see fall behind the list. Each frame the renderer gives them a small budget, 1.5 milliseconds, and lets them catch up in slices of 128 records, the chunks nearest the view first.
In a real seek on the Kursk map, from 20:00 back to 16:40 with the camera in the north-east corner, eight chunks were behind after the seek. Four frames later every chunk was current; one of them got 1,792 records, fourteen slices, inside a single frame's budget. When the camera moves, the chunks that come into view are usually already current, and if one is not, it paints its backlog at once.
One more small optimisation: the bounding boxes of the records are kept in a flat Float64Array that starts at 4096 numbers and doubles when it is full. A box is four numbers in a row, so checking it creates no object and leaves nothing for the browser's garbage collector. This is the pattern throughout the game: do the work once, remember how far you got, and spread the rest thinly over the frames.
budget = 1.5 ms per frame, slice = 128 records 1 792 records / 128 = 14 slices boxes = Float64Array(4096) = 1024 records × 4 numbers; full → 8192


Rewind is a replay of the list
Because the list is append only and every seed is in it, the ground is a pure function of the list: the baked base picture plus every record painted in order. That gives rewind for free. When you seek back in a replay, or load a save, the renderer resets every chunk to its original baked picture and replays the list from record zero up to the new time, the chunks in view first.
Every crater lands in the same place with the same seed, so it gets the same shape and the same specks. A field after a load is pixel for pixel the field before it. On the Kursk map, repainting all 5,772 records of a twenty-minute battle took 26 to 31 milliseconds for the chunks in view, one render included, and another 2 to 5 for the rest: about 30 milliseconds in all.
The game is deterministic by design, and the decals are part of that promise. The simulation does not know what the ground looks like, and the renderer decides nothing about the battle. One writes, one paints, and the paint can always be redone.
ground = base picture + paint(list[0 … n]) Kursk, 20:00: 5 772 records → 26–31 ms (chunks in view) + 2–5 ms (the rest)
Tracks
A track mark is the most common record in the game, so its recipe has to be cheap. A tracked vehicle writes a track record every 1.1 units of distance travelled. A metre is 3.3 units, so that is three records per metre, each one a pair of prints, one under each track. A drive of 100 metres leaves about 300 records.
Each print is 1.3 units long, a little longer than the 1.1-unit step, so neighbouring prints overlap and the rut is continuous. The width of a print is 17 % of the hull width. A T-34 is 10.27 units wide, 3.1 metres, so its print is about half a metre wide. Wheeled vehicles use a thinner tyre print, 11 % of the hull. Inside each print, tread bars repeat every 0.35 units.
On grass the print is painted at 30 % opacity. On a dirt road it is half that, because packed earth shows less. On mud or a ploughed field it is 1.3 times darker and 1.3 times wider. And prints painted over prints keep darkening. That is how a churned field happens on its own: nobody draws it, it is just dozens of tanks' worth of overlap.
1 m = 3.3 units; 3.3 / 1.1 = 3 records per metre; 100 m → 300 records print length 1.3 > step 1.1 → a continuous rut T-34: hull 10.27 units = 3.1 m; print = 0.17 × 3.1 = 0.53 m alpha: grass 0.3, dirt road 0.3 × 0.5 = 0.15, plough / mud 0.3 × 1.3 = 0.39 (and 1.3 × wider)

Tracks on snow and sand, and the pivot
The ground tells the print what to look like. On light snow the print is grey-blue and 15 % wider, with dark slush pushed up at its edges. On deep snow it is 1.6 times wider, a furrow with a bright lip of snow thrown out at the sides. On firm sand it is pale. On soft sand it becomes a furrow with its own lip.
The record is the same in every case: a track, a position, a heading, a width, and a number for the kind of ground under it, which the simulation already knows. The renderer turns that number into a palette. The simulation does not have to know about slush or lips at all.
One more record belongs to the tracks. When a tank turns on the spot, its tracks tear the ground in a circle. Every 25 degrees of turning the simulation appends a pivot record, and the renderer paints a ring with 16 clods thrown around it. A full turn is about fourteen records; the tank in the video left fifteen rings on top of each other, a dark torn circle, and you can tell from the ground where the column turned.
light snow: width × 1.15, deep snow: width × 1.6 pivot: a record every 25° of turning, 360 / 25 = 14.4 per full turn

Craters
A crater is the most elaborate decal, and it is still painted once. Its radius is the shell's blast radius times 0.45, in model units, and times 3.75 more to get pixels. A 20 mm shell makes a mark of about 3 pixels. A 76 mm gun makes a crater of 12 pixels, a 105 mm one of 20, a 152 mm howitzer 25, and a 250 kg bomb 37. A shell that hits armour makes no crater at all, because the ground was not hit. Mines have their own radii, 2.4 for an anti-tank mine and 1.2 for an anti-personnel one.
The shape comes from the seed. One of three outlines is chosen by the seed modulo 3: round, an oval stretched by up to 30 %, or a lobed shape with 16 % wobble, drawn as a closed line of 28 segments.
Then the layers, in order. A halo of disturbed earth out to 2.4 radii. Eight to thirteen rays of thrown soil. Twenty-two clods, each with one lit pixel on its top left and a shadow below, because the light of the baked ground comes from the upper left and the clods must agree with it. A rim out to 1.3 radii, a ring of soot at 1.04, then the bowl: a gradient down to 88 % of the radius, the far wall lit, the near wall in shadow. All of it fits in a box that reaches 2.8 radii plus 4 pixels from the centre, and that box is what the chunk test uses.
r = blast · 0.45 units, r in px = blast · 0.45 · 3.75 20 mm: 2 → 3.4 px 76 mm: 7 → 11.8 105 mm: 12 → 20.3 152 mm: 15 → 25.3 SC250 bomb: 22 → 37.1 box = r · 3.75 · 2.8 + 4 px each way 76 mm: 11.8 · 2.8 + 4 = 37.1 px each way → a box of about 74 × 74 px

The ground chooses the palette
As with tracks, the crater reads the ground. On a road the earth is lighter. In a wheat field the straw is pressed flat out to one and a half radii, so a crater in wheat looks like a crater in wheat and not a hole in a lawn. On snow the dark earth makes a black ring, with 26 specks of it thrown around. On sand the halo is pale and the clods are dark subsoil.
In a trench only the bowl is painted, because a rim and rays would paint over the dug earth of the trench. On water nothing is painted at all. The scorch mark that comes with a burning vehicle is simpler: a radial gradient and 22 specks, 30 % wider on snow, where the snow has melted round the fire.
The simulation never knows any of this. It wrote a crater at a position, with a number for the ground it landed on. The renderer read that number, saw snow, and chose the palette.

Bodies and wrecks
Bodies follow the same path, with a delay. A man who dies is a sprite for three seconds, playing one of three death animations chosen by his number modulo 3. Then the last frame of that animation, in his direction, is drawn into the chunk canvas with the same arithmetic the sprite used: the ground point, minus the anchor times the frame size, plus the trim offset, rounded to whole pixels. The baked body sits exactly where the sprite was, and then the sprite is destroyed.
There are two exceptions. A man who dies on a bridge deck stays a sprite, because the deck is not the ground. A man who drowns at a crossing simply vanishes under the water.
Wrecked guns are baked too, half a second after their fire goes out, and so are machine-gun nests and weapon teams. Vehicle wrecks are not: a dead tank stays a sprite for good. It burns for 25 to 60 seconds and then smoulders for the rest of the mission. And once something is baked it is part of the ground, so the fog of war does not hide it. You can see where you lost a squad even when that ground is deep in the fog.
frame = [die, dieb, diec][id % 3], frame 7, one of 8 directions x = round(sx − ax · orig.w) + trim.x y = round(sy + cut − ay · orig.h) + trim.y vehicle wreck burns 25 + R · 35 s = 25–60 s, then smoulders

Small things
Some records are tiny. A spent brass case is a dot of 2 × 1 pixels in a dull gold. A field gun leaves one at its breech with every shot: after three minutes of firing the gun in the video had written 30 casing records, and it stands in a pool of them. A fired anti-tank launcher leaves its empty tube in the grass. These cost nothing, and they are what makes the ground look lived on.
And here is a choice worth naming. The craters a map starts with, from earlier fighting, are part of the terrain: they give infantry cover of 0.6 and slow vehicles down. The craters the battle makes are only paint. The simulation writes the list and never reads it back, so a new crater changes nothing in the rules. The battlefield remembers, but it remembers in pictures.
casing: 2 × 1 px, rgba(180, 140, 60, 0.9), one per shot of a field gun
A short history of marks on the ground
Marks on surfaces are as old as 3D shooters. In the middle of the nineties, shooters began to leave bullet holes and scorch marks on their walls: small pictures pasted onto a surface, which engine programmers call decals, after the transfers on a plastic model kit. Each one cost something to draw, so a game kept a fixed number and removed the oldest, or let them fade after a few seconds.
Strategy games with a fixed camera had an advantage. Their ground was already a picture, and a picture can be painted on. Sudden Strike, in 2000, kept its craters for the whole mission, and that was part of its feel: a war that leaves traces.
The two approaches are still the two approaches today. Draw a sprite every frame, and you can move it and fade it, but you pay every frame. Stamp it into a texture, and it is free forever, but it is part of the ground now. For a battlefield that is supposed to remember, the choice is easy.
What it costs
In the heaviest stress battle the game has, with 1,318 men and 139 vehicles alive, the list reaches 83,236 records after four and a half minutes. A real mission goes as far: on Goodwood, the largest map, the list has 71,182 records at five minutes and 116,645 at ten, and 114,973 of those are track prints. Drawn as sprites, that would be a hundred thousand draws every frame for the marks alone. Stamped, each one costs a few microseconds once, spread over the frames, and then nothing.
The bar the game had to pass was 1,500 craters and tracks after five minutes at 55 frames per second or more, which is 18.2 milliseconds a frame. In an earlier measurement of the stress battle, with 96,000 records on the ground, the renderer's median frame was 5 to 8 milliseconds, far inside that bar.
The one real cost is the upload. When a chunk canvas changes, it has to go to the graphics card again, and a 1024-pixel square takes 3 to 10 milliseconds to send, a large slice of a 16.7-millisecond frame. So in normal play the renderer uploads at most one changed chunk every fourth frame, and a new mark may reach the screen a few frames late. Nobody notices, because they are looking at the explosion.
One list, painted once, replayed on demand: that is how the ground keeps its memory.
stress battle, 4:30: 83 236 records, 1 318 + 139 alive Goodwood: 71 182 at 5:00, 116 645 at 10:00 (tracks 114 973 = 98.6 %) the bar: 1 500 marks at ≥ 55 fps → 1000 / 55 = 18.2 ms a frame upload of a 1024² chunk: 3–10 ms; at most one every 4th frame
