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