Coming up with rules and systems and algorithms to generate content is hard enough, but added to that challenge is the fact that we don’t have the benefit of any sort of pre-processing. If you’ve ever used a level editor, you know those things can eat a ton of time. They can take the data, cull out what isn’t needed, pre-compute the expensive stuff, and package things in a nice, organized way so that when the game is running, it can pull data off the disk and put it right to work.
With procedural stuff, you’ve got to do that work while the game is running. Without slowing things down. This moves all of that complexity into the game, and makes the system more complicated by requiring that it be done piecemeal. If you’ve played Minecraft, you’ve probably noticed the heavy lurch you get when the game has to generate some new landscape for you. I’m going to face that same problem with this project.
But I’m getting ahead of myself. First, a bit about how my program creates the terrain. First, it takes that low-level topography I generated in the previous step:
Very bland, of course. We don’t want to generate an entire continent of endless speed bumps, so we also have some topographical data stretched out over a much larger scale:
Note how this looks kind of mechanical. You can see large, flat surfaces everywhere. By itself, this would make the continent feel sort of like the whole world was made from geometric primitives. But if we combine the two data sets:
I’ve exaggerated the hills for effect. The large hills give the world shape, the small ones give it detail. Together they make something roughly presentable. From now on, I’ll be calling these two sets the “topography” and the “detail”.
How it works is this:
The world is divided into regions. Some regions will have strong topography, normal detail. Others will have muted topography, but strong detail. I can exaggerate one data set over the other to create different landscapes. (Low rolling hills, flat deserts, spiky mountains.) Each region also has an overall height bias, so that I can shove some of them into the sea and lift others up. Right now the regions are hard-coded, but eventually I’ll have some sort of logic to generate them as well. Eventually, regions will also have different coloring.
As you move around the world, it generates this landscape. Some logic goes into figuring out what the surfaces should be. Flat spots should be grassy. Hilly spots should be dirt. Steep bits should be rock. Stuff touching the water should be sand. These sections of terrain are generated in pages. Eventually, they’ll be saved to disk once they’re generated, in much the same way that Minecraft does.
Then it comes time to turn this data into actual polygons for rendering.
Currently, the program will just add more terrain as you run along, forever. Well, not forever. But it will happily churn them out until you run out of memory. It doesn’t clean out data yet, so once something is in memory, it stays there. Josh joked that it’s now officially a game. “See how far you get before it crashes. You want to play on easy mode? Buy more memory.”
Running out of memory is kind of abrupt. The program runs fine until the moment I have too much texture data, at which point the framerate drops from 90, to 5. I pushed it once and nearly brought down my machine. It took a loooong time to bring up the task manager and kill the program.
Still, that means I got the high score!
Yes, I am aware that it looks horrible and bland. Next time we’ll liven it up with proper variety. And maybe look into fixing that memory hoarding problem.
Bethesda’s Launcher is Everything You Expect
From the company that brought us Fallout 76 comes a storefront / Steam competitor. It's a work of perfect awfulness. This is a monument to un-usability and anti-features.
A stream-of-gameplay review of Dead Island. This game is a cavalcade of bugs and bad design choices.
What Does a Robot Want?
No, self-aware robots aren't going to turn on us, Skynet-style. Not unless we designed them to.
Quakecon 2012 Annotated
An interesting but technically dense talk about gaming technology. I translate it for the non-coders.
What is Vulkan?
There's a new graphics API in town. What does that mean, and why do we need it?