Skip to content

Commit

Permalink
Improve aura rendering performance
Browse files Browse the repository at this point in the history
Instead of testing each aura square against each source point of the
aura, compute the full clockwise sweep polygons for the collisionType to
reduce edge intersection tests in core foundry methods.
Rendering the full polygon is wasteful for small aura shapes, but
greatly improves performance for large auras.
  • Loading branch information
Codas committed Nov 10, 2024
1 parent 290b90d commit 5fc2829
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/module/canvas/token/aura/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export function getAreaSquares(data: GetAreaSquaresParams): EffectAreaSquare[] {
return new PointSource({ object: tokenObject });
})();

const tokenCenterPolygons = tokenCenters.map((c) =>
CONFIG.Canvas.polygonBackends[collisionType].create(c, {
type: collisionType,
source: pointSource,
boundaryShape: data.bounds

Check failure on line 68 in src/module/canvas/token/aura/util.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Type 'Rectangle' is missing the following properties from type '(Rectangle | Polygon | Circle)[]': length, pop, push, concat, and 40 more.
}),
)

return emptyVector
.reduce(
(squares: EffectAreaSquare[][]) => {
Expand All @@ -76,13 +84,9 @@ export function getAreaSquares(data: GetAreaSquaresParams): EffectAreaSquare[] {
.flat()
.filter((s) => measureDistanceCuboid(tokenBounds, s) <= data.radius)
.map((square) => {
square.active = tokenCenters.some(
square.active = tokenCenterPolygons.some(
(c) =>
!CONFIG.Canvas.polygonBackends[collisionType].testCollision(c, square.center, {
type: collisionType,
mode: "any",
source: pointSource,
}),
c.contains(square.center.x, square.center.y)
);
return square;
});
Expand Down

0 comments on commit 5fc2829

Please sign in to comment.