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); $timeu = microtime(true);
foreach($blockUpdates->getAll() as $bupdate){ 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; return true;
} }

View File

@ -35,8 +35,10 @@ class WoodBlock extends SolidBlock{
WoodBlock::OAK => "Oak Wood", WoodBlock::OAK => "Oak Wood",
WoodBlock::SPRUCE => "Spruce Wood", WoodBlock::SPRUCE => "Spruce Wood",
WoodBlock::BIRCH => "Birch 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; return false;
} }
$this->chunks[$index] = array(); $this->chunks[$index] = array();
$this->chunkChange[$index] = array(); $this->chunkChange[$index] = array(-1 => false);
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){ for($Y = 0; $Y < $this->levelData["height"]; ++$Y){
$t = 1 << $Y; $t = 1 << $Y;
if(($info[0] & $t) === $t){ if(($info[0] & $t) === $t){
@ -267,6 +267,7 @@ class PMFLevel extends PMF{
} }
$index = $this->getIndex($X, $Z); $index = $this->getIndex($X, $Z);
$this->chunks[$index][$Y] = str_repeat("\x00", 8192); $this->chunks[$index][$Y] = str_repeat("\x00", 8192);
$this->chunkChange[$index][-1] = true;
$this->chunkChange[$index][$Y] = 8192; $this->chunkChange[$index][$Y] = 8192;
$this->locationTable[$index][0] |= 1 << $Y; $this->locationTable[$index][0] |= 1 << $Y;
return true; return true;
@ -292,6 +293,7 @@ class PMFLevel extends PMF{
} }
$index = $this->getIndex($X, $Z); $index = $this->getIndex($X, $Z);
$this->chunks[$index][$Y] = (string) $data; $this->chunks[$index][$Y] = (string) $data;
$this->chunkChange[$index][-1] = true;
$this->chunkChange[$index][$Y] = 8192; $this->chunkChange[$index][$Y] = 8192;
$this->locationTable[$index][0] |= 1 << $Y; $this->locationTable[$index][0] |= 1 << $Y;
return true; return true;
@ -365,6 +367,7 @@ class PMFLevel extends PMF{
}else{ }else{
++$this->chunkChange[$index][$Y]; ++$this->chunkChange[$index][$Y];
} }
$this->chunkChange[$index][-1] = true;
return true; return true;
} }
return false; return false;
@ -377,6 +380,10 @@ class PMFLevel extends PMF{
return false; return false;
} }
$index = $this->getIndex($X, $Z); $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"); $chunk = @gzopen($this->getChunkPath($X, $Z), "wb9");
$bitmap = 0; $bitmap = 0;
for($Y = 0; $Y < $this->levelData["height"]; ++$Y){ for($Y = 0; $Y < $this->levelData["height"]; ++$Y){
@ -388,9 +395,11 @@ class PMFLevel extends PMF{
} }
$this->chunkChange[$index][$Y] = 0; $this->chunkChange[$index][$Y] = 0;
} }
$this->chunkChange[$index][-1] = false;
$this->locationTable[$index][0] = $bitmap; $this->locationTable[$index][0] = $bitmap;
$this->seek($this->payloadOffset + ($index << 1)); $this->seek($this->payloadOffset + ($index << 1));
$this->write(Utils::writeShort($this->locationTable[$index][0])); $this->write(Utils::writeShort($this->locationTable[$index][0]));
return true;
} }
public function doSaveRound(){ public function doSaveRound(){

View File

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