(svn r27232) -Fix: Tweak noise generator more precisely for different map sizes (chillcore)

This commit is contained in:
alberth 2015-04-11 18:46:01 +00:00
parent a91f74dbb3
commit 262c3c93c8

View File

@ -248,16 +248,41 @@ static height_t TGPGetMaxHeight()
*/
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] = {
/* Base noise amplitudes (multiplied by 1024) and indexed by "smoothness setting" and log2(frequency).
* Used for maps that have their smallest side smaller than 512. */
static const amplitude_t amplitudes_small[][10] = {
/* 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
{60000, 2273, 4142, 2253, 421, 213, 137, 177, 37, 16}, ///< Very smooth
{50000, 2273, 4142, 2253, 421, 213, 137, 177, 37, 61}, ///< Smooth
{40000, 2273, 4142, 2253, 421, 213, 137, 177, 37, 91}, ///< Rough
{30000, 2273, 4142, 2253, 421, 213, 137, 177, 37, 161}, ///< Very rough
};
/*
* Extrapolation factors for ranges before the table.
/* Base noise amplitudes (multiplied by 1024) and indexed by "smoothness setting" and log2(frequency).
* Used for maps that have their smallest side equal to 512. */
static const amplitude_t amplitudes_middle[][10] = {
{55000, 2273, 5142, 253, 2421, 213, 137, 177, 37, 16}, ///< Very smooth
{45000, 2273, 5142, 253, 2421, 213, 137, 177, 37, 61}, ///< Smooth
{35000, 2273, 5142, 253, 2421, 213, 137, 177, 37, 91}, ///< Rough
{25000, 2273, 5142, 253, 2421, 213, 137, 177, 37, 161}, ///< Very rough
};
/* Base noise amplitudes (multiplied by 1024) and indexed by "smoothness setting" and log2(frequency).
* Used for maps that have their smallest side bigger than 512. */
static const amplitude_t amplitudes_large[][10] = {
/* lowest frequency ...... highest (every corner) */
{55000, 2273, 5142, 253, 421, 2213, 137, 177, 37, 16}, ///< Very smooth
{45000, 2273, 5142, 253, 421, 2213, 137, 177, 37, 61}, ///< Smooth
{35000, 2273, 5142, 253, 421, 2213, 137, 177, 37, 91}, ///< Rough
{25000, 2273, 5142, 253, 421, 2213, 137, 177, 37, 161}, ///< Very rough
};
/* Make sure arrays cover all smoothness settings. */
assert_compile(lengthof(amplitudes_small) == TGEN_SMOOTHNESS_END);
assert_compile(lengthof(amplitudes_middle) == TGEN_SMOOTHNESS_END);
assert_compile(lengthof(amplitudes_large) == TGEN_SMOOTHNESS_END);
/* Extrapolation factors for ranges before the table.
* The extrapolation is needed to account for the higher map heights. They need larger
* areas with a particular gradient so that we are able to create maps without too
* many steep slopes up to the wanted height level. It's definitely not perfect since
@ -269,10 +294,20 @@ static amplitude_t GetAmplitude(int frequency)
static const double extrapolation_factors[] = { 3.3, 2.8, 2.3, 1.8 };
int smoothness = _settings_game.game_creation.tgen_smoothness;
int smallest_size = min(_settings_game.game_creation.map_x, _settings_game.game_creation.map_y);
/* Get the table index, and return that value if possible. */
int index = frequency - MAX_TGP_FREQUENCIES + lengthof(amplitudes[smoothness]);
amplitude_t amplitude = amplitudes[smoothness][max(0, index)];
int index;
amplitude_t amplitude;
if (smallest_size < 9) { // Smallest map side is less than 2^9 == 512.
index = frequency - MAX_TGP_FREQUENCIES + lengthof(amplitudes_small[0]);
amplitude = amplitudes_small[smoothness][max(0, index)];
} else if (smallest_size == 9) {
index = frequency - MAX_TGP_FREQUENCIES + lengthof(amplitudes_middle[0]);
amplitude = amplitudes_middle[smoothness][max(0, index)];
} else {
index = frequency - MAX_TGP_FREQUENCIES + lengthof(amplitudes_large[0]);
amplitude = amplitudes_large[smoothness][max(0, index)];
}
if (index >= 0) return amplitude;
/* We need to extrapolate the amplitude. */