ChunkMap: do not wantonly make empty chunks

- Removed calls that constructed an empty chunk, found it was invalid, and did nothing with said chunk

Partially addresses #2324
This commit is contained in:
Tiger Wang 2020-08-28 21:22:44 +01:00
parent b084f1f13f
commit 72ae5ecb5a
5 changed files with 133 additions and 245 deletions

View File

@ -59,10 +59,10 @@ cChunkMap::~cChunkMap()
cChunkPtr cChunkMap::ConstructChunk(int a_ChunkX, int a_ChunkZ) cChunk & cChunkMap::ConstructChunk(int a_ChunkX, int a_ChunkZ)
{ {
// If not exists insert. Then, return the chunk at these coordinates: // If not exists insert. Then, return the chunk at these coordinates:
return &m_Chunks.try_emplace( return m_Chunks.try_emplace(
ChunkCoordinate{ a_ChunkX, a_ChunkZ }, ChunkCoordinate{ a_ChunkX, a_ChunkZ },
a_ChunkX, a_ChunkZ, this, m_World, *m_Pool a_ChunkX, a_ChunkZ, this, m_World, *m_Pool
).first->second; ).first->second;
@ -72,19 +72,14 @@ cChunkPtr cChunkMap::ConstructChunk(int a_ChunkX, int a_ChunkZ)
cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkZ) cChunk & cChunkMap::GetChunk(int a_ChunkX, int a_ChunkZ)
{ {
ASSERT(m_CSChunks.IsLockedByCurrentThread()); // m_CSChunks should already be locked by the operation that called us ASSERT(m_CSChunks.IsLockedByCurrentThread()); // m_CSChunks should already be locked by the operation that called us
auto Chunk = ConstructChunk(a_ChunkX, a_ChunkZ); auto & Chunk = ConstructChunk(a_ChunkX, a_ChunkZ);
if (Chunk == nullptr) if (!Chunk.IsValid() && !Chunk.IsQueued())
{ {
return nullptr; Chunk.SetPresence(cChunk::cpQueued);
}
if (!Chunk->IsValid() && !Chunk->IsQueued())
{
Chunk->SetPresence(cChunk::cpQueued);
Chunk->SetShouldGenerateIfLoadFailed(true);
m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ); m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ);
} }
return Chunk; return Chunk;
@ -94,38 +89,6 @@ cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkZ)
cChunkPtr cChunkMap::GetChunkNoGen(cChunkCoords a_Chunk)
{
ASSERT(m_CSChunks.IsLockedByCurrentThread()); // m_CSChunks should already be locked by the operation that called us
auto Chunk = ConstructChunk(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
if (Chunk == nullptr)
{
return nullptr;
}
if (!Chunk->IsValid() && !Chunk->IsQueued())
{
Chunk->SetPresence(cChunk::cpQueued);
m_World->GetStorage().QueueLoadChunk(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
}
return Chunk;
}
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_Coords.m_ChunkX, a_Coords.m_ChunkZ);
}
cChunk * cChunkMap::FindChunk(int a_ChunkX, int a_ChunkZ) cChunk * cChunkMap::FindChunk(int a_ChunkX, int a_ChunkZ)
{ {
ASSERT(m_CSChunks.IsLockedByCurrentThread()); ASSERT(m_CSChunks.IsLockedByCurrentThread());
@ -143,7 +106,7 @@ void cChunkMap::SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClien
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return; return;
@ -161,7 +124,7 @@ bool cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -176,8 +139,8 @@ bool cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i
bool cChunkMap::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback) bool cChunkMap::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if (Chunk == nullptr) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
} }
@ -202,13 +165,14 @@ bool cChunkMap::DoWithChunkAt(Vector3i a_BlockPos, cChunkCallback a_Callback)
void cChunkMap::WakeUpSimulators(Vector3i a_Block) void cChunkMap::WakeUpSimulators(Vector3i a_Block)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(cChunkDef::BlockToChunk(a_Block)); const auto Position = cChunkDef::BlockToChunk(a_Block);
const auto Chunk = FindChunk(Position.m_ChunkX, Position.m_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return; return;
} }
m_World->GetSimulatorManager()->WakeUp(*Chunk, cChunkDef::AbsoluteToRelative(a_Block, Chunk->GetPos())); m_World->GetSimulatorManager()->WakeUp(*Chunk, cChunkDef::AbsoluteToRelative(a_Block, Position));
} }
@ -218,7 +182,7 @@ void cChunkMap::WakeUpSimulators(Vector3i a_Block)
void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return; return;
@ -233,7 +197,7 @@ void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ)
void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return; return;
@ -248,7 +212,7 @@ void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ)
void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return; return;
@ -266,11 +230,8 @@ void cChunkMap::SetChunkData(cSetChunkData & a_SetChunkData)
int ChunkZ = a_SetChunkData.GetChunkZ(); int ChunkZ = a_SetChunkData.GetChunkZ();
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if (Chunk == nullptr) ASSERT(Chunk != nullptr); // Chunk cannot have unloaded since it is marked as queued
{
return;
}
Chunk->SetAllData(a_SetChunkData); Chunk->SetAllData(a_SetChunkData);
if (a_SetChunkData.ShouldMarkDirty()) if (a_SetChunkData.ShouldMarkDirty())
@ -311,9 +272,10 @@ void cChunkMap::ChunkLighted(
) )
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if (Chunk == nullptr) if (Chunk == nullptr)
{ {
// Chunk probably unloaded in the meantime
return; return;
} }
Chunk->SetLight(a_BlockLight, a_SkyLight); Chunk->SetLight(a_BlockLight, a_SkyLight);
@ -332,7 +294,7 @@ bool cChunkMap::GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callb
return false; return false;
} }
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_Coords); const auto Chunk = FindChunk(a_Coords.m_ChunkX, a_Coords.m_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
// The chunk is not present // The chunk is not present
@ -349,7 +311,7 @@ bool cChunkMap::GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callb
bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes) bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -365,7 +327,7 @@ bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blo
bool cChunkMap::IsChunkQueued(int a_ChunkX, int a_ChunkZ) bool cChunkMap::IsChunkQueued(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
return (Chunk != nullptr) && Chunk->IsQueued(); return (Chunk != nullptr) && Chunk->IsQueued();
} }
@ -376,7 +338,7 @@ bool cChunkMap::IsChunkQueued(int a_ChunkX, int a_ChunkZ)
bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ) bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
return (Chunk != nullptr) && Chunk->IsValid(); return (Chunk != nullptr) && Chunk->IsValid();
} }
@ -387,7 +349,7 @@ bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ)
bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
return (Chunk != nullptr) && Chunk->HasAnyClients(); return (Chunk != nullptr) && Chunk->HasAnyClients();
} }
@ -402,15 +364,10 @@ int cChunkMap::GetHeight(int a_BlockX, int a_BlockZ)
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
int ChunkX, ChunkZ, BlockY = 0; int ChunkX, ChunkZ, BlockY = 0;
cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); auto & Chunk = GetChunk(ChunkX, ChunkZ);
if (Chunk == nullptr) if (Chunk.IsValid())
{ {
return 0; return Chunk.GetHeight(a_BlockX, a_BlockZ);
}
if (Chunk->IsValid())
{
return Chunk->GetHeight(a_BlockX, a_BlockZ);
} }
// The chunk is not valid, wait for it to become valid: // The chunk is not valid, wait for it to become valid:
@ -429,7 +386,7 @@ bool cChunkMap::TryGetHeight(int a_BlockX, int a_BlockZ, int & a_Height)
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
int ChunkX, ChunkZ, BlockY = 0; int ChunkX, ChunkZ, BlockY = 0;
cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -448,10 +405,10 @@ void cChunkMap::FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLET
auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
chunk->FastSetBlock(relPos, a_BlockType, a_BlockMeta); Chunk->FastSetBlock(relPos, a_BlockType, a_BlockMeta);
} }
} }
@ -493,10 +450,10 @@ BLOCKTYPE cChunkMap::GetBlock(Vector3i a_BlockPos)
// Query the chunk, if loaded: // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
return chunk->GetBlock(relPos); return Chunk->GetBlock(relPos);
} }
return 0; return 0;
} }
@ -512,10 +469,10 @@ NIBBLETYPE cChunkMap::GetBlockMeta(Vector3i a_BlockPos)
// Query the chunk, if loaded: // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
return chunk->GetMeta(relPos); return Chunk->GetMeta(relPos);
} }
return 0; return 0;
} }
@ -531,10 +488,10 @@ NIBBLETYPE cChunkMap::GetBlockSkyLight(Vector3i a_BlockPos)
// Query the chunk, if loaded: // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
return chunk->GetSkyLight(relPos); return Chunk->GetSkyLight(relPos);
} }
return 0; return 0;
} }
@ -550,10 +507,10 @@ NIBBLETYPE cChunkMap::GetBlockBlockLight(Vector3i a_BlockPos)
// Query the chunk, if loaded: // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
return chunk->GetBlockLight(relPos); return Chunk->GetBlockLight(relPos);
} }
return 0; return 0;
} }
@ -569,10 +526,10 @@ void cChunkMap::SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_BlockMeta)
// Query the chunk, if loaded: // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
chunk->SetMeta(relPos, a_BlockMeta); Chunk->SetMeta(relPos, a_BlockMeta);
} }
} }
@ -586,10 +543,10 @@ void cChunkMap::SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE
auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
chunk->SetBlock(relPos, a_BlockType, a_BlockMeta); Chunk->SetBlock(relPos, a_BlockType, a_BlockMeta);
} }
} }
@ -603,10 +560,10 @@ bool cChunkMap::GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, N
auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkCoord); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkCoord);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkCoord.m_ChunkX, chunkCoord.m_ChunkZ); const auto Chunk = FindChunk(chunkCoord.m_ChunkX, chunkCoord.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
chunk->GetBlockTypeMeta(relPos, a_BlockType, a_BlockMeta); Chunk->GetBlockTypeMeta(relPos, a_BlockType, a_BlockMeta);
return true; return true;
} }
return false; return false;
@ -623,10 +580,10 @@ bool cChunkMap::GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBL
// Query the chunk, if loaded: // Query the chunk, if loaded:
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if ((chunk != nullptr) && chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
chunk->GetBlockInfo(relPos, a_BlockType, a_Meta, a_SkyLight, a_BlockLight); Chunk->GetBlockInfo(relPos, a_BlockType, a_Meta, a_SkyLight, a_BlockLight);
return true; return true;
} }
return false; return false;
@ -641,17 +598,17 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks)
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
{ {
auto chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ); const auto Chunk = FindChunk(itr->m_ChunkX, itr->m_ChunkZ);
if ((chunk == nullptr) || !chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
continue; continue;
} }
Vector3i relPos(itr->m_RelX, itr->m_RelY, itr->m_RelZ); Vector3i relPos(itr->m_RelX, itr->m_RelY, itr->m_RelZ);
switch (chunk->GetBlock(relPos)) switch (Chunk->GetBlock(relPos))
{ {
CASE_TREE_OVERWRITTEN_BLOCKS: CASE_TREE_OVERWRITTEN_BLOCKS:
{ {
chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta); Chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta);
break; break;
} }
case E_BLOCK_LEAVES: case E_BLOCK_LEAVES:
@ -659,7 +616,7 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks)
{ {
if ((itr->m_BlockType == E_BLOCK_LOG) || (itr->m_BlockType == E_BLOCK_NEW_LOG)) if ((itr->m_BlockType == E_BLOCK_LOG) || (itr->m_BlockType == E_BLOCK_NEW_LOG))
{ {
chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta); Chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta);
} }
break; break;
} }
@ -677,7 +634,7 @@ EMCSBiome cChunkMap::GetBiomeAt (int a_BlockX, int a_BlockZ)
cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk != nullptr) && Chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
return Chunk->GetBiomeAt(X, Z); return Chunk->GetBiomeAt(X, Z);
@ -698,7 +655,7 @@ bool cChunkMap::SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome)
cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk != nullptr) && Chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
Chunk->SetBiomeAt(X, Z, a_Biome); Chunk->SetBiomeAt(X, Z, a_Biome);
@ -731,7 +688,7 @@ bool cChunkMap::SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMC
{ {
int MinRelZ = (z == MinChunkZ) ? MinZ : 0; int MinRelZ = (z == MinChunkZ) ? MinZ : 0;
int MaxRelZ = (z == MaxChunkZ) ? MaxZ : cChunkDef::Width - 1; int MaxRelZ = (z == MaxChunkZ) ? MaxZ : cChunkDef::Width - 1;
cChunkPtr Chunk = GetChunkNoLoad(x, z); const auto Chunk = FindChunk(x, z);
if ((Chunk != nullptr) && Chunk->IsValid()) if ((Chunk != nullptr) && Chunk->IsValid())
{ {
Chunk->SetAreaBiome(MinRelX, MaxRelX, MinRelZ, MaxRelZ, a_Biome); Chunk->SetAreaBiome(MinRelX, MaxRelX, MinRelZ, MaxRelZ, a_Biome);
@ -755,7 +712,7 @@ bool cChunkMap::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure)
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
for (sSetBlockVector::iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) for (sSetBlockVector::iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
{ {
cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ); const auto Chunk = FindChunk(itr->m_ChunkX, itr->m_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
if (!a_ContinueOnFailure) if (!a_ContinueOnFailure)
@ -782,13 +739,13 @@ bool cChunkMap::DigBlock(Vector3i a_BlockPos)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto destChunk = GetChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ); const auto Chunk = FindChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ);
if ((destChunk == nullptr) || !destChunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
} }
destChunk->SetBlock(relPos, E_BLOCK_AIR, 0); Chunk->SetBlock(relPos, E_BLOCK_AIR, 0);
} }
return true; return true;
} }
@ -803,12 +760,12 @@ cItems cChunkMap::PickupsFromBlock(Vector3i a_BlockPos, const cEntity * a_Digger
auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkCoords); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkCoords);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto destChunk = GetChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ); const auto Chunk = FindChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ);
if ((destChunk == nullptr) || !destChunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return {}; return {};
} }
return destChunk->PickupsFromBlock(relPos, a_Digger, a_Tool); return Chunk->PickupsFromBlock(relPos, a_Digger, a_Tool);
} }
@ -821,7 +778,7 @@ void cChunkMap::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer & a_Player)
cChunkDef::AbsoluteToRelative(a_X, a_Y, a_Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_X, a_Y, a_Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk != nullptr) && (Chunk->IsValid())) if ((Chunk != nullptr) && (Chunk->IsValid()))
{ {
Chunk->SendBlockTo(a_X, a_Y, a_Z, a_Player.GetClientHandle()); Chunk->SendBlockTo(a_X, a_Y, a_Z, a_Player.GetClientHandle());
@ -835,12 +792,12 @@ void cChunkMap::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer & a_Player)
void cChunkMap::CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback) void cChunkMap::CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk1 = GetChunkNoGen(a_ChunkX1, a_ChunkZ1); const auto Chunk1 = FindChunk(a_ChunkX1, a_ChunkZ1);
if (Chunk1 == nullptr) if (Chunk1 == nullptr)
{ {
return; return;
} }
cChunkPtr Chunk2 = GetChunkNoGen(a_ChunkX2, a_ChunkZ2); const auto Chunk2 = FindChunk(a_ChunkX2, a_ChunkZ2);
if (Chunk2 == nullptr) if (Chunk2 == nullptr)
{ {
return; return;
@ -886,12 +843,7 @@ void cChunkMap::CompareChunkClients(cChunk * a_Chunk1, cChunk * a_Chunk2, cClien
bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(a_ChunkX, a_ChunkZ); return GetChunk(a_ChunkX, a_ChunkZ).AddClient(a_Client);
if (Chunk == nullptr)
{
return false;
}
return Chunk->AddClient(a_Client);
} }
@ -901,11 +853,8 @@ bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Cli
void cChunkMap::RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) void cChunkMap::RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if (Chunk == nullptr) ASSERT(Chunk != nullptr);
{
return;
}
Chunk->RemoveClient(a_Client); Chunk->RemoveClient(a_Client);
} }
@ -929,8 +878,8 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client)
void cChunkMap::AddEntity(OwnedEntity a_Entity) void cChunkMap::AddEntity(OwnedEntity a_Entity)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); const auto Chunk = FindChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if (Chunk == nullptr) // This will assert inside GetChunk in Debug builds if (Chunk == nullptr)
{ {
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.", LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID() static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID()
@ -947,8 +896,8 @@ void cChunkMap::AddEntity(OwnedEntity a_Entity)
void cChunkMap::AddEntityIfNotPresent(OwnedEntity a_Entity) void cChunkMap::AddEntityIfNotPresent(OwnedEntity a_Entity)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); const auto Chunk = FindChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if (Chunk == nullptr) // This will assert inside GetChunk in Debug builds if (Chunk == nullptr)
{ {
LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.", LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID() static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID()
@ -985,7 +934,7 @@ bool cChunkMap::HasEntity(UInt32 a_UniqueID) const
OwnedEntity cChunkMap::RemoveEntity(cEntity & a_Entity) OwnedEntity cChunkMap::RemoveEntity(cEntity & a_Entity)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = a_Entity.GetParentChunk(); const auto Chunk = a_Entity.GetParentChunk();
if (Chunk == nullptr) if (Chunk == nullptr)
{ {
@ -1020,7 +969,7 @@ bool cChunkMap::ForEachEntity(cEntityCallback a_Callback) const
bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback a_Callback) bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1046,7 +995,7 @@ bool cChunkMap::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback a
{ {
for (int x = MinChunkX; x <= MaxChunkX; x++) for (int x = MinChunkX; x <= MaxChunkX; x++)
{ {
cChunkPtr Chunk = GetChunkNoGen(x, z); const auto Chunk = FindChunk(x, z);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
continue; continue;
@ -1282,7 +1231,7 @@ bool cChunkMap::DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback)
bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback a_Callback) bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1297,7 +1246,7 @@ bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEnti
bool cChunkMap::ForEachBrewingstandInChunk(int a_ChunkX, int a_ChunkZ, cBrewingstandCallback a_Callback) bool cChunkMap::ForEachBrewingstandInChunk(int a_ChunkX, int a_ChunkZ, cBrewingstandCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1312,7 +1261,7 @@ bool cChunkMap::ForEachBrewingstandInChunk(int a_ChunkX, int a_ChunkZ, cBrewings
bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback a_Callback) bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1327,7 +1276,7 @@ bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback a
bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback a_Callback) bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1342,7 +1291,7 @@ bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCa
bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback a_Callback) bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1357,7 +1306,7 @@ bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallba
bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback a_Callback) bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1372,7 +1321,7 @@ bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpens
bool cChunkMap::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback a_Callback) bool cChunkMap::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1390,7 +1339,7 @@ bool cChunkMap::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cB
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1408,7 +1357,7 @@ bool cChunkMap::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeacon
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1426,7 +1375,7 @@ bool cChunkMap::DoWithBedAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBedCallba
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1444,7 +1393,7 @@ bool cChunkMap::DoWithBrewingstandAt(int a_BlockX, int a_BlockY, int a_BlockZ, c
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1462,7 +1411,7 @@ bool cChunkMap::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCa
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1480,7 +1429,7 @@ bool cChunkMap::DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDis
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1498,7 +1447,7 @@ bool cChunkMap::DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropp
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1516,7 +1465,7 @@ bool cChunkMap::DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cD
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1534,7 +1483,7 @@ bool cChunkMap::DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurna
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1552,7 +1501,7 @@ bool cChunkMap::DoWithHopperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cHopper
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1570,7 +1519,7 @@ bool cChunkMap::DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNot
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1588,7 +1537,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1606,7 +1555,7 @@ bool cChunkMap::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHe
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1624,7 +1573,7 @@ bool cChunkMap::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlo
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1642,7 +1591,7 @@ bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString &
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1667,7 +1616,7 @@ void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkZ)
void cChunkMap::PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr<cChunkCoordCallback> a_Callback) void cChunkMap::PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr<cChunkCoordCallback> a_Callback)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
// If the chunk is not prepared, queue it in the lighting thread, that will do all the needed processing: // If the chunk is not prepared, queue it in the lighting thread, that will do all the needed processing:
if ((Chunk == nullptr) || !Chunk->IsValid() || !Chunk->IsLightValid()) if ((Chunk == nullptr) || !Chunk->IsValid() || !Chunk->IsLightValid())
@ -1766,11 +1715,8 @@ bool cChunkMap::GenerateChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback *
void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkZ) void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if (Chunk == nullptr) ASSERT(Chunk != nullptr); // Chunk cannot have unloaded since it is marked as queued
{
return;
}
Chunk->MarkLoadFailed(); Chunk->MarkLoadFailed();
} }
@ -1783,7 +1729,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); const auto Chunk = FindChunk(ChunkX, ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return false; return false;
@ -1798,13 +1744,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt
void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); ConstructChunk(a_ChunkX, a_ChunkZ).MarkRegenerating();
if (Chunk == nullptr)
{
// Not present
return;
}
Chunk->MarkRegenerating();
} }
@ -1814,7 +1754,7 @@ void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ)
bool cChunkMap::IsChunkLighted(int a_ChunkX, int a_ChunkZ) bool cChunkMap::IsChunkLighted(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ);
if (Chunk == nullptr) if (Chunk == nullptr)
{ {
// Not present // Not present
@ -1835,8 +1775,8 @@ bool cChunkMap::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinCh
{ {
for (int x = a_MinChunkX; x <= a_MaxChunkX; x++) for (int x = a_MinChunkX; x <= a_MaxChunkX; x++)
{ {
cChunkPtr Chunk = GetChunkNoLoad(x, z); const auto Chunk = FindChunk(x, z);
if ((Chunk == nullptr) || (!Chunk->IsValid())) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
// Not present / not valid // Not present / not valid
Result = false; Result = false;
@ -1897,8 +1837,8 @@ bool cChunkMap::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBl
{ {
for (int x = MinChunkX; x <= MaxChunkX; x++) for (int x = MinChunkX; x <= MaxChunkX; x++)
{ {
cChunkPtr Chunk = GetChunkNoLoad(x, z); const auto Chunk = FindChunk(x, z);
if ((Chunk == nullptr) || (!Chunk->IsValid())) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
// Not present / not valid // Not present / not valid
Result = false; Result = false;
@ -1938,12 +1878,12 @@ int cChunkMap::GrowPlantAt(Vector3i a_BlockPos, int a_NumStages)
auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos);
auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos);
cCSLock lock(m_CSChunks); cCSLock lock(m_CSChunks);
auto chunk = GetChunkNoLoad(chunkPos); const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
if (chunk == nullptr) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return 0; return 0;
} }
return chunk->GrowPlantAt(relPos, a_NumStages); return Chunk->GrowPlantAt(relPos, a_NumStages);
} }
@ -1956,7 +1896,7 @@ void cChunkMap::SetNextBlockToTick(const Vector3i a_BlockPos)
auto RelPos = cChunkDef::AbsoluteToRelative(a_BlockPos, ChunkPos); auto RelPos = cChunkDef::AbsoluteToRelative(a_BlockPos, ChunkPos);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto Chunk = GetChunkNoLoad(ChunkPos); const auto Chunk = FindChunk(ChunkPos.m_ChunkX, ChunkPos.m_ChunkZ);
if (Chunk != nullptr) if (Chunk != nullptr)
{ {
Chunk->SetNextBlockToTick(RelPos); Chunk->SetNextBlockToTick(RelPos);
@ -2025,7 +1965,7 @@ void cChunkMap::TickBlock(const Vector3i a_BlockPos)
auto ChunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto ChunkPos = cChunkDef::BlockToChunk(a_BlockPos);
auto RelPos = cChunkDef::AbsoluteToRelative(a_BlockPos, ChunkPos); auto RelPos = cChunkDef::AbsoluteToRelative(a_BlockPos, ChunkPos);
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
auto Chunk = GetChunkNoLoad(ChunkPos); const auto Chunk = FindChunk(ChunkPos.m_ChunkX, ChunkPos.m_ChunkZ);
if ((Chunk == nullptr) || !Chunk->IsValid()) if ((Chunk == nullptr) || !Chunk->IsValid())
{ {
return; return;
@ -2116,11 +2056,7 @@ void cChunkMap::ChunkValidated(void)
void cChunkMap::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked) void cChunkMap::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked)
{ {
cCSLock Lock(m_CSChunks); cCSLock Lock(m_CSChunks);
cChunkPtr Chunk = GetChunk(a_ChunkX, a_ChunkZ); GetChunk(a_ChunkX, a_ChunkZ).SetAlwaysTicked(a_AlwaysTicked);
if (Chunk != nullptr)
{
Chunk->SetAlwaysTicked(a_AlwaysTicked);
}
} }
@ -2157,13 +2093,9 @@ void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay)
const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks(); const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks();
for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr) for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr)
{ {
cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ); auto & Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ);
if (Chunk == nullptr) Chunk.Stay(true);
{ if (Chunk.IsValid())
continue;
}
Chunk->Stay(true);
if (Chunk->IsValid())
{ {
if (a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ)) if (a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ))
{ {
@ -2206,11 +2138,8 @@ void cChunkMap::DelChunkStay(cChunkStay & a_ChunkStay)
const cChunkCoordsVector & Chunks = a_ChunkStay.GetChunks(); const cChunkCoordsVector & Chunks = a_ChunkStay.GetChunks();
for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr) for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr)
{ {
cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkZ); const auto Chunk = FindChunk(itr->m_ChunkX, itr->m_ChunkZ);
if (Chunk == nullptr) ASSERT(Chunk != nullptr); // Stayed chunks cannot unload
{
continue;
}
Chunk->Stay(false); Chunk->Stay(false);
} // for itr - Chunks[] } // for itr - Chunks[]
a_ChunkStay.OnDisabled(); a_ChunkStay.OnDisabled();

View File

@ -42,7 +42,6 @@ class cBoundingBox;
class cDeadlockDetect; class cDeadlockDetect;
typedef std::list<cClientHandle *> cClientHandleList; typedef std::list<cClientHandle *> cClientHandleList;
typedef cChunk * cChunkPtr;
using cEntityCallback = cFunctionRef<bool(cEntity &)>; using cEntityCallback = cFunctionRef<bool(cEntity &)>;
using cBeaconCallback = cFunctionRef<bool(cBeaconEntity &)>; using cBeaconCallback = cFunctionRef<bool(cBeaconEntity &)>;
using cBedCallback = cFunctionRef<bool(cBedEntity &)>; using cBedCallback = cFunctionRef<bool(cBedEntity &)>;
@ -465,31 +464,11 @@ private:
std::unique_ptr<cAllocationPool<cChunkData::sChunkSection> > m_Pool; std::unique_ptr<cAllocationPool<cChunkData::sChunkSection> > m_Pool;
/** Returns or creates and returns a chunk pointer corresponding to the given chunk coordinates. /** Returns or creates and returns a chunk pointer corresponding to the given chunk coordinates.
Emplaces this chunk in the chunk map. Emplaces this chunk in the chunk map. */
Developers SHOULD use the GetChunk variants instead of this function. */ cChunk & ConstructChunk(int a_ChunkX, int a_ChunkZ);
cChunkPtr ConstructChunk(int a_ChunkX, int a_ChunkZ);
/** Constructs a chunk and queues it for loading / generating if not valid, returning it */ /** Constructs a chunk and queues it for loading / generating if not valid, returning it */
cChunkPtr GetChunk(int a_ChunkX, int a_ChunkZ); cChunk & GetChunk(int a_ChunkX, int a_ChunkZ);
/** Constructs a chunk and queues the chunk for loading if not valid, returning it; doesn't generate */
cChunkPtr GetChunkNoGen(cChunkCoords a_Chunk);
// Deprecated in favor of the vector version
cChunkPtr GetChunkNoGen(int a_ChunkX, int a_ChunkZ)
{
return GetChunkNoGen({a_ChunkX, a_ChunkZ});
}
/** Constructs a chunk, returning it. Doesn't load, doesn't generate */
cChunkPtr GetChunkNoLoad(cChunkCoords a_Coords);
/** OBSOLETE, use the cChunkCoords-based overload instead.
Constructs a chunk, returning it. Doesn't load, doesn't generate */
cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkZ)
{
return GetChunkNoLoad({a_ChunkX, a_ChunkZ});
}
/** Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSChunks is locked. To be called only from cChunkMap. */ /** Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSChunks is locked. To be called only from cChunkMap. */
cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); cChunk * FindChunk(int a_ChunkX, int a_ChunkZ);
@ -503,8 +482,3 @@ private:
void DelChunkStay(cChunkStay & a_ChunkStay); void DelChunkStay(cChunkStay & a_ChunkStay);
}; };

