Async chunk compression and serialization is now non-optional

This commit is contained in:
Dylan K. Taylor
2017-05-18 12:19:27 +01:00
parent 85c1535c75
commit 60f5c7ccef
6 changed files with 25 additions and 52 deletions

View File

@ -2409,13 +2409,13 @@ class Level implements ChunkManager, Metadatable{
}
}
public function chunkRequestCallback(int $x, int $z, string $payload){
public function chunkRequestCallback(int $x, int $z, BatchPacket $payload){
$this->timings->syncChunkSendTimer->startTiming();
$index = Level::chunkHash($x, $z);
if(!isset($this->chunkCache[$index]) and $this->cacheChunks and $this->server->getMemoryManager()->canUseChunkCache()){
$this->chunkCache[$index] = Level::getChunkCacheFromData($x, $z, $payload);
$this->chunkCache[$index] = $payload;
$this->sendChunkFromCache($x, $z);
$this->timings->syncChunkSendTimer->stopTiming();
return;
@ -2886,28 +2886,6 @@ class Level implements ChunkManager, Metadatable{
}
}
/**
* @param int $chunkX
* @param int $chunkZ
* @param string $payload
*
* @return DataPacket
*/
public static function getChunkCacheFromData($chunkX, $chunkZ, $payload){
$pk = new FullChunkDataPacket();
$pk->chunkX = $chunkX;
$pk->chunkZ = $chunkZ;
$pk->data = $payload;
$pk->encode();
$batch = new BatchPacket();
$batch->payload = zlib_encode(Binary::writeUnsignedVarInt(strlen($pk->getBuffer())) . $pk->getBuffer(), ZLIB_ENCODING_DEFLATE, Server::getInstance()->networkCompressionLevel);
$batch->encode();
$batch->isEncoded = true;
return $batch;
}
public function setMetadata($metadataKey, MetadataValue $metadataValue){
$this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $metadataValue);
}