pioneerspacesim/pioneer — pull request #699 by robn (2011-10-20 11:07:04+00:00)
Title: Terrain refactor

Refactor of `GeoSphereStyle`. My goals here are as follows:

* Remove the giant height/colour type switches in `GetHeight()` and `GetColor()`. There is no point doing this tests on every call as they never ever change.
* Move individual height/colour fractals and their initialisers out into their own files for easier maintenance.
* Do not do anything that will impact on performance (this is extremely heavily-used code).

I've built a set of templates to allow a class to be composed of the wanted height/color fractal combo. The idea being that when you request a terrain of a particular type you get only that terrain and nothing else.

The `HeightFractal` and `ColorFractal` classes are not completely self-contained. They each depend on a bunch of shared data, most notably `m_fracdef`. I could have put this out into a separate object but I didn't want the additional overhead to access them. Instead I've gone for a kind of composition using virtual inheritance to get a common baseclass. `GetHeight()` and `GetColor()` are pure; my understanding is that the compiler can optimise this to something very close to a direct call. Even if it can't though, it should still end up (probably imperceptably) faster than the switch and less convoluted than a separate data object.

Atmosphere properties (`PickAtmosphere()` and `GetAtmosphereFlavor()`) have been moved to `SBody`, as they are entirely dependent on body type.

I've deliberately not touched the actual algorithmic code. There's some reshuffling that can be done but its really just deckchairs until I properly understand the algorithms.

There's a little bit of cleanup work that could happen in `TerrainNoise.h`, but its all pretty low impact. I couldn't decide if the function names in `TerrainNoise` and `TerrainFeature` should be renamed to be more consistent with the rest of the code. I opted to leave it for now as its all fairly self-contained and it made it easier to just copy the code over.

I've tested by looking at a few objects in Sol and Eridani. Star and planet terrains look right, atmospheres appear to have the right colours, heightmaps are working. Detail changes appear to work. It might be worth doing a closer check if you're so inclined just to make sure, but it feels right.