mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Improved Level block update scheduling for repeated updates
This commit is contained in:
parent
666e5553c2
commit
474091c013
@ -157,6 +157,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
/** @var ReversePriorityQueue */
|
/** @var ReversePriorityQueue */
|
||||||
private $updateQueue;
|
private $updateQueue;
|
||||||
|
private $updateQueueIndex = [];
|
||||||
|
|
||||||
/** @var Player[][] */
|
/** @var Player[][] */
|
||||||
private $chunkSendQueue = [];
|
private $chunkSendQueue = [];
|
||||||
@ -508,6 +509,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->timings->doTickPending->startTiming();
|
$this->timings->doTickPending->startTiming();
|
||||||
while($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick){
|
while($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick){
|
||||||
$block = $this->getBlock($this->updateQueue->extract()["data"]);
|
$block = $this->getBlock($this->updateQueue->extract()["data"]);
|
||||||
|
unset($this->updateQueueIndex["{$block->x}:{$block->y}:{$block->z}"]);
|
||||||
$block->onUpdate(self::BLOCK_UPDATE_SCHEDULED);
|
$block->onUpdate(self::BLOCK_UPDATE_SCHEDULED);
|
||||||
}
|
}
|
||||||
$this->timings->doTickPending->stopTiming();
|
$this->timings->doTickPending->stopTiming();
|
||||||
@ -698,6 +700,11 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
* @param int $delay
|
* @param int $delay
|
||||||
*/
|
*/
|
||||||
public function scheduleUpdate(Vector3 $pos, $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());
|
$this->updateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user