performance improvements

This commit is contained in:
GameHerobrine 2024-07-04 05:27:43 +03:00
parent 2972e4567e
commit fcff48b5b8
3 changed files with 7 additions and 6 deletions

View file

@ -555,7 +555,7 @@ class Entity extends Position
$id = $this->level->level->getBlockID($x, $y, $z); $id = $this->level->level->getBlockID($x, $y, $z);
if($id > 0){ if($id > 0){
Block::$class[$id]::onEntityCollidedWithBlock($this->level, $x, $y, $z, $this); StaticBlock::$prealloc[$id]::onEntityCollidedWithBlock($this->level, $x, $y, $z, $this);
} }
} }
} }

View file

@ -8,6 +8,7 @@ class StaticBlock
const DEFAULT_HARDNESS = 0; const DEFAULT_HARDNESS = 0;
private static $NULL_BOUNDS; private static $NULL_BOUNDS;
public static $prealloc = [];
public static $isSolid = []; public static $isSolid = [];
public static $isTransparent = []; public static $isTransparent = [];
public static $isFlowable = []; public static $isFlowable = [];
@ -39,7 +40,7 @@ class StaticBlock
self::$slipperiness[$b->getID()] = $b->slipperiness; self::$slipperiness[$b->getID()] = $b->slipperiness;
self::$boundingBoxes[$b->getID()] = $b->boundingBox; self::$boundingBoxes[$b->getID()] = $b->boundingBox;
self::$hardness[$b->getID()] = $b->getHardness(); self::$hardness[$b->getID()] = $b->getHardness();
self::$prealloc[$b->getID()] = $b;
FireBlock::setFlammabilityAndCatchingChance($b->getID(), 0, 0); FireBlock::setFlammabilityAndCatchingChance($b->getID(), 0, 0);
self::setBlockBounds($b->getID(), 0, 0, 0, 1, 1, 1); self::setBlockBounds($b->getID(), 0, 0, 0, 1, 1, 1);
@ -116,7 +117,7 @@ class StaticBlock
} }
public static function getBlock($id){ public static function getBlock($id){
return Block::$class[$id] ?? Block::$class[0]; return self::$prealloc[$id] ?? self::$prealloc[0]; //accessing preallocated instances is faster Block::$class[$id] ?? Block::$class[0];
} }
public static function getHardness($id){ public static function getHardness($id){

View file

@ -218,7 +218,7 @@ class Level{
$v16 = ($y + 1) - LiquidBlock::getPercentAir($meta); $v16 = ($y + 1) - LiquidBlock::getPercentAir($meta);
if($maxY >= $v16){ if($maxY >= $v16){
$appliedVelocity = true; $appliedVelocity = true;
Block::$class[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec); StaticBlock::$prealloc[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec);
} }
} }
@ -256,7 +256,7 @@ class Level{
for($y = $y0 - 1; $y < $y1; ++$y) { for($y = $y0 - 1; $y < $y1; ++$y) {
$bid = $this->level->getBlockID($x, $y, $z); $bid = $this->level->getBlockID($x, $y, $z);
if($bid > 0){ if($bid > 0){
$blockBounds = Block::$class[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z); $blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
foreach($blockBounds as $blockBound){ foreach($blockBounds as $blockBound){
if($aABB->intersectsWith($blockBound)) $aABBs[] = $blockBound; if($aABB->intersectsWith($blockBound)) $aABBs[] = $blockBound;
@ -512,7 +512,7 @@ class Level{
$y = ($xyz >> 16) & 0x7f; $y = ($xyz >> 16) & 0x7f;
$id = $this->level->fastGetBlockID($cX, $y >> 4, $cZ, $x, $y & 0xf, $z, $index); $id = $this->level->fastGetBlockID($cX, $y >> 4, $cZ, $x, $y & 0xf, $z, $index);
if(isset(self::$randomUpdateBlocks[$id])){ if(isset(self::$randomUpdateBlocks[$id])){
$cl = Block::$class[$id]; $cl = StaticBlock::$prealloc[$id];
$cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4)); $cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4));
} }
} }