mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
First look at separating chunk sending from Level
This commit is contained in:
@ -744,6 +744,43 @@ class NetworkSession{
|
||||
return $this->sendDataPacket($pk);
|
||||
}
|
||||
|
||||
public function startUsingChunk(int $chunkX, int $chunkZ, bool $spawn = false) : void{
|
||||
ChunkCache::getInstance($this->player->getLevel())->request($chunkX, $chunkZ)->onResolve(
|
||||
|
||||
//this callback may be called synchronously or asynchronously, depending on whether the promise is resolved yet
|
||||
function(CompressBatchPromise $promise) use($chunkX, $chunkZ, $spawn){
|
||||
if(!$this->isConnected()){
|
||||
return;
|
||||
}
|
||||
$this->player->level->timings->syncChunkSendTimer->startTiming();
|
||||
try{
|
||||
$this->queueCompressed($promise);
|
||||
|
||||
foreach($this->player->getLevel()->getChunkEntities($chunkX, $chunkZ) as $entity){
|
||||
if($entity !== $this->player and !$entity->isClosed() and !$entity->isFlaggedForDespawn()){
|
||||
$entity->spawnTo($this->player);
|
||||
}
|
||||
}
|
||||
|
||||
if($spawn){
|
||||
//TODO: potential race condition during chunk sending could cause this to be called too early
|
||||
$this->onTerrainReady();
|
||||
}
|
||||
}finally{
|
||||
$this->player->level->timings->syncChunkSendTimer->stopTiming();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function stopUsingChunk(int $chunkX, int $chunkZ) : void{
|
||||
foreach($this->player->getLevel()->getChunkEntities($chunkX, $chunkZ) as $entity){
|
||||
if($entity !== $this->player){
|
||||
$entity->despawnFrom($this->player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function tick() : bool{
|
||||
if($this->handler instanceof LoginSessionHandler){
|
||||
if(time() >= $this->connectTime + 10){
|
||||
|
Reference in New Issue
Block a user