Tuned generator to use a better way to process chunks, closes #1807 #1794 #1740 #1741 #1685

This commit is contained in:
Shoghi Cervantes 2014-07-31 19:27:01 +02:00
parent 95b5979351
commit cb4a970631
10 changed files with 43 additions and 41 deletions

View File

@ -520,7 +520,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return $this->spawnPosition; return $this->spawnPosition;
}else{ }else{
$level = $this->server->getDefaultLevel(); $level = $this->server->getDefaultLevel();
return $level->getSpawn(); return $level->getSafeSpawn();
} }
} }
@ -1740,7 +1740,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->craftingType = 0; $this->craftingType = 0;
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->spawnPosition)); $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn()));
$this->teleport($ev->getRespawnPosition()); $this->teleport($ev->getRespawnPosition());
//$this->entity->fire = 0; //$this->entity->fire = 0;

View File

@ -1635,9 +1635,10 @@ class Level implements ChunkManager, Metadatable{
* Sets the spawnpoint * Sets the spawnpoint
* *
* @param Vector3 $pos * @param Vector3 $pos
* @deprecated
*/ */
public function setSpawn(Vector3 $pos){ public function setSpawn(Vector3 $pos){
$this->provider->setSpawn($pos); $this->setSpawnLocation($pos);
} }
/** /**

View File

@ -67,24 +67,16 @@ class Anvil extends McRegion{
return new ChunkRequestTask($this, $this->getLevel()->getID(), $x, $z); return new ChunkRequestTask($this, $this->getLevel()->getID(), $x, $z);
} }
public function loadChunk($chunkX, $chunkZ, $create = false){ /**
$index = Level::chunkHash($chunkX, $chunkZ); * @param $x
if(isset($this->chunks[$index])){ * @param $z
return true; *
} * @return RegionLoader
$regionX = $regionZ = null; */
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ); protected function getRegion($x, $z){
$this->loadRegion($regionX, $regionZ); $index = $x . ":" . $z;
$this->level->timings->syncChunkLoadDataTimer->startTiming(); return isset($this->regions[$index]) ? $this->regions[$index] : null;
$chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded
$this->level->timings->syncChunkLoadDataTimer->stopTiming();
if($chunk instanceof Chunk){
$this->chunks[$index] = $chunk;
}else{
return false;
}
} }
/** /**
@ -112,10 +104,9 @@ class Anvil extends McRegion{
$region->removeChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32); $region->removeChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32);
$this->loadChunk($chunkX, $chunkZ); $this->loadChunk($chunkX, $chunkZ);
}else{ }else{
$newChunk = clone $chunk; $chunk->setX($chunkX);
$newChunk->setX($chunkX); $chunk->setZ($chunkZ);
$newChunk->setZ($chunkZ); $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $newChunk;
//$this->saveChunk($chunkX, $chunkZ); //$this->saveChunk($chunkX, $chunkZ);
} }
} }

View File

@ -29,6 +29,7 @@ use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\ByteArray; use pocketmine\nbt\tag\ByteArray;
use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\IntArray; use pocketmine\nbt\tag\IntArray;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
@ -93,6 +94,8 @@ class Chunk extends BaseChunk{
} }
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $sections, $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $sections, $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
unset($this->nbt->Sections);
} }
/** /**
@ -151,6 +154,9 @@ class Chunk extends BaseChunk{
public function toBinary(){ public function toBinary(){
$nbt = $this->getNBT(); $nbt = $this->getNBT();
$nbt->xPos = new Int("xPos", $this->x);
$nbt->zPos = new Int("zPos", $this->z);
$nbt->Sections = new Enum("Sections", []); $nbt->Sections = new Enum("Sections", []);
$nbt->Sections->setTagType(NBT::TAG_Compound); $nbt->Sections->setTagType(NBT::TAG_Compound);
foreach($this->getSections() as $section){ foreach($this->getSections() as $section){

View File

@ -22,7 +22,6 @@
namespace pocketmine\level\format\anvil; namespace pocketmine\level\format\anvil;
use pocketmine\level\format\LevelProvider; use pocketmine\level\format\LevelProvider;
use pocketmine\level\format\mcregion\Chunk;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\ByteArray; use pocketmine\nbt\tag\ByteArray;
@ -31,7 +30,6 @@ use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\IntArray; use pocketmine\nbt\tag\IntArray;
use pocketmine\nbt\tag\Long; use pocketmine\nbt\tag\Long;
use pocketmine\Player;
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
@ -130,8 +128,4 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
$this->saveChunk($x, $z, $chunkData); $this->saveChunk($x, $z, $chunkData);
} }
public function writeChunk(Chunk $chunk){
$this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunk->toBinary());
}
} }

View File

@ -28,6 +28,7 @@ use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\ByteArray; use pocketmine\nbt\tag\ByteArray;
use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\IntArray; use pocketmine\nbt\tag\IntArray;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
@ -70,6 +71,10 @@ class Chunk extends BaseFullChunk{
} }
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt["Blocks"], $this->nbt["Data"], $this->nbt["SkyLight"], $this->nbt["BlockLight"], $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt["Blocks"], $this->nbt["Data"], $this->nbt["SkyLight"], $this->nbt["BlockLight"], $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
unset($this->nbt->Blocks);
unset($this->nbt->Data);
unset($this->nbt->SkyLight);
unset($this->nbt->BlockLight);
} }
public function getBlockId($x, $y, $z){ public function getBlockId($x, $y, $z){
@ -245,6 +250,9 @@ class Chunk extends BaseFullChunk{
public function toBinary(){ public function toBinary(){
$nbt = $this->getNBT(); $nbt = $this->getNBT();
$nbt->xPos = new Int("xPos", $this->x);
$nbt->zPos = new Int("zPos", $this->z);
$nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray()); $nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray());
$nbt->Data = new ByteArray("Data", $this->getBlockDataArray()); $nbt->Data = new ByteArray("Data", $this->getBlockDataArray());
$nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray()); $nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray());

View File

@ -142,12 +142,11 @@ class McRegion extends BaseLevelProvider{
$regionX = $regionZ = null; $regionX = $regionZ = null;
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ); self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
$this->loadRegion($regionX, $regionZ); $this->loadRegion($regionX, $regionZ);
$this->level->timings->syncChunkLoadDataTimer->startTiming(); $this->level->timings->syncChunkLoadDataTimer->startTiming();
$chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded $chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded
$this->level->timings->syncChunkLoadDataTimer->stopTiming(); $this->level->timings->syncChunkLoadDataTimer->stopTiming();
if($chunk instanceof Chunk){ if($chunk instanceof FullChunk){
$this->chunks[$index] = $chunk; $this->chunks[$index] = $chunk;
}else{ }else{
return false; return false;
@ -156,7 +155,7 @@ class McRegion extends BaseLevelProvider{
public function unloadChunk($x, $z, $safe = true){ public function unloadChunk($x, $z, $safe = true){
$chunk = $this->getChunk($x, $z, false); $chunk = $this->getChunk($x, $z, false);
if($chunk instanceof Chunk){ if($chunk instanceof FullChunk){
if($safe === true and $this->isChunkLoaded($x, $z)){ if($safe === true and $this->isChunkLoaded($x, $z)){
foreach($chunk->getEntities() as $entity){ foreach($chunk->getEntities() as $entity){
if($entity instanceof Player){ if($entity instanceof Player){
@ -233,10 +232,9 @@ class McRegion extends BaseLevelProvider{
$region->removeChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32); $region->removeChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32);
$this->loadChunk($chunkX, $chunkZ); $this->loadChunk($chunkX, $chunkZ);
}else{ }else{
$newChunk = clone $chunk; $chunk->setX($chunkX);
$newChunk->setX($chunkX); $chunk->setZ($chunkZ);
$newChunk->setZ($chunkZ); $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $newChunk;
//$this->saveChunk($chunkX, $chunkZ); //$this->saveChunk($chunkX, $chunkZ);
} }
} }
@ -255,7 +253,7 @@ class McRegion extends BaseLevelProvider{
public function isChunkPopulated($chunkX, $chunkZ){ public function isChunkPopulated($chunkX, $chunkZ){
$chunk = $this->getChunk($chunkX, $chunkZ); $chunk = $this->getChunk($chunkX, $chunkZ);
if($chunk instanceof Chunk){ if($chunk instanceof FullChunk){
return $chunk->isPopulated(); return $chunk->isPopulated();
}else{ }else{
return false; return false;

View File

@ -21,6 +21,7 @@
namespace pocketmine\level\format\mcregion; namespace pocketmine\level\format\mcregion;
use pocketmine\level\format\FullChunk;
use pocketmine\level\format\LevelProvider; use pocketmine\level\format\LevelProvider;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Byte;
@ -180,7 +181,7 @@ class RegionLoader{
$this->locationTable[$index][1] = 0; $this->locationTable[$index][1] = 0;
} }
public function writeChunk(Chunk $chunk){ public function writeChunk(FullChunk $chunk){
$this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunk->toBinary()); $this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunk->toBinary());
} }

View File

@ -122,6 +122,7 @@ class Flat extends Generator{
} }
} }
preg_match_all('#(([0-9a-z_]{1,})\(?([0-9a-z_ =:]{0,})\)?),?#', $options, $matches); preg_match_all('#(([0-9a-z_]{1,})\(?([0-9a-z_ =:]{0,})\)?),?#', $options, $matches);
foreach($matches[2] as $i => $option){ foreach($matches[2] as $i => $option){
$params = true; $params = true;

View File

@ -85,6 +85,7 @@ class GenerationChunkManager implements ChunkManager{
$index = Level::chunkHash($chunkX, $chunkZ); $index = Level::chunkHash($chunkX, $chunkZ);
$chunk = !isset($this->chunks[$index]) ? $this->requestChunk($chunkX, $chunkZ) : $this->chunks[$index]; $chunk = !isset($this->chunks[$index]) ? $this->requestChunk($chunkX, $chunkZ) : $this->chunks[$index];
$this->unloadQueue->detach($chunk); $this->unloadQueue->detach($chunk);
$this->changes[$index] = $chunk;
return $chunk; return $chunk;
} }
@ -112,6 +113,9 @@ class GenerationChunkManager implements ChunkManager{
} }
foreach($this->chunks as $chunk){ foreach($this->chunks as $chunk){
if(isset($this->changes[$index = Level::chunkHash($chunk->getX(), $chunk->getZ())])){
continue;
}
$this->unloadQueue->attach($chunk); $this->unloadQueue->attach($chunk);
} }
} }
@ -150,13 +154,11 @@ class GenerationChunkManager implements ChunkManager{
public function setChunkGenerated($chunkX, $chunkZ){ public function setChunkGenerated($chunkX, $chunkZ){
$chunk = $this->getChunk($chunkX, $chunkZ); $chunk = $this->getChunk($chunkX, $chunkZ);
$chunk->setGenerated(true); $chunk->setGenerated(true);
$this->changes[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
} }
public function setChunkPopulated($chunkX, $chunkZ){ public function setChunkPopulated($chunkX, $chunkZ){
$chunk = $this->getChunk($chunkX, $chunkZ); $chunk = $this->getChunk($chunkX, $chunkZ);
$chunk->setPopulated(true); $chunk->setPopulated(true);
$this->changes[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
} }
protected function requestChunk($chunkX, $chunkZ){ protected function requestChunk($chunkX, $chunkZ){