Added a voronoi biome generator (#180)
git-svn-id: http://mc-server.googlecode.com/svn/trunk@511 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
fbc497b97d
commit
79fddd3be0
@ -120,3 +120,60 @@ void cBioGenCheckerboard::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cBioGenVoronoi :
|
||||
|
||||
void cBioGenVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap)
|
||||
{
|
||||
int BaseZ = cChunkDef::Width * a_ChunkZ;
|
||||
int BaseX = cChunkDef::Width * a_ChunkX;
|
||||
for (int z = 0; z < cChunkDef::Width; z++)
|
||||
{
|
||||
int AbsoluteZ = BaseZ + z;
|
||||
for (int x = 0; x < cChunkDef::Width; x++)
|
||||
{
|
||||
cChunkDef::SetBiome(a_BiomeMap, x, z, VoronoiBiome(BaseX + x, AbsoluteZ));
|
||||
} // for x
|
||||
} // for z
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
double MinDist = m_CellSize * m_CellSize; // 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;
|
||||
|
||||
double Dist = sqrt((double)((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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@ Interfaces to the various biome generators:
|
||||
#pragma once
|
||||
|
||||
#include "cChunkGenerator.h"
|
||||
#include "cNoise.h"
|
||||
|
||||
|
||||
|
||||
@ -100,3 +101,30 @@ protected:
|
||||
|
||||
|
||||
|
||||
|
||||
class cBioGenVoronoi :
|
||||
public cBiomeGenList
|
||||
{
|
||||
public:
|
||||
cBioGenVoronoi(int a_Seed, int a_CellSize, const AString & a_Biomes) :
|
||||
cBiomeGenList(a_Biomes),
|
||||
m_CellSize(a_CellSize),
|
||||
m_Noise(a_Seed)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
int m_CellSize;
|
||||
|
||||
cNoise m_Noise;
|
||||
|
||||
// cBiomeGen override:
|
||||
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
||||
|
||||
EMCSBiome VoronoiBiome(int a_BlockX, int a_BlockZ);
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -127,6 +127,12 @@ void cChunkGenerator::InitBiomeGen(cIniFile & a_IniFile)
|
||||
AString Biomes = a_IniFile.GetValue("Generator", "CheckerBoardBiomes", "");
|
||||
m_BiomeGen = new cBioGenCheckerboard(BiomeSize, Biomes);
|
||||
}
|
||||
else if (NoCaseCompare(BiomeGenName, "voronoi") == 0)
|
||||
{
|
||||
int CellSize = a_IniFile.GetValueI("Generator", "VoronoiCellSize", 64);
|
||||
AString Biomes = a_IniFile.GetValue("Generator", "VoronoiBiomes", "");
|
||||
m_BiomeGen = new cBioGenVoronoi(m_Seed, CellSize, Biomes);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NoCaseCompare(BiomeGenName, "distortedvoronoi") != 0)
|
||||
|
Loading…
Reference in New Issue
Block a user