1
0

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>
This commit is contained in:
Tiger Wang
2021-03-05 13:03:55 +00:00
committed by GitHub
parent 5fa45182e8
commit 868cd94ee9
39 changed files with 1106 additions and 2203 deletions

View File

@@ -30,12 +30,7 @@
// cChunkMap:
cChunkMap::cChunkMap(cWorld * a_World) :
m_World(a_World),
m_Pool(
std::make_unique<cListAllocationPool<cChunkData::sChunkSection>>(
std::make_unique<cStarvationCallbacks>(), 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);