diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-28 22:22:44 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-28 22:22:44 +0200 |
commit | 72ae5ecb5a5a8585935be6a954f480a406550b5c (patch) | |
tree | ef4acd137953ca2ddf56ffd834196403c841783e /src | |
parent | Remove unneeded MarkDirty, SendToClients parameters of SetMeta (diff) | |
download | cuberite-72ae5ecb5a5a8585935be6a954f480a406550b5c.tar cuberite-72ae5ecb5a5a8585935be6a954f480a406550b5c.tar.gz cuberite-72ae5ecb5a5a8585935be6a954f480a406550b5c.tar.bz2 cuberite-72ae5ecb5a5a8585935be6a954f480a406550b5c.tar.lz cuberite-72ae5ecb5a5a8585935be6a954f480a406550b5c.tar.xz cuberite-72ae5ecb5a5a8585935be6a954f480a406550b5c.tar.zst cuberite-72ae5ecb5a5a8585935be6a954f480a406550b5c.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/ChunkMap.cpp | 325 | ||||
-rw-r--r-- | src/ChunkMap.h | 32 | ||||
-rw-r--r-- | src/LineBlockTracer.cpp | 9 | ||||
-rw-r--r-- | src/Map.cpp | 5 | ||||
-rw-r--r-- | src/Simulator/Simulator.cpp | 7 |
5 files changed, 133 insertions, 245 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 5d50a96bf..8b859c1b8 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -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: - return &m_Chunks.try_emplace( + return m_Chunks.try_emplace( ChunkCoordinate{ a_ChunkX, a_ChunkZ }, a_ChunkX, a_ChunkZ, this, m_World, *m_Pool ).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 - auto Chunk = ConstructChunk(a_ChunkX, a_ChunkZ); - if (Chunk == nullptr) - { - return nullptr; - } - if (!Chunk->IsValid() && !Chunk->IsQueued()) + auto & Chunk = ConstructChunk(a_ChunkX, a_ChunkZ); + if (!Chunk.IsValid() && !Chunk.IsQueued()) { - Chunk->SetPresence(cChunk::cpQueued); - Chunk->SetShouldGenerateIfLoadFailed(true); + Chunk.SetPresence(cChunk::cpQueued); m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ); } 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) { 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); int 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()) { return; @@ -161,7 +124,7 @@ bool cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i cCSLock Lock(m_CSChunks); int 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()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); - if (Chunk == nullptr) + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); + if ((Chunk == nullptr) || !Chunk->IsValid()) { return false; } @@ -202,13 +165,14 @@ bool cChunkMap::DoWithChunkAt(Vector3i a_BlockPos, cChunkCallback a_Callback) void cChunkMap::WakeUpSimulators(Vector3i a_Block) { 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()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { return; @@ -233,7 +197,7 @@ void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { return; @@ -248,7 +212,7 @@ void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { return; @@ -266,11 +230,8 @@ void cChunkMap::SetChunkData(cSetChunkData & a_SetChunkData) int ChunkZ = a_SetChunkData.GetChunkZ(); { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ); - if (Chunk == nullptr) - { - return; - } + const auto Chunk = FindChunk(ChunkX, ChunkZ); + ASSERT(Chunk != nullptr); // Chunk cannot have unloaded since it is marked as queued Chunk->SetAllData(a_SetChunkData); if (a_SetChunkData.ShouldMarkDirty()) @@ -311,9 +272,10 @@ void cChunkMap::ChunkLighted( ) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if (Chunk == nullptr) { + // Chunk probably unloaded in the meantime return; } Chunk->SetLight(a_BlockLight, a_SkyLight); @@ -332,7 +294,7 @@ bool cChunkMap::GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callb return false; } 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()) { // 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); return (Chunk != nullptr) && Chunk->HasAnyClients(); } @@ -402,15 +364,10 @@ int cChunkMap::GetHeight(int a_BlockX, int a_BlockZ) cCSLock Lock(m_CSChunks); int ChunkX, ChunkZ, BlockY = 0; cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); - if (Chunk == nullptr) + auto & Chunk = GetChunk(ChunkX, ChunkZ); + if (Chunk.IsValid()) { - return 0; - } - - if (Chunk->IsValid()) - { - return Chunk->GetHeight(a_BlockX, a_BlockZ); + return Chunk.GetHeight(a_BlockX, a_BlockZ); } // 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); int ChunkX, ChunkZ, BlockY = 0; 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()) { return false; @@ -448,10 +405,10 @@ void cChunkMap::FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLET 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()) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + 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: cCSLock Lock(m_CSChunks); - auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); - if ((chunk != nullptr) && chunk->IsValid()) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + if ((Chunk != nullptr) && Chunk->IsValid()) { - return chunk->GetBlock(relPos); + return Chunk->GetBlock(relPos); } return 0; } @@ -512,10 +469,10 @@ NIBBLETYPE cChunkMap::GetBlockMeta(Vector3i a_BlockPos) // Query the chunk, if loaded: cCSLock Lock(m_CSChunks); - auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); - if ((chunk != nullptr) && chunk->IsValid()) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + if ((Chunk != nullptr) && Chunk->IsValid()) { - return chunk->GetMeta(relPos); + return Chunk->GetMeta(relPos); } return 0; } @@ -531,10 +488,10 @@ NIBBLETYPE cChunkMap::GetBlockSkyLight(Vector3i a_BlockPos) // Query the chunk, if loaded: cCSLock Lock(m_CSChunks); - auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); - if ((chunk != nullptr) && chunk->IsValid()) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + if ((Chunk != nullptr) && Chunk->IsValid()) { - return chunk->GetSkyLight(relPos); + return Chunk->GetSkyLight(relPos); } return 0; } @@ -550,10 +507,10 @@ NIBBLETYPE cChunkMap::GetBlockBlockLight(Vector3i a_BlockPos) // Query the chunk, if loaded: cCSLock Lock(m_CSChunks); - auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); - if ((chunk != nullptr) && chunk->IsValid()) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + if ((Chunk != nullptr) && Chunk->IsValid()) { - return chunk->GetBlockLight(relPos); + return Chunk->GetBlockLight(relPos); } return 0; } @@ -569,10 +526,10 @@ void cChunkMap::SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_BlockMeta) // Query the chunk, if loaded: cCSLock Lock(m_CSChunks); - auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); - if ((chunk != nullptr) && chunk->IsValid()) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + 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); cCSLock Lock(m_CSChunks); - auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); - if ((chunk != nullptr) && chunk->IsValid()) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + 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); cCSLock Lock(m_CSChunks); - auto chunk = GetChunk(chunkCoord.m_ChunkX, chunkCoord.m_ChunkZ); - if ((chunk != nullptr) && chunk->IsValid()) + const auto Chunk = FindChunk(chunkCoord.m_ChunkX, chunkCoord.m_ChunkZ); + if ((Chunk != nullptr) && Chunk->IsValid()) { - chunk->GetBlockTypeMeta(relPos, a_BlockType, a_BlockMeta); + Chunk->GetBlockTypeMeta(relPos, a_BlockType, a_BlockMeta); return true; } return false; @@ -623,10 +580,10 @@ bool cChunkMap::GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBL // Query the chunk, if loaded: cCSLock Lock(m_CSChunks); - auto chunk = GetChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); - if ((chunk != nullptr) && chunk->IsValid()) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + 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 false; @@ -641,17 +598,17 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks) cCSLock Lock(m_CSChunks); for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) { - auto chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ); - if ((chunk == nullptr) || !chunk->IsValid()) + const auto Chunk = FindChunk(itr->m_ChunkX, itr->m_ChunkZ); + if ((Chunk == nullptr) || !Chunk->IsValid()) { continue; } Vector3i relPos(itr->m_RelX, itr->m_RelY, itr->m_RelZ); - switch (chunk->GetBlock(relPos)) + switch (Chunk->GetBlock(relPos)) { CASE_TREE_OVERWRITTEN_BLOCKS: { - chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta); + Chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta); break; } 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)) { - chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta); + Chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta); } break; } @@ -677,7 +634,7 @@ EMCSBiome cChunkMap::GetBiomeAt (int a_BlockX, int a_BlockZ) cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk != nullptr) && Chunk->IsValid()) { 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); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk != nullptr) && Chunk->IsValid()) { 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 MaxRelZ = (z == MaxChunkZ) ? MaxZ : cChunkDef::Width - 1; - cChunkPtr Chunk = GetChunkNoLoad(x, z); + const auto Chunk = FindChunk(x, z); if ((Chunk != nullptr) && Chunk->IsValid()) { 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); 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 (!a_ContinueOnFailure) @@ -782,13 +739,13 @@ bool cChunkMap::DigBlock(Vector3i a_BlockPos) { cCSLock Lock(m_CSChunks); - auto destChunk = GetChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ); - if ((destChunk == nullptr) || !destChunk->IsValid()) + const auto Chunk = FindChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ); + if ((Chunk == nullptr) || !Chunk->IsValid()) { return false; } - destChunk->SetBlock(relPos, E_BLOCK_AIR, 0); + Chunk->SetBlock(relPos, E_BLOCK_AIR, 0); } return true; } @@ -803,12 +760,12 @@ cItems cChunkMap::PickupsFromBlock(Vector3i a_BlockPos, const cEntity * a_Digger auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkCoords); cCSLock Lock(m_CSChunks); - auto destChunk = GetChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ); - if ((destChunk == nullptr) || !destChunk->IsValid()) + const auto Chunk = FindChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ); + if ((Chunk == nullptr) || !Chunk->IsValid()) { 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); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk != nullptr) && (Chunk->IsValid())) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk1 = GetChunkNoGen(a_ChunkX1, a_ChunkZ1); + const auto Chunk1 = FindChunk(a_ChunkX1, a_ChunkZ1); if (Chunk1 == nullptr) { return; } - cChunkPtr Chunk2 = GetChunkNoGen(a_ChunkX2, a_ChunkZ2); + const auto Chunk2 = FindChunk(a_ChunkX2, a_ChunkZ2); if (Chunk2 == nullptr) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunk(a_ChunkX, a_ChunkZ); - if (Chunk == nullptr) - { - return false; - } - return Chunk->AddClient(a_Client); + return GetChunk(a_ChunkX, a_ChunkZ).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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); - if (Chunk == nullptr) - { - return; - } + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); + ASSERT(Chunk != nullptr); Chunk->RemoveClient(a_Client); } @@ -929,8 +878,8 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client) void cChunkMap::AddEntity(OwnedEntity a_Entity) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); - if (Chunk == nullptr) // This will assert inside GetChunk in Debug builds + const auto Chunk = FindChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); + if (Chunk == nullptr) { 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() @@ -947,8 +896,8 @@ void cChunkMap::AddEntity(OwnedEntity a_Entity) void cChunkMap::AddEntityIfNotPresent(OwnedEntity a_Entity) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); - if (Chunk == nullptr) // This will assert inside GetChunk in Debug builds + const auto Chunk = FindChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); + if (Chunk == nullptr) { 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() @@ -985,7 +934,7 @@ bool cChunkMap::HasEntity(UInt32 a_UniqueID) const OwnedEntity cChunkMap::RemoveEntity(cEntity & a_Entity) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = a_Entity.GetParentChunk(); + const auto Chunk = a_Entity.GetParentChunk(); 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { return false; @@ -1046,7 +995,7 @@ bool cChunkMap::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback a { for (int x = MinChunkX; x <= MaxChunkX; x++) { - cChunkPtr Chunk = GetChunkNoGen(x, z); + const auto Chunk = FindChunk(x, z); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + const auto Chunk = FindChunk(ChunkX, ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { 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) { 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 ((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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); - if (Chunk == nullptr) - { - return; - } + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); + ASSERT(Chunk != nullptr); // Chunk cannot have unloaded since it is marked as queued Chunk->MarkLoadFailed(); } @@ -1783,7 +1729,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt cCSLock Lock(m_CSChunks); int 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()) { 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) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); - if (Chunk == nullptr) - { - // Not present - return; - } - Chunk->MarkRegenerating(); + ConstructChunk(a_ChunkX, a_ChunkZ).MarkRegenerating(); } @@ -1814,7 +1754,7 @@ void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ) bool cChunkMap::IsChunkLighted(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ); + const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); if (Chunk == nullptr) { // 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++) { - cChunkPtr Chunk = GetChunkNoLoad(x, z); - if ((Chunk == nullptr) || (!Chunk->IsValid())) + const auto Chunk = FindChunk(x, z); + if ((Chunk == nullptr) || !Chunk->IsValid()) { // Not present / not valid 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++) { - cChunkPtr Chunk = GetChunkNoLoad(x, z); - if ((Chunk == nullptr) || (!Chunk->IsValid())) + const auto Chunk = FindChunk(x, z); + if ((Chunk == nullptr) || !Chunk->IsValid()) { // Not present / not valid Result = false; @@ -1938,12 +1878,12 @@ int cChunkMap::GrowPlantAt(Vector3i a_BlockPos, int a_NumStages) auto chunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto relPos = cChunkDef::AbsoluteToRelative(a_BlockPos, chunkPos); cCSLock lock(m_CSChunks); - auto chunk = GetChunkNoLoad(chunkPos); - if (chunk == nullptr) + const auto Chunk = FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ); + if ((Chunk == nullptr) || !Chunk->IsValid()) { 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); cCSLock Lock(m_CSChunks); - auto Chunk = GetChunkNoLoad(ChunkPos); + const auto Chunk = FindChunk(ChunkPos.m_ChunkX, ChunkPos.m_ChunkZ); if (Chunk != nullptr) { Chunk->SetNextBlockToTick(RelPos); @@ -2025,7 +1965,7 @@ void cChunkMap::TickBlock(const Vector3i a_BlockPos) auto ChunkPos = cChunkDef::BlockToChunk(a_BlockPos); auto RelPos = cChunkDef::AbsoluteToRelative(a_BlockPos, ChunkPos); cCSLock Lock(m_CSChunks); - auto Chunk = GetChunkNoLoad(ChunkPos); + const auto Chunk = FindChunk(ChunkPos.m_ChunkX, ChunkPos.m_ChunkZ); if ((Chunk == nullptr) || !Chunk->IsValid()) { return; @@ -2116,11 +2056,7 @@ void cChunkMap::ChunkValidated(void) void cChunkMap::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = GetChunk(a_ChunkX, a_ChunkZ); - if (Chunk != nullptr) - { - Chunk->SetAlwaysTicked(a_AlwaysTicked); - } + GetChunk(a_ChunkX, a_ChunkZ).SetAlwaysTicked(a_AlwaysTicked); } @@ -2157,13 +2093,9 @@ void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay) const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks(); for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr) { - cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ); - if (Chunk == nullptr) - { - continue; - } - Chunk->Stay(true); - if (Chunk->IsValid()) + auto & Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ); + Chunk.Stay(true); + if (Chunk.IsValid()) { 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(); for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr) { - cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkZ); - if (Chunk == nullptr) - { - continue; - } + const auto Chunk = FindChunk(itr->m_ChunkX, itr->m_ChunkZ); + ASSERT(Chunk != nullptr); // Stayed chunks cannot unload Chunk->Stay(false); } // for itr - Chunks[] a_ChunkStay.OnDisabled(); diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 8fc1a57f9..e426dd298 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -42,7 +42,6 @@ class cBoundingBox; class cDeadlockDetect; typedef std::list<cClientHandle *> cClientHandleList; -typedef cChunk * cChunkPtr; using cEntityCallback = cFunctionRef<bool(cEntity &)>; using cBeaconCallback = cFunctionRef<bool(cBeaconEntity &)>; using cBedCallback = cFunctionRef<bool(cBedEntity &)>; @@ -465,31 +464,11 @@ private: std::unique_ptr<cAllocationPool<cChunkData::sChunkSection> > m_Pool; /** Returns or creates and returns a chunk pointer corresponding to the given chunk coordinates. - Emplaces this chunk in the chunk map. - Developers SHOULD use the GetChunk variants instead of this function. */ - cChunkPtr ConstructChunk(int a_ChunkX, int a_ChunkZ); + Emplaces this chunk in the chunk map. */ + cChunk & ConstructChunk(int a_ChunkX, int a_ChunkZ); /** Constructs a chunk and queues it for loading / generating if not valid, returning it */ - cChunkPtr 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}); - } + cChunk & GetChunk(int a_ChunkX, int 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. */ cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); @@ -503,8 +482,3 @@ private: void DelChunkStay(cChunkStay & a_ChunkStay); }; - - - - - diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index 6160f8485..49eba9ac8 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -287,12 +287,8 @@ bool cLineBlockTracer::ChunkCallback(cChunk * a_Chunk) // This is the actual line tracing loop. for (;;) { - // Report the current block through the callbacks: - if (a_Chunk == nullptr) - { - m_Callbacks->OnNoChunk(); - return false; - } + // Our caller (DoWithChunk callback) should never give nothing: + ASSERT(a_Chunk != nullptr); // Move to next block if (!MoveToNextBlock()) @@ -324,6 +320,7 @@ bool cLineBlockTracer::ChunkCallback(cChunk * a_Chunk) return false; } + // Report the current block through the callbacks: if (a_Chunk->IsValid()) { BLOCKTYPE BlockType; diff --git a/src/Map.cpp b/src/Map.cpp index a17e332da..30d761154 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -125,11 +125,6 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) ColorID PixelData; m_World->DoWithChunk(ChunkX, ChunkZ, [&](cChunk & a_Chunk) { - if (!a_Chunk.IsValid()) - { - return false; - } - if (GetDimension() == dimNether) { // TODO 2014-02-22 xdot: Nether maps diff --git a/src/Simulator/Simulator.cpp b/src/Simulator/Simulator.cpp index 6b39b81d5..36b03520c 100644 --- a/src/Simulator/Simulator.cpp +++ b/src/Simulator/Simulator.cpp @@ -132,13 +132,6 @@ void cSimulator::WakeUp(const cCuboid & a_Area) { 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 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); |