Skip to content

Commit

Permalink
perf: Improve pointer perf by keeping geometry local space (#3013)
Browse files Browse the repository at this point in the history
This PR improves point testing against geometry by transforming the point to local geometry space
  • Loading branch information
eonarheim authored Nov 29, 2024
1 parent a24c2f6 commit fb6b821
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ are doing mtv adjustments during precollision.

### Updates

- Perf improve PolygonCollider.contains(...) perf by keeping geometry tests in local space.
- Perf improvement to image rendering! with ImageRendererV2! Roughly doubles the performance of image rendering
- Perf improvement to retrieving components with `ex.Entity.get()` which widely improves engine performance
- Non-breaking parameters that reference `delta` to `elapsedMs` to better communicate intent and units
Expand Down
14 changes: 9 additions & 5 deletions src/engine/Collision/Colliders/PolygonCollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,17 @@ export class PolygonCollider extends Collider {
public contains(point: Vector): boolean {
// Always cast to the right, as long as we cast in a consistent fixed direction we
// will be fine
const testRay = new Ray(point, new Vector(1, 0));
const intersectCount = this.getSides().reduce(function (accum, side) {
const localPoint = this._transform.applyInverse(point);
const testRay = new Ray(localPoint, new Vector(1, 0));

let intersectCount = 0;
const sides = this.getLocalSides();
for (let sideIndex = 0; sideIndex < sides.length; sideIndex++) {
const side = sides[sideIndex];
if (testRay.intersect(side) >= 0) {
return accum + 1;
intersectCount++;
}
return accum;
}, 0);
}

if (intersectCount % 2 === 0) {
return false;
Expand Down

0 comments on commit fb6b821

Please sign in to comment.