mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-28 22:30:01 +00:00
Improved chunk ticking
This commit is contained in:
parent
83360187c9
commit
5a55040ab9
@ -614,16 +614,20 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$chunkX = $chunkZ = null;
|
$blockTest = 0;
|
||||||
|
|
||||||
foreach($this->chunkTickList as $index => $players){
|
foreach($this->chunkTickList as $index => $players){
|
||||||
Level::getXZ($index, $chunkX, $chunkZ);
|
Level::getXZ($index, $chunkX, $chunkZ);
|
||||||
|
|
||||||
if(!$this->isChunkLoaded($chunkX, $chunkZ) or isset($this->unloadQueue[$index]) and $players > 0){
|
$chunk = $this->getChunk($chunkX, $chunkZ, false);
|
||||||
|
|
||||||
|
if($chunk === null){
|
||||||
unset($this->chunkTickList[$index]);
|
unset($this->chunkTickList[$index]);
|
||||||
continue;
|
continue;
|
||||||
|
}elseif($players <= 0){
|
||||||
|
unset($this->chunkTickList[$index]);
|
||||||
}
|
}
|
||||||
$chunk = $this->getChunk($chunkX, $chunkZ, true);
|
|
||||||
|
|
||||||
foreach($chunk->getEntities() as $entity){
|
foreach($chunk->getEntities() as $entity){
|
||||||
$entity->scheduleUpdate();
|
$entity->scheduleUpdate();
|
||||||
@ -634,13 +638,12 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
foreach($chunk->getSections() as $section){
|
foreach($chunk->getSections() as $section){
|
||||||
if(!($section instanceof EmptyChunkSection)){
|
if(!($section instanceof EmptyChunkSection)){
|
||||||
$Y = $section->getY();
|
$Y = $section->getY();
|
||||||
$k = mt_rand(0, PHP_INT_MAX);
|
$k = mt_rand(0, 0x7fffffff);
|
||||||
for($i = 0; $i < 3; ++$i){
|
for($i = 0; $i < 3; ++$i, $k >>= 10){
|
||||||
$j = $k >> 2;
|
$x = $k & 0x0f;
|
||||||
$x = $j & 0x0f;
|
$y = ($k >> 8) & 0x0f;
|
||||||
$y = ($j >> 8) & 0x0f;
|
$z = ($k >> 16) & 0x0f;
|
||||||
$z = ($j >> 16) & 0x0f;
|
|
||||||
$k %= 1073741827;
|
|
||||||
$blockId = $section->getBlockId($x, $y, $z);
|
$blockId = $section->getBlockId($x, $y, $z);
|
||||||
if(isset($this->randomTickBlocks[$blockId])){
|
if(isset($this->randomTickBlocks[$blockId])){
|
||||||
$class = $this->randomTickBlocks[$blockId];
|
$class = $this->randomTickBlocks[$blockId];
|
||||||
@ -656,15 +659,15 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
for($Y = 0; $Y < 8; ++$Y){
|
for($Y = 0; $Y < 8 and ($Y >= 4 and $blockTest !== 0); ++$Y){
|
||||||
$k = mt_rand(0, PHP_INT_MAX);
|
$blockTest = 0;
|
||||||
for($i = 0; $i < 3; ++$i){
|
$k = mt_rand(0, 0x7fffffff);
|
||||||
$j = $k >> 2;
|
for($i = 0; $i < 3; ++$i, $k >>= 10){
|
||||||
$x = $j & 0x0f;
|
$x = $k & 0x0f;
|
||||||
$y = ($j >> 8) & 0x0f;
|
$y = ($k >> 8) & 0x0f;
|
||||||
$z = ($j >> 16) & 0x0f;
|
$z = ($k >> 16) & 0x0f;
|
||||||
$k %= 1073741827;
|
|
||||||
$blockId = $chunk->getBlockId($x, $y + ($Y << 4), $z);
|
$blockTest |= $blockId = $chunk->getBlockId($x, $y + ($Y << 4), $z);
|
||||||
if(isset($this->randomTickBlocks[$blockId])){
|
if(isset($this->randomTickBlocks[$blockId])){
|
||||||
$class = $this->randomTickBlocks[$blockId];
|
$class = $this->randomTickBlocks[$blockId];
|
||||||
/** @var Block $block */
|
/** @var Block $block */
|
||||||
@ -2028,7 +2031,8 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function queueUnloadChunk($x, $z){
|
protected function queueUnloadChunk($x, $z){
|
||||||
$this->unloadQueue[Level::chunkHash($x, $z)] = microtime(true);
|
$this->unloadQueue[$index = Level::chunkHash($x, $z)] = microtime(true);
|
||||||
|
unset($this->chunkTickList[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unloadChunkRequest($x, $z, $safe = true){
|
public function unloadChunkRequest($x, $z, $safe = true){
|
||||||
@ -2079,6 +2083,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
unset($this->chunks[$index]);
|
unset($this->chunks[$index]);
|
||||||
unset($this->usedChunks[$index]);
|
unset($this->usedChunks[$index]);
|
||||||
|
unset($this->chunkTickList[$index]);
|
||||||
Cache::remove("world:" . $this->getId() . ":$index");
|
Cache::remove("world:" . $this->getId() . ":$index");
|
||||||
|
|
||||||
$this->timings->doChunkUnload->stopTiming();
|
$this->timings->doChunkUnload->stopTiming();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user