From 868cd94ee9a5a0638c014a4cc42224f01ff234c8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 5 Mar 2021 13:03:55 +0000 Subject: Prepare ChunkData for BlockState storage (#5105) * Rename ChunkData Creatable test * Add missing Y-check in RedstoneWireHandler * Remove ChunkDef.h dependency in Scoreboard * Prepare ChunkData for BlockState storage + Split chunk block, meta, block & sky light storage + Load the height map from disk - Reduce duplicated code in ChunkData - Remove saving MCSBiomes, there aren't any - Remove the allocation pool, ref #4315, #3864 * fixed build * fixed test * fixed the debug compile Co-authored-by: 12xx12 <44411062+12xx12@users.noreply.github.com> --- src/ChunkMap.cpp | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) (limited to 'src/ChunkMap.cpp') diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index c1d9b78ab..dbd6f8cf3 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -30,12 +30,7 @@ // cChunkMap: cChunkMap::cChunkMap(cWorld * a_World) : - m_World(a_World), - m_Pool( - std::make_unique>( - std::make_unique(), 1600u, 5000u - ) - ) + m_World(a_World) { } @@ -43,25 +38,12 @@ cChunkMap::cChunkMap(cWorld * a_World) : -cChunkMap::~cChunkMap() -{ - // Explicitly destroy all chunks, so that they're guaranteed to be - // destroyed before other internals. This fixes crashes on stopping the server. - // because the chunk destructor deletes entities and those may access the chunkmap. - // Also, the cChunkData destructor accesses the chunkMap's allocator. - m_Chunks.clear(); -} - - - - - 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( { a_ChunkX, a_ChunkZ }, - a_ChunkX, a_ChunkZ, this, m_World, *m_Pool + a_ChunkX, a_ChunkZ, this, m_World ).first->second; } @@ -232,15 +214,15 @@ void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkZ) -void cChunkMap::SetChunkData(cSetChunkData & a_SetChunkData) +void cChunkMap::SetChunkData(struct SetChunkData && a_SetChunkData) { - int ChunkX = a_SetChunkData.GetChunkX(); - int ChunkZ = a_SetChunkData.GetChunkZ(); + const int ChunkX = a_SetChunkData.Chunk.m_ChunkX; + const int ChunkZ = a_SetChunkData.Chunk.m_ChunkZ; { cCSLock Lock(m_CSChunks); const auto Chunk = FindChunk(ChunkX, ChunkZ); ASSERT(Chunk != nullptr); // Chunk cannot have unloaded since it is marked as queued - Chunk->SetAllData(a_SetChunkData); + Chunk->SetAllData(std::move(a_SetChunkData)); // Notify relevant ChunkStays: cChunkStays ToBeDisabled; @@ -310,22 +292,6 @@ 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); - const auto Chunk = FindChunk(a_ChunkX, a_ChunkZ); - if ((Chunk == nullptr) || !Chunk->IsValid()) - { - return false; - } - Chunk->GetBlockTypes(a_BlockTypes); - return true; -} - - - - - bool cChunkMap::IsChunkQueued(int a_ChunkX, int a_ChunkZ) const { cCSLock Lock(m_CSChunks); -- cgit v1.2.3