Voronoi-related biomegens use the new cVoronoiMap class.
This commit is contained in:
parent
187a0dbaa2
commit
bec27617a2
@ -267,7 +267,8 @@ void cBioGenVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap &
|
|||||||
int AbsoluteZ = BaseZ + z;
|
int AbsoluteZ = BaseZ + z;
|
||||||
for (int x = 0; x < cChunkDef::Width; x++)
|
for (int x = 0; x < cChunkDef::Width; x++)
|
||||||
{
|
{
|
||||||
cChunkDef::SetBiome(a_BiomeMap, x, z, VoronoiBiome(BaseX + x, AbsoluteZ));
|
int VoronoiCellValue = m_Voronoi.GetValueAt(BaseX + x, AbsoluteZ) / 8;
|
||||||
|
cChunkDef::SetBiome(a_BiomeMap, x, z, m_Biomes[VoronoiCellValue % m_BiomesCount]);
|
||||||
} // for x
|
} // for x
|
||||||
} // for z
|
} // for z
|
||||||
}
|
}
|
||||||
@ -279,45 +280,8 @@ void cBioGenVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap &
|
|||||||
void cBioGenVoronoi::InitializeBiomeGen(cIniFile & a_IniFile)
|
void cBioGenVoronoi::InitializeBiomeGen(cIniFile & a_IniFile)
|
||||||
{
|
{
|
||||||
super::InitializeBiomeGen(a_IniFile);
|
super::InitializeBiomeGen(a_IniFile);
|
||||||
m_CellSize = a_IniFile.GetValueSetI("Generator", "VoronoiCellSize", 64);
|
m_Voronoi.SetCellSize(a_IniFile.GetValueSetI("Generator", "VoronoiCellSize", 64));
|
||||||
AString Biomes = a_IniFile.GetValueSet ("Generator", "VoronoiBiomes", "");
|
InitializeBiomes (a_IniFile.GetValueSet ("Generator", "VoronoiBiomes", ""));
|
||||||
InitializeBiomes(Biomes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EMCSBiome cBioGenVoronoi::VoronoiBiome(int a_BlockX, int a_BlockZ)
|
|
||||||
{
|
|
||||||
int CellX = a_BlockX / m_CellSize;
|
|
||||||
int CellZ = a_BlockZ / m_CellSize;
|
|
||||||
|
|
||||||
// Note that Noise values need to be divided by 8 to gain a uniform modulo-2^n distribution
|
|
||||||
|
|
||||||
// Get 5x5 neighboring cell seeds, compare distance to each. Return the biome in the minumim-distance cell
|
|
||||||
int MinDist = m_CellSize * m_CellSize * 16; // There has to be a cell closer than this
|
|
||||||
EMCSBiome res = biPlains; // Will be overriden
|
|
||||||
for (int x = CellX - 2; x <= CellX + 2; x++)
|
|
||||||
{
|
|
||||||
int BaseX = x * m_CellSize;
|
|
||||||
for (int z = CellZ - 2; z < CellZ + 2; z++)
|
|
||||||
{
|
|
||||||
int OffsetX = (m_Noise.IntNoise3DInt(x, 16 * x + 32 * z, z) / 8) % m_CellSize;
|
|
||||||
int OffsetZ = (m_Noise.IntNoise3DInt(x, 32 * x - 16 * z, z) / 8) % m_CellSize;
|
|
||||||
int SeedX = BaseX + OffsetX;
|
|
||||||
int SeedZ = z * m_CellSize + OffsetZ;
|
|
||||||
|
|
||||||
int Dist = (SeedX - a_BlockX) * (SeedX - a_BlockX) + (SeedZ - a_BlockZ) * (SeedZ - a_BlockZ);
|
|
||||||
if (Dist < MinDist)
|
|
||||||
{
|
|
||||||
MinDist = Dist;
|
|
||||||
res = m_Biomes[(m_Noise.IntNoise3DInt(x, x - z + 1000, z) / 8) % m_BiomesCount];
|
|
||||||
}
|
|
||||||
} // for z
|
|
||||||
} // for x
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -348,8 +312,8 @@ void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::B
|
|||||||
int AbsoluteZ = BaseZ + z;
|
int AbsoluteZ = BaseZ + z;
|
||||||
for (int x = 0; x < cChunkDef::Width; x++)
|
for (int x = 0; x < cChunkDef::Width; x++)
|
||||||
{
|
{
|
||||||
// Distort(BaseX + x, AbsoluteZ, DistX, DistZ);
|
int VoronoiCellValue = m_Voronoi.GetValueAt(DistortX[x][z], DistortZ[x][z]) / 8;
|
||||||
cChunkDef::SetBiome(a_BiomeMap, x, z, VoronoiBiome(DistortX[x][z], DistortZ[x][z]));
|
cChunkDef::SetBiome(a_BiomeMap, x, z, m_Biomes[VoronoiCellValue % m_BiomesCount]);
|
||||||
} // for x
|
} // for x
|
||||||
} // for z
|
} // for z
|
||||||
}
|
}
|
||||||
@ -360,10 +324,10 @@ void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::B
|
|||||||
|
|
||||||
void cBioGenDistortedVoronoi::InitializeBiomeGen(cIniFile & a_IniFile)
|
void cBioGenDistortedVoronoi::InitializeBiomeGen(cIniFile & a_IniFile)
|
||||||
{
|
{
|
||||||
// Do NOT call super::InitializeBiomeGen(), as it would try to read Voronoi params instead of DistortedVoronoi params
|
super::InitializeBiomeGen(a_IniFile);
|
||||||
m_CellSize = a_IniFile.GetValueSetI("Generator", "DistortedVoronoiCellSize", 96);
|
m_CellSize = a_IniFile.GetValueSetI("Generator", "DistortedVoronoiCellSize", 96);
|
||||||
AString Biomes = a_IniFile.GetValueSet ("Generator", "DistortedVoronoiBiomes", "");
|
m_Voronoi.SetCellSize(m_CellSize);
|
||||||
InitializeBiomes(Biomes);
|
InitializeBiomes(a_IniFile.GetValueSet("Generator", "DistortedVoronoiBiomes", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ Interfaces to the various biome generators:
|
|||||||
|
|
||||||
#include "ComposableGenerator.h"
|
#include "ComposableGenerator.h"
|
||||||
#include "../Noise.h"
|
#include "../Noise.h"
|
||||||
|
#include "../VoronoiMap.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -123,14 +124,12 @@ class cBioGenVoronoi :
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
cBioGenVoronoi(int a_Seed) :
|
cBioGenVoronoi(int a_Seed) :
|
||||||
m_Noise(a_Seed)
|
m_Voronoi(a_Seed)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_CellSize;
|
cVoronoiMap m_Voronoi;
|
||||||
|
|
||||||
cNoise m_Noise;
|
|
||||||
|
|
||||||
// cBiomeGen overrides:
|
// cBiomeGen overrides:
|
||||||
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
||||||
@ -144,16 +143,28 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
class cBioGenDistortedVoronoi :
|
class cBioGenDistortedVoronoi :
|
||||||
public cBioGenVoronoi
|
public cBiomeGenList
|
||||||
{
|
{
|
||||||
typedef cBioGenVoronoi super;
|
typedef cBiomeGenList super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cBioGenDistortedVoronoi(int a_Seed) :
|
cBioGenDistortedVoronoi(int a_Seed) :
|
||||||
cBioGenVoronoi(a_Seed)
|
m_Noise(a_Seed),
|
||||||
|
m_Voronoi(a_Seed),
|
||||||
|
m_CellSize(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Noise used for the distortion
|
||||||
|
cNoise m_Noise;
|
||||||
|
|
||||||
|
/// The underlying Voronoi map of the biomes
|
||||||
|
cVoronoiMap m_Voronoi;
|
||||||
|
|
||||||
|
/// Size of the Voronoi cells, also used for distortion amplitude
|
||||||
|
int m_CellSize;
|
||||||
|
|
||||||
// cBiomeGen overrides:
|
// cBiomeGen overrides:
|
||||||
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
||||||
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
|
|
||||||
cVoronoiMap::cVoronoiMap(int a_Seed, int a_CellSize) :
|
cVoronoiMap::cVoronoiMap(int a_Seed, int a_CellSize) :
|
||||||
m_Noise(a_Seed * 13 + 7),
|
m_Noise(a_Seed),
|
||||||
m_CellSize(a_CellSize)
|
m_CellSize(a_CellSize)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user