mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Removed SimpleChunk from generator, core, use binary representation of chunks
This commit is contained in:
@ -22,7 +22,7 @@
|
||||
namespace pocketmine\level\generator;
|
||||
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\level\format\SimpleChunk;
|
||||
use pocketmine\level\format\FullChunk;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
@ -30,10 +30,10 @@ class GenerationChunkManager implements ChunkManager{
|
||||
|
||||
protected $levelID;
|
||||
|
||||
/** @var SimpleChunk[] */
|
||||
/** @var FullChunk[] */
|
||||
protected $chunks = [];
|
||||
|
||||
/** @var \SplObjectStorage<SimpleChunk> */
|
||||
/** @var \SplObjectStorage<FullChunk> */
|
||||
protected $unloadQueue;
|
||||
|
||||
/** @var Generator */
|
||||
@ -44,6 +44,8 @@ class GenerationChunkManager implements ChunkManager{
|
||||
|
||||
protected $seed;
|
||||
|
||||
protected $changes = [];
|
||||
|
||||
public function __construct(GenerationManager $manager, $levelID, $seed, $class, array $options){
|
||||
if(!is_subclass_of($class, "pocketmine\\level\\generator\\Generator")){
|
||||
throw new \Exception("Class is not a subclass of Generator");
|
||||
@ -77,7 +79,7 @@ class GenerationChunkManager implements ChunkManager{
|
||||
* @param $chunkX
|
||||
* @param $chunkZ
|
||||
*
|
||||
* @return SimpleChunk
|
||||
* @return FullChunk
|
||||
*/
|
||||
public function getChunk($chunkX, $chunkZ){
|
||||
$index = Level::chunkHash($chunkX, $chunkZ);
|
||||
@ -87,28 +89,24 @@ class GenerationChunkManager implements ChunkManager{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $set
|
||||
*
|
||||
* @return SimpleChunk[]
|
||||
* @return FullChunk[]
|
||||
*/
|
||||
public function getChangedChunks($set = true){
|
||||
$changed = [];
|
||||
foreach($this->chunks as $chunk){
|
||||
if($chunk->hasChanged($set)){
|
||||
$changed[] = $chunk;
|
||||
}
|
||||
}
|
||||
public function getChangedChunks(){
|
||||
return $this->changes;
|
||||
}
|
||||
|
||||
return $changed;
|
||||
public function cleanChangedChunks(){
|
||||
$this->changes = [];
|
||||
}
|
||||
|
||||
public function doGarbageCollection(){
|
||||
if($this->unloadQueue->count() > 0){
|
||||
/** @var SimpleChunk $chunk */
|
||||
/** @var FullChunk $chunk */
|
||||
foreach($this->unloadQueue as $chunk){
|
||||
if(!$chunk->hasChanged(false)){
|
||||
unset($this->chunks[Level::chunkHash($chunk->getX(), $chunk->getZ())]);
|
||||
if(isset($this->changes[$index = Level::chunkHash($chunk->getX(), $chunk->getZ())])){
|
||||
continue;
|
||||
}
|
||||
unset($this->chunks[$index]);
|
||||
$this->unloadQueue->detach($chunk);
|
||||
}
|
||||
}
|
||||
@ -119,7 +117,7 @@ class GenerationChunkManager implements ChunkManager{
|
||||
}
|
||||
|
||||
public function generateChunk($chunkX, $chunkZ){
|
||||
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = new SimpleChunk($chunkX, $chunkZ, 0);
|
||||
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $this->requestChunk($chunkX, $chunkZ);
|
||||
$this->generator->generateChunk($chunkX, $chunkZ);
|
||||
$this->setChunkGenerated($chunkX, $chunkZ);
|
||||
}
|
||||
@ -150,11 +148,15 @@ class GenerationChunkManager implements ChunkManager{
|
||||
}
|
||||
|
||||
public function setChunkGenerated($chunkX, $chunkZ){
|
||||
$this->getChunk($chunkX, $chunkZ)->setGenerated(true);
|
||||
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||
$chunk->setGenerated(true);
|
||||
$this->changes[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
|
||||
}
|
||||
|
||||
public function setChunkPopulated($chunkX, $chunkZ){
|
||||
$this->getChunk($chunkX, $chunkZ)->setPopulated(true);
|
||||
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||
$chunk->setPopulated(true);
|
||||
$this->changes[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
|
||||
}
|
||||
|
||||
protected function requestChunk($chunkX, $chunkZ){
|
||||
@ -166,11 +168,12 @@ class GenerationChunkManager implements ChunkManager{
|
||||
/**
|
||||
* @param int $chunkX
|
||||
* @param int $chunkZ
|
||||
* @param SimpleChunk $chunk
|
||||
* @param FullChunk $chunk
|
||||
*/
|
||||
public function setChunk($chunkX, $chunkZ, SimpleChunk $chunk){
|
||||
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
|
||||
if($chunk->isGenerated() and $chunk->isPopulated()){
|
||||
public function setChunk($chunkX, $chunkZ, FullChunk $chunk){
|
||||
$this->chunks[$index = Level::chunkHash($chunkX, $chunkZ)] = $chunk;
|
||||
$this->changes[$index] = $chunk;
|
||||
if($chunk->isPopulated()){
|
||||
//TODO: Queue to be sent
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user