From 765d4f30c74c739bcb7443395c7310eef56f5393 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 30 Jul 2014 17:30:22 +0200 Subject: [PATCH] Added caching to non-converted network chunks --- src/pocketmine/level/Level.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index f80021cbd..2fb978586 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1414,6 +1414,11 @@ class Level implements ChunkManager, Metadatable{ } protected function getNetworkChunk($x, $z){ + $index = Level::chunkHash($x, $z); + if(ADVANCED_CACHE == true and ($cache = Cache::get("world:".$this->getID().":" . $index)) !== false){ + return $cache; + } + $chunk = $this->getChunkAt($x, $z, true); $tiles = ""; $nbt = new NBT(NBT::LITTLE_ENDIAN); @@ -1429,7 +1434,12 @@ class Level implements ChunkManager, Metadatable{ $biomeColors .= Binary::writeInt($color); } - return zlib_encode(Binary::writeLInt($x) . Binary::writeLInt($z) . $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . $chunk->getBiomeIdArray() . $biomeColors . $tiles, ZLIB_ENCODING_DEFLATE, Level::$COMPRESSION_LEVEL); + $encoded = zlib_encode(Binary::writeLInt($x) . Binary::writeLInt($z) . $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . $chunk->getBiomeIdArray() . $biomeColors . $tiles, ZLIB_ENCODING_DEFLATE, Level::$COMPRESSION_LEVEL); + if(ADVANCED_CACHE == true){ + Cache::add("world:".$this->getID().":" . $index, $encoded); + } + + return $encoded; } protected function processChunkRequest(){