Thursday, January 31, 2019

World generation: the basics

So how best to model a world?

Ideally of course we'd make a spherical model, but that is horribly complicated and involves lots of maths. A slightly simpler method is to use a cube-sphere, which is basically a cube that's distorted to look like a sphere.



This allows you to store your terrains in square arrays, which is simple, without too much distortion. So a lot of games that portray planets, such as Spore and No Man's Sky, do this. This method also allows you to set up a quadtree system, which means that as you zoom in to the cube-sphere you can create new levels of detail, giving the impression of a huge, massively detailed world. That's what No Man's Sky does. But I'm not doing it, because it's too difficult.

(I may, in the future, adapt my terrain generation methods to a cube-sphere system. I'm reasonably sure I know how it could be done, at least in theory. But not for now.)

Instead, I'm going to generate flat maps. The world will be twice as wide east-west as it is north-south, and it will wrap from east to west but not from north to south. That means, in effect, that the world is a huge cylinder. This is unrealistic, but for my purposes it's good enough. In the real world, because we don't tend to think about the poles, we do think of the world as a big cylinder for all practical purposes.

This also means that the map will contain more temperate/subpolar regions, and fewer tropical/equatorial ones, than a genuine sphere would. But, again, that's something I can live with.

What sort of structure should the map have? One method that seems to be popular at the moment is the Voronoi diagram. This basically splits up the map into irregularly-shaped cells, and then you use these cells as the basic components of your terrain. This results in an automatically irregularly-shaped terrain that avoids unwanted straight lines and the like. Amit Patel has popularised this method, and it's the one used by both Martin O'Leary and Scott Turner as well as Max Ganiev and I'm sure lots of other people too. The problem with it, though, is that while it's excellent for making maps, it's not good for storing information about terrains. With this method, you can't tell the height of any given point on the map, only that of each Voronoi cell. You can't really model any other features of the world, such as weather; in fact to do that you have to convert your Voronoi map into a traditional array and then back again. In other words, manipulating data in a Voronoi diagram is appallingly difficult, but that's what we need to do if we're going to model the world as opposed to just make a map.

So I'm not going to use Voronoi diagrams. (I'm not going to use hexes either, as Shelby Maddox does, because I want the worlds to look as natural as possible rather than tiled.) I'm going to store my worlds as traditional, 2D arrays, which you can think of as simple rectangular grids. Each point on the grid corresponds to a point in the world. We can have one array to store the height of each point, one grid to store the wind speed at each point, one to store the temperature, and so on. And I'm going to display this information using proper old-fashioned raster graphics, none of this fancy Scalable Vector Graphics. Undiscovered Worlds is old-school.

So having established all that, how do we generate our world? As explained in the first post, UW follows a two-part process:

(1) Generate a global map.
(2) When prompted, generate a regional map based on a small part of the global map, but more detailed.

Our first task, then, is (1).

No comments:

Post a Comment