pioneerspacesim/pioneer — pull request #2163 by fluffyfreak (2013-03-27 22:52:42+00:00)
Title: Multithreaded Job based Terrain Patch generation.

# Description:
There's a few things here, job, multithreading, memory usage reduction.

## JobSwarm:
I've integrated a simple multithreading job library called [JobSwarm](https://code.google.com/p/jobswarm/) and then I've parcelled up the terrain patch generation made it use as many hardware threads as you can throw at it :)

## Multithreading:
The library can be used for many other tasks. I've only implemented what I need for the terrain system.

## Memory Usage Reduction:
Sat on Earth with the terrain detail to max I've reduced the footprint from ~700MiB to ~280MiB. Most of this was done by storing only the height instead of the full vector3d of positions, then reconstructing it in UpdateVBOs - a 2/3rds saving.
Normals are single precision floats so a 50% saving. The colour is a Color3ub (3 bytes) instead of vector3d (24 bytes) so there's another 21 byte saved PER VERTEX!!!

I think there's more that can be done here, the normal can be packed into 2 16bit values stored in a uint32 because it doesn't need all that precision, that could then be reconstructed either in UpdateVBOs. Or it could be turned into a texture and used in the shader to reconstruct the full normal. See [this article on options](http://aras-p.info/texts/CompactNormalStorage.html). The heightmap could probably be done as a 32bit float too if I subtracted the clipCentroid length at generation time instead of leaving it until UpdateVBOs.

# Problems:
A lack of testing, I've done what I can, going in and out of the game, exiting and restarting etc. Going from planet to planet, system to system and it all seems robust... however.
Whenever I've worked on multithreaded tech' before it's never during development that you see the problems, only when people are using it so it needs others to take a look.

On my quad core i7 with 8 hardware threads this thing is much faster at generating the terrain. On my dual core laptop, it might actaully be a bit slower :/

# Summary:
Summary? Um, it's great? please test! Kthxbye!

Andy