summaryrefslogtreecommitdiffstats
path: root/src/ChunkMap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ChunkMap.cpp')
-rw-r--r--src/ChunkMap.cpp205
1 files changed, 75 insertions, 130 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index ec6b74192..32c7d548f 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -135,10 +135,10 @@ cChunkPtr cChunkMap::GetChunkNoGen(cChunkCoords a_Chunk)
-cChunkPtr cChunkMap::GetChunkNoLoad(int a_ChunkX, int a_ChunkZ)
+cChunkPtr cChunkMap::GetChunkNoLoad(cChunkCoords a_Coords)
{
ASSERT(m_CSChunks.IsLockedByCurrentThread()); // m_CSChunks should already be locked by the operation that called us
- return ConstructChunk(a_ChunkX, a_ChunkZ);
+ return ConstructChunk(a_Coords.m_ChunkX, a_Coords.m_ChunkZ);
}
@@ -460,6 +460,23 @@ bool cChunkMap::TryGetHeight(int a_BlockX, int a_BlockZ, int & a_Height)
+void cChunkMap::FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
+{
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
+
+ cCSLock Lock(m_CSChunks);
+ auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
+ if ((chunk != nullptr) && chunk->IsValid())
+ {
+ chunk->FastSetBlock(relPos, a_BlockType, a_BlockMeta);
+ }
+}
+
+
+
+
+
void cChunkMap::SetBlocks(const sSetBlockVector & a_Blocks)
{
cCSLock lock(m_CSChunks);
@@ -515,18 +532,17 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer & a_Player)
-BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
+BLOCKTYPE cChunkMap::GetBlock(Vector3i a_BlockPos)
{
- int X = a_BlockX, Y = a_BlockY, Z = a_BlockZ;
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
// Query the chunk, if loaded:
cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
- if ((Chunk != nullptr) && Chunk->IsValid())
+ auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
+ if ((chunk != nullptr) && chunk->IsValid())
{
- return Chunk->GetBlock(X, Y, Z);
+ return chunk->GetBlock(relPos);
}
return 0;
}
@@ -535,18 +551,17 @@ BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
-NIBBLETYPE cChunkMap::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
+NIBBLETYPE cChunkMap::GetBlockMeta(Vector3i a_BlockPos)
{
- int X = a_BlockX, Y = a_BlockY, Z = a_BlockZ;
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
// Query the chunk, if loaded:
cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
- if ((Chunk != nullptr) && Chunk->IsValid())
+ auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
+ if ((chunk != nullptr) && chunk->IsValid())
{
- return Chunk->GetMeta(X, Y, Z);
+ return chunk->GetMeta(relPos);
}
return 0;
}
@@ -555,16 +570,17 @@ NIBBLETYPE cChunkMap::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
-NIBBLETYPE cChunkMap::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ)
+NIBBLETYPE cChunkMap::GetBlockSkyLight(Vector3i a_BlockPos)
{
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
+ // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
- if ((Chunk != nullptr) && Chunk->IsValid())
+ auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
+ if ((chunk != nullptr) && chunk->IsValid())
{
- return Chunk->GetSkyLight(a_BlockX, a_BlockY, a_BlockZ);
+ return chunk->GetSkyLight(relPos);
}
return 0;
}
@@ -573,16 +589,17 @@ NIBBLETYPE cChunkMap::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ)
-NIBBLETYPE cChunkMap::GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ)
+NIBBLETYPE cChunkMap::GetBlockBlockLight(Vector3i a_BlockPos)
{
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
+ // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
- if ((Chunk != nullptr) && Chunk->IsValid())
+ auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
+ if ((chunk != nullptr) && chunk->IsValid())
{
- return Chunk->GetBlockLight(a_BlockX, a_BlockY, a_BlockZ);
+ return chunk->GetBlockLight(relPos);
}
return 0;
}
@@ -591,17 +608,17 @@ NIBBLETYPE cChunkMap::GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_Block
-void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, bool a_ShouldMarkDirty, bool a_ShouldInformClients)
+void cChunkMap::SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_BlockMeta, bool a_ShouldMarkDirty, bool a_ShouldInformClients)
{
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
- // a_BlockXYZ now contains relative coords!
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
+ // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
- if ((Chunk != nullptr) && Chunk->IsValid())
+ auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
+ if ((chunk != nullptr) && chunk->IsValid())
{
- Chunk->SetMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta, a_ShouldMarkDirty, a_ShouldInformClients);
+ chunk->SetMeta(relPos, a_BlockMeta, a_ShouldMarkDirty, a_ShouldInformClients);
}
}
@@ -611,11 +628,11 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP
void cChunkMap::SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
- auto chunkCoord = cChunkDef::BlockToChunk(a_BlockPos);
- auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkCoord);
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
cCSLock Lock(m_CSChunks);
- auto chunk = GetChunk(chunkCoord.m_ChunkX, chunkCoord.m_ChunkZ);
+ auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid())
{
BLOCKTYPE blockType;
@@ -652,16 +669,17 @@ bool cChunkMap::GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, N
-bool cChunkMap::GetBlockInfo(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight)
+bool cChunkMap::GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight)
{
- int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ;
- cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ);
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
+ // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
- if ((Chunk != nullptr) && Chunk->IsValid())
+ auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
+ if ((chunk != nullptr) && chunk->IsValid())
{
- Chunk->GetBlockInfo(X, Y, Z, a_BlockType, a_Meta, a_SkyLight, a_BlockLight);
+ chunk->GetBlockInfo(relPos, a_BlockType, a_Meta, a_SkyLight, a_BlockLight);
return true;
}
return false;
@@ -1973,72 +1991,17 @@ void cChunkMap::GetChunkStats(int & a_NumChunksValid, int & a_NumChunksDirty)
-bool cChunkMap::GrowMelonPumpkin(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType)
+int cChunkMap::GrowPlantAt(Vector3i a_BlockPos, int a_NumStages)
{
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
-
- cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
- if (Chunk != nullptr)
- {
- return Chunk->GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, a_BlockType);
- }
- return false;
-}
-
-
-
-
-
-int cChunkMap::GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow)
-{
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
-
- cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
- if (Chunk != nullptr)
- {
- return Chunk->GrowSugarcane(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow);
- }
- return 0;
-}
-
-
-
-
-
-int cChunkMap::GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow)
-{
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
-
- cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
- if (Chunk != nullptr)
- {
- return Chunk->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow);
- }
- return 0;
-}
-
-
-
-
-
-bool cChunkMap::GrowTallGrass(int a_BlockX, int a_BlockY, int a_BlockZ)
-{
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
-
- cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
- if (Chunk != nullptr)
+ auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
+ cCSLock lock(m_CSChunks);
+ auto chunk = GetChunkNoLoad(chunkPos);
+ if (chunk == nullptr)
{
- return Chunk->GrowTallGrass(a_BlockX, a_BlockY, a_BlockZ);
+ return 0;
}
- return 0;
+ return chunk->GrowPlantAt(relPos, a_NumStages);
}
@@ -2208,17 +2171,16 @@ void cChunkMap::ChunkValidated(void)
-void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
+void cChunkMap::QueueTickBlock(Vector3i a_AbsPos)
{
- int ChunkX, ChunkZ;
- cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
- // a_BlockXYZ now contains relative coords!
+ auto chunkCoords = cChunkDef::BlockToChunk(a_AbsPos);
+ auto relPos = cChunkDef::AbsoluteToRelative(a_AbsPos, chunkCoords);
cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(chunkCoords);
if (Chunk != nullptr)
{
- Chunk->QueueTickBlock(a_BlockX, a_BlockY, a_BlockZ);
+ Chunk->QueueTickBlock(relPos);
}
}
@@ -2258,23 +2220,6 @@ void cChunkMap::UntrackInDeadlockDetect(cDeadlockDetect & a_DeadlockDetect)
-void cChunkMap::FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
-{
- int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ;
- cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
-
- cCSLock Lock(m_CSChunks);
- cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
- if ((Chunk != nullptr) && Chunk->IsValid())
- {
- Chunk->FastSetBlock(X, Y, Z, a_BlockType, a_BlockMeta);
- }
-}
-
-
-
-
-
void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay)
{
cCSLock Lock(m_CSChunks);