more chunk loading tweaks

This commit is contained in:
GameHerobrine 2023-02-26 15:46:43 +03:00
parent 37bbfe2d81
commit 57f1a9d38e

View file

@ -406,10 +406,10 @@ class Player{
$Z = $this->entity->z >> 4; $Z = $this->entity->z >> 4;
$this->chunksOrder = []; $this->chunksOrder = [];
if($this->generator != 0) $chunkToUnload = $this->chunksLoaded; if($this->generator != 0) $chunkToUnload = $this->chunksLoaded;
$startX = $this->generator === 1 ? $X - 8 : 0; $startX = $this->generator === 1 ? $X - 4 : 0;
$stopX = $this->generator === 1 ? $X + 8 : 15; $stopX = $this->generator === 1 ? $X + 4 : 15;
$startZ = $this->generator === 1 ? $Z - 8 : 0; $startZ = $this->generator === 1 ? $Z - 4 : 0;
$stopZ = $this->generator === 1 ? $Z + 8 : 15; $stopZ = $this->generator === 1 ? $Z + 4 : 15;
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;
@ -426,8 +426,9 @@ class Player{
$chunkI = explode(":", $chunk); $chunkI = explode(":", $chunk);
$cX = $chunkI[0]; $cX = $chunkI[0];
$cZ = $chunkI[1]; $cZ = $chunkI[1];
//console("Unloading chunk $cX:$cZ");
unset($this->chunksLoaded[$chunk]); unset($this->chunksLoaded[$chunk]);
$this->level->unloadChunk($cX, $cZ, true); $this->level->freeChunk($cX, $cZ, $this);
$this->dataPacket(new UnloadChunkPacket($cX, $cZ)); $this->dataPacket(new UnloadChunkPacket($cX, $cZ));
} }
} }
@ -476,13 +477,14 @@ class Player{
} }
public function entityTick(){ public function entityTick(){
//ConsoleAPI::debug("{$this->username}, cl: ".count($this->chunksLoaded).", oc: ".count($this->chunksOrder));
if(count($this->chunksOrder) <= 0 && $this->generator != 0){ if(count($this->chunksOrder) <= 0 && $this->generator != 0){
$this->orderChunks(); $this->orderChunks();
} }
if($this->reload && $this->generator != 0){ //if($this->reload && $this->generator != 0){
$this->getNextChunk($this->level); $this->getNextChunk($this->level);
$this->reload = false; // $this->reload = false;
} //}
} }
public function getNextChunk($world){ public function getNextChunk($world){
@ -492,7 +494,7 @@ class Player{
foreach($this->chunkCount as $count => $t){ foreach($this->chunkCount as $count => $t){
if(isset($this->recoveryQueue[$count]) or isset($this->resendQueue[$count])){ if(isset($this->recoveryQueue[$count]) or isset($this->resendQueue[$count])){
$this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world); //$this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world);
return; return;
}else{ }else{
unset($this->chunkCount[$count]); unset($this->chunkCount[$count]);
@ -515,7 +517,7 @@ class Player{
$c = key($this->chunksOrder); $c = key($this->chunksOrder);
$d = $c != null ? $this->chunksOrder[$c] : null; $d = $c != null ? $this->chunksOrder[$c] : null;
if($c === null or $d === null){ if($c === null or $d === null){
$this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world); //$this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world);
return false; return false;
} }
@ -543,7 +545,7 @@ class Player{
$this->lastChunk = [$x, $z]; $this->lastChunk = [$x, $z];
$this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world); //$this->server->schedule(MAX_CHUNK_RATE, [$this, "getNextChunk"], $world);
} }
/** /**