From a1611de3a321816cd2a45b3d8e6b402fbb0a3039 Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 13 Oct 2014 14:14:04 +0000 Subject: (svn r27007) -Codechange: allow for more frequencies (based on patch by ic111) --- src/tgp.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/tgp.cpp b/src/tgp.cpp index e67820155..12a3ffc2c 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -204,8 +204,8 @@ static HeightMap _height_map = {NULL, 0, 0, 0, 0}; /** Walk through all items of _height_map.h */ #define FOR_ALL_TILES_IN_HEIGHT(h) for (h = _height_map.h; h < &_height_map.h[_height_map.total_size]; h++) -/** Maximum index into array of noise amplitudes */ -static const uint TGP_FREQUENCY_MAX = 6; +/** Maximum number of TGP noise frequencies. */ +static const int MAX_TGP_FREQUENCIES = 7; /** Desired water percentage (100% == 1024) - indexed by _settings_game.difficulty.quantity_sea_lakes */ static const amplitude_t _water_percent[4] = {20, 80, 250, 400}; @@ -316,19 +316,21 @@ static inline height_t RandomHeight(amplitude_t rMax) * Base Perlin noise generator - fills height map with raw Perlin noise. * * This runs several iterations with increasing precision; the last iteration looks at areas - * of 1 by 1 tiles, the second to last at 2 by 2 tiles and the initial 2**TGP_FREQUENCY_MAX - * by 2**TGP_FREQUENCY_MAX tiles. + * of 1 by 1 tiles, the second to last at 2 by 2 tiles and the initial 2**MAX_TGP_FREQUENCIES + * by 2**MAX_TGP_FREQUENCIES tiles. */ static void HeightMapGenerate() { /* Trying to apply noise to uninitialized height map */ assert(_height_map.h != NULL); - for (uint frequency = 0; frequency <= TGP_FREQUENCY_MAX; frequency++) { + int start = max(MAX_TGP_FREQUENCIES - (int)min(MapLogX(), MapLogY()), 0); + + for (int frequency = start; frequency < MAX_TGP_FREQUENCIES; frequency++) { const amplitude_t amplitude = GetAmplitude(frequency); - const int step = 1 << (TGP_FREQUENCY_MAX - frequency); + const int step = 1 << (MAX_TGP_FREQUENCIES - frequency - 1); - if (frequency == 0) { + if (frequency == start) { /* This is first round, we need to establish base heights with step = size_min */ for (int y = 0; y <= _height_map.size_y; y += step) { for (int x = 0; x <= _height_map.size_x; x += step) { -- cgit v1.2.3-54-g00ecf