diff options
Diffstat (limited to 'src/ChunkMap.cpp')
-rw-r--r-- | src/ChunkMap.cpp | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index b1a7d6ec5..fcd990ad6 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -114,11 +114,11 @@ cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkZ) -cChunkPtr cChunkMap::GetChunkNoGen(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_ChunkX, a_ChunkZ); + auto Chunk = ConstructChunk(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); if (Chunk == nullptr) { return nullptr; @@ -126,7 +126,7 @@ cChunkPtr cChunkMap::GetChunkNoGen(int a_ChunkX, int a_ChunkZ) if (!Chunk->IsValid() && !Chunk->IsQueued()) { Chunk->SetPresence(cChunk::cpQueued); - m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ); + m_World->GetStorage().QueueLoadChunk(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); } return Chunk; @@ -739,17 +739,15 @@ bool cChunkMap::DoWithChunkAt(Vector3i a_BlockPos, std::function<bool(cChunk &)> -void cChunkMap::WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ) +void cChunkMap::WakeUpSimulators(Vector3i a_Block) { cCSLock Lock(m_CSChunks); - int ChunkX, ChunkZ; - cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); - cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(cChunkDef::BlockToChunk(a_Block)); if ((Chunk == nullptr) || !Chunk->IsValid()) { return; } - m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, Chunk); + m_World->GetSimulatorManager()->WakeUp(a_Block, Chunk); } @@ -1139,7 +1137,7 @@ void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_B if ((Chunk != nullptr) && Chunk->IsValid()) { Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_SendToClients); - m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, Chunk); + m_World->GetSimulatorManager()->WakeUp({a_BlockX, a_BlockY, a_BlockZ}, Chunk); } BlockHandler(a_BlockType)->OnPlaced(ChunkInterface, *m_World, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); } @@ -1360,7 +1358,7 @@ bool cChunkMap::DigBlock(int a_BlockX, int a_BlockY, int a_BlockZ) } DestChunk->SetBlock(PosX, PosY, PosZ, E_BLOCK_AIR, 0); - m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, DestChunk); + m_World->GetSimulatorManager()->WakeUp({a_BlockX, a_BlockY, a_BlockZ}, DestChunk); } return true; @@ -1497,38 +1495,38 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client) -void cChunkMap::AddEntity(cEntity * a_Entity) +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 { LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.", - static_cast<void *>(a_Entity), a_Entity->GetClass(), a_Entity->GetUniqueID() + static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID() ); return; } - Chunk->AddEntity(a_Entity); + Chunk->AddEntity(std::move(a_Entity)); } -void cChunkMap::AddEntityIfNotPresent(cEntity * 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 { LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.", - static_cast<void *>(a_Entity), a_Entity->GetClass(), a_Entity->GetUniqueID() + static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID() ); return; } if (!Chunk->HasEntity(a_Entity->GetUniqueID())) { - Chunk->AddEntity(a_Entity); + Chunk->AddEntity(std::move(a_Entity)); } } @@ -1553,17 +1551,18 @@ bool cChunkMap::HasEntity(UInt32 a_UniqueID) -void cChunkMap::RemoveEntity(cEntity * a_Entity) +OwnedEntity cChunkMap::RemoveEntity(cEntity & a_Entity) { cCSLock Lock(m_CSChunks); - cChunkPtr Chunk = a_Entity->GetParentChunk(); + cChunkPtr Chunk = a_Entity.GetParentChunk(); - // Even if a chunk is not valid, it may still contain entities such as players; make sure to remove them (#1190) if (Chunk == nullptr) { - return; + return nullptr; } - Chunk->RemoveEntity(a_Entity); + + // Remove the entity no matter whether the chunk itself is valid or not (#1190) + return Chunk->RemoveEntity(a_Entity); } @@ -1821,8 +1820,8 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_ // Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391): m_World->GetSimulatorManager()->WakeUpArea(cCuboid( - bx - ExplosionSizeInt - 1, MinY, bz - ExplosionSizeInt - 1, - bx + ExplosionSizeInt + 1, MaxY, bz + ExplosionSizeInt + 1 + {bx - ExplosionSizeInt - 1, MinY, bz - ExplosionSizeInt - 1}, + {bx + ExplosionSizeInt + 1, MaxY, bz + ExplosionSizeInt + 1} )); } |