mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
added chunk unloading(average chunks per player in inf world: 289now)
This commit is contained in:
parent
d85814e036
commit
37bbfe2d81
2 changed files with 36 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ class Player{
|
||||||
public $entity = false;
|
public $entity = false;
|
||||||
|
|
||||||
private $generator = 0; //TODO modify in config?
|
private $generator = 0; //TODO modify in config?
|
||||||
|
private $reload = true;
|
||||||
public $auth = false;
|
public $auth = false;
|
||||||
public $CID;
|
public $CID;
|
||||||
public $MTU;
|
public $MTU;
|
||||||
|
|
@ -405,6 +405,7 @@ class Player{
|
||||||
$X = $this->entity->x >> 4;
|
$X = $this->entity->x >> 4;
|
||||||
$Z = $this->entity->z >> 4;
|
$Z = $this->entity->z >> 4;
|
||||||
$this->chunksOrder = [];
|
$this->chunksOrder = [];
|
||||||
|
if($this->generator != 0) $chunkToUnload = $this->chunksLoaded;
|
||||||
$startX = $this->generator === 1 ? $X - 8 : 0;
|
$startX = $this->generator === 1 ? $X - 8 : 0;
|
||||||
$stopX = $this->generator === 1 ? $X + 8 : 15;
|
$stopX = $this->generator === 1 ? $X + 8 : 15;
|
||||||
$startZ = $this->generator === 1 ? $Z - 8 : 0;
|
$startZ = $this->generator === 1 ? $Z - 8 : 0;
|
||||||
|
|
@ -412,6 +413,7 @@ class Player{
|
||||||
for($x = $startX; $x <= $stopX; ++$x){
|
for($x = $startX; $x <= $stopX; ++$x){
|
||||||
for($z = $startZ; $z <= $stopZ; ++$z){
|
for($z = $startZ; $z <= $stopZ; ++$z){
|
||||||
$d = $x . ":" . $z;
|
$d = $x . ":" . $z;
|
||||||
|
if($this->generator != 0) unset($chunkToUnload[$d]);
|
||||||
//if($x < 0 || $x > 15 || $z < 0 || $z > 15) continue; //TODO infinite worlds
|
//if($x < 0 || $x > 15 || $z < 0 || $z > 15) continue; //TODO infinite worlds
|
||||||
if(!isset($this->chunksLoaded[$d])){
|
if(!isset($this->chunksLoaded[$d])){
|
||||||
$this->chunksOrder[$d] = abs($x - $X) + abs($z - $Z);
|
$this->chunksOrder[$d] = abs($x - $X) + abs($z - $Z);
|
||||||
|
|
@ -419,6 +421,19 @@ class Player{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
asort($this->chunksOrder);
|
asort($this->chunksOrder);
|
||||||
|
if($this->generator != 0){
|
||||||
|
foreach($chunkToUnload as $chunk => $useless){
|
||||||
|
$chunkI = explode(":", $chunk);
|
||||||
|
$cX = $chunkI[0];
|
||||||
|
$cZ = $chunkI[1];
|
||||||
|
unset($this->chunksLoaded[$chunk]);
|
||||||
|
$this->level->unloadChunk($cX, $cZ, true);
|
||||||
|
$this->dataPacket(new UnloadChunkPacket($cX, $cZ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->reload = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadAllChunks(){
|
public function loadAllChunks(){
|
||||||
|
|
@ -432,9 +447,9 @@ class Player{
|
||||||
public function useChunk($X, $Z){
|
public function useChunk($X, $Z){
|
||||||
$Yndex = 0;
|
$Yndex = 0;
|
||||||
for($iY = 0; $iY < 8; ++$iY){
|
for($iY = 0; $iY < 8; ++$iY){
|
||||||
if(isset($this->chunksOrder["$X:$iY:$Z"])){
|
if(isset($this->chunksOrder["$X:$Z"])){
|
||||||
unset($this->chunksOrder["$X:$iY:$Z"]);
|
unset($this->chunksOrder["$X:$Z"]);
|
||||||
$this->chunksLoaded["$X:$iY:$Z"] = true;
|
$this->chunksLoaded["$X:$Z"] = true;
|
||||||
$Yndex |= 1 << $iY;
|
$Yndex |= 1 << $iY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -459,7 +474,17 @@ class Player{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public $reordered = false;
|
|
||||||
|
public function entityTick(){
|
||||||
|
if(count($this->chunksOrder) <= 0 && $this->generator != 0){
|
||||||
|
$this->orderChunks();
|
||||||
|
}
|
||||||
|
if($this->reload && $this->generator != 0){
|
||||||
|
$this->getNextChunk($this->level);
|
||||||
|
$this->reload = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getNextChunk($world){
|
public function getNextChunk($world){
|
||||||
if($this->connected === false or $world != $this->level){
|
if($this->connected === false or $world != $this->level){
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1477,7 +1502,8 @@ class Player{
|
||||||
$this->sendSettings();
|
$this->sendSettings();
|
||||||
//$this->teleport($pos);
|
//$this->teleport($pos);
|
||||||
//$this->orderChunks();
|
//$this->orderChunks();
|
||||||
$this->server->schedule(50, array($this, "orderChunks"), array(), true);
|
//$this->server->schedule(50, array($this, "orderChunks"), array(), true);
|
||||||
|
$this->server->schedule(50, array($this, "orderChunks"), array());
|
||||||
$this->getNextChunk($this->level);
|
$this->getNextChunk($this->level);
|
||||||
$this->sendInventory();
|
$this->sendInventory();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -730,6 +730,10 @@ class Entity extends Position
|
||||||
$this->updateMovement();
|
$this->updateMovement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->isPlayer()){
|
||||||
|
$this->player->entityTick();
|
||||||
|
}
|
||||||
|
|
||||||
$this->needsUpdate = $hasUpdate;
|
$this->needsUpdate = $hasUpdate;
|
||||||
$this->lastUpdate = $now;
|
$this->lastUpdate = $now;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue