mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Chunk: move protocol-specific getSubChunkSendCount() to network chunk serializer
This commit is contained in:
parent
23e2e7c320
commit
eedc9eaee1
@ -61,7 +61,7 @@ class ChunkRequestTask extends AsyncTask{
|
||||
|
||||
public function onRun() : void{
|
||||
$chunk = FastChunkSerializer::deserialize($this->chunk);
|
||||
$subCount = $chunk->getSubChunkSendCount();
|
||||
$subCount = ChunkSerializer::getSubChunkCount($chunk);
|
||||
$payload = ChunkSerializer::serialize($chunk, $this->tiles);
|
||||
$this->setResult(Zlib::compress(PacketBatch::fromPackets(LevelChunkPacket::withoutCache($this->chunkX, $this->chunkZ, $subCount, $payload))->getBuffer(), $this->compressionLevel));
|
||||
}
|
||||
|
@ -35,6 +35,24 @@ final class ChunkSerializer{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of subchunks that will be sent from the given chunk.
|
||||
* Chunks are sent in a stack, so every chunk below the top non-empty one must be sent.
|
||||
* @param Chunk $chunk
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getSubChunkCount(Chunk $chunk) : int{
|
||||
for($count = $chunk->getSubChunks()->count(); $count > 0; --$count){
|
||||
if($chunk->getSubChunk($count - 1)->isEmptyFast()){
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Chunk $chunk
|
||||
*
|
||||
@ -44,7 +62,7 @@ final class ChunkSerializer{
|
||||
*/
|
||||
public static function serialize(Chunk $chunk, ?string $tiles = null) : string{
|
||||
$stream = new NetworkBinaryStream();
|
||||
$subChunkCount = $chunk->getSubChunkSendCount();
|
||||
$subChunkCount = self::getSubChunkCount($chunk);
|
||||
for($y = 0; $y < $subChunkCount; ++$y){
|
||||
$layers = $chunk->getSubChunk($y)->getBlockLayers();
|
||||
$stream->putByte(8); //version
|
||||
|
@ -682,22 +682,6 @@ class Chunk{
|
||||
return $this->subChunks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count of subchunks that need sending to players
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSubChunkSendCount() : int{
|
||||
for($count = $this->subChunks->count(); $count > 0; --$count){
|
||||
if($this->subChunks[$count - 1]->isEmptyFast()){
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes of empty subchunks and frees data where possible
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user