Level: minor de-spaghettification of chunk requesting

Now the Level tells the player to request chunks on tick, instead of the server doing it.
This commit is contained in:
Dylan K. Taylor 2018-07-18 16:48:53 +01:00
parent e57dd3e8ba
commit 1144620f2b
3 changed files with 19 additions and 20 deletions

View File

@ -1140,6 +1140,20 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
Timings::$playerChunkOrderTimer->stopTiming(); Timings::$playerChunkOrderTimer->stopTiming();
} }
public function doChunkRequests(){
if(!$this->isOnline()){
return;
}
if($this->nextChunkOrderRun-- <= 0){
$this->orderChunks();
}
if(count($this->loadQueue) > 0){
$this->sendNextChunk();
}
}
/** /**
* @return Position * @return Position
*/ */
@ -1774,20 +1788,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->dataPacket($pk); $this->dataPacket($pk);
} }
public function checkNetwork(){
if(!$this->isOnline()){
return;
}
if($this->nextChunkOrderRun-- <= 0){
$this->orderChunks();
}
if(count($this->loadQueue) > 0){
$this->sendNextChunk();
}
}
/** /**
* Returns whether the player can interact with the specified position. This checks distance and direction. * Returns whether the player can interact with the specified position. This checks distance and direction.
* *

View File

@ -2511,10 +2511,6 @@ class Server{
$this->checkTickUpdates($this->tickCounter, $tickTime); $this->checkTickUpdates($this->tickCounter, $tickTime);
foreach($this->players as $player){
$player->checkNetwork();
}
if(($this->tickCounter % 20) === 0){ if(($this->tickCounter % 20) === 0){
if($this->doTitleTick){ if($this->doTitleTick){
$this->titleTick(); $this->titleTick();

View File

@ -787,7 +787,10 @@ class Level implements ChunkManager, Metadatable{
} }
$this->processChunkRequest(); foreach($this->players as $p){
$p->doChunkRequests();
}
$this->processChunkRequests();
if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){ if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){
$this->checkSleep(); $this->checkSleep();
@ -2464,7 +2467,7 @@ class Level implements ChunkManager, Metadatable{
} }
} }
private function processChunkRequest(){ private function processChunkRequests(){
if(count($this->chunkSendQueue) > 0){ if(count($this->chunkSendQueue) > 0){
$this->timings->syncChunkSendTimer->startTiming(); $this->timings->syncChunkSendTimer->startTiming();