Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A faster way to check if a block's AABBs can exceed its 1x1x1 cell #6604

Open
dktapps opened this issue Jan 27, 2025 · 0 comments
Open

A faster way to check if a block's AABBs can exceed its 1x1x1 cell #6604

dktapps opened this issue Jan 27, 2025 · 0 comments
Labels
Category: Core Related to internal functionality Performance Type: Enhancement Contributes features or other improvements to PocketMine-MP

Comments

@dktapps
Copy link
Member

dktapps commented Jan 27, 2025

Problem description

$cellBB = AxisAlignedBB::one()->offset($x, $y, $z);
foreach(Facing::OFFSET as [$dx, $dy, $dz]){
$extraBoxes = $this->getBlockAt($x + $dx, $y + $dy, $z + $dz)->getCollisionBoxes();
foreach($extraBoxes as $extraBox){
if($extraBox->intersectsWith($cellBB)){
$boxes[] = $extraBox;
}
}
}

This code multiplies the performance impact of block AABB collision checking (used for entity movement).
It's only needed to ensure blocks with oversized AABBs like fences are correctly accounted for during collision checks.
However, these blocks are the exception and not the norm, so paying a performance penalty on all blocks is pretty unpleasant.

Proposed solution

If we had a way to tell from the block's stateID whether its AABB may exceed the cell boundaries, we could avoid a lot of unnecessary work in this function. Unfortunately I don't see a nice way to implement this without BC breaks.

Blocks currently aren't required to declare this information, so we'd have to infer it by looking at the results of getCollisionBoxes() for each state. This is OK since recalculateCollisionBoxes() is supposed to only be influenced by state anyway (not coordinates).

However, AABB overflow can also be influenced by stuff like getModelPositionOffset(), which is currently not restricted in any way.

Options are:

  • Block::mayExceedCellBounds() which returns true by default, overridden to false for most PM blocks (boilerplaty but preserves BC)
  • RuntimeBlockStateRegistry->oversizedAABB (array<stateID, bool>), which would need reflection to check whether getModelPositionOffset() is overridden (shitty hack but little code needed)

Alternative solutions or workarounds

No response

@dktapps dktapps added Category: Core Related to internal functionality Performance Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Jan 27, 2025
@dktapps dktapps changed the title Require blocks to declare whether they may exceed the 1x1x1 cube containing them A faster way to check if a block's AABBs can exceed its 1x1x1 cell Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Core Related to internal functionality Performance Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
Development

No branches or pull requests

1 participant