7 #include "../BlockArea.h" 8 #include "../LinearUpscale.h" 25 for (
int x = 0; x <= 2; x++)
27 int BaseX = ChunkX + x - 1;
28 for (
int z = 0; z <= 2; z++)
30 int BaseZ = ChunkZ + z - 1;
34 if ((x != 1) || (z != 1))
42 m_BiomeGen->GenBiomes ({BaseX, BaseZ}, WorkerDesc.GetBiomeMap());
43 m_ShapeGen->GenShape ({BaseX, BaseZ}, workerShape);
44 WorkerDesc.SetHeightFromShape (workerShape);
55 for (
int i = 0; i < NumTrees; i++)
61 IgnoredOverflow.reserve(OutsideOther.size());
62 ApplyTreeImage(ChunkX, ChunkZ, a_ChunkDesc, OutsideOther, IgnoredOverflow);
63 IgnoredOverflow.clear();
64 IgnoredOverflow.reserve(OutsideLogs.size());
65 ApplyTreeImage(ChunkX, ChunkZ, a_ChunkDesc, OutsideLogs, IgnoredOverflow);
77 int a_ChunkX,
int a_ChunkZ,
int a_Seq,
88 if ((Height <= 0) || (Height >= 230))
109 for (sSetBlockVector::const_iterator itr = TreeLogs.begin(); itr != TreeLogs.end(); ++itr)
111 if ((itr->m_ChunkX != a_ChunkX) || (itr->m_ChunkZ != a_ChunkZ))
137 ApplyTreeImage(a_ChunkX, a_ChunkZ, a_ChunkDesc, TreeOther, a_OutsideOther);
138 ApplyTreeImage(a_ChunkX, a_ChunkZ, a_ChunkDesc, TreeLogs, a_OutsideLogs);
146 int a_ChunkX,
int a_ChunkZ,
153 for (sSetBlockVector::const_iterator itr = a_Image.begin(), end = a_Image.end(); itr != end; ++itr)
155 if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ) && (itr->m_RelY <
cChunkDef::Height))
158 switch (a_ChunkDesc.
GetBlockType(itr->m_RelX, itr->m_RelY, itr->m_RelZ))
171 a_ChunkDesc.
SetBlockTypeMeta(itr->m_RelX, itr->m_RelY, itr->m_RelZ, itr->m_BlockType, itr->m_BlockMeta);
189 a_Overflow.push_back(*itr);
198 int a_ChunkX,
int a_ChunkZ,
215 case biEnd:
return 0;
274 ASSERT(!
"Invalid biome in cStructGenTrees::GetNumTrees");
282 for (
auto Biome : a_Biomes)
284 NumTrees += BiomeTrees(Biome);
286 return NumTrees / 1024;
301 for (
int z = -1; z < 2; z++)
for (
int x = -1; x < 2; x++)
309 CreateLakeImage(ChunkX + x, ChunkZ + z, a_ChunkDesc.
GetMinHeight(), Lake);
329 int MinHeight = std::max(a_MaxLakeHeight - 6, 2);
332 int OffsetX = 4 * ((Rnd & 0x07) + ((Rnd & 0x38) >> 3) + ((Rnd & 0x1c0) >> 6) + ((Rnd & 0xe00) >> 9)) / 7 - 8;
335 int OffsetZ = 4 * ((Rnd & 0x07) + ((Rnd & 0x38) >> 3) + ((Rnd & 0x1c0) >> 6) + ((Rnd & 0xe00) >> 9)) / 7 - 8;
338 int HeightY = 1 + (((Rnd & 0x1ff) % MinHeight) + (((Rnd >> 9) & 0x1ff) % MinHeight)) / 2;
340 a_Lake.
SetOrigin(OffsetX, HeightY, OffsetZ);
343 int NumBubbles = 4 + ((Rnd >> 18) & 0x03);
345 for (
int i = 0; i < NumBubbles; i++)
348 const int BubbleR = 2 + (BubbleRnd & 0x03);
349 const int Range = 16 - 2 * BubbleR;
350 const int BubbleX = BubbleR + (BubbleRnd % Range);
352 const int BubbleY = 4 + (BubbleRnd & 0x01);
354 const int BubbleZ = BubbleR + (BubbleRnd % Range);
355 const int HalfR = BubbleR / 2;
356 const int RSquared = BubbleR * BubbleR;
357 for (
int y = -HalfR; y <= HalfR; y++)
360 int DistY = 4 * y * y / 3;
361 int IdxY = (BubbleY + y) * 16 * 16;
362 for (
int z = -BubbleR; z <= BubbleR; z++)
364 int DistYZ = DistY + z * z;
365 if (DistYZ >= RSquared)
369 int IdxYZ = BubbleX + IdxY + (BubbleZ + z) * 16;
370 for (
int x = -BubbleR; x <= BubbleR; x++)
372 if (x * x + DistYZ < RSquared)
382 for (
int y = 0; y < 4; y++)
384 for (
int z = 0; z < 16; z++)
for (
int x = 0; x < 16; x++)
386 if (BlockTypes[x + z * 16 + y * 16 * 16] ==
E_BLOCK_AIR)
388 BlockTypes[x + z * 16 + y * 16 * 16] = m_Fluid;
407 m_Noise2(a_Seed + 1000)
425 const int SEGMENT_HEIGHT = 8;
432 int FloorBuf1[17 * 17];
433 int FloorBuf2[17 * 17];
434 int * FloorHi = FloorBuf1;
435 int * FloorLo = FloorBuf2;
443 FloorLo[INTERPOL_X * x + 17 * INTERPOL_Z * z] =
448 LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo);
451 for (
int Segment = BaseY; Segment < MaxHeight; Segment += SEGMENT_HEIGHT)
456 FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = (
458 m_Noise2.
IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256
461 LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi);
464 for (
int z = 0; z < 16; z++)
for (
int x = 0; x < 16; x++)
470 int Lo = FloorLo[x + 17 * z] / 256;
471 int Hi = FloorHi[x + 17 * z] / 256;
472 for (
int y = 0; y < SEGMENT_HEIGHT; y++)
474 int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT;
485 std::swap(FloorLo, FloorHi);
496 for (
size_t i = 0; i <
ARRAYCOUNT(Biomes); i++)
522 m_NoiseX(a_Seed + 1000),
523 m_NoiseY(a_Seed + 2000),
524 m_NoiseZ(a_Seed + 3000),
525 m_NoiseH(a_Seed + 4000)
537 for (
int y = 50; y < 128; y++)
551 int MembraneHeight = 96 -
static_cast<int>((DistortY +
m_NoiseH.
CubicNoise2D(NoiseX + DistortX, NoiseZ + DistortZ)) * 30);
552 if (MembraneHeight < y)
HEIGHTTYPE GetMaxHeight(void) const
Returns the maximum height value in the heightmap.
Byte Shape[256 *16 *16]
The datatype used to represent the entire chunk worth of shape.
void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
#define CASE_TREE_ALLOWED_BLOCKS
int GetOriginZ(void) const
void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta=0, NIBBLETYPE a_BlockLight=0, NIBBLETYPE a_BlockSkyLight=0x0f)
Fills the entire block area with the specified data.
int IntNoise2DInt(int a_X, int a_Y) const
static bool IsSolid(BLOCKTYPE a_Type)
unsigned char BLOCKTYPE
The datatype used by blockdata.
cTerrainCompositionGenPtr m_CompositionGen
virtual void GenFinish(cChunkDesc &a_ChunkDesc) override
EMCSBiome GetBiome(int a_RelX, int a_RelZ) const
int IntNoise3DInt(int a_X, int a_Y, int a_Z) const
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
void CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeHeight, cBlockArea &a_Lake)
Creates a lake image for the specified chunk into a_Lake.
unsigned char HEIGHTTYPE
The type used by the heightmap.
virtual void GenFinish(cChunkDesc &a_ChunkDesc) override
void WriteBlockArea(const cBlockArea &a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy=cBlockArea::msOverwrite)
Writes the block area into the chunk, with its origin set at the specified relative coords...
virtual void GenFinish(cChunkDesc &a_ChunkDesc) override
void UpdateHeightmap(void)
Updates the heightmap to match the current contents.
BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const
int GetOriginY(void) const
virtual void GenFinish(cChunkDesc &a_ChunkDesc) override
void GetTreeImageByBiome(Vector3i a_BlockPos, cNoise &a_Noise, int a_Seq, EMCSBiome a_Biome, sSetBlockVector &a_LogBlocks, sSetBlockVector &a_OtherBlocks)
Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a tree at the sp...
float NOISE_DATATYPE
The datatype used by all the noise generators.
HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ) const
HEIGHTTYPE GetMinHeight(void) const
Returns the minimum height value in the heightmap.
cStructGenDirectOverhangs(int a_Seed)
cStructGenDistortedMembraneOverhangs(int a_Seed)
int GetNumTrees(int a_ChunkX, int a_ChunkZ, const cChunkDef::BiomeMap &a_Biomes)
cTerrainShapeGenPtr m_ShapeGen
NOISE_DATATYPE CubicNoise3D(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z) const
void ApplyTreeImage(int a_ChunkX, int a_ChunkZ, cChunkDesc &a_ChunkDesc, const sSetBlockVector &a_Image, sSetBlockVector &a_Overflow)
Applies an image into chunk blockdata; all blocks outside the chunk will be appended to a_Overflow...
void SetChunkCoords(cChunkCoords a_Coords)
int GetOriginX(void) const
BLOCKTYPE * GetBlockTypes(void) const
Returns the internal pointer to the block types.
void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes=baTypes|baMetas|baBlockEntities)
Creates a new area of the specified size and contents.
void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
Resets the origin.
NOISE_DATATYPE CubicNoise2D(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y) const
void GenerateSingleTree(int a_ChunkX, int a_ChunkZ, int a_Seq, cChunkDesc &a_ChunkDesc, sSetBlockVector &a_OutsideLogs, sSetBlockVector &a_OutsideOther)
Generates and applies an image of a single tree.
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
#define CASE_TREE_OVERWRITTEN_BLOCKS
#define UNREACHABLE(x)
Use to mark code that should be impossible to reach.
void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
std::vector< sSetBlock > sSetBlockVector
cChunkDef::BiomeMap & GetBiomeMap(void)
bool HasWantedBiome(cChunkDesc &a_ChunkDesc) const