View File

@ -287,12 +287,8 @@ bool cLineBlockTracer::ChunkCallback(cChunk * a_Chunk)
// This is the actual line tracing loop. // This is the actual line tracing loop.
for (;;) for (;;)
{ {
// Report the current block through the callbacks: // Our caller (DoWithChunk callback) should never give nothing:
if (a_Chunk == nullptr) ASSERT(a_Chunk != nullptr);
{
m_Callbacks->OnNoChunk();
return false;
}
// Move to next block // Move to next block
if (!MoveToNextBlock()) if (!MoveToNextBlock())
@ -324,6 +320,7 @@ bool cLineBlockTracer::ChunkCallback(cChunk * a_Chunk)
return false; return false;
} }
// Report the current block through the callbacks:
if (a_Chunk->IsValid()) if (a_Chunk->IsValid())
{ {
BLOCKTYPE BlockType; BLOCKTYPE BlockType;

View File

@ -125,11 +125,6 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z)
ColorID PixelData; ColorID PixelData;
m_World->DoWithChunk(ChunkX, ChunkZ, [&](cChunk & a_Chunk) m_World->DoWithChunk(ChunkX, ChunkZ, [&](cChunk & a_Chunk)
{ {
if (!a_Chunk.IsValid())
{
return false;
}
if (GetDimension() == dimNether) if (GetDimension() == dimNether)
{ {
// TODO 2014-02-22 xdot: Nether maps // TODO 2014-02-22 xdot: Nether maps

View File

@ -132,13 +132,6 @@ void cSimulator::WakeUp(const cCuboid & a_Area)
{ {
m_World.DoWithChunk(cx, cz, [this, &area](cChunk & a_CBChunk) -> bool m_World.DoWithChunk(cx, cz, [this, &area](cChunk & a_CBChunk) -> bool
{ {
if (!a_CBChunk.IsValid())
{
LOGWARNING("%s: Trying to wake up inside a non-valid chunk [%d, %d]. Ignoring.",
__FUNCTION__, a_CBChunk.GetPosX(), a_CBChunk.GetPosZ()
);
return true;
}
int startX = std::max(area.p1.x, a_CBChunk.GetPosX() * cChunkDef::Width); int startX = std::max(area.p1.x, a_CBChunk.GetPosX() * cChunkDef::Width);
int startZ = std::max(area.p1.z, a_CBChunk.GetPosZ() * cChunkDef::Width); int startZ = std::max(area.p1.z, a_CBChunk.GetPosZ() * cChunkDef::Width);
int endX = std::min(area.p2.x, a_CBChunk.GetPosX() * cChunkDef::Width + cChunkDef::Width - 1); int endX = std::min(area.p2.x, a_CBChunk.GetPosX() * cChunkDef::Width + cChunkDef::Width - 1);