Skip to content

Commit

Permalink
[#3284] perf: reduce allocations for GraphicsGroup draw calls (#3285)
Browse files Browse the repository at this point in the history
Closes #3284 

## Changes:

- reuse single cumulative bounding box for local bounds calculation of `GraphicsGroup` to reduce per-draw allocations
  • Loading branch information
blakearoberts authored Nov 29, 2024
1 parent cc7c805 commit fd327b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ are doing mtv adjustments during precollision.
* `EventEmitter`s
* `GraphicsSystem` entity iteration
* `PointerSystem` entity iteration
- Perf improvements to `GraphicsGroup` by reducing per draw allocations in bounds calculations

### Changed

Expand Down
6 changes: 3 additions & 3 deletions src/engine/Graphics/GraphicsGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ export class GraphicsGroup extends Graphic implements HasTick {
}

public get localBounds(): BoundingBox {
let bb = new BoundingBox();
const bb = new BoundingBox();
for (const member of this.members) {
if (member instanceof Graphic) {
bb = member.localBounds.combine(bb);
member.localBounds.combine(bb, bb);
} else {
const { graphic, offset: pos, useBounds } = member;
const shouldUseBounds = useBounds === undefined ? true : useBounds;
if (graphic) {
if (shouldUseBounds) {
bb = graphic.localBounds.translate(pos).combine(bb);
graphic.localBounds.translate(pos).combine(bb, bb);
}
} else {
this._logger.warnOnce(`Graphics group member has an null or undefined graphic, member definition: ${JSON.stringify(member)}.`);
Expand Down

0 comments on commit fd327b7

Please sign in to comment.