mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-20 12:44:01 +00:00
LevelProvider: added calculateChunkCount()
this will be used to provide progress information to the user during world conversion.
This commit is contained in:
parent
1bb9b3d3ab
commit
3509b26751
@ -111,4 +111,10 @@ interface LevelProvider{
|
|||||||
*/
|
*/
|
||||||
public function getAllChunks() : \Generator;
|
public function getAllChunks() : \Generator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of chunks in the provider. Used for world conversion time estimations.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function calculateChunkCount() : int;
|
||||||
}
|
}
|
||||||
|
@ -373,4 +373,14 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function calculateChunkCount() : int{
|
||||||
|
$count = 0;
|
||||||
|
foreach($this->db->getIterator() as $key => $_){
|
||||||
|
if(strlen($key) === 9 and substr($key, -1) === self::TAG_VERSION){
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,8 +208,8 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
$this->getRegion($regionX, $regionZ)->writeChunk($chunkX & 0x1f, $chunkZ & 0x1f, $this->serializeChunk($chunk));
|
$this->getRegion($regionX, $regionZ)->writeChunk($chunkX & 0x1f, $chunkZ & 0x1f, $this->serializeChunk($chunk));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllChunks() : \Generator{
|
private function createRegionIterator() : \RegexIterator{
|
||||||
$iterator = new \RegexIterator(
|
return new \RegexIterator(
|
||||||
new \FilesystemIterator(
|
new \FilesystemIterator(
|
||||||
$this->path . '/region/',
|
$this->path . '/region/',
|
||||||
\FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS
|
\FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS
|
||||||
@ -217,6 +217,10 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
'/\/r\.(-?\d+)\.(-?\d+)\.' . static::getRegionFileExtension() . '$/',
|
'/\/r\.(-?\d+)\.(-?\d+)\.' . static::getRegionFileExtension() . '$/',
|
||||||
\RegexIterator::GET_MATCH
|
\RegexIterator::GET_MATCH
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllChunks() : \Generator{
|
||||||
|
$iterator = $this->createRegionIterator();
|
||||||
|
|
||||||
foreach($iterator as $region){
|
foreach($iterator as $region){
|
||||||
$rX = ((int) $region[1]) << 5;
|
$rX = ((int) $region[1]) << 5;
|
||||||
@ -232,4 +236,13 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function calculateChunkCount() : int{
|
||||||
|
$count = 0;
|
||||||
|
foreach($this->createRegionIterator() as $region){
|
||||||
|
$this->loadRegion((int) $region[1], (int) $region[2]);
|
||||||
|
$count += $this->getRegion((int) $region[1], (int) $region[2])->calculateChunkCount();
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,4 +289,14 @@ class RegionLoader{
|
|||||||
public function getFilePath() : string{
|
public function getFilePath() : string{
|
||||||
return $this->filePath;
|
return $this->filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function calculateChunkCount() : int{
|
||||||
|
$count = 0;
|
||||||
|
for($i = 0; $i < 1024; ++$i){
|
||||||
|
if($this->isChunkGenerated($i)){
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user