From 5fb2526e0739fa27d925a686669f2c3aef56e825 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 12 Nov 2014 21:24:26 +0100 Subject: Generator: Shape initial refactoring. The code compiles, but several structure generators are broken, crash on start. --- src/Generating/StructGen.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/Generating/StructGen.cpp') diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index bdefcd8c1..1c83cf78f 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -37,10 +37,12 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) Dest = &WorkerDesc; WorkerDesc.SetChunkCoords(BaseX, BaseZ); + // TODO: This may cause a lot of wasted calculations, instead of pulling data out of a single (cChunkDesc) cache + + cChunkDesc::Shape workerShape; m_BiomeGen->GenBiomes (BaseX, BaseZ, WorkerDesc.GetBiomeMap()); - m_HeightGen->GenHeightMap (BaseX, BaseZ, WorkerDesc.GetHeightMap()); - m_CompositionGen->ComposeTerrain(WorkerDesc); - // TODO: Free the entity lists + m_ShapeGen->GenShape (BaseX, BaseZ, workerShape); + m_CompositionGen->ComposeTerrain(WorkerDesc, workerShape); } else { @@ -390,7 +392,7 @@ void cStructGenLakes::GenFinish(cChunkDesc & a_ChunkDesc) } cBlockArea Lake; - CreateLakeImage(ChunkX + x, ChunkZ + z, Lake); + CreateLakeImage(ChunkX + x, ChunkZ + z, a_ChunkDesc.GetMinHeight(), Lake); int OfsX = Lake.GetOriginX() + x * cChunkDef::Width; int OfsZ = Lake.GetOriginZ() + z * cChunkDef::Width; @@ -404,25 +406,13 @@ void cStructGenLakes::GenFinish(cChunkDesc & a_ChunkDesc) -void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, cBlockArea & a_Lake) +void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeHeight, cBlockArea & a_Lake) { a_Lake.Create(16, 8, 16); a_Lake.Fill(cBlockArea::baTypes, E_BLOCK_SPONGE); // Sponge is the NOP blocktype for lake merging strategy - // Find the minimum height in this chunk: - cChunkDef::HeightMap HeightMap; - m_HeiGen->GenHeightMap(a_ChunkX, a_ChunkZ, HeightMap); - HEIGHTTYPE MinHeight = HeightMap[0]; - for (size_t i = 1; i < ARRAYCOUNT(HeightMap); i++) - { - if (HeightMap[i] < MinHeight) - { - MinHeight = HeightMap[i]; - } - } - // Make a random position in the chunk by using a random 16 block XZ offset and random height up to chunk's max height minus 6 - MinHeight = std::max(MinHeight - 6, 2); + int MinHeight = std::max(a_MaxLakeHeight - 6, 2); int Rnd = m_Noise.IntNoise3DInt(a_ChunkX, 128, a_ChunkZ) / 11; // Random offset [-8 .. 8], with higher probability around 0; add up four three-bit-wide randoms [0 .. 28], divide and subtract to get range int OffsetX = 4 * ((Rnd & 0x07) + ((Rnd & 0x38) >> 3) + ((Rnd & 0x1c0) >> 6) + ((Rnd & 0xe00) >> 9)) / 7 - 8; -- cgit v1.2.3 From 7a3b3aeb3c28b7ba899d6dff2b5e160a95529f40 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 13 Nov 2014 21:28:50 +0100 Subject: Gen refactor: Implemented CompositedHeiGen. This fixes crashes in the Village generator due to the missing generator. --- src/Generating/StructGen.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Generating/StructGen.cpp') diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 1c83cf78f..ca8f0411f 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -42,6 +42,7 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) cChunkDesc::Shape workerShape; m_BiomeGen->GenBiomes (BaseX, BaseZ, WorkerDesc.GetBiomeMap()); m_ShapeGen->GenShape (BaseX, BaseZ, workerShape); + WorkerDesc.SetHeightFromShape (workerShape); m_CompositionGen->ComposeTerrain(WorkerDesc, workerShape); } else -- cgit v1.2.3 From 564b9ad33711b45c59d3c001df1b9206c7cbf60e Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 15 Nov 2014 21:45:24 +0100 Subject: Generator: Fixed crash with trees too high. --- src/Generating/StructGen.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/Generating/StructGen.cpp') diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index ca8f0411f..2f685c808 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -100,7 +100,7 @@ void cStructGenTrees::GenerateSingleTree( int Height = a_ChunkDesc.GetHeight(x, z); - if ((Height <= 0) || (Height > 240)) + if ((Height <= 0) || (Height >= 230)) { return; } @@ -128,6 +128,11 @@ void cStructGenTrees::GenerateSingleTree( // Outside the chunk continue; } + if (itr->y >= cChunkDef::Height) + { + // Above the chunk, cut off (this shouldn't happen too often, we're limiting trees to y < 230) + continue; + } BLOCKTYPE Block = a_ChunkDesc.GetBlockType(itr->x, itr->y, itr->z); switch (Block) @@ -162,7 +167,7 @@ void cStructGenTrees::ApplyTreeImage( // Put the generated image into a_BlockTypes, push things outside this chunk into a_Blocks for (sSetBlockVector::const_iterator itr = a_Image.begin(), end = a_Image.end(); itr != end; ++itr) { - if ((itr->ChunkX == a_ChunkX) && (itr->ChunkZ == a_ChunkZ)) + if ((itr->ChunkX == a_ChunkX) && (itr->ChunkZ == a_ChunkZ) && (itr->y < cChunkDef::Height)) { // Inside this chunk, integrate into a_ChunkDesc: switch (a_ChunkDesc.GetBlockType(itr->x, itr->y, itr->z)) -- cgit v1.2.3