From 06a0f169dd97122c4baacd22ebbe52782878d5a8 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 4 Jun 2013 18:45:30 +0200 Subject: [PATCH] Better auto-save, less resource and disk usage --- src/API/LevelAPI.php | 2 +- src/material/block/solid/Wood.php | 4 +++- src/pmf/Level.php | 11 ++++++++++- src/world/Level.php | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 1de55bd28..808a100f8 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -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; } diff --git a/src/material/block/solid/Wood.php b/src/material/block/solid/Wood.php index a87c3b360..1fe7b7abb 100644 --- a/src/material/block/solid/Wood.php +++ b/src/material/block/solid/Wood.php @@ -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]; } } \ No newline at end of file diff --git a/src/pmf/Level.php b/src/pmf/Level.php index 8294e573f..19df270ec 100644 --- a/src/pmf/Level.php +++ b/src/pmf/Level.php @@ -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(){ diff --git a/src/world/Level.php b/src/world/Level.php index 812b49888..630e0d9e7 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -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){