mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 19:37:17 +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 */
|
||||
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());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user