mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 15:05:33 +00:00
Minor performance improvement to explosions
This improves calculation time by 20-25% per explosion on flat terrain.
This commit is contained in:
parent
eeedcf7332
commit
cd02f1e4be
@ -58,6 +58,8 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
public static $transparent = null;
|
public static $transparent = null;
|
||||||
/** @var \SplFixedArray<bool> */
|
/** @var \SplFixedArray<bool> */
|
||||||
public static $diffusesSkyLight = null;
|
public static $diffusesSkyLight = null;
|
||||||
|
/** @var \SplFixedArray */
|
||||||
|
public static $blastResistance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the block factory. By default this is called only once on server start, however you may wish to use
|
* Initializes the block factory. By default this is called only once on server start, however you may wish to use
|
||||||
@ -75,6 +77,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
self::$hardness = new \SplFixedArray(256);
|
self::$hardness = new \SplFixedArray(256);
|
||||||
self::$transparent = new \SplFixedArray(256);
|
self::$transparent = new \SplFixedArray(256);
|
||||||
self::$diffusesSkyLight = new \SplFixedArray(256);
|
self::$diffusesSkyLight = new \SplFixedArray(256);
|
||||||
|
self::$blastResistance = new \SplFixedArray(256);
|
||||||
|
|
||||||
self::registerBlock(new Air());
|
self::registerBlock(new Air());
|
||||||
self::registerBlock(new Stone());
|
self::registerBlock(new Stone());
|
||||||
@ -366,6 +369,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
self::$light[$id] = $block->getLightLevel();
|
self::$light[$id] = $block->getLightLevel();
|
||||||
self::$lightFilter[$id] = $block->getLightFilter() + 1; //opacity plus 1 standard light filter
|
self::$lightFilter[$id] = $block->getLightFilter() + 1; //opacity plus 1 standard light filter
|
||||||
self::$diffusesSkyLight[$id] = $block->diffusesSkyLight();
|
self::$diffusesSkyLight[$id] = $block->diffusesSkyLight();
|
||||||
|
self::$blastResistance[$id] = $block->getBlastResistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,23 +89,27 @@ class Explosion{
|
|||||||
$vBlock->x = $pointerX >= $x ? $x : $x - 1;
|
$vBlock->x = $pointerX >= $x ? $x : $x - 1;
|
||||||
$vBlock->y = $pointerY >= $y ? $y : $y - 1;
|
$vBlock->y = $pointerY >= $y ? $y : $y - 1;
|
||||||
$vBlock->z = $pointerZ >= $z ? $z : $z - 1;
|
$vBlock->z = $pointerZ >= $z ? $z : $z - 1;
|
||||||
|
|
||||||
if(!$this->level->isInWorld($vBlock->x, $vBlock->y, $vBlock->z)){
|
if(!$this->level->isInWorld($vBlock->x, $vBlock->y, $vBlock->z)){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$block = $this->level->getBlock($vBlock);
|
|
||||||
|
|
||||||
if($block->getId() !== 0){
|
$blockId = $this->level->getBlockIdAt($vBlock->x, $vBlock->y, $vBlock->z);
|
||||||
$blastForce -= ($block->getBlastResistance() / 5 + 0.3) * $this->stepLen;
|
|
||||||
|
if($blockId !== 0){
|
||||||
|
$blastForce -= (Block::$blastResistance[$blockId] / 5 + 0.3) * $this->stepLen;
|
||||||
if($blastForce > 0){
|
if($blastForce > 0){
|
||||||
if(!isset($this->affectedBlocks[$index = Level::blockHash($block->x, $block->y, $block->z)])){
|
if(!isset($this->affectedBlocks[$index = Level::blockHash($vBlock->x, $vBlock->y, $vBlock->z)])){
|
||||||
$this->affectedBlocks[$index] = $block;
|
$this->affectedBlocks[$index] = $this->level->getBlock($vBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$pointerX += $vector->x;
|
$pointerX += $vector->x;
|
||||||
$pointerY += $vector->y;
|
$pointerY += $vector->y;
|
||||||
$pointerZ += $vector->z;
|
$pointerZ += $vector->z;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user