mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 15:35:52 +00:00
World: Avoid unnecessary Vector3 usages in neighbour block update scheduling
The old code was allocating 6 Vector3s which were all immediately discarded. In addition, we didn't need to take the performance hit of reading Vector3 properties when we could have just passed integers directly. The real performance difference of this is likely to be close to zero, but it's still worth doing.
This commit is contained in:
parent
f868c1d8c6
commit
73659318f6
@ -1455,9 +1455,9 @@ class World implements ChunkManager{
|
||||
$this->scheduledBlockUpdateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), $delay + $this->server->getTick());
|
||||
}
|
||||
|
||||
private function tryAddToNeighbourUpdateQueue(Vector3 $pos) : void{
|
||||
if($this->isInWorld($pos->x, $pos->y, $pos->z)){
|
||||
$hash = World::blockHash($pos->x, $pos->y, $pos->z);
|
||||
private function tryAddToNeighbourUpdateQueue(int $x, int $y, int $z) : void{
|
||||
if($this->isInWorld($x, $y, $z)){
|
||||
$hash = World::blockHash($x, $y, $z);
|
||||
if(!isset($this->neighbourBlockUpdateQueueIndex[$hash])){
|
||||
$this->neighbourBlockUpdateQueue->enqueue($hash);
|
||||
$this->neighbourBlockUpdateQueueIndex[$hash] = true;
|
||||
@ -1465,17 +1465,28 @@ class World implements ChunkManager{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identical to {@link World::notifyNeighbourBlockUpdate()}, but without the Vector3 requirement. We don't want or
|
||||
* need Vector3 in the places where this is called.
|
||||
*
|
||||
* TODO: make this the primary method in PM6
|
||||
*/
|
||||
private function internalNotifyNeighbourBlockUpdate(int $x, int $y, int $z) : void{
|
||||
$this->tryAddToNeighbourUpdateQueue($x, $y, $z);
|
||||
foreach(Facing::OFFSET as [$dx, $dy, $dz]){
|
||||
$this->tryAddToNeighbourUpdateQueue($x + $dx, $y + $dy, $z + $dz);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the blocks at and around the position that the block at the position may have changed.
|
||||
* This will cause onNearbyBlockChange() to be called for these blocks.
|
||||
* TODO: Accept plain integers in PM6 - the Vector3 requirement is an unnecessary inconvenience
|
||||
*
|
||||
* @see Block::onNearbyBlockChange()
|
||||
*/
|
||||
public function notifyNeighbourBlockUpdate(Vector3 $pos) : void{
|
||||
$this->tryAddToNeighbourUpdateQueue($pos);
|
||||
foreach($pos->sides() as $side){
|
||||
$this->tryAddToNeighbourUpdateQueue($side);
|
||||
}
|
||||
$this->internalNotifyNeighbourBlockUpdate($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1943,7 +1954,7 @@ class World implements ChunkManager{
|
||||
|
||||
if($update){
|
||||
$this->updateAllLight($x, $y, $z);
|
||||
$this->notifyNeighbourBlockUpdate($pos);
|
||||
$this->internalNotifyNeighbourBlockUpdate($x, $y, $z);
|
||||
}
|
||||
|
||||
$this->timings->setBlock->stopTiming();
|
||||
|
Loading…
x
Reference in New Issue
Block a user