mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
Infinite player chunk sending (not yet visible :( )
This commit is contained in:
parent
cbe07a1fa0
commit
4acb4541ab
@ -63,6 +63,7 @@ class Player{
|
|||||||
public $blocked = true;
|
public $blocked = true;
|
||||||
public $achievements = array();
|
public $achievements = array();
|
||||||
public $chunksLoaded = array();
|
public $chunksLoaded = array();
|
||||||
|
private $viewDistance;
|
||||||
private $chunksOrder = array();
|
private $chunksOrder = array();
|
||||||
private $lastMeasure = 0;
|
private $lastMeasure = 0;
|
||||||
private $bandwidthRaw = 0;
|
private $bandwidthRaw = 0;
|
||||||
@ -112,6 +113,7 @@ class Player{
|
|||||||
$this->armor = array();
|
$this->armor = array();
|
||||||
$this->gamemode = $this->server->gamemode;
|
$this->gamemode = $this->server->gamemode;
|
||||||
$this->level = $this->server->api->level->getDefault();
|
$this->level = $this->server->api->level->getDefault();
|
||||||
|
$this->viewDistance = (int) $this->server->api->getProperty("view-distance");
|
||||||
$this->slot = 0;
|
$this->slot = 0;
|
||||||
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
|
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
|
||||||
$this->packetStats = array(0,0);
|
$this->packetStats = array(0,0);
|
||||||
@ -148,22 +150,35 @@ class Player{
|
|||||||
if(!($this->entity instanceof Entity) or $this->connected === false){
|
if(!($this->entity instanceof Entity) or $this->connected === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$X = ($this->entity->x - 0.5) / 16;
|
|
||||||
$Z = ($this->entity->z - 0.5) / 16;
|
$newOrder = array();
|
||||||
$v = new Vector2($X, $Z);
|
$lastLoaded = $this->chunksLoaded;
|
||||||
$this->chunksOrder = array();
|
$centerX = intval(($this->entity->x - 0.5) / 16);
|
||||||
for($x = 0; $x < 16; ++$x){
|
$centerZ = intval(($this->entity->z - 0.5) / 16);
|
||||||
for($z = 0; $z < 16; ++$z){
|
$startX = $centerX - $this->viewDistance;
|
||||||
$dist = $v->distance(new Vector2($x, $z));
|
$startZ = $centerZ - $this->viewDistance;
|
||||||
for($y = 0; $y < 8; ++$y){
|
$finalX = $centerX + $this->viewDistance;
|
||||||
$d = $x.":".$y.":".$z;
|
$finalZ = $centerZ + $this->viewDistance;
|
||||||
if(!isset($this->chunksLoaded[$d])){
|
for($X = $startX; $X <= $finalX; ++$X){
|
||||||
$this->chunksOrder[$d] = $dist;
|
for($Z = $startZ; $Z <= $finalZ; ++$Z){
|
||||||
|
$distance = abs($X - $centerX) + abs($Z - $centerZ);
|
||||||
|
for($Y = 0; $Y < 8; ++$Y){
|
||||||
|
$index = "$X:$Y:$Z";
|
||||||
|
if(!isset($lastLoaded[$index])){
|
||||||
|
$newOrder[$index] = $distance;
|
||||||
|
}else{
|
||||||
|
unset($lastLoaded[$index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
asort($this->chunksOrder);
|
asort($newOrder);
|
||||||
|
$this->chunksOrder = $newOrder;
|
||||||
|
foreach($lastLoaded as $index => $distance){
|
||||||
|
$id = explode(":", $index);
|
||||||
|
$this->level->freeChunk($id[0], $id[2], $this);
|
||||||
|
unset($this->chunksLoaded[$index]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNextChunk(){
|
public function getNextChunk(){
|
||||||
@ -195,7 +210,7 @@ class Player{
|
|||||||
|
|
||||||
$c = key($this->chunksOrder);
|
$c = key($this->chunksOrder);
|
||||||
$d = @$this->chunksOrder[$c];
|
$d = @$this->chunksOrder[$c];
|
||||||
if($c === null or $d > $this->server->api->getProperty("view-distance")){
|
if($c === null){
|
||||||
$this->server->schedule(50, array($this, "getNextChunk"));
|
$this->server->schedule(50, array($this, "getNextChunk"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1468,7 +1483,7 @@ class Player{
|
|||||||
}
|
}
|
||||||
$this->sendInventory();
|
$this->sendInventory();
|
||||||
$this->sendSettings();
|
$this->sendSettings();
|
||||||
$this->server->schedule(50, array($this, "orderChunks"), array(), true);
|
$this->server->schedule(30, array($this, "orderChunks"), array(), true);
|
||||||
$this->blocked = false;
|
$this->blocked = false;
|
||||||
|
|
||||||
$pk = new SetTimePacket;
|
$pk = new SetTimePacket;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user