Moved light population to an async task when needed, improved empty chunks

This commit is contained in:
Shoghi Cervantes
2015-05-28 23:13:20 +02:00
parent 0f5f71e612
commit c578898aa4
7 changed files with 104 additions and 11 deletions

View File

@ -31,6 +31,7 @@ use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\IntArray;
use pocketmine\nbt\tag\Long;
use pocketmine\Player;
use pocketmine\utils\Binary;

View File

@ -164,12 +164,6 @@ abstract class BaseFullChunk implements FullChunk{
$this->isInit = true;
}
if(!$this->isLightPopulated() and $this->isPopulated()){
$this->recalculateHeightMap();
$this->populateSkyLight();
$this->setLightPopulated();
}
}
public function getX(){

View File

@ -109,7 +109,7 @@ class EmptyChunkSection implements ChunkSection{
}
final public function getBlockSkyLight($x, $y, $z){
return 0;
return 15;
}
final public function setBlockSkyLight($x, $y, $z, $level){

View File

@ -29,6 +29,9 @@ use pocketmine\utils\Binary;
class Chunk extends BaseFullChunk{
const DATA_LENGTH = 16384 * (2 + 1 + 1 + 1) + 256 + 1024;
protected $isLightPopulated = false;
protected $isPopulated = false;
protected $isGenerated = false;
@ -195,6 +198,20 @@ class Chunk extends BaseFullChunk{
return substr($this->blockLight, ($x << 10) + ($z << 6), 64);
}
/**
* @return bool
*/
public function isLightPopulated(){
return $this->isLightPopulated;
}
/**
* @param int $value
*/
public function setLightPopulated($value = 1){
$this->isLightPopulated = (bool) $value;
}
/**
* @return bool
*/
@ -350,7 +367,9 @@ class Chunk extends BaseFullChunk{
*/
public static function getEmptyChunk($chunkX, $chunkZ, LevelProvider $provider = null){
try{
return new Chunk($provider instanceof LevelProvider ? $provider : LevelDB::class, $chunkX, $chunkZ, str_repeat("\x00", 16384 * (2 + 1 + 1 + 1) + 256 + 1024));
$chunk = new Chunk($provider instanceof LevelProvider ? $provider : LevelDB::class, $chunkX, $chunkZ, str_repeat("\x00", self::DATA_LENGTH));
$chunk->skyLight = str_repeat("\xff", 16384);
return $chunk;
}catch(\Exception $e){
return null;
}

View File

@ -238,7 +238,7 @@ class Chunk extends BaseFullChunk{
}
public function setLightPopulated($value = 1){
$this->nbt->LightPopulated = new Byte("LightPopulated", $value);
$this->nbt->LightPopulated = new Byte("LightPopulated", $value ? 1 : 0);
$this->hasChanged = true;
}
@ -253,7 +253,7 @@ class Chunk extends BaseFullChunk{
* @param int $value
*/
public function setPopulated($value = 1){
$this->nbt->TerrainPopulated = new Byte("TerrainPopulated", (int) $value);
$this->nbt->TerrainPopulated = new Byte("TerrainPopulated", $value ? 1 : 0);
$this->hasChanged = true;
}
@ -428,7 +428,7 @@ class Chunk extends BaseFullChunk{
$chunk->data = str_repeat("\x00", 16384);
$chunk->blocks = $chunk->data . $chunk->data;
$chunk->skyLight = $chunk->data;
$chunk->skyLight = str_repeat("\xff", 16384);
$chunk->blockLight = $chunk->data;
$chunk->heightMap = array_fill(0, 256, 0);