Wipe internal block AABB cache only for specific blocks that need it

the vast majority of blocks don't need this cache erasing, so it's costing performance for no good reason.
This commit is contained in:
Dylan K. Taylor 2023-10-23 17:38:04 +01:00
parent f655eda3b3
commit d637370b83
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
5 changed files with 11 additions and 6 deletions

View File

@ -346,17 +346,13 @@ class Block{
/**
* Called when this block is created, set, or has a neighbouring block update, to re-detect dynamic properties which
* are not saved on the world.
*
* Clears any cached precomputed objects, such as bounding boxes. Remove any outdated precomputed things such as
* AABBs and force recalculation.
* are not saved in the blockstate ID.
* If any such properties are updated, don't forget to clear things like AABB caches if necessary.
*
* A replacement block may be returned. This is useful if the block type changed due to reading of world data (e.g.
* data from a block entity).
*/
public function readStateFromWorld() : Block{
$this->collisionBoxes = null;
return $this;
}
@ -596,6 +592,7 @@ class Block{
*/
final public function position(World $world, int $x, int $y, int $z) : void{
$this->position = new Position($x, $y, $z, $world);
$this->collisionBoxes = null;
}
/**

View File

@ -51,6 +51,8 @@ class Door extends Transparent{
public function readStateFromWorld() : Block{
parent::readStateFromWorld();
$this->collisionBoxes = null;
//copy door properties from other half
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
if($other instanceof Door && $other->hasSameTypeId($this)){

View File

@ -40,6 +40,8 @@ class Fence extends Transparent{
public function readStateFromWorld() : Block{
parent::readStateFromWorld();
$this->collisionBoxes = null;
foreach(Facing::HORIZONTAL as $facing){
$block = $this->getSide($facing);
if($block instanceof static || $block instanceof FenceGate || $block->getSupportType(Facing::opposite($facing)) === SupportType::FULL){

View File

@ -49,6 +49,8 @@ class Stair extends Transparent{
public function readStateFromWorld() : Block{
parent::readStateFromWorld();
$this->collisionBoxes = null;
$clockwise = Facing::rotateY($this->facing, true);
if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){
$this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT : StairShape::OUTER_LEFT;

View File

@ -39,6 +39,8 @@ class Thin extends Transparent{
public function readStateFromWorld() : Block{
parent::readStateFromWorld();
$this->collisionBoxes = null;
foreach(Facing::HORIZONTAL as $facing){
$side = $this->getSide($facing);
if($side instanceof Thin || $side instanceof Wall || $side->getSupportType(Facing::opposite($facing)) === SupportType::FULL){