mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Possible fix for #1920
This commit is contained in:
parent
d04e994d1b
commit
3cc4afbcd6
@ -83,7 +83,6 @@ class GenerationChunkManager implements ChunkManager{
|
||||
if($chunk === null){
|
||||
throw new \Exception("null chunk received");
|
||||
}
|
||||
$this->changes[$index] = $chunk;
|
||||
|
||||
return $chunk;
|
||||
}
|
||||
@ -104,12 +103,17 @@ class GenerationChunkManager implements ChunkManager{
|
||||
}
|
||||
|
||||
public function doGarbageCollection(){
|
||||
$count = 0;
|
||||
|
||||
foreach($this->chunks as $index => $chunk){
|
||||
if(!isset($this->changes[$index]) or $chunk->isPopulated()){
|
||||
unset($this->chunks[$index]);
|
||||
unset($this->changes[$index]);
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function generateChunk($chunkX, $chunkZ){
|
||||
@ -154,19 +158,18 @@ class GenerationChunkManager implements ChunkManager{
|
||||
}
|
||||
|
||||
public function setChunkGenerated($chunkX, $chunkZ){
|
||||
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||
$chunk->setGenerated(true);
|
||||
try{
|
||||
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||
$chunk->setGenerated(true);
|
||||
$this->changes["$chunkX:$chunkZ"] = $chunk;
|
||||
}catch(\Exception $e){}
|
||||
}
|
||||
|
||||
public function setChunkPopulated($chunkX, $chunkZ){
|
||||
|
||||
try{
|
||||
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||
$chunk->setPopulated(true);
|
||||
$this->changes["$chunkX:$chunkZ"] = $chunk;
|
||||
}catch(\Exception $e){}
|
||||
}
|
||||
|
||||
|
@ -100,8 +100,6 @@ class GenerationManager{
|
||||
/** @var GenerationChunkManager[] */
|
||||
protected $levels = [];
|
||||
|
||||
protected $generatedQueue = [];
|
||||
|
||||
/** @var array */
|
||||
protected $requestQueue = [];
|
||||
|
||||
@ -145,15 +143,13 @@ class GenerationManager{
|
||||
protected function openLevel($levelID, $seed, $class, array $options){
|
||||
if(!isset($this->levels[$levelID])){
|
||||
$this->levels[$levelID] = new GenerationChunkManager($this, $levelID, $seed, $class, $options);
|
||||
$this->generatedQueue[$levelID] = [];
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateChunk($levelID, $chunkX, $chunkZ){
|
||||
if(isset($this->levels[$levelID]) and !isset($this->generatedQueue[$levelID][$index = Level::chunkHash($chunkX, $chunkZ)])){
|
||||
if(isset($this->levels[$levelID])){
|
||||
$this->levels[$levelID]->populateChunk($chunkX, $chunkZ); //Request population directly
|
||||
if(isset($this->levels[$levelID])){
|
||||
$this->generatedQueue[$levelID][$index] = true;
|
||||
foreach($this->levels[$levelID]->getChangedChunks() as $index => $chunk){
|
||||
if($chunk->isPopulated()){
|
||||
$this->sendChunk($levelID, $chunk);
|
||||
@ -161,11 +157,8 @@ class GenerationManager{
|
||||
}
|
||||
}
|
||||
|
||||
if(count($this->generatedQueue[$levelID]) > 4){
|
||||
$this->levels[$levelID]->doGarbageCollection();
|
||||
$this->generatedQueue[$levelID] = [];
|
||||
$this->levels[$levelID]->cleanChangedChunks();
|
||||
}
|
||||
$this->levels[$levelID]->doGarbageCollection();
|
||||
$this->levels[$levelID]->cleanChangedChunks();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,7 +167,6 @@ class GenerationManager{
|
||||
if(!isset($this->levels[$levelID])){
|
||||
$this->levels[$levelID]->shutdown();
|
||||
unset($this->levels[$levelID]);
|
||||
unset($this->generatedQueue[$levelID]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user