diff options
author | rubidium <rubidium@openttd.org> | 2014-10-13 14:12:06 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2014-10-13 14:12:06 +0000 |
commit | 344a7a0f1667e04a949d69a9944792955c6cd9ce (patch) | |
tree | 6f7b0da828940bca8aab1cc88f483c1ee8bb135f /src | |
parent | a200656534ac75d0570cbfd86c9c1a1cb48e7de8 (diff) | |
download | openttd-344a7a0f1667e04a949d69a9944792955c6cd9ce.tar.xz |
(svn r27006) -Codechange: move getting of the amplitude to a seperate function
Diffstat (limited to 'src')
-rw-r--r-- | src/tgp.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/tgp.cpp b/src/tgp.cpp index 8a511114b..e67820155 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -207,22 +207,6 @@ static HeightMap _height_map = {NULL, 0, 0, 0, 0}; /** Maximum index into array of noise amplitudes */ static const uint TGP_FREQUENCY_MAX = 6; -/** - * Noise amplitudes (multiplied by 1024) - * - indexed by "smoothness setting" and log2(frequency) - */ -static const amplitude_t _amplitudes_by_smoothness_and_frequency[4][TGP_FREQUENCY_MAX + 1] = { - /* lowest frequncy.... ...highest (every corner) */ - /* Very smooth */ - {16000, 5600, 1968, 688, 240, 16, 16}, - /* Smooth */ - {16000, 16000, 6448, 3200, 1024, 128, 16}, - /* Rough */ - {16000, 19200, 12800, 8000, 3200, 256, 64}, - /* Very Rough */ - {24000, 16000, 19200, 16000, 8000, 512, 320}, -}; - /** Desired water percentage (100% == 1024) - indexed by _settings_game.difficulty.quantity_sea_lakes */ static const amplitude_t _water_percent[4] = {20, 80, 250, 400}; @@ -256,6 +240,27 @@ static height_t TGPGetMaxHeight() } /** + * Get the amplitude associated with the currently selected + * smoothness and maximum height level. + * @param frequency The frequency to get the amplitudes for + * @return The amplitudes to apply to the map. + */ +static amplitude_t GetAmplitude(int frequency) +{ + /* Base noise amplitudes (multiplied by 1024) and indexed by "smoothness setting" and log2(frequency). */ + static const amplitude_t amplitudes[][7] = { + /* lowest frequency ...... highest (every corner) */ + {16000, 5600, 1968, 688, 240, 16, 16}, ///< Very smooth + {24000, 12800, 6400, 2700, 1024, 128, 16}, ///< Smooth + {32000, 19200, 12800, 8000, 3200, 256, 64}, ///< Rough + {48000, 24000, 19200, 16000, 8000, 512, 320}, ///< Very rough + }; + + int smoothness = _settings_game.game_creation.tgen_smoothness; + return amplitudes[smoothness][frequency]; +} + +/** * Check if a X/Y set are within the map. * @param x coordinate x * @param y coordinate y @@ -320,7 +325,7 @@ static void HeightMapGenerate() assert(_height_map.h != NULL); for (uint frequency = 0; frequency <= TGP_FREQUENCY_MAX; frequency++) { - const amplitude_t amplitude = _amplitudes_by_smoothness_and_frequency[_settings_game.game_creation.tgen_smoothness][frequency]; + const amplitude_t amplitude = GetAmplitude(frequency); const int step = 1 << (TGP_FREQUENCY_MAX - frequency); if (frequency == 0) { @@ -505,7 +510,7 @@ static void HeightMapCurves(uint level) height_t y; ///< The height to scale to. }; /* Scaled curve maps; value is in height_ts. */ -#define F(fraction) ((height_t)(fraction * mh))) +#define F(fraction) ((height_t)(fraction * mh)) const control_point_t curve_map_1[] = { { F(0.0), F(0.0) }, { F(0.6 / 3), F(0.1) }, { F(2.4 / 3), F(0.4 / 3) }, { F(1.0), F(0.4) } }; const control_point_t curve_map_2[] = { { F(0.0), F(0.0) }, { F(0.2 / 3), F(0.1) }, { F(1.6 / 3), F(0.4 / 3) }, { F(2.4 / 3), F(0.8 / 3) }, { F(1.0), F(0.6) } }; const control_point_t curve_map_3[] = { { F(0.0), F(0.0) }, { F(0.2 / 3), F(0.1) }, { F(1.6 / 3), F(0.8 / 3) }, { F(2.4 / 3), F(1.8 / 3) }, { F(1.0), F(0.8) } }; |