There's a moment in Free Roam that I never get tired of. You point the car at the horizon, hold the throttle, and just... go. No track, no walls, no clock. The ground rolls up into a ridge, you hit the crest at speed, and the car takes off.
What most people don't realize is how much trickery is going on to make that moment possible, especially on the phone I built the game around.
No track. No clock. Just space.
The floor is a budget phone
When I started the phone version of Lumen Run, I chose a budget phone as my "floor": a Moto G Play, with about 3.7 GB of memory and a modest screen. The rule was that the game has to look its best and run smoothly on that phone. Stronger phones can then step up from there.
Why a budget phone? Because if something runs well on the weakest phone I'm testing, it runs well everywhere.
So here was my problem. Free Roam ships with ten worlds, and each one is just over 8 km across. That's about 67 square kilometers of land, a long drive from one edge to the other. And a budget phone can only draw so much at once.
Step one: making a world that's worth driving on
Before I could worry about drawing it, I needed the land itself. Each world is described by a height map. Picture a giant sheet of graph paper laid over the world, with a height written at every crossing, one about every eight meters. Join the dots, and you've got hills.
Each world starts from a fixed "seed", so it is the same place every visit and you can learn it. Then I do things that have nothing to do with the graphics: I place mountain ranges along winding lines, patches of hill country, mesas with a ramp up the side, dry lake beds, canyons, craters and ice shelves, depending on the world. Then I simulate rain. A great many imaginary drops fall on the land, run downhill and carve gullies, which is what makes it look like a real landscape and not computer noise.
My first drive taught me a lesson. The land was too hilly and too same-y. My note to myself said: less hills and more flat areas, more diverse terrain, less like a noise algorithm. So now most of every world is nearly flat, with broad levels at different heights and gentle slopes between them. It runs from a little over half in Neon Valley to nearly nine tenths in the flattest worlds, like Hologram. That gives you space to go fast, and the odd mountain to launch off.
Each world's whole map is tiny to store: about 2 MB.
Step two: only draw what you can see
You can't draw 67 square kilometers at full detail at once. A budget phone would fall over. So the world is cut into tiles, each about a third of a mile square (512 m), like the squares on a paper road atlas. There are sixteen across one of the built-in worlds.
And here's the key idea, which is exactly how a map app works when you zoom: each tile is drawn at a level of detail that matches how far away it is.
Within about 650 m of the car (a little under half a mile), the ground is drawn finely, a point every 8 m.
Out to about 1.3 km, a point every 16 m.
Out to about 2.2 km, every 32 m, and then every 64 m for the last stretch.
Past the fog, which closes in at about 2.6 km, a tile isn't drawn at all.
It's the same trick a painter uses. The face in the foreground gets the tiny brushwork, while the mountains behind it are a few broad strokes. Your eyes can't tell the difference, but the phone can.
As you drive, new tiles are built just ahead of you, a couple per frame, and the fine detail behind you is let go. The payoff is the part I like best: what's drawn stays about the same, whatever the size of the world. Whether the world is 8 km across or 32 km, the game is only ever drawing the neighborhood around the car.
Sharp where you're looking. Soft where you're not.
One little problem: where a detailed tile meets a coarser one, the edges don't quite line up, and you get hairline cracks. The fix is almost comically simple. Each tile hangs a short skirt down from its edges, like a curtain, to hide the gap.
For the curious: why "drawn in pieces" matters so much on a phone On my phone, every point of land costs real work, every single frame. Early on, in the racing scene, I found the game was processing all the land's corners, including the ones behind the camera. Cutting the land into tiles that the camera can skip one by one saved a couple of milliseconds a frame. That sounds tiny, but a frame at 60 per second only gets about 16 milliseconds, so a couple of milliseconds is a big slice of the budget. The lesson from my testing was that "per-point work is expensive on this GPU".
Step three: a forest of trees, drawn smartly
Land isn't the only cost. Free Roam is full of trees, rocks, crystals, cacti, pylons and other things to smash for Lux. Draw each as its own object, and the phone would drown.
Two tricks help.
First: stamping. Imagine a rubber stamp of a pine tree. You don't draw a new tree for every tree. You stamp the same tree thousands of times, in different places. The graphics world calls this instancing. The phone learns "this is a tree" once, then draws the whole forest in one go.
Second: only near the car. With the Scenery setting on, which is the normal way to play, scenery is drawn only within about 620 m of the car (roughly 0.4 of a mile), fading in over the last stretch. Past that, it isn't drawn at all. It's like a stage with a spotlight. The actors outside the light aren't being lit, so nobody pays for them.
Thousands of trees, but only the ones near you are real.
Step four: the memory diet
Speed isn't the only limit on a phone. There's also memory, and I learned that the hard way, in two ways.
The leaky races. Early on, I ran twenty races back to back to see what would happen. The game's memory crept from about 220 MB up to 560 MB before it levelled out. Each race was leaving its graphics set-up behind in the corner, like leaving the lights on in every room you've walked through. I fixed it, and after that it stayed flat at about 210 MB.
The scenery that was too well prepared. Later, with my bigger desktop worlds, I measured how much memory a 32 km world needed, and it was far too much. The world was laying out all its scenery the moment it opened, and the drawing system had reserved room for the whole world's scenery (about 790,000 pieces on a 32 km world) in order to draw about 400 at a time. I changed it so that the game only keeps track of what's near the car, in compact lists, and the drawing system only reserves what it actually shows.
The result: the scenery's own memory dropped by about four fifths, a 32 km world's footprint on my desktop fell by almost a third, and my browser's total use fell by about a fifth. The same change reached the phone, where Free Roam's working memory dropped from about 117 MB to less than half of that, which helps keep it running smoothly on a phone with little to spare.
For the curious: how big is a world, really? A 32 km world's height map is 4,097 points across. In memory, that's about 67 MB of heights, and saved to disk it's about 34 MB. The scenery in the world I tested was about 395,000 pieces, which would once have eaten around 255 MB, and now takes about 50.
Free Roam on a budget phone, with the frame-rate counter on.
So how does it run on the phone?
On the Moto G Play, a Free Roam world opens in about two seconds. In my latest tests (on the Mid graphics setting) the four worlds I benchmarked, Neon Valley, Verdant, Hologram and Inferno, ran at between about 49 and 60 frames a second, with two of them right on 60. The whole app sat at about 180 to 200 MB of memory in Free Roam, on a phone with around 3.7 GB.
I don't take any of this on trust. I test on the phone itself, driving the same stretch of road each time so the numbers are fair, and I compare pictures pixel by pixel to be sure that a speed-up hasn't quietly changed how things look.
Then I gave it to the desktop: the World Lab
Once Free Roam worked, I wanted to hand over the controls. On Windows, once you've finished the Story, you can open the World Lab and make your own worlds:
Size: 8, 16, 24 or 32 km across. A 32 km world has sixteen times the land of an 8 km one.
Hills: from nearly flat to mountainous.
A seed: the same seed always makes the same world, so you can share it.
Towns and cities: none, few, some or many, joined by roads.
Gravity: from floaty to heavy. Turn it all the way down, and you hit a pebble and take off.
Because tiles stream, the same trick that makes the 8 km phone world possible also lets a 32 km one work. In my testing, a 32 km world with towns drove at 60 frames a second on my desktop.
Pick a size. Pick a seed. Go.
Your own world, seen from above.
Making a world wasn't instant at first. My first 16 km world took 75 seconds, and I thought it was painfully slow. So I did some smarter sums, which got it down to about 21 seconds. Then I spread the work across the computer's cores, cutting the world into strips and making them all at once, then joining them. On my 24-core desktop a 16 km world now takes about four seconds. A 32 km one, with its towns and roads, takes about 17 seconds. On a computer with fewer cores it takes longer. The strips are rained on with a little overlap, so there's no seam where they meet.
Bigger is not just "the same, stretched" either. When I first made a world twice as wide, it had four times the features, all the same size, which was really just an 8 km world repeated four times. Now it has about twice as many, and each one is bigger: ranges are longer, plateaus are broader and craters are wider. A 16 km world feels bigger.
And I got a few things wrong along the way.
The mysterious triangles. I made the first 32 km world, and strange triangle patterns appeared across the hills. The ground was only sampled every 16 m, wide enough to show on slopes. Now every world size uses a point every 8 m, which costs more work but looks right.
The hovering roads. I noticed that, in the distance, roads in towns seemed to float above the hills, or sink into them. The reason was the same drawing trick that makes the world fast (the detail tiers): past a certain distance the land was drawn more coarsely, and that dropped the little banks and cuttings I'd shaped for the roads. Now the land is drawn finely as far out as the roads are drawn.
A 32 km world, with towns.
What I like most about it
The thing about a big world is that it doesn't have to be big everywhere at once. Nothing in the game is drawn unless you can see it. It's all tiles, stamps and spotlights.
There's the world as it exists, tens of kilometers of it, quietly waiting. And then there's the world as the phone knows it: the neighborhood around your car, rebuilt a couple of tiles at a time as you drive.
The edge of the world, drawn as a fence of light.
Try it
Free Roam opens after you finish the Story, and the World Lab is part of the Windows game. The free demo covers chapter 1 and Quick Race, so it won't show you any of this, but it will give you a taste of the racing and the Viper boss.
Free demo: Play it in your browser
Android: Lumen Run on Google Play
Tell me what you'd put in your own 32 km world. I'd love to know.
Obsidian Wolf
Comments
No comments yet. Be the first to say hello.