9 #include "../IniFile.h"
10 #include "../LinearUpscale.h"
72 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
73 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
74 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
75 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
76 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
77 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
78 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
79 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
80 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
91 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
96 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
101 {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
122 m_NoiseDistortX(a_Seed + 1000),
123 m_NoiseDistortZ(a_Seed + 2000),
124 m_CurChunkCoords(0x7fffffff, 0x7fffffff),
125 m_BiomeGen(a_BiomeGen),
126 m_UnderlyingHeiGen(a_Seed, a_BiomeGen),
127 m_HeightGen(m_UnderlyingHeiGen, 64),
128 m_IsInitialized(false)
194 m_NoiseDistortX.
Generate3D(DistortNoiseX,
DIM_X,
DIM_Y,
DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, Workspace);
195 m_NoiseDistortZ.
Generate3D(DistortNoiseZ,
DIM_X,
DIM_Y,
DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, Workspace);
201 for (
int z = 0; z <
DIM_Z; z++)
203 int AmpIdx = z *
DIM_X;
204 for (
int y = 0; y <
DIM_Y; y++)
207 for (
int x = 0; x <
DIM_X; x++)
239 int idx = x + 17 * 257 * z;
296 for (
int z = -1; z <= 1; z++)
298 for (
int x = -1; x <= 1; x++)
304 for (
int z = 0; z <
DIM_Z; z++)
306 for (
int x = 0; x <
DIM_Z; x++)
320 int BiomeCounts[256];
321 memset(BiomeCounts, 0,
sizeof(BiomeCounts));
323 for (
int z = -8; z <= 8; z++)
328 int WeightZ = 9 - abs(z);
329 for (
int x = -8; x <= 8; x++)
335 int WeightX = 9 - abs(x);
336 BiomeCounts[Biome] += WeightX + WeightZ;
337 Sum += WeightX + WeightZ;
344 ASSERT(!
"cHeiGenBiomal: Biome sum failed, no known biome around");
352 for (
size_t i = 0; i <
ARRAYCOUNT(BiomeCounts); i++)
354 if (BiomeCounts[i] <= 0)
370 a_DistortAmpX = AmpX / Sum;
371 a_DistortAmpZ = AmpZ / Sum;
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
unsigned char HEIGHTTYPE
The type used by the heightmap.
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
void LinearUpscale3DArray(TYPE *a_Src, int a_SrcSizeX, int a_SrcSizeY, int a_SrcSizeZ, TYPE *a_Dst, int a_UpscaleX, int a_UpscaleY, int a_UpscaleZ)
Linearly interpolates values in the array between the equidistant anchor points (upscales).
float NOISE_DATATYPE
The datatype used by all the noise generators.
Wraps the chunk coords into a single structure.
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
Byte Shape[256 *16 *16]
The datatype used to represent the entire chunk worth of shape.
The interface that a biome generator must implement A biome generator takes chunk coords on input and...
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap)=0
Generates biomes for the given chunk.
NOISE_DATATYPE m_DistortAmpZ[DIM_X *DIM_Z]
cPerlinNoise m_NoiseDistortZ
virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape &a_Shape) override
Generates the shape for the given chunk.
NOISE_DATATYPE m_FrequencyX
static const int INTERPOL_Y
static const int INTERPOL_X
cChunkCoords m_CurChunkCoords
cChunkDef::BiomeMap BiomeNeighbors[3][3]
NOISE_DATATYPE m_FrequencyZ
cChunkDef::HeightMap m_CurChunkHeights
Heightmap for the current chunk, before distortion (from m_HeightGen).
void Initialize(cIniFile &a_IniFile)
Reads the settings from the ini file.
static const int INTERPOL_Z
int GetHeightmapAt(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Z)
Calculates the heightmap value (before distortion) at the specified (floating-point) coords.
cBiomeGen & m_BiomeGen
The bime generator to query for biomes.
cHeiGenCache m_HeightGen
Cache for m_UnderlyingHeiGen.
cPerlinNoise m_NoiseDistortX
void UpdateDistortAmps(void)
Updates m_DistortAmpX/Z[] based on m_CurChunkX and m_CurChunkZ.
void GetDistortAmpsAt(BiomeNeighbors &a_Neighbors, int a_RelX, int a_RelZ, NOISE_DATATYPE &a_DistortAmpX, NOISE_DATATYPE &a_DistortAmpZ)
Calculates the X and Z distortion amplitudes based on the neighbors' biomes.
NOISE_DATATYPE m_DistortedHeightmap[17 *257 *17]
NOISE_DATATYPE m_DistortAmpX[DIM_X *DIM_Z]
static const sGenParam m_GenParam[256]
This table assigns a relative maximum overhang size in each direction to biomes.
NOISE_DATATYPE m_FrequencyY
void PrepareState(cChunkCoords a_ChunkCoords)
Unless the LastChunk coords are equal to coords given, prepares the internal state (noise arrays,...
cDistortedHeightmap(int a_Seed, cBiomeGen &a_BiomeGen)
virtual void InitializeShapeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
bool m_IsInitialized
True if Initialize() has been called.
void GenerateHeightArray(void)
Generates the m_DistortedHeightmap array for the current chunk.
NOISE_DATATYPE m_DistortAmpZ
NOISE_DATATYPE m_DistortAmpX
virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap &a_HeightMap) override
Retrieves the heightmap for the specified chunk.
virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ) override
Returns the height at the specified column.
int GetValueSetI(const AString &keyname, const AString &valuename, const int defValue=0) override
double GetValueSetF(const AString &keyname, const AString &valuename, const double defValue=0.0)
void Generate3D(NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, int a_SizeZ, NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY, NOISE_DATATYPE a_StartZ, NOISE_DATATYPE a_EndZ, NOISE_DATATYPE *a_Workspace=nullptr) const
Fills a 3D array with the values of the noise.
void AddOctave(NOISE_DATATYPE a_Frequency, NOISE_DATATYPE a_Amplitude)
Adds a new octave to the list of octaves that compose this noise.