2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// HeiGen.cpp
|
|
|
|
|
|
|
|
// Implements the various terrain height generators
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "HeiGen.h"
|
2013-05-12 13:55:49 -04:00
|
|
|
#include "../LinearUpscale.h"
|
2013-11-27 02:40:59 -05:00
|
|
|
#include "inifile/iniFile.h"
|
2014-01-09 04:21:26 -05:00
|
|
|
#include "DistortedHeightmap.h"
|
|
|
|
#include "EndGen.h"
|
|
|
|
#include "Noise3DGenerator.h"
|
2013-10-11 04:18:01 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-01-09 04:21:26 -05:00
|
|
|
// cTerrainHeightGen:
|
|
|
|
|
|
|
|
cTerrainHeightGen * cTerrainHeightGen::CreateHeightGen(cIniFile &a_IniFile, cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault)
|
|
|
|
{
|
|
|
|
AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", "");
|
|
|
|
if (HeightGenName.empty())
|
|
|
|
{
|
|
|
|
LOGWARN("[Generator] HeightGen value not set in world.ini, using \"Biomal\".");
|
|
|
|
HeightGenName = "Biomal";
|
|
|
|
}
|
|
|
|
|
|
|
|
a_CacheOffByDefault = false;
|
|
|
|
cTerrainHeightGen * res = NULL;
|
|
|
|
if (NoCaseCompare(HeightGenName, "flat") == 0)
|
|
|
|
{
|
|
|
|
res = new cHeiGenFlat;
|
|
|
|
a_CacheOffByDefault = true; // We're generating faster than a cache would retrieve data
|
|
|
|
}
|
|
|
|
else if (NoCaseCompare(HeightGenName, "classic") == 0)
|
|
|
|
{
|
|
|
|
res = new cHeiGenClassic(a_Seed);
|
|
|
|
}
|
|
|
|
else if (NoCaseCompare(HeightGenName, "DistortedHeightmap") == 0)
|
|
|
|
{
|
|
|
|
res = new cDistortedHeightmap(a_Seed, a_BiomeGen);
|
|
|
|
}
|
|
|
|
else if (NoCaseCompare(HeightGenName, "End") == 0)
|
|
|
|
{
|
|
|
|
res = new cEndGen(a_Seed);
|
|
|
|
}
|
2014-06-09 17:40:51 -04:00
|
|
|
else if (NoCaseCompare(HeightGenName, "Mountains") == 0)
|
|
|
|
{
|
|
|
|
res = new cHeiGenMountains(a_Seed);
|
|
|
|
}
|
2014-01-09 04:21:26 -05:00
|
|
|
else if (NoCaseCompare(HeightGenName, "Noise3D") == 0)
|
|
|
|
{
|
|
|
|
res = new cNoise3DComposable(a_Seed);
|
|
|
|
}
|
|
|
|
else if (NoCaseCompare(HeightGenName, "biomal") == 0)
|
|
|
|
{
|
|
|
|
res = new cHeiGenBiomal(a_Seed, a_BiomeGen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Performance-testing:
|
|
|
|
LOGINFO("Measuring performance of cHeiGenBiomal...");
|
|
|
|
clock_t BeginTick = clock();
|
|
|
|
for (int x = 0; x < 500; x++)
|
|
|
|
{
|
|
|
|
cChunkDef::HeightMap Heights;
|
|
|
|
res->GenHeightMap(x * 5, x * 5, Heights);
|
|
|
|
}
|
|
|
|
clock_t Duration = clock() - BeginTick;
|
|
|
|
LOGINFO("HeightGen for 500 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC);
|
|
|
|
//*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No match found, force-set the default and retry
|
|
|
|
LOGWARN("Unknown HeightGen \"%s\", using \"Biomal\" instead.", HeightGenName.c_str());
|
2014-01-10 10:33:53 -05:00
|
|
|
a_IniFile.DeleteValue("Generator", "HeightGen");
|
2014-01-09 04:21:26 -05:00
|
|
|
a_IniFile.SetValue("Generator", "HeightGen", "Biomal");
|
|
|
|
return CreateHeightGen(a_IniFile, a_BiomeGen, a_Seed, a_CacheOffByDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the settings:
|
|
|
|
res->InitializeHeightGen(a_IniFile);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-14 09:06:06 -04:00
|
|
|
// cHeiGenFlat:
|
|
|
|
|
|
|
|
void cHeiGenFlat::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap)
|
|
|
|
{
|
2013-12-20 10:01:34 -05:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(a_HeightMap); i++)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
a_HeightMap[i] = m_Height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
void cHeiGenFlat::InitializeHeightGen(cIniFile & a_IniFile)
|
|
|
|
{
|
|
|
|
m_Height = a_IniFile.GetValueSetI("Generator", "FlatHeight", m_Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-14 09:06:06 -04:00
|
|
|
// cHeiGenCache:
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
cHeiGenCache::cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, int a_CacheSize) :
|
2012-06-14 09:06:06 -04:00
|
|
|
m_HeiGenToCache(a_HeiGenToCache),
|
|
|
|
m_CacheSize(a_CacheSize),
|
|
|
|
m_CacheOrder(new int[a_CacheSize]),
|
|
|
|
m_CacheData(new sCacheData[a_CacheSize]),
|
|
|
|
m_NumHits(0),
|
|
|
|
m_NumMisses(0),
|
|
|
|
m_TotalChain(0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_CacheSize; i++)
|
|
|
|
{
|
|
|
|
m_CacheOrder[i] = i;
|
|
|
|
m_CacheData[i].m_ChunkX = 0x7fffffff;
|
|
|
|
m_CacheData[i].m_ChunkZ = 0x7fffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cHeiGenCache::~cHeiGenCache()
|
|
|
|
{
|
2012-11-15 09:02:17 -05:00
|
|
|
delete[] m_CacheData;
|
2014-06-19 04:49:56 -04:00
|
|
|
m_CacheData = NULL;
|
2012-11-15 09:02:17 -05:00
|
|
|
delete[] m_CacheOrder;
|
2014-06-19 04:49:56 -04:00
|
|
|
m_CacheOrder = NULL;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cHeiGenCache::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap)
|
|
|
|
{
|
2013-05-05 12:27:08 -04:00
|
|
|
/*
|
2012-06-14 09:06:06 -04:00
|
|
|
if (((m_NumHits + m_NumMisses) % 1024) == 10)
|
|
|
|
{
|
|
|
|
LOGD("HeiGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + m_NumMisses));
|
|
|
|
LOGD("HeiGenCache: Avg cache chain length: %.2f", (float)m_TotalChain / m_NumHits);
|
|
|
|
}
|
2013-05-05 12:27:08 -04:00
|
|
|
//*/
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < m_CacheSize; i++)
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
(m_CacheData[m_CacheOrder[i]].m_ChunkX != a_ChunkX) ||
|
|
|
|
(m_CacheData[m_CacheOrder[i]].m_ChunkZ != a_ChunkZ)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Found it in the cache
|
|
|
|
int Idx = m_CacheOrder[i];
|
|
|
|
|
|
|
|
// Move to front:
|
|
|
|
for (int j = i; j > 0; j--)
|
|
|
|
{
|
|
|
|
m_CacheOrder[j] = m_CacheOrder[j - 1];
|
|
|
|
}
|
|
|
|
m_CacheOrder[0] = Idx;
|
|
|
|
|
|
|
|
// Use the cached data:
|
|
|
|
memcpy(a_HeightMap, m_CacheData[Idx].m_HeightMap, sizeof(a_HeightMap));
|
|
|
|
|
|
|
|
m_NumHits++;
|
|
|
|
m_TotalChain += i;
|
|
|
|
return;
|
|
|
|
} // for i - cache
|
|
|
|
|
|
|
|
// Not in the cache:
|
|
|
|
m_NumMisses++;
|
2013-10-11 04:18:01 -04:00
|
|
|
m_HeiGenToCache.GenHeightMap(a_ChunkX, a_ChunkZ, a_HeightMap);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// Insert it as the first item in the MRU order:
|
|
|
|
int Idx = m_CacheOrder[m_CacheSize - 1];
|
|
|
|
for (int i = m_CacheSize - 1; i > 0; i--)
|
|
|
|
{
|
|
|
|
m_CacheOrder[i] = m_CacheOrder[i - 1];
|
|
|
|
} // for i - m_CacheOrder[]
|
|
|
|
m_CacheOrder[0] = Idx;
|
|
|
|
memcpy(m_CacheData[Idx].m_HeightMap, a_HeightMap, sizeof(a_HeightMap));
|
|
|
|
m_CacheData[Idx].m_ChunkX = a_ChunkX;
|
|
|
|
m_CacheData[Idx].m_ChunkZ = a_ChunkZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
void cHeiGenCache::InitializeHeightGen(cIniFile & a_IniFile)
|
|
|
|
{
|
|
|
|
m_HeiGenToCache.InitializeHeightGen(a_IniFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-06 08:20:25 -04:00
|
|
|
bool cHeiGenCache::GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_CacheSize; i++)
|
|
|
|
{
|
|
|
|
if ((m_CacheData[i].m_ChunkX == a_ChunkX) && (m_CacheData[i].m_ChunkZ == a_ChunkZ))
|
|
|
|
{
|
|
|
|
a_Height = cChunkDef::GetHeight(m_CacheData[i].m_HeightMap, a_RelX, a_RelZ);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} // for i - m_CacheData[]
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-14 09:06:06 -04:00
|
|
|
// cHeiGenClassic:
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
cHeiGenClassic::cHeiGenClassic(int a_Seed) :
|
2012-06-14 09:06:06 -04:00
|
|
|
m_Seed(a_Seed),
|
2013-10-11 04:18:01 -04:00
|
|
|
m_Noise(a_Seed)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float cHeiGenClassic::GetNoise(float x, float y)
|
|
|
|
{
|
|
|
|
float oct1 = m_Noise.CubicNoise2D(x * m_HeightFreq1, y * m_HeightFreq1) * m_HeightAmp1;
|
|
|
|
float oct2 = m_Noise.CubicNoise2D(x * m_HeightFreq2, y * m_HeightFreq2) * m_HeightAmp2;
|
|
|
|
float oct3 = m_Noise.CubicNoise2D(x * m_HeightFreq3, y * m_HeightFreq3) * m_HeightAmp3;
|
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
float height = m_Noise.CubicNoise2D(x * 0.1f, y * 0.1f) * 2;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
float flatness = ((m_Noise.CubicNoise2D(x * 0.5f, y * 0.5f) + 1.f) * 0.5f) * 1.1f; // 0 ... 1.5
|
2012-06-14 09:06:06 -04:00
|
|
|
flatness *= flatness * flatness;
|
|
|
|
|
|
|
|
return (oct1 + oct2 + oct3) * flatness + height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cHeiGenClassic::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap)
|
|
|
|
{
|
2014-07-17 16:50:58 -04:00
|
|
|
for (int z = 0; z < cChunkDef::Width; z++)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
const float zz = (float)(a_ChunkZ * cChunkDef::Width + z);
|
|
|
|
for (int x = 0; x < cChunkDef::Width; x++)
|
|
|
|
{
|
|
|
|
const float xx = (float)(a_ChunkX * cChunkDef::Width + x);
|
|
|
|
|
|
|
|
int hei = 64 + (int)(GetNoise(xx * 0.05f, zz * 0.05f) * 16);
|
|
|
|
if (hei < 10)
|
|
|
|
{
|
|
|
|
hei = 10;
|
|
|
|
}
|
|
|
|
if (hei > 250)
|
|
|
|
{
|
|
|
|
hei = 250;
|
|
|
|
}
|
2014-07-18 03:57:34 -04:00
|
|
|
cChunkDef::SetHeight(a_HeightMap, x, z, hei);
|
2012-06-14 09:06:06 -04:00
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
void cHeiGenClassic::InitializeHeightGen(cIniFile & a_IniFile)
|
|
|
|
{
|
|
|
|
m_HeightFreq1 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq1", 0.1);
|
|
|
|
m_HeightFreq2 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq2", 1.0);
|
|
|
|
m_HeightFreq3 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq3", 2.0);
|
|
|
|
m_HeightAmp1 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp1", 1.0);
|
|
|
|
m_HeightAmp2 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp2", 0.5);
|
|
|
|
m_HeightAmp3 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp3", 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-06-09 17:40:51 -04:00
|
|
|
// cHeiGenMountains:
|
|
|
|
|
|
|
|
cHeiGenMountains::cHeiGenMountains(int a_Seed) :
|
|
|
|
m_Seed(a_Seed),
|
|
|
|
m_Noise(a_Seed)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cHeiGenMountains::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap)
|
|
|
|
{
|
|
|
|
NOISE_DATATYPE StartX = (NOISE_DATATYPE)(a_ChunkX * cChunkDef::Width);
|
|
|
|
NOISE_DATATYPE EndX = (NOISE_DATATYPE)(a_ChunkX * cChunkDef::Width + cChunkDef::Width - 1);
|
|
|
|
NOISE_DATATYPE StartZ = (NOISE_DATATYPE)(a_ChunkZ * cChunkDef::Width);
|
|
|
|
NOISE_DATATYPE EndZ = (NOISE_DATATYPE)(a_ChunkZ * cChunkDef::Width + cChunkDef::Width - 1);
|
|
|
|
NOISE_DATATYPE Workspace[16 * 16];
|
|
|
|
NOISE_DATATYPE Noise[16 * 16];
|
|
|
|
NOISE_DATATYPE PerlinNoise[16 * 16];
|
|
|
|
m_Noise.Generate2D(Noise, 16, 16, StartX, EndX, StartZ, EndZ, Workspace);
|
|
|
|
m_Perlin.Generate2D(PerlinNoise, 16, 16, StartX, EndX, StartZ, EndZ, Workspace);
|
|
|
|
for (int z = 0; z < cChunkDef::Width; z++)
|
|
|
|
{
|
|
|
|
int IdxZ = z * cChunkDef::Width;
|
|
|
|
for (int x = 0; x < cChunkDef::Width; x++)
|
|
|
|
{
|
|
|
|
int idx = IdxZ + x;
|
|
|
|
int hei = 100 - (int)((Noise[idx] + PerlinNoise[idx]) * 15);
|
|
|
|
if (hei < 10)
|
|
|
|
{
|
|
|
|
hei = 10;
|
|
|
|
}
|
|
|
|
if (hei > 250)
|
|
|
|
{
|
|
|
|
hei = 250;
|
|
|
|
}
|
2014-07-18 03:57:34 -04:00
|
|
|
cChunkDef::SetHeight(a_HeightMap, x, z, hei);
|
2014-06-09 17:40:51 -04:00
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cHeiGenMountains::InitializeHeightGen(cIniFile & a_IniFile)
|
|
|
|
{
|
|
|
|
// TODO: Read the params from an INI file
|
|
|
|
m_Noise.AddOctave(0.1f, 0.1f);
|
|
|
|
m_Noise.AddOctave(0.05f, 0.5f);
|
|
|
|
m_Noise.AddOctave(0.02f, 1.5f);
|
|
|
|
|
|
|
|
m_Perlin.AddOctave(0.01f, 1.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-14 09:06:06 -04:00
|
|
|
// cHeiGenBiomal:
|
|
|
|
|
2013-11-28 15:15:50 -05:00
|
|
|
const cHeiGenBiomal::sGenParam cHeiGenBiomal::m_GenParam[256] =
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
/* Fast-changing | Middle-changing | Slow-changing |*/
|
|
|
|
/* Biome | Freq1 | Amp1 | Freq2 | Amp2 | Freq3 | Amp3 | BaseHeight */
|
2013-11-28 15:15:50 -05:00
|
|
|
/* biOcean */ { 0.1f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 50},
|
|
|
|
/* biPlains */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68},
|
|
|
|
/* biDesert */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68},
|
|
|
|
/* biExtremeHills */ { 0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 100},
|
|
|
|
/* biForest */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70},
|
|
|
|
/* biTaiga */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70},
|
|
|
|
/* biSwampland */ { 0.1f, 1.1f, 0.05f, 1.5f, 0.02f, 2.5f, 61.5},
|
|
|
|
/* biRiver */ { 0.2f, 0.1f, 0.05f, 0.1f, 0.01f, 0.1f, 56},
|
|
|
|
/* biNether */ { 0.1f, 0.0f, 0.01f, 0.0f, 0.01f, 0.0f, 0}, // Unused, but must be here due to indexing
|
|
|
|
/* biSky */ { 0.1f, 0.0f, 0.01f, 0.0f, 0.01f, 0.0f, 0}, // Unused, but must be here due to indexing
|
|
|
|
/* biFrozenOcean */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40},
|
|
|
|
/* biFrozenRiver */ { 0.2f, 0.1f, 0.05f, 0.1f, 0.01f, 0.1f, 56},
|
|
|
|
/* biIcePlains */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68},
|
|
|
|
/* biIceMountains */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80},
|
|
|
|
/* biMushroomIsland */ { 0.1f, 2.0f, 0.05f, 8.0f, 0.01f, 6.0f, 80},
|
|
|
|
/* biMushroomShore */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 64},
|
|
|
|
/* biBeach */ { 0.1f, 0.5f, 0.05f, 1.0f, 0.01f, 1.0f, 64},
|
|
|
|
/* biDesertHills */ { 0.2f, 2.0f, 0.05f, 5.0f, 0.01f, 4.0f, 75},
|
|
|
|
/* biForestHills */ { 0.2f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80},
|
|
|
|
/* biTaigaHills */ { 0.2f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80},
|
|
|
|
/* biExtremeHillsEdge */ { 0.2f, 3.0f, 0.05f, 16.0f, 0.01f, 12.0f, 80},
|
|
|
|
/* biJungle */ { 0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70},
|
|
|
|
/* biJungleHills */ { 0.2f, 3.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80},
|
|
|
|
/* biJungleEdge */ { 0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70},
|
|
|
|
/* biDeepOcean */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40},
|
|
|
|
/* biStoneBeach */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40},
|
|
|
|
/* biColdBeach */ { 0.1f, 0.5f, 0.05f, 1.0f, 0.01f, 1.0f, 64},
|
|
|
|
/* biBirchForest */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70},
|
|
|
|
/* biBirchForestHills */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80},
|
|
|
|
/* biRoofedForest */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70},
|
|
|
|
/* biColdTaiga */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70},
|
|
|
|
/* biColdTaigaHills */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80},
|
|
|
|
/* biMegaTaiga */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70},
|
|
|
|
/* biMegaTaigaHills */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80},
|
|
|
|
/* biExtremeHillsPlus */ { 0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 120},
|
|
|
|
/* biSavanna */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68},
|
|
|
|
/* biSavannaPlateau */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80},
|
2013-11-29 15:47:09 -05:00
|
|
|
/* biMesa */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 70}, // 165
|
2013-11-28 15:15:50 -05:00
|
|
|
/* biMesaPlateauF */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80},
|
|
|
|
/* biMesaPlateau */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80},
|
|
|
|
|
|
|
|
// biomes 40 .. 128 are unused, 89 empty placeholders here:
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, // 40 .. 49
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, // 50 .. 59
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, // 60 .. 69
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, // 70 .. 79
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, // 80 .. 89
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, // 90 .. 99
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, // 100 .. 109
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, // 110 .. 119
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, {}, // 120 .. 128
|
|
|
|
|
|
|
|
/* biSunflowerPlains */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 129
|
|
|
|
/* biDesertM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 130
|
|
|
|
/* biExtremeHillsM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 131
|
|
|
|
/* biFlowerForest */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 132
|
|
|
|
/* biTaigaM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 133
|
2014-08-02 15:44:16 -04:00
|
|
|
/* biSwamplandM */ { 1.0f, 2.0f, 1.10f, 5.0f, 0.01f, 8.0f, 60}, // 134
|
2013-11-28 15:15:50 -05:00
|
|
|
|
|
|
|
// Biomes 135 .. 139 unused, 5 empty placeholders here:
|
|
|
|
{}, {}, {}, {}, {}, // 135 .. 139
|
|
|
|
|
|
|
|
/* biIcePlainsSpikes */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 140
|
|
|
|
|
|
|
|
// Biomes 141 .. 148 unused, 8 empty placeholders here:
|
|
|
|
{}, {}, {}, {}, {}, {}, {}, {}, // 141 .. 148
|
|
|
|
|
|
|
|
/* biJungleM */ { 0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, // 149
|
|
|
|
{}, // 150
|
|
|
|
/* biJungleEdgeM */ { 0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, // 151
|
|
|
|
{}, {}, {}, // 152 .. 154
|
|
|
|
/* biBirchForestM */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 155
|
|
|
|
/* biBirchForestHillsM */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, // 156
|
|
|
|
/* biRoofedForestM */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 157
|
|
|
|
/* biColdTaigaM */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 158
|
|
|
|
{}, // 159
|
|
|
|
/* biMegaSpruceTaiga */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 160
|
|
|
|
/* biMegaSpruceTaigaHills */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, // 161
|
|
|
|
/* biExtremeHillsPlusM */ { 0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 120}, // 162
|
|
|
|
/* biSavannaM */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, // 163
|
|
|
|
/* biSavannaPlateauM */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 164
|
2013-11-29 15:47:09 -05:00
|
|
|
/* biMesaBryce */ { 0.2f, 2.0f, 0.1f, 30.0f, 0.01f, 8.0f, 80},
|
2013-11-28 15:15:50 -05:00
|
|
|
/* biMesaPlateauFM */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 166
|
|
|
|
/* biMesaPlateauM */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 167
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cHeiGenBiomal::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap)
|
|
|
|
{
|
|
|
|
// Generate a 3x3 chunk area of biomes around this chunk:
|
|
|
|
BiomeNeighbors Biomes;
|
|
|
|
for (int z = -1; z <= 1; z++)
|
|
|
|
{
|
|
|
|
for (int x = -1; x <= 1; x++)
|
|
|
|
{
|
|
|
|
m_BiomeGen.GenBiomes(a_ChunkX + x, a_ChunkZ + z, Biomes[x + 1][z + 1]);
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
|
2013-04-22 15:27:15 -04:00
|
|
|
/*
|
|
|
|
_X 2013_04_22:
|
|
|
|
There's no point in precalculating the entire perlin noise arrays, too many values are calculated uselessly,
|
|
|
|
resulting in speed DEcrease.
|
|
|
|
*/
|
|
|
|
|
2013-04-22 16:12:04 -04:00
|
|
|
//*
|
2013-03-20 16:41:19 -04:00
|
|
|
// Linearly interpolate 4x4 blocks of heightmap:
|
2013-04-22 16:12:04 -04:00
|
|
|
// Must be done on a floating point datatype, else the results are ugly!
|
2013-03-20 16:41:19 -04:00
|
|
|
const int STEPZ = 4; // Must be a divisor of 16
|
|
|
|
const int STEPX = 4; // Must be a divisor of 16
|
2013-04-22 16:12:04 -04:00
|
|
|
NOISE_DATATYPE Height[17 * 17];
|
2013-03-20 16:41:19 -04:00
|
|
|
for (int z = 0; z < 17; z += STEPZ)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < 17; x += STEPX)
|
|
|
|
{
|
|
|
|
Height[x + 17 * z] = GetHeightAt(x, z, a_ChunkX, a_ChunkZ, Biomes);
|
|
|
|
}
|
|
|
|
}
|
2014-03-21 17:53:46 -04:00
|
|
|
LinearUpscale2DArrayInPlace<17, 17, STEPX, STEPZ>(Height);
|
2013-03-20 16:41:19 -04:00
|
|
|
|
|
|
|
// Copy into the heightmap
|
|
|
|
for (int z = 0; z < cChunkDef::Width; z++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < cChunkDef::Width; x++)
|
|
|
|
{
|
2013-04-22 16:12:04 -04:00
|
|
|
cChunkDef::SetHeight(a_HeightMap, x, z, (int)Height[x + 17 * z]);
|
2013-03-20 16:41:19 -04:00
|
|
|
}
|
|
|
|
}
|
2013-04-22 16:12:04 -04:00
|
|
|
//*/
|
2013-03-20 16:41:19 -04:00
|
|
|
|
2013-04-22 16:12:04 -04:00
|
|
|
/*
|
2012-06-14 09:06:06 -04:00
|
|
|
// For each height, go through neighboring biomes and add up their idea of height:
|
|
|
|
for (int z = 0; z < cChunkDef::Width; z++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < cChunkDef::Width; x++)
|
|
|
|
{
|
|
|
|
cChunkDef::SetHeight(a_HeightMap, x, z, GetHeightAt(x, z, a_ChunkX, a_ChunkZ, Biomes));
|
|
|
|
} // for x
|
|
|
|
}
|
2013-04-22 16:12:04 -04:00
|
|
|
//*/
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-11 04:18:01 -04:00
|
|
|
void cHeiGenBiomal::InitializeHeightGen(cIniFile & a_IniFile)
|
|
|
|
{
|
|
|
|
// No user-settable params
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-22 16:12:04 -04:00
|
|
|
NOISE_DATATYPE cHeiGenBiomal::GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const cHeiGenBiomal::BiomeNeighbors & a_BiomeNeighbors)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
// Sum up how many biomes of each type there are in the neighborhood:
|
2013-11-28 15:15:50 -05:00
|
|
|
int BiomeCounts[256];
|
2012-06-14 09:06:06 -04:00
|
|
|
memset(BiomeCounts, 0, sizeof(BiomeCounts));
|
|
|
|
int Sum = 0;
|
|
|
|
for (int z = -8; z <= 8; z++)
|
|
|
|
{
|
|
|
|
int FinalZ = a_RelZ + z + cChunkDef::Width;
|
|
|
|
int IdxZ = FinalZ / cChunkDef::Width;
|
|
|
|
int ModZ = FinalZ % cChunkDef::Width;
|
|
|
|
int WeightZ = 9 - abs(z);
|
|
|
|
for (int x = -8; x <= 8; x++)
|
|
|
|
{
|
|
|
|
int FinalX = a_RelX + x + cChunkDef::Width;
|
|
|
|
int IdxX = FinalX / cChunkDef::Width;
|
|
|
|
int ModX = FinalX % cChunkDef::Width;
|
|
|
|
EMCSBiome Biome = cChunkDef::GetBiome(a_BiomeNeighbors[IdxX][IdxZ], ModX, ModZ);
|
|
|
|
int WeightX = 9 - abs(x);
|
|
|
|
BiomeCounts[Biome] += WeightX + WeightZ;
|
|
|
|
Sum += WeightX + WeightZ;
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
|
|
|
|
// For each biome type that has a nonzero count, calc its height and add it:
|
|
|
|
if (Sum > 0)
|
|
|
|
{
|
2013-04-22 16:12:04 -04:00
|
|
|
NOISE_DATATYPE Height = 0;
|
2012-06-14 09:06:06 -04:00
|
|
|
int BlockX = a_ChunkX * cChunkDef::Width + a_RelX;
|
|
|
|
int BlockZ = a_ChunkZ * cChunkDef::Width + a_RelZ;
|
2013-12-20 10:01:34 -05:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(BiomeCounts); i++)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
if (BiomeCounts[i] == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-28 15:15:50 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
// Sanity checks for biome parameters, enable them to check the biome param table in runtime (slow):
|
|
|
|
ASSERT(m_GenParam[i].m_HeightFreq1 >= 0);
|
|
|
|
ASSERT(m_GenParam[i].m_HeightFreq1 < 1000);
|
|
|
|
ASSERT(m_GenParam[i].m_HeightFreq2 >= 0);
|
|
|
|
ASSERT(m_GenParam[i].m_HeightFreq2 < 1000);
|
|
|
|
ASSERT(m_GenParam[i].m_HeightFreq3 >= 0);
|
|
|
|
ASSERT(m_GenParam[i].m_HeightFreq3 < 1000);
|
|
|
|
*/
|
|
|
|
|
2013-04-22 16:12:04 -04:00
|
|
|
NOISE_DATATYPE oct1 = m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq1, BlockZ * m_GenParam[i].m_HeightFreq1) * m_GenParam[i].m_HeightAmp1;
|
|
|
|
NOISE_DATATYPE oct2 = m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq2, BlockZ * m_GenParam[i].m_HeightFreq2) * m_GenParam[i].m_HeightAmp2;
|
|
|
|
NOISE_DATATYPE oct3 = m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq3, BlockZ * m_GenParam[i].m_HeightFreq3) * m_GenParam[i].m_HeightAmp3;
|
|
|
|
Height += BiomeCounts[i] * (m_GenParam[i].m_BaseHeight + oct1 + oct2 + oct3);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-04-22 16:12:04 -04:00
|
|
|
NOISE_DATATYPE res = Height / Sum;
|
|
|
|
return std::min((NOISE_DATATYPE)250, std::max(res, (NOISE_DATATYPE)5));
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// No known biome around? Weird. Return a bogus value:
|
|
|
|
ASSERT(!"cHeiGenBiomal: Biome sum failed, no known biome around");
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|