mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 04:38:35 +00:00
Improved chunk serialization
This commit is contained in:
parent
81feff6d0d
commit
c1846e3bcf
@ -160,6 +160,9 @@ class Chunk extends BaseChunk{
|
|||||||
$nbt->Sections = new Enum("Sections", []);
|
$nbt->Sections = new Enum("Sections", []);
|
||||||
$nbt->Sections->setTagType(NBT::TAG_Compound);
|
$nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||||
foreach($this->getSections() as $section){
|
foreach($this->getSections() as $section){
|
||||||
|
if($section instanceof EmptyChunkSection){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$nbt->Sections[$section->getY()] = new Compound(null, [
|
$nbt->Sections[$section->getY()] = new Compound(null, [
|
||||||
"Y" => new Byte("Y", $section->getY()),
|
"Y" => new Byte("Y", $section->getY()),
|
||||||
"Blocks" => new ByteArray("Blocks", $section->getIdArray()),
|
"Blocks" => new ByteArray("Blocks", $section->getIdArray()),
|
||||||
|
@ -70,6 +70,16 @@ class Chunk extends BaseFullChunk{
|
|||||||
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("\x00\x85\xb2\x4a")));
|
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("\x00\x85\xb2\x4a")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!isset($this->nbt->Blocks)){
|
||||||
|
$this->nbt->Blocks = new ByteArray("Blocks", str_repeat("\x00", 32768));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($this->nbt->Data)){
|
||||||
|
$this->nbt->Data = new ByteArray("Data", $half = str_repeat("\x00", 16384));
|
||||||
|
$this->nbt->SkyLight = new ByteArray("SkyLight", $half);
|
||||||
|
$this->nbt->BlockLight = new ByteArray("BlockLight", $half);
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt["Blocks"], $this->nbt["Data"], $this->nbt["SkyLight"], $this->nbt["BlockLight"], $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
|
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt["Blocks"], $this->nbt["Data"], $this->nbt["SkyLight"], $this->nbt["BlockLight"], $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
|
||||||
unset($this->nbt->Blocks);
|
unset($this->nbt->Blocks);
|
||||||
unset($this->nbt->Data);
|
unset($this->nbt->Data);
|
||||||
@ -253,6 +263,7 @@ class Chunk extends BaseFullChunk{
|
|||||||
$nbt->xPos = new Int("xPos", $this->x);
|
$nbt->xPos = new Int("xPos", $this->x);
|
||||||
$nbt->zPos = new Int("zPos", $this->z);
|
$nbt->zPos = new Int("zPos", $this->z);
|
||||||
|
|
||||||
|
if($this->isGenerated()){
|
||||||
$nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray());
|
$nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray());
|
||||||
$nbt->Data = new ByteArray("Data", $this->getBlockDataArray());
|
$nbt->Data = new ByteArray("Data", $this->getBlockDataArray());
|
||||||
$nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray());
|
$nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray());
|
||||||
@ -260,6 +271,7 @@ class Chunk extends BaseFullChunk{
|
|||||||
|
|
||||||
$nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray());
|
$nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray());
|
||||||
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
|
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
|
||||||
|
}
|
||||||
|
|
||||||
$entities = [];
|
$entities = [];
|
||||||
|
|
||||||
|
@ -144,12 +144,17 @@ class GenerationManager{
|
|||||||
$this->levels[$levelID]->populateChunk($chunkX, $chunkZ); //Request population directly
|
$this->levels[$levelID]->populateChunk($chunkX, $chunkZ); //Request population directly
|
||||||
if(isset($this->levels[$levelID])){
|
if(isset($this->levels[$levelID])){
|
||||||
$this->generatedQueue[$levelID][$index] = true;
|
$this->generatedQueue[$levelID][$index] = true;
|
||||||
if(count($this->generatedQueue[$levelID]) > 6){
|
if(count($this->generatedQueue[$levelID]) > 2){
|
||||||
foreach($this->levels[$levelID]->getChangedChunks() as $chunk){
|
foreach($this->levels[$levelID]->getChangedChunks() as $chunk){
|
||||||
|
if($chunk->isPopulated()){
|
||||||
$this->sendChunk($levelID, $chunk);
|
$this->sendChunk($levelID, $chunk);
|
||||||
}
|
}
|
||||||
$this->levels[$levelID]->doGarbageCollection();
|
}
|
||||||
$this->levels[$levelID]->cleanChangedChunks();
|
$this->levels[$levelID]->cleanChangedChunks();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($this->generatedQueue[$levelID]) > 8){
|
||||||
|
$this->levels[$levelID]->doGarbageCollection();
|
||||||
$this->generatedQueue[$levelID] = [];
|
$this->generatedQueue[$levelID] = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user