Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Possible fix for #1920
Browse files Browse the repository at this point in the history
  • Loading branch information
shoghicp committed Sep 22, 2014
1 parent d04e994 commit 3cc4afb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/pocketmine/level/generator/GenerationChunkManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public function getChunk($chunkX, $chunkZ){
if($chunk === null){
throw new \Exception("null chunk received");
}
$this->changes[$index] = $chunk;

return $chunk;
}
Expand All @@ -104,12 +103,17 @@ public function cleanChangedChunk($index){
}

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){
Expand Down Expand Up @@ -154,19 +158,18 @@ public function isChunkPopulated($chunkX, $chunkZ){
}

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){}
}

Expand Down
14 changes: 3 additions & 11 deletions src/pocketmine/level/generator/GenerationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class GenerationManager{
/** @var GenerationChunkManager[] */
protected $levels = [];

protected $generatedQueue = [];

/** @var array */
protected $requestQueue = [];

Expand Down Expand Up @@ -145,27 +143,22 @@ public function __construct(GenerationThread $thread, \Logger $logger, \ClassLoa
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);
$this->levels[$levelID]->cleanChangedChunk($index);
}
}

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();
}
}
}
Expand All @@ -174,7 +167,6 @@ protected function closeLevel($levelID){
if(!isset($this->levels[$levelID])){
$this->levels[$levelID]->shutdown();
unset($this->levels[$levelID]);
unset($this->generatedQueue[$levelID]);
}
}

Expand Down

0 comments on commit 3cc4afb

Please sign in to comment.