Better auto-save, less resource and disk usage

This commit is contained in:
Shoghi Cervantes 2013-06-04 18:45:30 +02:00
parent f12620f376
commit 06a0f169dd
4 changed files with 15 additions and 4 deletions

View File

@ -200,7 +200,7 @@ class LevelAPI{
$timeu = microtime(true);
foreach($blockUpdates->getAll() as $bupdate){
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), $bupdate["delay"], (int) $bupdate["type"]);
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
}
return true;
}

View File

@ -35,8 +35,10 @@ class WoodBlock extends SolidBlock{
WoodBlock::OAK => "Oak Wood",
WoodBlock::SPRUCE => "Spruce Wood",
WoodBlock::BIRCH => "Birch Wood",
3 => "",
);
$this->name = $names[$this->meta & 0x03];
$this->meta &= 0x03;
$this->name = $names[$this->meta];
}
}

View File

@ -211,7 +211,7 @@ class PMFLevel extends PMF{
return false;
}
$this->chunks[$index] = array();
$this->chunkChange[$index] = array();
$this->chunkChange[$index] = array(-1 => false);
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){
$t = 1 << $Y;
if(($info[0] & $t) === $t){
@ -267,6 +267,7 @@ class PMFLevel extends PMF{
}
$index = $this->getIndex($X, $Z);
$this->chunks[$index][$Y] = str_repeat("\x00", 8192);
$this->chunkChange[$index][-1] = true;
$this->chunkChange[$index][$Y] = 8192;
$this->locationTable[$index][0] |= 1 << $Y;
return true;
@ -292,6 +293,7 @@ class PMFLevel extends PMF{
}
$index = $this->getIndex($X, $Z);
$this->chunks[$index][$Y] = (string) $data;
$this->chunkChange[$index][-1] = true;
$this->chunkChange[$index][$Y] = 8192;
$this->locationTable[$index][0] |= 1 << $Y;
return true;
@ -365,6 +367,7 @@ class PMFLevel extends PMF{
}else{
++$this->chunkChange[$index][$Y];
}
$this->chunkChange[$index][-1] = true;
return true;
}
return false;
@ -377,6 +380,10 @@ class PMFLevel extends PMF{
return false;
}
$index = $this->getIndex($X, $Z);
if(!isset($this->chunkChange[$index]) or $this->chunkChange[$index][-1] === false){//No changes in chunk
return true;
}
$chunk = @gzopen($this->getChunkPath($X, $Z), "wb9");
$bitmap = 0;
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){
@ -388,9 +395,11 @@ class PMFLevel extends PMF{
}
$this->chunkChange[$index][$Y] = 0;
}
$this->chunkChange[$index][-1] = false;
$this->locationTable[$index][0] = $bitmap;
$this->seek($this->payloadOffset + ($index << 1));
$this->write(Utils::writeShort($this->locationTable[$index][0]));
return true;
}
public function doSaveRound(){

View File

@ -251,7 +251,7 @@ class Level{
$this->level->setData("time", (int) $this->time);
$this->level->doSaveRound();
$this->level->saveData();
$this->nextSave = microtime(true) + 90;
$this->nextSave = microtime(true) + 45;
}
public function getBlock(Vector3 $pos){