From 474091c0138f07029ec21959701ae6cd36ea2d10 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 26 Sep 2014 16:55:34 +0200 Subject: [PATCH] Improved Level block update scheduling for repeated updates --- src/pocketmine/level/Level.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 61a70471e..78ca1e856 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -157,6 +157,7 @@ class Level implements ChunkManager, Metadatable{ /** @var ReversePriorityQueue */ private $updateQueue; + private $updateQueueIndex = []; /** @var Player[][] */ private $chunkSendQueue = []; @@ -508,6 +509,7 @@ class Level implements ChunkManager, Metadatable{ $this->timings->doTickPending->startTiming(); while($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick){ $block = $this->getBlock($this->updateQueue->extract()["data"]); + unset($this->updateQueueIndex["{$block->x}:{$block->y}:{$block->z}"]); $block->onUpdate(self::BLOCK_UPDATE_SCHEDULED); } $this->timings->doTickPending->stopTiming(); @@ -698,6 +700,11 @@ class Level implements ChunkManager, Metadatable{ * @param int $delay */ public function scheduleUpdate(Vector3 $pos, $delay){ + $index = "{$pos->x}:{$pos->y}:{$pos->z}"; + if(isset($this->updateQueueIndex[$index]) and $this->updateQueueIndex[$index] <= $delay){ + return; + } + $this->updateQueueIndex[$index] = $delay; $this->updateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick()); }