From a2ffa432b31096f2533ecb50f49ba450b29a2989 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 1 Sep 2019 09:30:00 +0200 Subject: Separated chunk generator from world / plugin interfaces. The generator now only takes care of servicing synchronous "GetChunk(X, Y)" and "GetBiomes(X, Y)" requests. --- src/World.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 10 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 2b151af8e..a619ea9c6 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1648,13 +1648,13 @@ void cWorld::GrowTreeFromSapling(int a_X, int a_Y, int a_Z, NIBBLETYPE a_Sapling case E_META_SAPLING_ACACIA: GetAcaciaTreeImage (a_X, a_Y, a_Z, Noise, WorldAge, Logs, Other); break; case E_META_SAPLING_JUNGLE: { - bool IsLarge = GetLargeTreeAdjustment(*this, a_X, a_Y, a_Z, a_SaplingMeta); + bool IsLarge = GetLargeTreeAdjustment(a_X, a_Y, a_Z, a_SaplingMeta); GetJungleTreeImage (a_X, a_Y, a_Z, Noise, WorldAge, Logs, Other, IsLarge); break; } case E_META_SAPLING_DARK_OAK: { - if (!GetLargeTreeAdjustment(*this, a_X, a_Y, a_Z, a_SaplingMeta)) + if (!GetLargeTreeAdjustment(a_X, a_Y, a_Z, a_SaplingMeta)) { return; } @@ -1672,6 +1672,92 @@ void cWorld::GrowTreeFromSapling(int a_X, int a_Y, int a_Z, NIBBLETYPE a_Sapling +bool cWorld::GetLargeTreeAdjustment(int & a_X, int & a_Y, int & a_Z, NIBBLETYPE a_Meta) +{ + bool IsLarge = true; + a_Meta = a_Meta & 0x07; + + // Check to see if we are the northwest corner + for (int x = 0; x < 2; ++x) + { + for (int z = 0; z < 2; ++z) + { + NIBBLETYPE meta; + BLOCKTYPE type; + GetBlockTypeMeta(a_X + x, a_Y, a_Z + z, type, meta); + IsLarge = IsLarge && (type == E_BLOCK_SAPLING) && ((a_Meta & meta) == a_Meta); + } + } + + if (IsLarge) + { + return true; + } + + IsLarge = true; + // Check to see if we are the southwest corner + for (int x = 0; x < 2; ++x) + { + for (int z = 0; z > -2; --z) + { + NIBBLETYPE meta; + BLOCKTYPE type; + GetBlockTypeMeta(a_X + x, a_Y, a_Z + z, type, meta); + IsLarge = IsLarge && (type == E_BLOCK_SAPLING) && ((a_Meta & meta) == a_Meta); + } + } + + if (IsLarge) + { + --a_Z; + return true; + } + + IsLarge = true; + // Check to see if we are the southeast corner + for (int x = 0; x > -2; --x) + { + for (int z = 0; z > -2; --z) + { + NIBBLETYPE meta; + BLOCKTYPE type; + GetBlockTypeMeta(a_X + x, a_Y, a_Z + z, type, meta); + IsLarge = IsLarge && (type == E_BLOCK_SAPLING) && ((a_Meta & meta) == a_Meta); + } + } + + if (IsLarge) + { + --a_Z; + --a_X; + return true; + } + + IsLarge = true; + // Check to see if we are the northeast corner + for (int x = 0; x > -2; --x) + { + for (int z = 0; z < 2; ++z) + { + NIBBLETYPE meta; + BLOCKTYPE type; + GetBlockTypeMeta(a_X + x, a_Y, a_Z + z, type, meta); + IsLarge = IsLarge && (type == E_BLOCK_SAPLING) && ((a_Meta & meta) == a_Meta); + } + } + + if (IsLarge) + { + --a_X; + } + + return IsLarge; +} + + + + + void cWorld::GrowTreeByBiome(int a_X, int a_Y, int a_Z) { cNoise Noise(m_Generator.GetSeed()); @@ -2514,7 +2600,7 @@ void cWorld::QueueSetChunkData(cSetChunkDataPtr a_SetChunkData) if (!a_SetChunkData->AreBiomesValid()) { // The biomes are not assigned, get them from the generator: - m_Generator.GenerateBiomes(a_SetChunkData->GetChunkX(), a_SetChunkData->GetChunkZ(), a_SetChunkData->GetBiomes()); + m_Generator.GenerateBiomes({a_SetChunkData->GetChunkX(), a_SetChunkData->GetChunkZ()}, a_SetChunkData->GetBiomes()); a_SetChunkData->MarkBiomesValid(); } @@ -3157,7 +3243,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) { m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ); - m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ, true); + m_Generator.QueueGenerateChunk({a_ChunkX, a_ChunkZ}, true); } @@ -3770,27 +3856,27 @@ void cWorld::cChunkGeneratorCallbacks::OnChunkGenerated(cChunkDesc & a_ChunkDesc -bool cWorld::cChunkGeneratorCallbacks::IsChunkValid(int a_ChunkX, int a_ChunkZ) +bool cWorld::cChunkGeneratorCallbacks::IsChunkValid(cChunkCoords a_Coords) { - return m_World->IsChunkValid(a_ChunkX, a_ChunkZ); + return m_World->IsChunkValid(a_Coords.m_ChunkX, a_Coords.m_ChunkZ); } -bool cWorld::cChunkGeneratorCallbacks::IsChunkQueued(int a_ChunkX, int a_ChunkZ) +bool cWorld::cChunkGeneratorCallbacks::IsChunkQueued(cChunkCoords a_Coords) { - return m_World->IsChunkQueued(a_ChunkX, a_ChunkZ); + return m_World->IsChunkQueued(a_Coords.m_ChunkX, a_Coords.m_ChunkZ); } -bool cWorld::cChunkGeneratorCallbacks::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) +bool cWorld::cChunkGeneratorCallbacks::HasChunkAnyClients(cChunkCoords a_Coords) { - return m_World->HasChunkAnyClients(a_ChunkX, a_ChunkZ); + return m_World->HasChunkAnyClients(a_Coords.m_ChunkX, a_Coords.m_ChunkZ); } -- cgit v1.2.3