1
0

Initial Mesa Bryce implementation.

This commit is contained in:
madmaxoft 2014-06-10 22:59:45 +02:00
parent c259dad7b8
commit 1ff1a93866
4 changed files with 116 additions and 4 deletions

View File

@ -282,7 +282,7 @@ cDistortedHeightmap::cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen) :
m_OceanFloorSelect(a_Seed + 3000),
m_MesaFloor(a_Seed + 4000),
m_BiomeGen(a_BiomeGen),
m_UnderlyingHeiGen(a_Seed, a_BiomeGen),
m_UnderlyingHeiGen(a_Seed),
m_HeightGen(m_UnderlyingHeiGen, 64),
m_IsInitialized(false)
{
@ -308,6 +308,8 @@ void cDistortedHeightmap::Initialize(cIniFile & a_IniFile)
return;
}
((cTerrainHeightGen &)m_UnderlyingHeiGen).InitializeHeightGen(a_IniFile);
// Read the params from the INI file:
m_SeaLevel = a_IniFile.GetValueSetI("Generator", "DistortedHeightmapSeaLevel", 62);
m_FrequencyX = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "DistortedHeightmapFrequencyX", 10);

View File

@ -64,9 +64,9 @@ protected:
int m_CurChunkZ;
NOISE_DATATYPE m_DistortedHeightmap[17 * 257 * 17];
cBiomeGen & m_BiomeGen;
cHeiGenBiomal m_UnderlyingHeiGen; // This generator provides us with base heightmap (before distortion)
cHeiGenCache m_HeightGen; // Cache above m_UnderlyingHeiGen
cBiomeGen & m_BiomeGen;
cHeiGenMesaBryce m_UnderlyingHeiGen; // This generator provides us with base heightmap (before distortion)
cHeiGenCache m_HeightGen; // Cache above m_UnderlyingHeiGen
/// Heightmap for the current chunk, before distortion (from m_HeightGen). Used for optimization.
cChunkDef::HeightMap m_CurChunkHeights;

View File

@ -47,6 +47,10 @@ cTerrainHeightGen * cTerrainHeightGen::CreateHeightGen(cIniFile &a_IniFile, cBio
{
res = new cEndGen(a_Seed);
}
else if (NoCaseCompare(HeightGenName, "MesaBryce") == 0)
{
res = new cHeiGenMesaBryce(a_Seed);
}
else if (NoCaseCompare(HeightGenName, "Mountains") == 0)
{
res = new cHeiGenMountains(a_Seed);
@ -366,6 +370,91 @@ void cHeiGenMountains::InitializeHeightGen(cIniFile & a_IniFile)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cHeiGenMesaBryce:
cHeiGenMesaBryce::cHeiGenMesaBryce(int a_Seed) :
m_Seed(a_Seed),
m_PerlinHFHA(a_Seed),
m_PerlinLFLA(a_Seed + 10)
{
}
void cHeiGenMesaBryce::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 Noise1[16 * 16];
NOISE_DATATYPE Noise2[16 * 16];
NOISE_DATATYPE Noise3[16 * 16];
m_PerlinHFHA.Generate2D(Noise1, 16, 16, StartX, EndX, StartZ, EndZ, Workspace);
m_PerlinLFLA.Generate2D(Noise2, 16, 16, StartX, EndX, StartZ, EndZ, Workspace);
m_PerlinTops.Generate2D(Noise3, 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 = 70 + (int)(std::min(Noise1[idx], Noise2[idx]) * 15);
int hei;
if (Noise1[idx] > 1.5f)
{
hei = 83 + (int)floor(Noise3[idx]);
}
else
{
hei = 63 + (int)floor(Noise2[idx]);
}
/*
NOISE_DATATYPE v1 = sqrt(sqrt(std::max(Noise1[idx], (NOISE_DATATYPE)0))) - 50;
int hei = 60 + (int)floor(std::max(v1, 5 + Noise2[idx]));
*/
if (hei < 10)
{
hei = 10;
}
if (hei > 250)
{
hei = 250;
}
cChunkDef::SetHeight(a_HeightMap, x , z, hei);
} // for x
} // for z
}
void cHeiGenMesaBryce::InitializeHeightGen(cIniFile & a_IniFile)
{
// TODO: Read the params from an INI file
// m_PerlinHFHA.AddOctave(0.32f, 0.1);
/*
m_PerlinHFHA.AddOctave(0.13f, 17800000);
m_PerlinHFHA.AddOctave(0.12f, 19000000);
*/
m_PerlinHFHA.AddOctave(0.13f, 2);
m_PerlinHFHA.AddOctave(0.12f, 2);
m_PerlinLFLA.AddOctave(0.04f, 1);
m_PerlinLFLA.AddOctave(0.02f, 2);
m_PerlinTops.AddOctave(0.1f, 8);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cHeiGenBiomal:

View File

@ -127,6 +127,27 @@ protected:
class cHeiGenMesaBryce :
public cTerrainHeightGen
{
public:
cHeiGenMesaBryce(int a_Seed);
protected:
int m_Seed;
cPerlinNoise m_PerlinHFHA; // HighFrequencyHighAmplitude, for the hills
cPerlinNoise m_PerlinLFLA; // LowFrequencyLowAmplitude, for the floor
cPerlinNoise m_PerlinTops;
// cTerrainHeightGen overrides:
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
} ;
class cHeiGenBiomal :
public cTerrainHeightGen
{