mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 19:02:59 +00:00
Async chunk compression and serialization is now non-optional
This commit is contained in:
@ -33,6 +33,7 @@ use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\LongTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\scheduler\AsyncTask;
|
||||
|
||||
abstract class BaseLevelProvider implements LevelProvider{
|
||||
/** @var Level */
|
||||
@ -41,8 +42,6 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
protected $path;
|
||||
/** @var CompoundTag */
|
||||
protected $levelData;
|
||||
/** @var bool */
|
||||
protected $asyncChunkRequest = false;
|
||||
|
||||
public function __construct(Level $level, string $path){
|
||||
$this->level = $level;
|
||||
@ -66,7 +65,6 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
if(!isset($this->levelData->generatorOptions)){
|
||||
$this->levelData->generatorOptions = new StringTag("generatorOptions", "");
|
||||
}
|
||||
$this->asyncChunkRequest = (bool) $this->level->getServer()->getProperty("chunk-sending.async-chunk-request", false);
|
||||
}
|
||||
|
||||
public function getPath() : string{
|
||||
@ -131,19 +129,12 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
file_put_contents($this->getPath() . "level.dat", $buffer);
|
||||
}
|
||||
|
||||
public function requestChunkTask(int $x, int $z){
|
||||
public function requestChunkTask(int $x, int $z) : AsyncTask{
|
||||
$chunk = $this->getChunk($x, $z, false);
|
||||
if(!($chunk instanceof Chunk)){
|
||||
throw new ChunkException("Invalid Chunk sent");
|
||||
}
|
||||
|
||||
if($this->asyncChunkRequest){
|
||||
return new ChunkRequestTask($this->level, $chunk);
|
||||
}
|
||||
|
||||
//non-async, call the callback directly with serialized data
|
||||
$this->getLevel()->chunkRequestCallback($x, $z, $chunk->networkSerialize());
|
||||
|
||||
return null;
|
||||
return new ChunkRequestTask($this->level, $chunk);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ namespace pocketmine\level\format\io;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\network\mcpe\protocol\BatchPacket;
|
||||
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
|
||||
use pocketmine\scheduler\AsyncTask;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\tile\Spawnable;
|
||||
@ -38,8 +40,11 @@ class ChunkRequestTask extends AsyncTask{
|
||||
|
||||
protected $tiles;
|
||||
|
||||
protected $compressionLevel;
|
||||
|
||||
public function __construct(Level $level, Chunk $chunk){
|
||||
$this->levelId = $level->getId();
|
||||
$this->compressionLevel = $level->getServer()->networkCompressionLevel;
|
||||
|
||||
$this->chunk = $chunk->fastSerialize();
|
||||
$this->chunkX = $chunk->getX();
|
||||
@ -61,9 +66,16 @@ class ChunkRequestTask extends AsyncTask{
|
||||
public function onRun(){
|
||||
$chunk = Chunk::fastDeserialize($this->chunk);
|
||||
|
||||
$ordered = $chunk->networkSerialize() . $this->tiles;
|
||||
$pk = new FullChunkDataPacket();
|
||||
$pk->chunkX = $this->chunkX;
|
||||
$pk->chunkZ = $this->chunkZ;
|
||||
$pk->data = $chunk->networkSerialize() . $this->tiles;
|
||||
|
||||
$this->setResult($ordered, false);
|
||||
$batch = new BatchPacket();
|
||||
$batch->addPacket($pk);
|
||||
$batch->compress($this->compressionLevel);
|
||||
|
||||
$this->setResult($batch);
|
||||
}
|
||||
|
||||
public function onCompletion(Server $server){
|
||||
|
@ -26,6 +26,7 @@ namespace pocketmine\level\format\io;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\scheduler\AsyncTask;
|
||||
|
||||
interface LevelProvider{
|
||||
|
||||
@ -166,9 +167,9 @@ interface LevelProvider{
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
*
|
||||
* @return \pocketmine\scheduler\AsyncTask|null
|
||||
* @return AsyncTask
|
||||
*/
|
||||
public function requestChunkTask(int $x, int $z);
|
||||
public function requestChunkTask(int $x, int $z) : AsyncTask;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
Reference in New Issue
Block a user