From 96abd759aeb0a0d2eb5262021e10f6dd94c8b4e0 Mon Sep 17 00:00:00 2001 From: Arne Link Date: Sun, 10 Nov 2024 16:04:44 +0100 Subject: [PATCH] Improve aura rendering performance 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. --- src/module/canvas/token/aura/util.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/module/canvas/token/aura/util.ts b/src/module/canvas/token/aura/util.ts index 8bebae38911..fb442a92dc8 100644 --- a/src/module/canvas/token/aura/util.ts +++ b/src/module/canvas/token/aura/util.ts @@ -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], + }), + ); + return emptyVector .reduce( (squares: EffectAreaSquare[][]) => { @@ -76,14 +84,7 @@ export function getAreaSquares(data: GetAreaSquaresParams): EffectAreaSquare[] { .flat() .filter((s) => measureDistanceCuboid(tokenBounds, s) <= data.radius) .map((square) => { - square.active = tokenCenters.some( - (c) => - !CONFIG.Canvas.polygonBackends[collisionType].testCollision(c, square.center, { - type: collisionType, - mode: "any", - source: pointSource, - }), - ); + square.active = tokenCenterPolygons.some((c) => c.contains(square.center.x, square.center.y)); return square; }); }