@flare-engine/physics 0.4.11 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.d.mts +42 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +42 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +143 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +142 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/collider.ts","../src/raycast.ts","../src/shape.ts","../src/spatial-index.ts","../src/collision-world.ts","../src/solid-grid.ts"],"sourcesContent":["import type { Shape } from './shape.js';\n\n/** Collider component data attached to an ECS entity. */\nexport interface Collider {\n /** The collision shape. */\n shape: Shape;\n /** If true, generates trigger events but no physical response. */\n isTrigger: boolean;\n /** Collision layer bitmask — which layer this collider belongs to. */\n layer: number;\n /** Collision mask — which layers this collider can interact with. */\n mask: number;\n}\n\n/** Create a collider with default settings. */\nexport function createCollider(shape: Shape, opts?: Partial<Omit<Collider, 'shape'>>): Collider {\n return {\n shape,\n isTrigger: opts?.isTrigger ?? false,\n layer: opts?.layer ?? 1,\n mask: opts?.mask ?? 0xffffffff,\n };\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport type { Shape } from './shape.js';\n\n/** Result of a raycast hit. */\nexport interface RaycastHit {\n /** The entity that was hit. */\n entity: number;\n /** Distance from ray origin to hit point. */\n distance: number;\n /** World-space hit point. */\n point: Vec2;\n /** Surface normal at hit point. */\n normal: Vec2;\n}\n\n/** Entity entry for raycast — position + shape. */\nexport interface RaycastTarget {\n entity: number;\n shape: Shape;\n x: number;\n y: number;\n}\n\n/**\n * Cast a ray against a list of targets. Returns the closest hit, or null.\n * @param ox Ray origin X\n * @param oy Ray origin Y\n * @param dx Ray direction X (should be normalized)\n * @param dy Ray direction Y (should be normalized)\n * @param maxDist Maximum raycast distance\n * @param targets Array of entities to test against\n */\nexport function raycast(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n targets: readonly RaycastTarget[],\n): RaycastHit | null {\n let closest: RaycastHit | null = null;\n\n for (let i = 0; i < targets.length; i++) {\n const t = targets[i]!;\n const hit = rayVsShape(ox, oy, dx, dy, maxDist, t);\n if (hit && (closest === null || hit.distance < closest.distance)) {\n closest = hit;\n }\n }\n\n return closest;\n}\n\nfunction rayVsShape(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n target: RaycastTarget,\n): RaycastHit | null {\n if (target.shape.type === 'aabb') {\n return rayVsAABB(\n ox,\n oy,\n dx,\n dy,\n maxDist,\n target.entity,\n target.x,\n target.y,\n target.shape.hw,\n target.shape.hh,\n );\n }\n return rayVsCircle(\n ox,\n oy,\n dx,\n dy,\n maxDist,\n target.entity,\n target.x,\n target.y,\n target.shape.radius,\n );\n}\n\nfunction rayVsAABB(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n): RaycastHit | null {\n const minX = cx - hw;\n const maxX = cx + hw;\n const minY = cy - hh;\n const maxY = cy + hh;\n\n const invDx = dx !== 0 ? 1 / dx : dx >= 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;\n const invDy = dy !== 0 ? 1 / dy : dy >= 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;\n\n const tx1 = (minX - ox) * invDx;\n const tx2 = (maxX - ox) * invDx;\n const ty1 = (minY - oy) * invDy;\n const ty2 = (maxY - oy) * invDy;\n\n const tMinX = Math.min(tx1, tx2);\n const tMaxX = Math.max(tx1, tx2);\n const tMinY = Math.min(ty1, ty2);\n const tMaxY = Math.max(ty1, ty2);\n\n const tMin = Math.max(tMinX, tMinY);\n const tMax = Math.min(tMaxX, tMaxY);\n\n if (tMax < 0 || tMin > tMax || tMin > maxDist) return null;\n\n const t = tMin >= 0 ? tMin : tMax;\n if (t > maxDist || t < 0) return null;\n\n const px = ox + dx * t;\n const py = oy + dy * t;\n\n // Compute normal\n let nx = 0;\n let ny = 0;\n if (tMinX > tMinY) {\n nx = dx < 0 ? 1 : -1;\n } else {\n ny = dy < 0 ? 1 : -1;\n }\n\n return {\n entity,\n distance: t,\n point: { x: px, y: py },\n normal: { x: nx, y: ny },\n };\n}\n\nfunction rayVsCircle(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n cx: number,\n cy: number,\n radius: number,\n): RaycastHit | null {\n const fx = ox - cx;\n const fy = oy - cy;\n\n const a = dx * dx + dy * dy;\n const b = 2 * (fx * dx + fy * dy);\n const c = fx * fx + fy * fy - radius * radius;\n\n if (a < 1e-12) return null; // Zero-length direction\n\n const discriminant = b * b - 4 * a * c;\n if (discriminant < 0) return null;\n\n const sqrtDisc = Math.sqrt(discriminant);\n let t = (-b - sqrtDisc) / (2 * a);\n\n // If entry point is behind, try exit point\n if (t < 0) {\n t = (-b + sqrtDisc) / (2 * a);\n }\n if (t < 0 || t > maxDist) return null;\n\n const px = ox + dx * t;\n const py = oy + dy * t;\n const nx = px - cx;\n const ny = py - cy;\n const len = Math.sqrt(nx * nx + ny * ny);\n\n return {\n entity,\n distance: t,\n point: { x: px, y: py },\n normal: len > 0 ? { x: nx / len, y: ny / len } : { x: 0, y: 0 },\n };\n}\n\n/**\n * Zero-alloc ray-vs-shape test: writes into `out` and returns it, or returns\n * `null` without touching `out`.\n *\n * The allocating `raycast()` above builds a fresh `RaycastHit` — with two nested\n * `Vec2` objects — for **every candidate it tests**, then discards all but the\n * closest. That is three objects per candidate per ray. This variant exists so\n * `CollisionWorld.raycast` can test a whole broadphase cell without allocating.\n */\nexport function rayVsShapeInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n shape: Shape,\n x: number,\n y: number,\n out: RaycastHit,\n): RaycastHit | null {\n if (shape.type === 'aabb') {\n return rayVsAABBInto(ox, oy, dx, dy, maxDist, entity, x, y, shape.hw, shape.hh, out);\n }\n return rayVsCircleInto(ox, oy, dx, dy, maxDist, entity, x, y, shape.radius, out);\n}\n\nfunction rayVsAABBInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n bx: number,\n by: number,\n hw: number,\n hh: number,\n out: RaycastHit,\n): RaycastHit | null {\n const invDx = dx !== 0 ? 1 / dx : Number.POSITIVE_INFINITY;\n const invDy = dy !== 0 ? 1 / dy : Number.POSITIVE_INFINITY;\n\n const tx1 = (bx - hw - ox) * invDx;\n const tx2 = (bx + hw - ox) * invDx;\n const ty1 = (by - hh - oy) * invDy;\n const ty2 = (by + hh - oy) * invDy;\n\n const tMinX = Math.min(tx1, tx2);\n const tMaxX = Math.max(tx1, tx2);\n const tMinY = Math.min(ty1, ty2);\n const tMaxY = Math.max(ty1, ty2);\n\n const tMin = Math.max(tMinX, tMinY);\n const tMax = Math.min(tMaxX, tMaxY);\n if (tMax < 0 || tMin > tMax) return null;\n\n const t = tMin < 0 ? tMax : tMin;\n if (t > maxDist || t < 0) return null;\n\n out.entity = entity;\n out.distance = t;\n out.point.x = ox + dx * t;\n out.point.y = oy + dy * t;\n if (tMinX > tMinY) {\n out.normal.x = dx < 0 ? 1 : -1;\n out.normal.y = 0;\n } else {\n out.normal.x = 0;\n out.normal.y = dy < 0 ? 1 : -1;\n }\n return out;\n}\n\nfunction rayVsCircleInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n cx: number,\n cy: number,\n radius: number,\n out: RaycastHit,\n): RaycastHit | null {\n const fx = ox - cx;\n const fy = oy - cy;\n const a = dx * dx + dy * dy;\n if (a < 1e-12) return null;\n\n const b = 2 * (fx * dx + fy * dy);\n const c = fx * fx + fy * fy - radius * radius;\n const discriminant = b * b - 4 * a * c;\n if (discriminant < 0) return null;\n\n const sqrtDisc = Math.sqrt(discriminant);\n let t = (-b - sqrtDisc) / (2 * a);\n if (t < 0) t = (-b + sqrtDisc) / (2 * a);\n if (t < 0 || t > maxDist) return null;\n\n const px = ox + dx * t;\n const py = oy + dy * t;\n const nx = px - cx;\n const ny = py - cy;\n const len = Math.sqrt(nx * nx + ny * ny);\n\n out.entity = entity;\n out.distance = t;\n out.point.x = px;\n out.point.y = py;\n out.normal.x = len > 0 ? nx / len : 0;\n out.normal.y = len > 0 ? ny / len : 0;\n return out;\n}\n","import type { Rect } from '@flare-engine/math';\n\n/** AABB shape — axis-aligned bounding box. */\nexport interface AABBShape {\n readonly type: 'aabb';\n /** Half-width. */\n readonly hw: number;\n /** Half-height. */\n readonly hh: number;\n}\n\n/** Circle shape. */\nexport interface CircleShape {\n readonly type: 'circle';\n readonly radius: number;\n}\n\n/** Union of supported physics shapes. */\nexport type Shape = AABBShape | CircleShape;\n\n/** Create an AABB shape from width and height. */\nexport function AABB(width: number, height: number): AABBShape {\n return { type: 'aabb', hw: width * 0.5, hh: height * 0.5 };\n}\n\n/** Create a circle shape from radius. */\nexport function CircleShape(radius: number): CircleShape {\n return { type: 'circle', radius };\n}\n\n/** Compute the bounding rect of a shape at a given position. */\nexport function shapeBounds(shape: Shape, x: number, y: number): Rect {\n if (shape.type === 'aabb') {\n return { x: x - shape.hw, y: y - shape.hh, width: shape.hw * 2, height: shape.hh * 2 };\n }\n return {\n x: x - shape.radius,\n y: y - shape.radius,\n width: shape.radius * 2,\n height: shape.radius * 2,\n };\n}\n\n/** Zero-alloc variant — writes the shape bounds into the provided output rect. */\nexport function shapeBoundsInto(shape: Shape, x: number, y: number, out: Rect): Rect {\n if (shape.type === 'aabb') {\n out.x = x - shape.hw;\n out.y = y - shape.hh;\n out.width = shape.hw * 2;\n out.height = shape.hh * 2;\n return out;\n }\n out.x = x - shape.radius;\n out.y = y - shape.radius;\n out.width = shape.radius * 2;\n out.height = shape.radius * 2;\n return out;\n}\n\n/** Test overlap between two positioned shapes. Returns true if overlapping. */\nexport function shapeOverlap(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n): boolean {\n if (shapeA.type === 'aabb' && shapeB.type === 'aabb') {\n return aabbVsAabb(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.hw, shapeB.hh);\n }\n if (shapeA.type === 'circle' && shapeB.type === 'circle') {\n return circleVsCircle(ax, ay, shapeA.radius, bx, by, shapeB.radius);\n }\n // Mixed: one AABB, one circle\n if (shapeA.type === 'aabb' && shapeB.type === 'circle') {\n return aabbVsCircle(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.radius);\n }\n return aabbVsCircle(\n bx,\n by,\n (shapeB as AABBShape).hw,\n (shapeB as AABBShape).hh,\n ax,\n ay,\n (shapeA as CircleShape).radius,\n );\n}\n\nfunction aabbVsAabb(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n bx: number,\n by: number,\n bhw: number,\n bhh: number,\n): boolean {\n return Math.abs(ax - bx) < ahw + bhw && Math.abs(ay - by) < ahh + bhh;\n}\n\nfunction circleVsCircle(\n ax: number,\n ay: number,\n ar: number,\n bx: number,\n by: number,\n br: number,\n): boolean {\n const dx = bx - ax;\n const dy = by - ay;\n const radSum = ar + br;\n return dx * dx + dy * dy < radSum * radSum;\n}\n\nfunction aabbVsCircle(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n cx: number,\n cy: number,\n cr: number,\n): boolean {\n const left = ax - ahw;\n const right = ax + ahw;\n const top = ay - ahh;\n const bottom = ay + ahh;\n const closestX = cx < left ? left : cx > right ? right : cx;\n const closestY = cy < top ? top : cy > bottom ? bottom : cy;\n const dx = cx - closestX;\n const dy = cy - closestY;\n const distSq = dx * dx + dy * dy;\n // Strict, like aabbVsAabb and circleVsCircle: exactly-touching shapes do not\n // collide. A centre on or inside the box collides when the radius is positive;\n // a zero radius counts only strictly inside, as a zero-size box does.\n if (distSq > 0) return distSq < cr * cr;\n return cr > 0 || (cx > left && cx < right && cy > top && cy < bottom);\n}\n\n/**\n * Minimum translation vector: the shortest push that separates two overlapping\n * shapes.\n *\n * `shapeOverlap` answers *whether* two shapes collide and nothing more, which\n * leaves a detection-only consumer with no way to resolve the collision. This is\n * that missing step: `out.x`/`out.y` are a unit axis and `out.depth` is how far\n * along it `b` must move to just stop touching `a`.\n *\n * Returns `null` when the shapes are not overlapping, leaving `out` untouched so\n * a caller may reuse one buffer across many pairs.\n *\n * The degenerate concentric case (identical centres) has no meaningful axis;\n * `(1, 0)` is returned so the caller still gets a usable separation instead of\n * `NaN` from normalising a zero vector.\n */\nexport interface Overlap {\n /** Unit separation axis, pointing from `a` toward `b`. */\n x: number;\n y: number;\n /** Penetration depth along that axis. */\n depth: number;\n}\n\n/** A fresh, zeroed overlap record. Allocate once outside the loop and reuse. */\nexport function createOverlap(): Overlap {\n return { x: 0, y: 0, depth: 0 };\n}\n\nexport function overlapInto(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n out: Overlap,\n): Overlap | null {\n if (shapeA.type === 'aabb' && shapeB.type === 'aabb') {\n return aabbAabbOverlap(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.hw, shapeB.hh, out);\n }\n if (shapeA.type === 'circle' && shapeB.type === 'circle') {\n return circleCircleOverlap(ax, ay, shapeA.radius, bx, by, shapeB.radius, out);\n }\n if (shapeA.type === 'aabb' && shapeB.type === 'circle') {\n return aabbCircleOverlap(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.radius, out, false);\n }\n // Circle vs AABB — solve as AABB vs circle, then flip the axis so it still\n // points from `a` to `b`.\n return aabbCircleOverlap(\n bx,\n by,\n (shapeB as AABBShape).hw,\n (shapeB as AABBShape).hh,\n ax,\n ay,\n (shapeA as CircleShape).radius,\n out,\n true,\n );\n}\n\n/** Minimum translation vector. Allocates — see `overlapInto` for the hot path. */\nexport function overlap(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n): Overlap | null {\n return overlapInto(shapeA, ax, ay, shapeB, bx, by, createOverlap());\n}\n\nfunction aabbAabbOverlap(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n bx: number,\n by: number,\n bhw: number,\n bhh: number,\n out: Overlap,\n): Overlap | null {\n const dx = bx - ax;\n const dy = by - ay;\n const overlapX = ahw + bhw - Math.abs(dx);\n if (overlapX <= 0) return null;\n const overlapY = ahh + bhh - Math.abs(dy);\n if (overlapY <= 0) return null;\n\n // The minimum translation is along whichever axis is least penetrated.\n if (overlapX < overlapY) {\n out.x = dx < 0 ? -1 : 1;\n out.y = 0;\n out.depth = overlapX;\n } else {\n out.x = 0;\n out.y = dy < 0 ? -1 : 1;\n out.depth = overlapY;\n }\n return out;\n}\n\nfunction circleCircleOverlap(\n ax: number,\n ay: number,\n ar: number,\n bx: number,\n by: number,\n br: number,\n out: Overlap,\n): Overlap | null {\n const dx = bx - ax;\n const dy = by - ay;\n const radSum = ar + br;\n const distSq = dx * dx + dy * dy;\n if (distSq >= radSum * radSum) return null;\n\n const dist = Math.sqrt(distSq);\n if (dist === 0) {\n // Concentric: no meaningful axis, so pick one rather than divide by zero.\n out.x = 1;\n out.y = 0;\n out.depth = radSum;\n return out;\n }\n out.x = dx / dist;\n out.y = dy / dist;\n out.depth = radSum - dist;\n return out;\n}\n\nfunction aabbCircleOverlap(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n cx: number,\n cy: number,\n cr: number,\n out: Overlap,\n flip: boolean,\n): Overlap | null {\n const left = ax - ahw;\n const right = ax + ahw;\n const top = ay - ahh;\n const bottom = ay + ahh;\n const closestX = cx < left ? left : cx > right ? right : cx;\n const closestY = cy < top ? top : cy > bottom ? bottom : cy;\n const dx = cx - closestX;\n const dy = cy - closestY;\n const distSq = dx * dx + dy * dy;\n\n if (distSq > 0) {\n // Centre outside the box: separate along the closest-point normal.\n if (distSq >= cr * cr) return null;\n const dist = Math.sqrt(distSq);\n const nx = dx / dist;\n const ny = dy / dist;\n out.x = flip ? -nx : nx;\n out.y = flip ? -ny : ny;\n out.depth = cr - dist;\n return out;\n }\n\n // Centre inside the box: push out through the nearest face.\n const toLeft = cx - left;\n const toRight = right - cx;\n const toTop = cy - top;\n const toBottom = bottom - cy;\n let nx = -1;\n let ny = 0;\n let depth = toLeft;\n if (toRight < depth) {\n nx = 1;\n ny = 0;\n depth = toRight;\n }\n if (toTop < depth) {\n nx = 0;\n ny = -1;\n depth = toTop;\n }\n if (toBottom < depth) {\n nx = 0;\n ny = 1;\n depth = toBottom;\n }\n // Zero radius on the boundary is exactly touching, not overlapping.\n if (depth + cr <= 0) return null;\n out.x = flip ? -nx : nx;\n out.y = flip ? -ny : ny;\n out.depth = depth + cr;\n return out;\n}\n","import type { Rect } from '@flare-engine/math';\n\n// Internal entry: bounding rect (minX, minY, maxX, maxY) plus a per-query stamp\n// for zero-alloc dedup.\ninterface _Entry<T> {\n readonly item: T;\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n _stamp: number;\n}\n\n// Uniform grid cell size in world units. Tuned for typical game-object sizes (16–64 px).\nconst CELL = 64;\n\n// Packed cell-key encoding. Supports cell coords in [-32768, 32767],\n// i.e. world coordinates ±2 097 152. All keys fit within Number.MAX_SAFE_INTEGER.\nconst KEY_RANGE = 65536; // 2^16\nconst KEY_OFFSET = 32768; // 2^15\n\nfunction _key(cx: number, cy: number): number {\n return (cx + KEY_OFFSET) * KEY_RANGE + (cy + KEY_OFFSET);\n}\n\n// Inclusive min cell that contains world coordinate v.\nfunction _cMin(v: number): number {\n return Math.floor(v / CELL);\n}\n\n// Inclusive max cell that contains world coordinate v (exclusive-end: a coord\n// falling exactly on a cell boundary is NOT part of the adjacent cell — matches\n// the strict-inequality overlap semantics of query()).\nfunction _cMax(v: number): number {\n return Math.ceil(v / CELL) - 1;\n}\n\n// Supported cell-coordinate range for the packed key above.\nconst MIN_CELL = -KEY_OFFSET;\nconst MAX_CELL = KEY_OFFSET - 1;\n\n// Bounds a derived cell coordinate to the packed-key range. Without this, a\n// non-finite world coordinate (±Infinity — an unbounded raycast maxDist, or an\n// entity parked at Infinity) makes cxMin/cxMax/cyMin/cyMax infinite, and\n// `for (cx = cxMin; cx <= cxMax; cx++)` never exits: once cx itself is\n// Infinity, `cx <= Infinity` stays true and `cx++` is a no-op, so the loop\n// spins forever pushing/reading the same bucket (unbounded memory growth on\n// the link side). NaN is left untouched: every comparison against NaN is\n// false, so the loop already runs zero times, which is the existing (safe)\n// behaviour for a degenerate direction like `0 * Infinity`.\nfunction _clampCell(c: number): number {\n if (c > MAX_CELL) return MAX_CELL;\n if (c < MIN_CELL) return MIN_CELL;\n return c;\n}\n\n/**\n * Uniform spatial-hash broadphase.\n * `insert`, `remove`, and `update` are O(cells touched) — O(1) for typical entities.\n * `query` walks only the cells overlapping the given rect; result order is unspecified.\n * Zero-alloc in the query hot-path: duplicate suppression uses a monotone stamp counter,\n * not a per-call Set.\n */\nexport class SpatialIndex<T> {\n private _data: _Entry<T>[] = [];\n private _slots = new Map<T, number>(); // item → dense-array slot\n private _cells = new Map<number, _Entry<T>[]>(); // packed cell key → bucket\n private _gen = 0; // monotone query-generation counter\n\n /** Number of items in the index. */\n get size(): number {\n return this._data.length;\n }\n\n /** Insert an item with a bounding rect. */\n insert(item: T, bounds: Rect): void {\n const entry: _Entry<T> = {\n item,\n minX: bounds.x,\n minY: bounds.y,\n maxX: bounds.x + bounds.width,\n maxY: bounds.y + bounds.height,\n _stamp: 0,\n };\n this._slots.set(item, this._data.length);\n this._data.push(entry);\n this._link(entry);\n }\n\n /** Remove an item. Returns false when the item was not present. */\n remove(item: T): boolean {\n const slot = this._slots.get(item);\n if (slot === undefined) return false;\n const entry = this._data[slot]!;\n this._unlink(entry);\n this._slots.delete(item);\n // Swap-remove: plug the hole with the last element.\n const last = this._data.pop()!;\n if (slot < this._data.length) {\n this._data[slot] = last;\n this._slots.set(last.item, slot);\n }\n return true;\n }\n\n /** Update the bounds for an existing item. No-op when the item is absent. */\n update(item: T, bounds: Rect): void {\n const slot = this._slots.get(item);\n if (slot === undefined) return;\n const entry = this._data[slot]!;\n this._unlink(entry);\n entry.minX = bounds.x;\n entry.minY = bounds.y;\n entry.maxX = bounds.x + bounds.width;\n entry.maxY = bounds.y + bounds.height;\n this._link(entry);\n }\n\n /**\n * Query all items whose bounds overlap the given rect.\n * Result order is unspecified. Appends to `result` when provided and returns it.\n */\n query(bounds: Rect, result?: T[]): T[] {\n const out = result ?? [];\n const gen = ++this._gen;\n\n const qMinX = bounds.x;\n const qMinY = bounds.y;\n const qMaxX = bounds.x + bounds.width;\n const qMaxY = bounds.y + bounds.height;\n\n const cxMin = _clampCell(_cMin(qMinX));\n const cxMax = _clampCell(_cMax(qMaxX));\n const cyMin = _clampCell(_cMin(qMinY));\n const cyMax = _clampCell(_cMax(qMaxY));\n\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const bucket = this._cells.get(_key(cx, cy));\n if (bucket === undefined) continue;\n for (let i = 0; i < bucket.length; i++) {\n const e = bucket[i]!;\n if (e._stamp === gen) continue; // already emitted this query\n e._stamp = gen;\n if (e.maxX > qMinX && e.minX < qMaxX && e.maxY > qMinY && e.minY < qMaxY) {\n out.push(e.item);\n }\n }\n }\n }\n return out;\n }\n\n /** Remove all items. */\n clear(): void {\n this._data.length = 0;\n this._slots.clear();\n this._cells.clear();\n }\n\n // Register entry in all grid cells it overlaps.\n private _link(entry: _Entry<T>): void {\n const cxMin = _clampCell(_cMin(entry.minX));\n const cxMax = _clampCell(_cMax(entry.maxX));\n const cyMin = _clampCell(_cMin(entry.minY));\n const cyMax = _clampCell(_cMax(entry.maxY));\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const k = _key(cx, cy);\n let b = this._cells.get(k);\n if (b === undefined) {\n b = [];\n this._cells.set(k, b);\n }\n b.push(entry);\n }\n }\n }\n\n // Remove entry from all grid cells it currently occupies.\n private _unlink(entry: _Entry<T>): void {\n const cxMin = _clampCell(_cMin(entry.minX));\n const cxMax = _clampCell(_cMax(entry.maxX));\n const cyMin = _clampCell(_cMin(entry.minY));\n const cyMax = _clampCell(_cMax(entry.maxY));\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const b = this._cells.get(_key(cx, cy));\n if (b === undefined) continue;\n const i = b.indexOf(entry);\n if (i !== -1) {\n // Swap-remove within the bucket.\n const last = b.pop()!;\n if (i < b.length) b[i] = last;\n }\n }\n }\n }\n}\n","import { Signal } from '@flare-engine/events';\nimport type { Rect } from '@flare-engine/math';\nimport type { Collider } from './collider.js';\nimport type { RaycastHit } from './raycast.js';\nimport { rayVsShapeInto } from './raycast.js';\nimport type { Shape } from './shape.js';\nimport { shapeBoundsInto, shapeOverlap } from './shape.js';\nimport { SpatialIndex } from './spatial-index.js';\n\n/** Collision pair data emitted by collision signals. */\nexport interface CollisionPair {\n readonly entityA: number;\n readonly entityB: number;\n}\n\n/** Per-entity collision data stored in the world. */\ninterface CollisionEntry {\n entity: number;\n shape: Shape;\n x: number;\n y: number;\n isTrigger: boolean;\n layer: number;\n mask: number;\n}\n\n// Packed pair-key layout: `lo * ENTITY_SHIFT + hi`, lo = min(a,b), hi = max(a,b).\n// 2^26 fits within Number.MAX_SAFE_INTEGER for 26+26 bits → max entity id ~67M.\nconst ENTITY_SHIFT = 2 ** 26;\n\n/** Padding applied to a ray's query AABB — see `CollisionWorld.raycast`. */\nconst RAY_BOUNDS_PAD = 1e-6;\n\nfunction encodePair(a: number, b: number): number {\n const lo = a < b ? a : b;\n const hi = a < b ? b : a;\n return lo * ENTITY_SHIFT + hi;\n}\n\nfunction decodeLo(key: number): number {\n return Math.floor(key / ENTITY_SHIFT);\n}\n\nfunction decodeHi(key: number): number {\n return key - Math.floor(key / ENTITY_SHIFT) * ENTITY_SHIFT;\n}\n\n/**\n * AABB collision world. Manages entities with shapes, detects overlaps each step,\n * and emits collision/trigger signals.\n */\nexport class CollisionWorld {\n readonly onCollisionStart = new Signal<CollisionPair>();\n readonly onCollisionEnd = new Signal<CollisionPair>();\n readonly onTriggerEnter = new Signal<CollisionPair>();\n readonly onTriggerExit = new Signal<CollisionPair>();\n\n private entries = new Map<number, CollisionEntry>();\n private spatial = new SpatialIndex<number>();\n /**\n * Two pre-allocated pair buffers — swapped each step (no per-frame allocation).\n * Keys are packed numbers via `encodePair(a, b)`.\n */\n private pairBufA = new Set<number>();\n private pairBufB = new Set<number>();\n private activePairs: Set<number> = this.pairBufA;\n /** Reusable query result buffer. */\n private queryBuf: number[] = [];\n /** Reusable bounds rect — avoids per-entity Rect allocation in step(). */\n private boundsBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n /** Add an entity with a shape. Positional twin of `addCollider`. */\n add(\n entity: number,\n shape: Shape,\n x: number,\n y: number,\n isTrigger = false,\n layer = 1,\n mask = 0xffffffff,\n ): void {\n const entry: CollisionEntry = { entity, shape, x, y, isTrigger, layer, mask };\n const exists = this.entries.has(entity);\n this.entries.set(entity, entry);\n shapeBoundsInto(shape, x, y, this.boundsBuf);\n if (exists) {\n this.spatial.update(entity, this.boundsBuf);\n } else {\n this.spatial.insert(entity, this.boundsBuf);\n }\n }\n\n /**\n * Add an entity from a `Collider`. Its `shape`, `isTrigger`, `layer` and `mask`\n * are copied at add time — later edits to the collider do not reach the world;\n * re-add to change them. Re-adding an existing entity replaces its data.\n */\n addCollider(entity: number, collider: Collider, x: number, y: number): void {\n this.add(entity, collider.shape, x, y, collider.isTrigger, collider.layer, collider.mask);\n }\n\n /** Remove an entity from the world. Emits exit signals for any active pairs. */\n remove(entity: number): void {\n const entry = this.entries.get(entity);\n if (!entry) return;\n\n this.entries.delete(entity);\n this.spatial.remove(entity);\n\n // Fire exit signals for all active pairs involving this entity\n for (const key of this.activePairs) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n if (lo !== entity && hi !== entity) continue;\n this.activePairs.delete(key);\n const otherEntity = lo === entity ? hi : lo;\n const otherEntry = this.entries.get(otherEntity);\n const pair: CollisionPair = { entityA: lo, entityB: hi };\n if (entry.isTrigger || otherEntry?.isTrigger) {\n this.onTriggerExit.emit(pair);\n } else {\n this.onCollisionEnd.emit(pair);\n }\n }\n }\n\n /** Update an entity's position. */\n setPosition(entity: number, x: number, y: number): void {\n const entry = this.entries.get(entity);\n if (!entry) return;\n entry.x = x;\n entry.y = y;\n shapeBoundsInto(entry.shape, x, y, this.boundsBuf);\n this.spatial.update(entity, this.boundsBuf);\n }\n\n /** Number of entities in the world. */\n get size(): number {\n return this.entries.size;\n }\n\n /** Number of broadphase records (one per live entity after add/remove). Diagnostic for broadphase growth. */\n get broadphaseSize(): number {\n return this.spatial.size;\n }\n\n /** Run one collision detection step. */\n step(): void {\n const newPairs = this.activePairs === this.pairBufA ? this.pairBufB : this.pairBufA;\n newPairs.clear();\n\n for (const entryA of this.entries.values()) {\n const entityA = entryA.entity;\n shapeBoundsInto(entryA.shape, entryA.x, entryA.y, this.boundsBuf);\n this.queryBuf.length = 0;\n this.spatial.query(this.boundsBuf, this.queryBuf);\n\n for (let i = 0; i < this.queryBuf.length; i++) {\n const entityB = this.queryBuf[i]!;\n if (entityB <= entityA) continue; // Avoid self and duplicates\n\n const entryB = this.entries.get(entityB);\n if (!entryB) continue;\n\n // Layer/mask filtering\n if ((entryA.layer & entryB.mask) === 0 && (entryB.layer & entryA.mask) === 0) continue;\n\n // Narrowphase\n if (!shapeOverlap(entryA.shape, entryA.x, entryA.y, entryB.shape, entryB.x, entryB.y)) {\n continue;\n }\n\n newPairs.add(encodePair(entityA, entityB));\n }\n }\n\n // Enter/start events — pair objects are allocated here only on state transitions.\n for (const key of newPairs) {\n if (!this.activePairs.has(key)) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n const a = this.entries.get(lo);\n const b = this.entries.get(hi);\n const pair: CollisionPair = { entityA: lo, entityB: hi };\n if (a?.isTrigger || b?.isTrigger) {\n this.onTriggerEnter.emit(pair);\n } else {\n this.onCollisionStart.emit(pair);\n }\n }\n }\n\n // Exit/end events\n for (const key of this.activePairs) {\n if (!newPairs.has(key)) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n const a = this.entries.get(lo);\n const b = this.entries.get(hi);\n const pair: CollisionPair = { entityA: lo, entityB: hi };\n if (a?.isTrigger || b?.isTrigger) {\n this.onTriggerExit.emit(pair);\n } else {\n this.onCollisionEnd.emit(pair);\n }\n }\n }\n\n this.activePairs = newPairs;\n }\n\n /** Zero-alloc collider bounds — writes the AABB of entity's shape into `out`. Returns null when entity is absent. */\n getColliderBoundsInto(entity: number, out: Rect): Rect | null {\n const entry = this.entries.get(entity);\n if (!entry) return null;\n shapeBoundsInto(entry.shape, entry.x, entry.y, out);\n return out;\n }\n\n /** Allocating convenience wrapper — returns a fresh Rect or null when entity is absent. */\n getColliderBounds(entity: number): Rect | null {\n const entry = this.entries.get(entity);\n if (!entry) return null;\n return shapeBoundsInto(entry.shape, entry.x, entry.y, { x: 0, y: 0, width: 0, height: 0 });\n }\n\n /** Remove all entities. */\n clear(): void {\n this.entries.clear();\n this.spatial.clear();\n this.pairBufA.clear();\n this.pairBufB.clear();\n this.activePairs = this.pairBufA;\n }\n\n /** Reused across raycasts — see `raycast`. */\n private raycastBounds: Rect = { x: 0, y: 0, width: 0, height: 0 };\n private raycastCandidates: number[] = [];\n private raycastHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n };\n\n /**\n * Cast a ray against the colliders in this world.\n *\n * The standalone `raycast()` export tests a caller-supplied target array, so\n * it neither sees the world's colliders nor benefits from the broadphase — an\n * O(n) scan sitting beside an O(1) index. This walks only the cells the ray's\n * bounding box touches.\n *\n * `mask` is a layer bitmask filtered against each collider's `layer`, using the\n * bits colliders already carry; it defaults to every layer. Triggers are\n * included — a ray asking \"what is over there\" wants them.\n *\n * The returned record is **reused between calls**: read it, or copy what you\n * need, before casting again. That is what keeps a per-frame ray allocation-\n * free, and it is why the standalone helper's fresh-object-per-candidate cost\n * was worth removing.\n *\n * `maxDist` must be finite — this requires a bounded ray, not the\n * `Number.POSITIVE_INFINITY` \"unbounded ray\" idiom some engines accept. The\n * broadphase below is a uniform grid: an infinite `maxDist` derives an\n * infinite cell range and never terminates the walk. Pass a large finite\n * bound instead (e.g. the map's diagonal) to cast \"until it leaves the\n * populated area\". A non-finite `maxDist` returns `null`.\n */\n raycast(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n mask = 0xffffffff,\n ): RaycastHit | null {\n if (!Number.isFinite(maxDist)) return null;\n\n // Bounding box of the whole ray — the broadphase is rect-based, so this is\n // a conservative prefilter, not the intersection test itself.\n const ex = ox + dx * maxDist;\n const ey = oy + dy * maxDist;\n const minX = ox < ex ? ox : ex;\n const minY = oy < ey ? oy : ey;\n // Padded so the rect always has non-zero extent on both axes. An axis-\n // aligned ray is otherwise degenerate — a horizontal ray has height 0 — and\n // SpatialIndex derives its cell range with an exclusive end (`_cMax` is\n // `ceil(v / CELL) - 1`), so a zero-height rect yields cyMin 0 > cyMax -1 and\n // the cell loop never runs. The broadphase is a conservative prefilter\n // anyway, so over-including by a hair costs nothing: the exact ray test\n // below rejects the extras.\n this.raycastBounds.x = minX - RAY_BOUNDS_PAD;\n this.raycastBounds.y = minY - RAY_BOUNDS_PAD;\n this.raycastBounds.width = Math.abs(ex - ox) + RAY_BOUNDS_PAD * 2;\n this.raycastBounds.height = Math.abs(ey - oy) + RAY_BOUNDS_PAD * 2;\n\n this.raycastCandidates.length = 0;\n this.spatial.query(this.raycastBounds, this.raycastCandidates);\n\n let bestDist = Number.POSITIVE_INFINITY;\n let found = false;\n for (let i = 0; i < this.raycastCandidates.length; i++) {\n const entry = this.entries.get(this.raycastCandidates[i]!);\n if (entry === undefined) continue;\n if ((entry.layer & mask) === 0) continue;\n const hit = rayVsShapeInto(\n ox,\n oy,\n dx,\n dy,\n maxDist,\n entry.entity,\n entry.shape,\n entry.x,\n entry.y,\n this.scratchHit,\n );\n if (hit !== null && hit.distance < bestDist) {\n bestDist = hit.distance;\n found = true;\n this.raycastHit.entity = hit.entity;\n this.raycastHit.distance = hit.distance;\n this.raycastHit.point.x = hit.point.x;\n this.raycastHit.point.y = hit.point.y;\n this.raycastHit.normal.x = hit.normal.x;\n this.raycastHit.normal.y = hit.normal.y;\n }\n }\n return found ? this.raycastHit : null;\n }\n\n /** Scratch record handed to `rayVsShapeInto` per candidate. */\n private scratchHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n };\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/**\n * Minimal structural type for a solid tile position in grid coordinates.\n * `TileCollider[]` from `@flare-engine/tilemap` is structurally assignable here\n * so callers can pass `extractColliders(map)` directly — no tilemap dep needed.\n */\nexport interface SolidTile {\n readonly row: number;\n readonly col: number;\n}\n\n/**\n * How `isBlockedAABB` treats cells outside the grid.\n * `'solid'` — the map edge is a wall; any box that leaves the map is blocked.\n * `'open'` — cells outside the grid are empty, so a body can walk off the map;\n * use it for seams between adjacent region maps.\n */\nexport type SolidGridOutside = 'solid' | 'open';\n\nexport interface SolidGridOptions {\n /** Defaults to `'solid'`. */\n readonly outside?: SolidGridOutside;\n}\n\n/**\n * Precomputed solid-tile lookup used by `isBlockedAABB` and `moveAndSlideInto`.\n * `solid` has `width * height` cells indexed `row * width + col`; non-zero means\n * solid. Build once per map load via `buildSolidGrid`.\n */\nexport interface SolidGrid {\n readonly width: number;\n readonly height: number;\n readonly tileSize: number;\n readonly solid: Uint8Array;\n readonly outside: SolidGridOutside;\n}\n\n/**\n * Build a `SolidGrid` from a list of solid tile positions.\n * Input is structurally typed (`readonly SolidTile[]`) so the caller does not\n * need to import `@flare-engine/tilemap` — physics stays tilemap-free.\n */\nexport function buildSolidGrid(\n width: number,\n height: number,\n tileSize: number,\n tiles: readonly SolidTile[],\n options?: SolidGridOptions,\n): SolidGrid {\n const solid = new Uint8Array(width * height);\n for (const t of tiles) {\n solid[t.row * width + t.col] = 1;\n }\n return { width, height, tileSize, solid, outside: options?.outside ?? 'solid' };\n}\n\n/**\n * Half-open boundary constant: the AABB is treated as [min, max) so a box\n * whose max edge lands exactly on a tile boundary does NOT overlap that tile.\n */\nconst EDGE = 1e-4;\n\n/**\n * Returns `true` when an axis-aligned box centered at (`x`, `y`) with\n * half-extents (`halfW`, `halfH`) overlaps a solid tile. Leaving the map\n * blocks only when the grid was built with `outside: 'solid'` (the default);\n * with `'open'` the out-of-grid cells are empty and only the in-grid cells the\n * box overlaps are tested. Uses half-open EDGE semantics on max edges.\n */\nexport function isBlockedAABB(\n grid: SolidGrid,\n x: number,\n y: number,\n halfW: number,\n halfH: number,\n): boolean {\n const ts = grid.tileSize;\n let minCol = Math.floor((x - halfW) / ts);\n let maxCol = Math.floor((x + halfW - EDGE) / ts);\n let minRow = Math.floor((y - halfH) / ts);\n let maxRow = Math.floor((y + halfH - EDGE) / ts);\n if (minCol < 0 || minRow < 0 || maxCol >= grid.width || maxRow >= grid.height) {\n if (grid.outside === 'solid') return true;\n // Clamp to the in-grid cells; a box fully outside yields an empty range.\n if (minCol < 0) minCol = 0;\n if (minRow < 0) minRow = 0;\n if (maxCol >= grid.width) maxCol = grid.width - 1;\n if (maxRow >= grid.height) maxRow = grid.height - 1;\n }\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n if (grid.solid[row * grid.width + col] !== 0) {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * Axis-separated slide movement. Attempts to move by (`dx`, `dy`); each axis\n * is applied independently so a blocked diagonal input slides along the wall.\n * The y-check uses the already-updated x position.\n * Zero-alloc: writes result into the provided `out` Vec2 and returns it.\n */\nexport function moveAndSlideInto(\n grid: SolidGrid,\n x: number,\n y: number,\n dx: number,\n dy: number,\n halfW: number,\n halfH: number,\n out: Vec2,\n): Vec2 {\n let nx = x;\n let ny = y;\n if (dx !== 0 && !isBlockedAABB(grid, nx + dx, ny, halfW, halfH)) nx += dx;\n if (dy !== 0 && !isBlockedAABB(grid, nx, ny + dy, halfW, halfH)) ny += dy;\n out.x = nx;\n out.y = ny;\n return out;\n}\n"],"mappings":";;;AAeA,SAAgB,eAAe,OAAc,MAAmD;CAC9F,OAAO;EACL;EACA,WAAW,MAAM,aAAa;EAC9B,OAAO,MAAM,SAAS;EACtB,MAAM,MAAM,QAAQ;CACtB;AACF;;;;;;;;;;;ACUA,SAAgB,QACd,IACA,IACA,IACA,IACA,SACA,SACmB;CACnB,IAAI,UAA6B;CAEjC,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;EACvC,MAAM,IAAI,QAAQ;EAClB,MAAM,MAAM,WAAW,IAAI,IAAI,IAAI,IAAI,SAAS,CAAC;EACjD,IAAI,QAAQ,YAAY,QAAQ,IAAI,WAAW,QAAQ,WACrD,UAAU;CAEd;CAEA,OAAO;AACT;AAEA,SAAS,WACP,IACA,IACA,IACA,IACA,SACA,QACmB;CACnB,IAAI,OAAO,MAAM,SAAS,QACxB,OAAO,UACL,IACA,IACA,IACA,IACA,SACA,OAAO,QACP,OAAO,GACP,OAAO,GACP,OAAO,MAAM,IACb,OAAO,MAAM,EACf;CAEF,OAAO,YACL,IACA,IACA,IACA,IACA,SACA,OAAO,QACP,OAAO,GACP,OAAO,GACP,OAAO,MAAM,MACf;AACF;AAEA,SAAS,UACP,IACA,IACA,IACA,IACA,SACA,QACA,IACA,IACA,IACA,IACmB;CACnB,MAAM,OAAO,KAAK;CAClB,MAAM,OAAO,KAAK;CAClB,MAAM,OAAO,KAAK;CAClB,MAAM,OAAO,KAAK;CAElB,MAAM,QAAQ,OAAO,IAAI,IAAI,KAAK,MAAM,IAAI,OAAO,oBAAoB,OAAO;CAC9E,MAAM,QAAQ,OAAO,IAAI,IAAI,KAAK,MAAM,IAAI,OAAO,oBAAoB,OAAO;CAE9E,MAAM,OAAO,OAAO,MAAM;CAC1B,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;CAC/C,IAAI,SAAS,KAAK,SAAS,KAAK,UAAU,KAAK,SAAS,UAAU,KAAK,QAAQ;EAC7E,IAAI,KAAK,YAAY,SAAS,OAAO;EAErC,IAAI,SAAS,GAAG,SAAS;EACzB,IAAI,SAAS,GAAG,SAAS;EACzB,IAAI,UAAU,KAAK,OAAO,SAAS,KAAK,QAAQ;EAChD,IAAI,UAAU,KAAK,QAAQ,SAAS,KAAK,SAAS;CACpD;CACA,KAAK,IAAI,MAAM,QAAQ,OAAO,QAAQ,OACpC,KAAK,IAAI,MAAM,QAAQ,OAAO,QAAQ,OACpC,IAAI,KAAK,MAAM,MAAM,KAAK,QAAQ,SAAS,GACzC,OAAO;CAIb,OAAO;AACT;;;;;;;AAQA,SAAgB,iBACd,MACA,GACA,GACA,IACA,IACA,OACA,OACA,KACM;CACN,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,OAAO,KAAK,CAAC,cAAc,MAAM,KAAK,IAAI,IAAI,OAAO,KAAK,GAAG,MAAM;CACvE,IAAI,OAAO,KAAK,CAAC,cAAc,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,GAAG,MAAM;CACvE,IAAI,IAAI;CACR,IAAI,IAAI;CACR,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/collider.ts","../src/raycast.ts","../src/shape.ts","../src/spatial-index.ts","../src/collision-world.ts","../src/solid-grid.ts"],"sourcesContent":["import type { Shape } from './shape.js';\n\n/** Collider component data attached to an ECS entity. */\nexport interface Collider {\n /** The collision shape. */\n shape: Shape;\n /** If true, generates trigger events but no physical response. */\n isTrigger: boolean;\n /** Collision layer bitmask — which layer this collider belongs to. */\n layer: number;\n /** Collision mask — which layers this collider can interact with. */\n mask: number;\n}\n\n/** Create a collider with default settings. */\nexport function createCollider(shape: Shape, opts?: Partial<Omit<Collider, 'shape'>>): Collider {\n return {\n shape,\n isTrigger: opts?.isTrigger ?? false,\n layer: opts?.layer ?? 1,\n mask: opts?.mask ?? 0xffffffff,\n };\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport type { Shape } from './shape.js';\n\n/** Result of a raycast hit. */\nexport interface RaycastHit {\n /** The entity that was hit. */\n entity: number;\n /** Distance from ray origin to hit point. */\n distance: number;\n /** World-space hit point. */\n point: Vec2;\n /** Surface normal at hit point. */\n normal: Vec2;\n}\n\n/** Entity entry for raycast — position + shape. */\nexport interface RaycastTarget {\n entity: number;\n shape: Shape;\n x: number;\n y: number;\n}\n\n/** Scratch record `raycast()` hands to `rayVsShapeInto` per candidate. */\nconst scratchHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n};\n\n/**\n * Cast a ray against a list of targets. Returns the closest hit, or null.\n *\n * The returned hit is a fresh object — the caller may keep it; later calls do\n * not overwrite it. Among targets at equal distance the first in `targets` wins.\n * @param ox Ray origin X\n * @param oy Ray origin Y\n * @param dx Ray direction X (should be normalized)\n * @param dy Ray direction Y (should be normalized)\n * @param maxDist Maximum raycast distance\n * @param targets Array of entities to test against\n */\nexport function raycast(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n targets: readonly RaycastTarget[],\n): RaycastHit | null {\n // Every later hit overwrites the scratch, so the best candidate so far is\n // held in locals and only the winner becomes an object.\n let found = false;\n let entity = -1;\n let distance = 0;\n let px = 0;\n let py = 0;\n let nx = 0;\n let ny = 0;\n\n for (let i = 0; i < targets.length; i++) {\n const t = targets[i]!;\n const hit = rayVsShapeInto(ox, oy, dx, dy, maxDist, t.entity, t.shape, t.x, t.y, scratchHit);\n if (hit !== null && (!found || hit.distance < distance)) {\n found = true;\n entity = hit.entity;\n distance = hit.distance;\n px = hit.point.x;\n py = hit.point.y;\n nx = hit.normal.x;\n ny = hit.normal.y;\n }\n }\n\n if (!found) return null;\n return { entity, distance, point: { x: px, y: py }, normal: { x: nx, y: ny } };\n}\n\n/**\n * Zero-alloc ray-vs-shape test: writes into `out` and returns it, or returns\n * `null` without touching `out`.\n *\n * This is the single implementation of the ray math. `raycast()` above and\n * `CollisionWorld.raycast` both run every candidate through it into a scratch\n * record, so neither allocates per candidate tested.\n */\nexport function rayVsShapeInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n shape: Shape,\n x: number,\n y: number,\n out: RaycastHit,\n): RaycastHit | null {\n if (shape.type === 'aabb') {\n return rayVsAABBInto(ox, oy, dx, dy, maxDist, entity, x, y, shape.hw, shape.hh, out);\n }\n return rayVsCircleInto(ox, oy, dx, dy, maxDist, entity, x, y, shape.radius, out);\n}\n\nfunction rayVsAABBInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n bx: number,\n by: number,\n hw: number,\n hh: number,\n out: RaycastHit,\n): RaycastHit | null {\n if (dx === 0 && dy === 0) return null;\n\n // A ray parallel to an axis never crosses that slab's planes: it is inside\n // the slab for all t or for none. Scaling by an infinite inverse instead\n // gives 0 * Infinity = NaN when the origin sits exactly on a plane.\n let tMinX = Number.NEGATIVE_INFINITY;\n let tMaxX = Number.POSITIVE_INFINITY;\n if (dx === 0) {\n if (ox < bx - hw || ox > bx + hw) return null;\n } else {\n const invDx = 1 / dx;\n const tx1 = (bx - hw - ox) * invDx;\n const tx2 = (bx + hw - ox) * invDx;\n tMinX = Math.min(tx1, tx2);\n tMaxX = Math.max(tx1, tx2);\n }\n\n let tMinY = Number.NEGATIVE_INFINITY;\n let tMaxY = Number.POSITIVE_INFINITY;\n if (dy === 0) {\n if (oy < by - hh || oy > by + hh) return null;\n } else {\n const invDy = 1 / dy;\n const ty1 = (by - hh - oy) * invDy;\n const ty2 = (by + hh - oy) * invDy;\n tMinY = Math.min(ty1, ty2);\n tMaxY = Math.max(ty1, ty2);\n }\n\n const tMin = Math.max(tMinX, tMinY);\n const tMax = Math.min(tMaxX, tMaxY);\n if (tMax < 0 || tMin > tMax) return null;\n\n const t = tMin < 0 ? tMax : tMin;\n if (t > maxDist || t < 0) return null;\n\n out.entity = entity;\n out.distance = t;\n out.point.x = ox + dx * t;\n out.point.y = oy + dy * t;\n if (tMinX > tMinY) {\n out.normal.x = dx < 0 ? 1 : -1;\n out.normal.y = 0;\n } else {\n out.normal.x = 0;\n out.normal.y = dy < 0 ? 1 : -1;\n }\n return out;\n}\n\nfunction rayVsCircleInto(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n entity: number,\n cx: number,\n cy: number,\n radius: number,\n out: RaycastHit,\n): RaycastHit | null {\n const fx = ox - cx;\n const fy = oy - cy;\n const a = dx * dx + dy * dy;\n if (a < 1e-12) return null; // Zero-length direction\n\n const b = 2 * (fx * dx + fy * dy);\n const c = fx * fx + fy * fy - radius * radius;\n const discriminant = b * b - 4 * a * c;\n if (discriminant < 0) return null;\n\n const sqrtDisc = Math.sqrt(discriminant);\n let t = (-b - sqrtDisc) / (2 * a);\n // If the entry point is behind the origin, try the exit point.\n if (t < 0) t = (-b + sqrtDisc) / (2 * a);\n if (t < 0 || t > maxDist) return null;\n\n const px = ox + dx * t;\n const py = oy + dy * t;\n const nx = px - cx;\n const ny = py - cy;\n const len = Math.sqrt(nx * nx + ny * ny);\n\n out.entity = entity;\n out.distance = t;\n out.point.x = px;\n out.point.y = py;\n out.normal.x = len > 0 ? nx / len : 0;\n out.normal.y = len > 0 ? ny / len : 0;\n return out;\n}\n","import type { Rect } from '@flare-engine/math';\n\n/** AABB shape — axis-aligned bounding box. */\nexport interface AABBShape {\n readonly type: 'aabb';\n /** Half-width. */\n readonly hw: number;\n /** Half-height. */\n readonly hh: number;\n}\n\n/** Circle shape. */\nexport interface CircleShape {\n readonly type: 'circle';\n readonly radius: number;\n}\n\n/** Union of supported physics shapes. */\nexport type Shape = AABBShape | CircleShape;\n\n/** Create an AABB shape from width and height. */\nexport function AABB(width: number, height: number): AABBShape {\n return { type: 'aabb', hw: width * 0.5, hh: height * 0.5 };\n}\n\n/** Create a circle shape from radius. */\nexport function CircleShape(radius: number): CircleShape {\n return { type: 'circle', radius };\n}\n\n/** Compute the bounding rect of a shape at a given position. */\nexport function shapeBounds(shape: Shape, x: number, y: number): Rect {\n if (shape.type === 'aabb') {\n return { x: x - shape.hw, y: y - shape.hh, width: shape.hw * 2, height: shape.hh * 2 };\n }\n return {\n x: x - shape.radius,\n y: y - shape.radius,\n width: shape.radius * 2,\n height: shape.radius * 2,\n };\n}\n\n/** Zero-alloc variant — writes the shape bounds into the provided output rect. */\nexport function shapeBoundsInto(shape: Shape, x: number, y: number, out: Rect): Rect {\n if (shape.type === 'aabb') {\n out.x = x - shape.hw;\n out.y = y - shape.hh;\n out.width = shape.hw * 2;\n out.height = shape.hh * 2;\n return out;\n }\n out.x = x - shape.radius;\n out.y = y - shape.radius;\n out.width = shape.radius * 2;\n out.height = shape.radius * 2;\n return out;\n}\n\n/** Test overlap between two positioned shapes. Returns true if overlapping. */\nexport function shapeOverlap(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n): boolean {\n if (shapeA.type === 'aabb' && shapeB.type === 'aabb') {\n return aabbVsAabb(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.hw, shapeB.hh);\n }\n if (shapeA.type === 'circle' && shapeB.type === 'circle') {\n return circleVsCircle(ax, ay, shapeA.radius, bx, by, shapeB.radius);\n }\n // Mixed: one AABB, one circle\n if (shapeA.type === 'aabb' && shapeB.type === 'circle') {\n return aabbVsCircle(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.radius);\n }\n return aabbVsCircle(\n bx,\n by,\n (shapeB as AABBShape).hw,\n (shapeB as AABBShape).hh,\n ax,\n ay,\n (shapeA as CircleShape).radius,\n );\n}\n\nfunction aabbVsAabb(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n bx: number,\n by: number,\n bhw: number,\n bhh: number,\n): boolean {\n return Math.abs(ax - bx) < ahw + bhw && Math.abs(ay - by) < ahh + bhh;\n}\n\nfunction circleVsCircle(\n ax: number,\n ay: number,\n ar: number,\n bx: number,\n by: number,\n br: number,\n): boolean {\n const dx = bx - ax;\n const dy = by - ay;\n const radSum = ar + br;\n return dx * dx + dy * dy < radSum * radSum;\n}\n\nfunction aabbVsCircle(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n cx: number,\n cy: number,\n cr: number,\n): boolean {\n const left = ax - ahw;\n const right = ax + ahw;\n const top = ay - ahh;\n const bottom = ay + ahh;\n const closestX = cx < left ? left : cx > right ? right : cx;\n const closestY = cy < top ? top : cy > bottom ? bottom : cy;\n const dx = cx - closestX;\n const dy = cy - closestY;\n const distSq = dx * dx + dy * dy;\n // Strict, like aabbVsAabb and circleVsCircle: exactly-touching shapes do not\n // collide. A centre on or inside the box collides when the radius is positive;\n // a zero radius counts only strictly inside, as a zero-size box does.\n if (distSq > 0) return distSq < cr * cr;\n return cr > 0 || (cx > left && cx < right && cy > top && cy < bottom);\n}\n\n/**\n * Minimum translation vector: the shortest push that separates two overlapping\n * shapes.\n *\n * `shapeOverlap` answers *whether* two shapes collide and nothing more, which\n * leaves a detection-only consumer with no way to resolve the collision. This is\n * that missing step: `out.x`/`out.y` are a unit axis and `out.depth` is how far\n * along it `b` must move to just stop touching `a`.\n *\n * Returns `null` when the shapes are not overlapping, leaving `out` untouched so\n * a caller may reuse one buffer across many pairs.\n *\n * The degenerate concentric case (identical centres) has no meaningful axis;\n * `(1, 0)` is returned so the caller still gets a usable separation instead of\n * `NaN` from normalising a zero vector.\n */\nexport interface Overlap {\n /** Unit separation axis, pointing from `a` toward `b`. */\n x: number;\n y: number;\n /** Penetration depth along that axis. */\n depth: number;\n}\n\n/** A fresh, zeroed overlap record. Allocate once outside the loop and reuse. */\nexport function createOverlap(): Overlap {\n return { x: 0, y: 0, depth: 0 };\n}\n\nexport function overlapInto(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n out: Overlap,\n): Overlap | null {\n if (shapeA.type === 'aabb' && shapeB.type === 'aabb') {\n return aabbAabbOverlap(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.hw, shapeB.hh, out);\n }\n if (shapeA.type === 'circle' && shapeB.type === 'circle') {\n return circleCircleOverlap(ax, ay, shapeA.radius, bx, by, shapeB.radius, out);\n }\n if (shapeA.type === 'aabb' && shapeB.type === 'circle') {\n return aabbCircleOverlap(ax, ay, shapeA.hw, shapeA.hh, bx, by, shapeB.radius, out, false);\n }\n // Circle vs AABB — solve as AABB vs circle, then flip the axis so it still\n // points from `a` to `b`.\n return aabbCircleOverlap(\n bx,\n by,\n (shapeB as AABBShape).hw,\n (shapeB as AABBShape).hh,\n ax,\n ay,\n (shapeA as CircleShape).radius,\n out,\n true,\n );\n}\n\n/** Minimum translation vector. Allocates — see `overlapInto` for the hot path. */\nexport function overlap(\n shapeA: Shape,\n ax: number,\n ay: number,\n shapeB: Shape,\n bx: number,\n by: number,\n): Overlap | null {\n return overlapInto(shapeA, ax, ay, shapeB, bx, by, createOverlap());\n}\n\nfunction aabbAabbOverlap(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n bx: number,\n by: number,\n bhw: number,\n bhh: number,\n out: Overlap,\n): Overlap | null {\n const dx = bx - ax;\n const dy = by - ay;\n const overlapX = ahw + bhw - Math.abs(dx);\n if (overlapX <= 0) return null;\n const overlapY = ahh + bhh - Math.abs(dy);\n if (overlapY <= 0) return null;\n\n // The minimum translation is along whichever axis is least penetrated.\n if (overlapX < overlapY) {\n out.x = dx < 0 ? -1 : 1;\n out.y = 0;\n out.depth = overlapX;\n } else {\n out.x = 0;\n out.y = dy < 0 ? -1 : 1;\n out.depth = overlapY;\n }\n return out;\n}\n\nfunction circleCircleOverlap(\n ax: number,\n ay: number,\n ar: number,\n bx: number,\n by: number,\n br: number,\n out: Overlap,\n): Overlap | null {\n const dx = bx - ax;\n const dy = by - ay;\n const radSum = ar + br;\n const distSq = dx * dx + dy * dy;\n if (distSq >= radSum * radSum) return null;\n\n const dist = Math.sqrt(distSq);\n if (dist === 0) {\n // Concentric: no meaningful axis, so pick one rather than divide by zero.\n out.x = 1;\n out.y = 0;\n out.depth = radSum;\n return out;\n }\n out.x = dx / dist;\n out.y = dy / dist;\n out.depth = radSum - dist;\n return out;\n}\n\nfunction aabbCircleOverlap(\n ax: number,\n ay: number,\n ahw: number,\n ahh: number,\n cx: number,\n cy: number,\n cr: number,\n out: Overlap,\n flip: boolean,\n): Overlap | null {\n const left = ax - ahw;\n const right = ax + ahw;\n const top = ay - ahh;\n const bottom = ay + ahh;\n const closestX = cx < left ? left : cx > right ? right : cx;\n const closestY = cy < top ? top : cy > bottom ? bottom : cy;\n const dx = cx - closestX;\n const dy = cy - closestY;\n const distSq = dx * dx + dy * dy;\n\n if (distSq > 0) {\n // Centre outside the box: separate along the closest-point normal.\n if (distSq >= cr * cr) return null;\n const dist = Math.sqrt(distSq);\n const nx = dx / dist;\n const ny = dy / dist;\n out.x = flip ? -nx : nx;\n out.y = flip ? -ny : ny;\n out.depth = cr - dist;\n return out;\n }\n\n // Centre inside the box: push out through the nearest face.\n const toLeft = cx - left;\n const toRight = right - cx;\n const toTop = cy - top;\n const toBottom = bottom - cy;\n let nx = -1;\n let ny = 0;\n let depth = toLeft;\n if (toRight < depth) {\n nx = 1;\n ny = 0;\n depth = toRight;\n }\n if (toTop < depth) {\n nx = 0;\n ny = -1;\n depth = toTop;\n }\n if (toBottom < depth) {\n nx = 0;\n ny = 1;\n depth = toBottom;\n }\n // Zero radius on the boundary is exactly touching, not overlapping.\n if (depth + cr <= 0) return null;\n out.x = flip ? -nx : nx;\n out.y = flip ? -ny : ny;\n out.depth = depth + cr;\n return out;\n}\n","import type { Rect } from '@flare-engine/math';\n\n// Internal entry: bounding rect (minX, minY, maxX, maxY) plus a per-query stamp\n// for zero-alloc dedup.\ninterface _Entry<T> {\n readonly item: T;\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n _stamp: number;\n}\n\n// Uniform grid cell size in world units. Tuned for typical game-object sizes (16–64 px).\nconst CELL = 64;\n\n// Packed cell-key encoding. Supports cell coords in [-32768, 32767],\n// i.e. world coordinates ±2 097 152. All keys fit within Number.MAX_SAFE_INTEGER.\nconst KEY_RANGE = 65536; // 2^16\nconst KEY_OFFSET = 32768; // 2^15\n\nfunction _key(cx: number, cy: number): number {\n return (cx + KEY_OFFSET) * KEY_RANGE + (cy + KEY_OFFSET);\n}\n\n// Inclusive min cell that contains world coordinate v.\nfunction _cMin(v: number): number {\n return Math.floor(v / CELL);\n}\n\n// Inclusive max cell that contains world coordinate v (exclusive-end: a coord\n// falling exactly on a cell boundary is NOT part of the adjacent cell — matches\n// the strict-inequality overlap semantics of query()).\nfunction _cMax(v: number): number {\n return Math.ceil(v / CELL) - 1;\n}\n\n// Supported cell-coordinate range for the packed key above.\nconst MIN_CELL = -KEY_OFFSET;\nconst MAX_CELL = KEY_OFFSET - 1;\n\n// Bounds a derived cell coordinate to the packed-key range. Without this, a\n// non-finite world coordinate (±Infinity — an unbounded raycast maxDist, or an\n// entity parked at Infinity) makes cxMin/cxMax/cyMin/cyMax infinite, and\n// `for (cx = cxMin; cx <= cxMax; cx++)` never exits: once cx itself is\n// Infinity, `cx <= Infinity` stays true and `cx++` is a no-op, so the loop\n// spins forever pushing/reading the same bucket (unbounded memory growth on\n// the link side). NaN is left untouched: every comparison against NaN is\n// false, so the loop already runs zero times, which is the existing (safe)\n// behaviour for a degenerate direction like `0 * Infinity`.\nfunction _clampCell(c: number): number {\n if (c > MAX_CELL) return MAX_CELL;\n if (c < MIN_CELL) return MIN_CELL;\n return c;\n}\n\n/**\n * Uniform spatial-hash broadphase.\n * `insert`, `remove`, and `update` are O(cells touched) — O(1) for typical entities.\n * `query` walks only the cells overlapping the given rect; result order is unspecified.\n * Zero-alloc in the query hot-path: duplicate suppression uses a monotone stamp counter,\n * not a per-call Set.\n */\nexport class SpatialIndex<T> {\n private _data: _Entry<T>[] = [];\n private _slots = new Map<T, number>(); // item → dense-array slot\n private _cells = new Map<number, _Entry<T>[]>(); // packed cell key → bucket\n private _gen = 0; // monotone query-generation counter\n\n /** Number of items in the index. */\n get size(): number {\n return this._data.length;\n }\n\n /**\n * Insert an item with a bounding rect. Inserting an item already in the index\n * replaces its bounds (upsert) — same as `update`.\n */\n insert(item: T, bounds: Rect): void {\n if (this._slots.has(item)) {\n this.update(item, bounds);\n return;\n }\n const entry: _Entry<T> = {\n item,\n minX: bounds.x,\n minY: bounds.y,\n maxX: bounds.x + bounds.width,\n maxY: bounds.y + bounds.height,\n _stamp: 0,\n };\n this._slots.set(item, this._data.length);\n this._data.push(entry);\n this._link(entry);\n }\n\n /** Remove an item. Returns false when the item was not present. */\n remove(item: T): boolean {\n const slot = this._slots.get(item);\n if (slot === undefined) return false;\n const entry = this._data[slot]!;\n this._unlink(entry);\n this._slots.delete(item);\n // Swap-remove: plug the hole with the last element.\n const last = this._data.pop()!;\n if (slot < this._data.length) {\n this._data[slot] = last;\n this._slots.set(last.item, slot);\n }\n return true;\n }\n\n /** Update the bounds for an existing item. No-op when the item is absent. */\n update(item: T, bounds: Rect): void {\n const slot = this._slots.get(item);\n if (slot === undefined) return;\n const entry = this._data[slot]!;\n this._unlink(entry);\n entry.minX = bounds.x;\n entry.minY = bounds.y;\n entry.maxX = bounds.x + bounds.width;\n entry.maxY = bounds.y + bounds.height;\n this._link(entry);\n }\n\n /**\n * Query all items whose bounds overlap the given rect.\n * Result order is unspecified. Appends to `result` when provided and returns it.\n */\n query(bounds: Rect, result?: T[]): T[] {\n const out = result ?? [];\n const gen = ++this._gen;\n\n const qMinX = bounds.x;\n const qMinY = bounds.y;\n const qMaxX = bounds.x + bounds.width;\n const qMaxY = bounds.y + bounds.height;\n\n const cxMin = _clampCell(_cMin(qMinX));\n const cxMax = _clampCell(_cMax(qMaxX));\n const cyMin = _clampCell(_cMin(qMinY));\n const cyMax = _clampCell(_cMax(qMaxY));\n\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const bucket = this._cells.get(_key(cx, cy));\n if (bucket === undefined) continue;\n for (let i = 0; i < bucket.length; i++) {\n const e = bucket[i]!;\n if (e._stamp === gen) continue; // already emitted this query\n e._stamp = gen;\n if (e.maxX > qMinX && e.minX < qMaxX && e.maxY > qMinY && e.minY < qMaxY) {\n out.push(e.item);\n }\n }\n }\n }\n return out;\n }\n\n /** Remove all items. */\n clear(): void {\n this._data.length = 0;\n this._slots.clear();\n this._cells.clear();\n }\n\n // Register entry in all grid cells it overlaps.\n private _link(entry: _Entry<T>): void {\n const cxMin = _clampCell(_cMin(entry.minX));\n const cxMax = _clampCell(_cMax(entry.maxX));\n const cyMin = _clampCell(_cMin(entry.minY));\n const cyMax = _clampCell(_cMax(entry.maxY));\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const k = _key(cx, cy);\n let b = this._cells.get(k);\n if (b === undefined) {\n b = [];\n this._cells.set(k, b);\n }\n b.push(entry);\n }\n }\n }\n\n // Remove entry from all grid cells it currently occupies.\n private _unlink(entry: _Entry<T>): void {\n const cxMin = _clampCell(_cMin(entry.minX));\n const cxMax = _clampCell(_cMax(entry.maxX));\n const cyMin = _clampCell(_cMin(entry.minY));\n const cyMax = _clampCell(_cMax(entry.maxY));\n for (let cx = cxMin; cx <= cxMax; cx++) {\n for (let cy = cyMin; cy <= cyMax; cy++) {\n const b = this._cells.get(_key(cx, cy));\n if (b === undefined) continue;\n const i = b.indexOf(entry);\n if (i !== -1) {\n // Swap-remove within the bucket.\n const last = b.pop()!;\n if (i < b.length) b[i] = last;\n }\n }\n }\n }\n}\n","import { Signal } from '@flare-engine/events';\nimport type { Rect } from '@flare-engine/math';\nimport type { Collider } from './collider.js';\nimport type { RaycastHit } from './raycast.js';\nimport { rayVsShapeInto } from './raycast.js';\nimport type { Shape } from './shape.js';\nimport { shapeBoundsInto, shapeOverlap } from './shape.js';\nimport { SpatialIndex } from './spatial-index.js';\n\n/** Collision pair data emitted by collision signals. */\nexport interface CollisionPair {\n readonly entityA: number;\n readonly entityB: number;\n}\n\n/** Per-entity collision data stored in the world. */\ninterface CollisionEntry {\n entity: number;\n shape: Shape;\n x: number;\n y: number;\n isTrigger: boolean;\n layer: number;\n mask: number;\n}\n\n// Packed pair-key layout: `lo * ENTITY_SHIFT + hi`, lo = min(a,b), hi = max(a,b).\n// 2^26 fits within Number.MAX_SAFE_INTEGER for 26+26 bits → max entity id ~67M.\nconst ENTITY_SHIFT = 2 ** 26;\n\n/** Padding applied to a ray's query AABB — see `CollisionWorld.raycast`. */\nconst RAY_BOUNDS_PAD = 1e-6;\n\nfunction encodePair(a: number, b: number): number {\n const lo = a < b ? a : b;\n const hi = a < b ? b : a;\n return lo * ENTITY_SHIFT + hi;\n}\n\nfunction decodeLo(key: number): number {\n return Math.floor(key / ENTITY_SHIFT);\n}\n\nfunction decodeHi(key: number): number {\n return key - Math.floor(key / ENTITY_SHIFT) * ENTITY_SHIFT;\n}\n\n/**\n * AABB collision world. Manages entities with shapes, detects overlaps each step,\n * and emits collision/trigger signals.\n */\nexport class CollisionWorld {\n readonly onCollisionStart = new Signal<CollisionPair>();\n readonly onCollisionEnd = new Signal<CollisionPair>();\n readonly onTriggerEnter = new Signal<CollisionPair>();\n readonly onTriggerExit = new Signal<CollisionPair>();\n\n private entries = new Map<number, CollisionEntry>();\n private spatial = new SpatialIndex<number>();\n /**\n * Two pre-allocated pair buffers — swapped each step (no per-frame allocation).\n * Keys are packed numbers via `encodePair(a, b)`.\n */\n private pairBufA = new Set<number>();\n private pairBufB = new Set<number>();\n private activePairs: Set<number> = this.pairBufA;\n /** Reusable query result buffer. */\n private queryBuf: number[] = [];\n /** Reusable bounds rect — avoids per-entity Rect allocation in step(). */\n private boundsBuf: Rect = { x: 0, y: 0, width: 0, height: 0 };\n\n /**\n * Add an entity with a shape. Positional twin of `addCollider`, and re-adding\n * follows the same rules.\n */\n add(\n entity: number,\n shape: Shape,\n x: number,\n y: number,\n isTrigger = false,\n layer = 1,\n mask = 0xffffffff,\n ): void {\n const entry: CollisionEntry = { entity, shape, x, y, isTrigger, layer, mask };\n const previous = this.entries.get(entity);\n this.entries.set(entity, entry);\n shapeBoundsInto(shape, x, y, this.boundsBuf);\n if (previous === undefined) {\n this.spatial.insert(entity, this.boundsBuf);\n return;\n }\n this.spatial.update(entity, this.boundsBuf);\n if (previous.isTrigger === isTrigger) return;\n\n // A pair is a trigger pair when either side is a trigger, so flipping this\n // side changes the kind only of pairs whose other side is solid. End those\n // now in their old family; the next step starts them in the new one.\n for (const key of this.activePairs) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n if (lo !== entity && hi !== entity) continue;\n const other = this.entries.get(lo === entity ? hi : lo);\n if (other?.isTrigger) continue;\n this.activePairs.delete(key);\n this.emitPair(lo, hi, previous, other, false);\n }\n }\n\n /**\n * Add an entity from a `Collider`. Its `shape`, `isTrigger`, `layer` and `mask`\n * are copied at add time — later edits to the collider do not reach the world;\n * re-add to change them. Re-adding an existing entity replaces its data.\n *\n * A re-add that flips `isTrigger` ends, during this call, every active pair\n * whose kind that changes, with the exit signal of its old kind\n * (`onTriggerExit` or `onCollisionEnd`). If the shapes still overlap, the next\n * `step` starts the pair again with the enter signal of its new kind. A pair\n * whose other side is a trigger stays a trigger pair and is left alone.\n */\n addCollider(entity: number, collider: Collider, x: number, y: number): void {\n this.add(entity, collider.shape, x, y, collider.isTrigger, collider.layer, collider.mask);\n }\n\n /** Remove an entity from the world. Emits exit signals for any active pairs. */\n remove(entity: number): void {\n const entry = this.entries.get(entity);\n if (!entry) return;\n\n this.entries.delete(entity);\n this.spatial.remove(entity);\n\n // Fire exit signals for all active pairs involving this entity\n for (const key of this.activePairs) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n if (lo !== entity && hi !== entity) continue;\n this.activePairs.delete(key);\n const otherEntity = lo === entity ? hi : lo;\n this.emitPair(lo, hi, entry, this.entries.get(otherEntity), false);\n }\n }\n\n /** Update an entity's position. */\n setPosition(entity: number, x: number, y: number): void {\n const entry = this.entries.get(entity);\n if (!entry) return;\n entry.x = x;\n entry.y = y;\n shapeBoundsInto(entry.shape, x, y, this.boundsBuf);\n this.spatial.update(entity, this.boundsBuf);\n }\n\n /** Number of entities in the world. */\n get size(): number {\n return this.entries.size;\n }\n\n /** Number of broadphase records (one per live entity after add/remove). Diagnostic for broadphase growth. */\n get broadphaseSize(): number {\n return this.spatial.size;\n }\n\n /** Run one collision detection step. */\n step(): void {\n const newPairs = this.activePairs === this.pairBufA ? this.pairBufB : this.pairBufA;\n newPairs.clear();\n\n for (const entryA of this.entries.values()) {\n const entityA = entryA.entity;\n shapeBoundsInto(entryA.shape, entryA.x, entryA.y, this.boundsBuf);\n this.queryBuf.length = 0;\n this.spatial.query(this.boundsBuf, this.queryBuf);\n\n for (let i = 0; i < this.queryBuf.length; i++) {\n const entityB = this.queryBuf[i]!;\n if (entityB <= entityA) continue; // Avoid self and duplicates\n\n const entryB = this.entries.get(entityB);\n if (!entryB) continue;\n\n // Layer/mask filtering\n if ((entryA.layer & entryB.mask) === 0 && (entryB.layer & entryA.mask) === 0) continue;\n\n // Narrowphase\n if (!shapeOverlap(entryA.shape, entryA.x, entryA.y, entryB.shape, entryB.x, entryB.y)) {\n continue;\n }\n\n newPairs.add(encodePair(entityA, entityB));\n }\n }\n\n // Enter/start events — pair objects are allocated here only on state transitions.\n for (const key of newPairs) {\n if (!this.activePairs.has(key)) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n this.emitPair(lo, hi, this.entries.get(lo), this.entries.get(hi), true);\n }\n }\n\n // Exit/end events\n for (const key of this.activePairs) {\n if (!newPairs.has(key)) {\n const lo = decodeLo(key);\n const hi = decodeHi(key);\n this.emitPair(lo, hi, this.entries.get(lo), this.entries.get(hi), false);\n }\n }\n\n this.activePairs = newPairs;\n }\n\n /**\n * The one place that decides trigger vs collision for a pair and emits its\n * enter or exit signal. `a` and `b` are the pair's two entries in either\n * order. They are passed in rather than looked up because in `remove` the\n * removed entity is already gone from `entries`.\n */\n private emitPair(\n lo: number,\n hi: number,\n a: CollisionEntry | undefined,\n b: CollisionEntry | undefined,\n entering: boolean,\n ): void {\n const pair: CollisionPair = { entityA: lo, entityB: hi };\n if (a?.isTrigger || b?.isTrigger) {\n if (entering) this.onTriggerEnter.emit(pair);\n else this.onTriggerExit.emit(pair);\n } else if (entering) {\n this.onCollisionStart.emit(pair);\n } else {\n this.onCollisionEnd.emit(pair);\n }\n }\n\n /** Zero-alloc collider bounds — writes the AABB of entity's shape into `out`. Returns null when entity is absent. */\n getColliderBoundsInto(entity: number, out: Rect): Rect | null {\n const entry = this.entries.get(entity);\n if (!entry) return null;\n shapeBoundsInto(entry.shape, entry.x, entry.y, out);\n return out;\n }\n\n /** Allocating convenience wrapper — returns a fresh Rect or null when entity is absent. */\n getColliderBounds(entity: number): Rect | null {\n const entry = this.entries.get(entity);\n if (!entry) return null;\n return shapeBoundsInto(entry.shape, entry.x, entry.y, { x: 0, y: 0, width: 0, height: 0 });\n }\n\n /** Remove all entities. */\n clear(): void {\n this.entries.clear();\n this.spatial.clear();\n this.pairBufA.clear();\n this.pairBufB.clear();\n this.activePairs = this.pairBufA;\n }\n\n /** Reused across raycasts — see `raycast`. */\n private raycastBounds: Rect = { x: 0, y: 0, width: 0, height: 0 };\n private raycastCandidates: number[] = [];\n private raycastHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n };\n\n /**\n * Cast a ray against the colliders in this world.\n *\n * The standalone `raycast()` export tests a caller-supplied target array, so\n * it neither sees the world's colliders nor benefits from the broadphase — an\n * O(n) scan sitting beside an O(1) index. This walks only the cells the ray's\n * bounding box touches.\n *\n * `mask` is a layer bitmask filtered against each collider's `layer`, using the\n * bits colliders already carry; it defaults to every layer. Triggers are\n * included — a ray asking \"what is over there\" wants them.\n *\n * The returned record is **reused between calls**: read it, or copy what you\n * need, before casting again. That is what keeps a per-frame ray allocation-\n * free; the standalone helper by contrast returns a fresh hit from each call\n * that hits, which the caller may keep.\n *\n * `maxDist` must be finite — this requires a bounded ray, not the\n * `Number.POSITIVE_INFINITY` \"unbounded ray\" idiom some engines accept. The\n * broadphase below is a uniform grid: an infinite `maxDist` derives an\n * infinite cell range and never terminates the walk. Pass a large finite\n * bound instead (e.g. the map's diagonal) to cast \"until it leaves the\n * populated area\". A non-finite `maxDist` returns `null`.\n */\n raycast(\n ox: number,\n oy: number,\n dx: number,\n dy: number,\n maxDist: number,\n mask = 0xffffffff,\n ): RaycastHit | null {\n if (!Number.isFinite(maxDist)) return null;\n\n // Bounding box of the whole ray — the broadphase is rect-based, so this is\n // a conservative prefilter, not the intersection test itself.\n const ex = ox + dx * maxDist;\n const ey = oy + dy * maxDist;\n const minX = ox < ex ? ox : ex;\n const minY = oy < ey ? oy : ey;\n // Padded so the rect always has non-zero extent on both axes. An axis-\n // aligned ray is otherwise degenerate — a horizontal ray has height 0 — and\n // SpatialIndex derives its cell range with an exclusive end (`_cMax` is\n // `ceil(v / CELL) - 1`), so a zero-height rect yields cyMin 0 > cyMax -1 and\n // the cell loop never runs. The broadphase is a conservative prefilter\n // anyway, so over-including by a hair costs nothing: the exact ray test\n // below rejects the extras.\n this.raycastBounds.x = minX - RAY_BOUNDS_PAD;\n this.raycastBounds.y = minY - RAY_BOUNDS_PAD;\n this.raycastBounds.width = Math.abs(ex - ox) + RAY_BOUNDS_PAD * 2;\n this.raycastBounds.height = Math.abs(ey - oy) + RAY_BOUNDS_PAD * 2;\n\n this.raycastCandidates.length = 0;\n this.spatial.query(this.raycastBounds, this.raycastCandidates);\n\n let bestDist = Number.POSITIVE_INFINITY;\n let found = false;\n for (let i = 0; i < this.raycastCandidates.length; i++) {\n const entry = this.entries.get(this.raycastCandidates[i]!);\n if (entry === undefined) continue;\n if ((entry.layer & mask) === 0) continue;\n const hit = rayVsShapeInto(\n ox,\n oy,\n dx,\n dy,\n maxDist,\n entry.entity,\n entry.shape,\n entry.x,\n entry.y,\n this.scratchHit,\n );\n if (hit !== null && hit.distance < bestDist) {\n bestDist = hit.distance;\n found = true;\n this.raycastHit.entity = hit.entity;\n this.raycastHit.distance = hit.distance;\n this.raycastHit.point.x = hit.point.x;\n this.raycastHit.point.y = hit.point.y;\n this.raycastHit.normal.x = hit.normal.x;\n this.raycastHit.normal.y = hit.normal.y;\n }\n }\n return found ? this.raycastHit : null;\n }\n\n /** Scratch record handed to `rayVsShapeInto` per candidate. */\n private scratchHit: RaycastHit = {\n entity: -1,\n distance: 0,\n point: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n };\n}\n","import type { Vec2 } from '@flare-engine/math';\n\n/**\n * Minimal structural type for a solid tile position in grid coordinates.\n * `TileCollider[]` from `@flare-engine/tilemap` is structurally assignable here\n * so callers can pass `extractColliders(map)` directly — no tilemap dep needed.\n */\nexport interface SolidTile {\n readonly row: number;\n readonly col: number;\n}\n\n/**\n * How `isBlockedAABB` treats cells outside the grid.\n * `'solid'` — the map edge is a wall; any box that leaves the map is blocked.\n * `'open'` — cells outside the grid are empty, so a body can walk off the map;\n * use it for seams between adjacent region maps.\n */\nexport type SolidGridOutside = 'solid' | 'open';\n\nexport interface SolidGridOptions {\n /** Defaults to `'solid'`. */\n readonly outside?: SolidGridOutside;\n}\n\n/**\n * Precomputed solid-tile lookup used by `isBlockedAABB` and `moveAndSlideInto`.\n * `solid` has `width * height` cells indexed `row * width + col`; non-zero means\n * solid. Build once per map load via `buildSolidGrid`.\n */\nexport interface SolidGrid {\n readonly width: number;\n readonly height: number;\n readonly tileSize: number;\n readonly solid: Uint8Array;\n readonly outside: SolidGridOutside;\n}\n\n/**\n * Build a `SolidGrid` from a list of solid tile positions.\n * Input is structurally typed (`readonly SolidTile[]`) so the caller does not\n * need to import `@flare-engine/tilemap` — physics stays tilemap-free.\n */\nexport function buildSolidGrid(\n width: number,\n height: number,\n tileSize: number,\n tiles: readonly SolidTile[],\n options?: SolidGridOptions,\n): SolidGrid {\n const solid = new Uint8Array(width * height);\n for (const t of tiles) {\n solid[t.row * width + t.col] = 1;\n }\n return { width, height, tileSize, solid, outside: options?.outside ?? 'solid' };\n}\n\n/**\n * Half-open boundary constant: the AABB is treated as [min, max) so a box\n * whose max edge lands exactly on a tile boundary does NOT overlap that tile.\n */\nconst EDGE = 1e-4;\n\n/**\n * Returns `true` when an axis-aligned box centered at (`x`, `y`) with\n * half-extents (`halfW`, `halfH`) overlaps a solid tile. Leaving the map\n * blocks only when the grid was built with `outside: 'solid'` (the default);\n * with `'open'` the out-of-grid cells are empty and only the in-grid cells the\n * box overlaps are tested. Uses half-open EDGE semantics on max edges.\n */\nexport function isBlockedAABB(\n grid: SolidGrid,\n x: number,\n y: number,\n halfW: number,\n halfH: number,\n): boolean {\n const ts = grid.tileSize;\n let minCol = Math.floor((x - halfW) / ts);\n let maxCol = Math.floor((x + halfW - EDGE) / ts);\n let minRow = Math.floor((y - halfH) / ts);\n let maxRow = Math.floor((y + halfH - EDGE) / ts);\n if (minCol < 0 || minRow < 0 || maxCol >= grid.width || maxRow >= grid.height) {\n if (grid.outside === 'solid') return true;\n // Clamp to the in-grid cells; a box fully outside yields an empty range.\n if (minCol < 0) minCol = 0;\n if (minRow < 0) minRow = 0;\n if (maxCol >= grid.width) maxCol = grid.width - 1;\n if (maxRow >= grid.height) maxRow = grid.height - 1;\n }\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n if (grid.solid[row * grid.width + col] !== 0) {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * Whether the cell at (`col`, `row`) is solid. Coordinates that name no cell\n * (out of range, or not an integer) follow the grid's own `outside` rule, like\n * `isBlockedAABB` at the map edge: solid on an `outside: 'solid'` grid, empty\n * on an `'open'` one. Zero-alloc.\n */\nexport function isSolidAt(grid: SolidGrid, col: number, row: number): boolean {\n if (!isCell(grid, col, row)) return grid.outside === 'solid';\n return grid.solid[row * grid.width + col] !== 0;\n}\n\n/**\n * Mark the cell at (`col`, `row`) solid or empty, for a door or a breakable\n * wall. Returns `true` when the cell was written, `false` (and writes nothing)\n * when the coordinates are out of range or not integers. Zero-alloc.\n */\nexport function setSolidAt(grid: SolidGrid, col: number, row: number, solid: boolean): boolean {\n if (!isCell(grid, col, row)) return false;\n grid.solid[row * grid.width + col] = solid ? 1 : 0;\n return true;\n}\n\nfunction isCell(grid: SolidGrid, col: number, row: number): boolean {\n return (\n Number.isInteger(col) &&\n Number.isInteger(row) &&\n col >= 0 &&\n col < grid.width &&\n row >= 0 &&\n row < grid.height\n );\n}\n\n/**\n * Axis-separated slide movement. Attempts to move by (`dx`, `dy`); each axis\n * is applied independently so a blocked diagonal input slides along the wall.\n * The y-check uses the already-updated x position.\n * Zero-alloc: writes result into the provided `out` Vec2 and returns it.\n */\nexport function moveAndSlideInto(\n grid: SolidGrid,\n x: number,\n y: number,\n dx: number,\n dy: number,\n halfW: number,\n halfH: number,\n out: Vec2,\n): Vec2 {\n let nx = x;\n let ny = y;\n if (dx !== 0 && !isBlockedAABB(grid, nx + dx, ny, halfW, halfH)) nx += dx;\n if (dy !== 0 && !isBlockedAABB(grid, nx, ny + dy, halfW, halfH)) ny += dy;\n out.x = nx;\n out.y = ny;\n return out;\n}\n"],"mappings":";;;AAeA,SAAgB,eAAe,OAAc,MAAmD;CAC9F,OAAO;EACL;EACA,WAAW,MAAM,aAAa;EAC9B,OAAO,MAAM,SAAS;EACtB,MAAM,MAAM,QAAQ;CACtB;AACF;;;ACEA,MAAM,aAAyB;CAC7B,QAAQ;CACR,UAAU;CACV,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;CACpB,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;AACvB;;;;;;;;;;;;;AAcA,SAAgB,QACd,IACA,IACA,IACA,IACA,SACA,SACmB;CAGnB,IAAI,QAAQ;CACZ,IAAI,SAAS;CACb,IAAI,WAAW;CACf,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CAET,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,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,GAAG,GAAG,OAAO,KAAK,YAAY;CACrD,OAAO,KAAK,MAAM,MAAM,KAAK,QAAQ,SAAS;AAChD;;;;;;AAOA,SAAgB,WAAW,MAAiB,KAAa,KAAa,OAAyB;CAC7F,IAAI,CAAC,OAAO,MAAM,KAAK,GAAG,GAAG,OAAO;CACpC,KAAK,MAAM,MAAM,KAAK,QAAQ,OAAO,QAAQ,IAAI;CACjD,OAAO;AACT;AAEA,SAAS,OAAO,MAAiB,KAAa,KAAsB;CAClE,OACE,OAAO,UAAU,GAAG,KACpB,OAAO,UAAU,GAAG,KACpB,OAAO,KACP,MAAM,KAAK,SACX,OAAO,KACP,MAAM,KAAK;AAEf;;;;;;;AAQA,SAAgB,iBACd,MACA,GACA,GACA,IACA,IACA,OACA,OACA,KACM;CACN,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,OAAO,KAAK,CAAC,cAAc,MAAM,KAAK,IAAI,IAAI,OAAO,KAAK,GAAG,MAAM;CACvE,IAAI,OAAO,KAAK,CAAC,cAAc,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,GAAG,MAAM;CACvE,IAAI,IAAI;CACR,IAAI,IAAI;CACR,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/physics",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "AABB collision, spatial index, raycasting",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"flare-engine",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"typecheck": "tsc --noEmit"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@flare-engine/events": "^0.4.
|
|
50
|
-
"@flare-engine/math": "^0.4.
|
|
49
|
+
"@flare-engine/events": "^0.4.13",
|
|
50
|
+
"@flare-engine/math": "^0.4.13"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=20"
|