Sunday, May 20, 2012

So Many Places To Go, Nodes To See

Hey Readers,

The past two weeks were all about OSM files. What are OSM files you ask? They're the files exported from Open Street Maps, they contain all the information you need to map out a city. Open Street Maps provide large files broken up by country / province/ state, or you can use one of the API's provided to download a finer grain chunk of data. To get the initial implementation going I downloaded a chunk of data equal to the DEM I'm currently rendering out. The OSM files store the data using the XML format. This means that the files are huuuge for even a small chunk of the earth. For the area I'm currently rendering the OSM file was about 110 MB. 110 MB is was way too big for my current needs.

The OSM files are fairly simple, they're broken up into 3 types of object Nodes, Ways, and Relations. Each of those objects can also have Tags which provide information about what they are. A node is a point in space, ways are made up of nodes, and relations are a collection of ways.

Since I only needed a subset of the data I set about making my own format which could be stored as binary. For the nodes, all I needed was the node id, longitude, and latitude. For the ways all I needed was the way id, and a list of node Ids, I haven't had a need for relations yet so I'm ignoring those and for the tags I'm storing a pair of values, the id of the object the tag belongs to and a hashed version of the string. After saving out all this data the file size went from 110 megs to about 8 megs. In the future if this is still too big there's still a few more tricks I could do to drop the size some more but for now this is very workable.

I spent about a week getting the data saving and loading into the game. The next step was to get the nodes rendering. I started drawing them as debug boxes but the game came to a crawl with a couple hundred boxes being drawn. This was no good! The problem was that my debug drawing was not optimized at all. I set about fixing my debug drawing by batching all the debug boxes together so they could be drawn with a single draw call. Now that I could draw around 2000 nodes without too much impact on the frame rate, the next optimization to make was to only draw the nodes that were visible within a certain radius. Down the road I should hook up frustum culling but for now the simple radius check is enough to get things going. After this I took a stab at getting the ways rendering. This wasn't too tough I just drew a line between all the nodes in each way. Seeing the nodes and ways rendering was exciting it was starting to feel like the world instead of some random landscape.

Next on the agenda is to clean up my terrain mesh subdivisions and  start getting the neighboring DEM's loading so we can get the whole planet rendering.

First shot of nodes rendering

Shot of ways rendering

Another shot of ways rendering

More ways rendering!

No comments:

Post a Comment