@daneren2005/shared-memory-physics 1.1.0 → 1.2.0

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 CHANGED
@@ -5,6 +5,8 @@
5
5
  lives in the ECS's shared-memory blocks, so the simulation can run on a worker thread while the main thread
6
6
  reads positions straight off its entities.
7
7
 
8
+ Examples at https://daneren2005.github.io/shared-memory-physics/
9
+
8
10
  The ECS (`>=1.1.1`) and the shared-memory primitives it is built on are **peer dependencies**: a game must
9
11
  register these components against the same copy of the ECS it builds its world with.
10
12
 
@@ -4,6 +4,7 @@ export interface BodyComponent {
4
4
  shape: number;
5
5
  collideCategory: number;
6
6
  collideMask: number;
7
+ sensor: boolean;
7
8
  }
8
9
  export declare const SHAPE_RECTANGLE = 1;
9
10
  export declare const SHAPE_CIRCLE = 2;
@@ -18,10 +19,13 @@ export interface BodyConfig {
18
19
  radius?: number;
19
20
  collideCategory?: number;
20
21
  collideMask?: number;
22
+ sensor?: boolean;
21
23
  }
22
24
  export declare const BODY_SHAPE_INDEX = 0;
23
25
  export declare const BODY_CATEGORY_INDEX = 1;
24
26
  export declare const BODY_MASK_INDEX = 2;
25
- export declare const BODY_SIZE = 3;
27
+ export declare const BODY_SENSOR_INDEX = 3;
28
+ export declare const BODY_SIZE = 4;
29
+ export declare function isSensor(body: Uint32Array): boolean;
26
30
  export declare const bodyDefinition: ComponentDefinition<BodyComponent, Uint32Array, BodyConfig>;
27
31
  export default bodyDefinition;
@@ -0,0 +1,12 @@
1
+ import type { ComponentDefinition } from '@daneren2005/shared-memory-ecs';
2
+ export interface BouncinessComponent {
3
+ index: number;
4
+ bounciness: number;
5
+ }
6
+ export interface BouncinessConfig {
7
+ bounciness?: number;
8
+ }
9
+ export declare const BOUNCINESS_INDEX = 0;
10
+ export declare const BOUNCINESS_SIZE = 1;
11
+ export declare const bouncinessDefinition: ComponentDefinition<BouncinessComponent, Float32Array, BouncinessConfig>;
12
+ export default bouncinessDefinition;
@@ -1,4 +1,5 @@
1
1
  import { type BodyComponent } from './body-component';
2
+ import { type BouncinessComponent } from './bounciness-component';
2
3
  import { type InterpolationComponent } from './interpolation-component';
3
4
  import { type TransformComponent } from './transform-component';
4
5
  import { type VelocityComponent } from './velocity-component';
@@ -6,12 +7,14 @@ export declare const physicsRegistry: {
6
7
  transform: import("@daneren2005/shared-memory-ecs").ComponentDefinition<TransformComponent, Float32Array<ArrayBufferLike>, import("./transform-component").TransformConfig, import("./transform-component").TransformSerialization>;
7
8
  velocity: import("@daneren2005/shared-memory-ecs").ComponentDefinition<VelocityComponent, Float32Array<ArrayBufferLike>, import("./velocity-component").VelocityConfig, import("./velocity-component").VelocityConfig>;
8
9
  body: import("@daneren2005/shared-memory-ecs").ComponentDefinition<BodyComponent, Uint32Array<ArrayBufferLike>, import("./body-component").BodyConfig, object>;
10
+ bounciness: import("@daneren2005/shared-memory-ecs").ComponentDefinition<BouncinessComponent, Float32Array<ArrayBufferLike>, import("./bounciness-component").BouncinessConfig, object>;
9
11
  interpolation: import("@daneren2005/shared-memory-ecs").ComponentDefinition<InterpolationComponent, Float32Array<ArrayBufferLike>, import("./interpolation-component").InterpolationConfig, object>;
10
12
  };
11
13
  export type PhysicsComponents = {
12
14
  transform: TransformComponent;
13
15
  velocity: VelocityComponent;
14
16
  body: BodyComponent;
17
+ bounciness: BouncinessComponent;
15
18
  interpolation: InterpolationComponent;
16
19
  };
17
20
  export type InterpolationComponents = {
@@ -22,6 +25,7 @@ export type PhysicsUpdateComponents = {
22
25
  transform: Float32Array;
23
26
  velocity: Float32Array;
24
27
  body?: Uint32Array;
28
+ bounciness?: Float32Array;
25
29
  interpolation?: Float32Array;
26
30
  };
27
31
  export type InterpolationUpdateComponents = {
package/dist/index.d.ts CHANGED
@@ -4,9 +4,12 @@ export type { TransformComponent, TransformConfig, TransformSerialization, } fro
4
4
  export { default as velocityDefinition } from './components/velocity-component';
5
5
  export { VELOCITY_X_INDEX, VELOCITY_Y_INDEX, VELOCITY_SIZE, } from './components/velocity-component';
6
6
  export type { VelocityComponent, VelocityConfig, VelocitySerialization, } from './components/velocity-component';
7
- export { default as bodyDefinition, canCollide } from './components/body-component';
8
- export { SHAPE_RECTANGLE, SHAPE_CIRCLE, SHAPE_CAPSULE, DEFAULT_COLLIDE_CATEGORY, DEFAULT_COLLIDE_MASK, BODY_SHAPE_INDEX, BODY_CATEGORY_INDEX, BODY_MASK_INDEX, BODY_SIZE, } from './components/body-component';
7
+ export { default as bodyDefinition, canCollide, isSensor } from './components/body-component';
8
+ export { SHAPE_RECTANGLE, SHAPE_CIRCLE, SHAPE_CAPSULE, DEFAULT_COLLIDE_CATEGORY, DEFAULT_COLLIDE_MASK, BODY_SHAPE_INDEX, BODY_CATEGORY_INDEX, BODY_MASK_INDEX, BODY_SENSOR_INDEX, BODY_SIZE, } from './components/body-component';
9
9
  export type { BodyComponent, BodyConfig, } from './components/body-component';
10
+ export { default as bouncinessDefinition } from './components/bounciness-component';
11
+ export { BOUNCINESS_INDEX, BOUNCINESS_SIZE, } from './components/bounciness-component';
12
+ export type { BouncinessComponent, BouncinessConfig, } from './components/bounciness-component';
10
13
  export { default as interpolationDefinition, snapEntity } from './components/interpolation-component';
11
14
  export { INTERPOLATION_X_INDEX, INTERPOLATION_Y_INDEX, INTERPOLATION_PREV_X_INDEX, INTERPOLATION_PREV_Y_INDEX, INTERPOLATION_PROGRESS_INDEX, INTERPOLATION_SYNCED_TICK_INDEX, INTERPOLATION_DURATION_INDEX, INTERPOLATION_TICK_INDEX, INTERPOLATION_SIZE, } from './components/interpolation-component';
12
15
  export type { InterpolationComponent, InterpolationConfig, SnappableEntity, } from './components/interpolation-component';
@@ -14,7 +17,7 @@ export { physicsRegistry } from './components/registry';
14
17
  export type { PhysicsComponents, PhysicsUpdateComponents, InterpolationComponents, InterpolationUpdateComponents, } from './components/registry';
15
18
  export { shapesOverlap, shapeHalfWidth, shapeHalfHeight, shapeIsEmpty, shapeRadius, capsuleHalfLength, boundsHalfWidth, boundsHalfHeight, orientedBoxesOverlap, segmentSegmentDistanceSquared, segmentBoxDistanceSquared, pointSegmentDistanceSquared, } from './math/shapes';
16
19
  export { default as CollisionBroadphase, COLLIDABLE_QUERY } from './systems/collision';
17
- export type { CollisionComponents, CollisionEntity, CollisionFunction, MovingEntity, SweepResult } from './systems/collision';
20
+ export type { CollisionComponents, CollisionEntity, CollisionFunction, MoveResult, MovingEntity, SweepResult } from './systems/collision';
18
21
  export { default as SpatialIndex } from './systems/spatial-index';
19
22
  export type { SpatialComponents, SpatialEntity, SpatialFilter } from './systems/spatial-index';
20
23
  export { default as physicsUpdate, createPhysicsUpdate, POSITION_UPDATED_EVENT } from './systems/physics-update';
package/dist/index.js CHANGED
@@ -99,22 +99,28 @@ var a = 0, o = 1, s = 2, c = 3, l = 4, u = 5, d = {
99
99
  function ee(e, t, n, r) {
100
100
  return (t & n) !== 0 && (r & e) !== 0;
101
101
  }
102
- var te = 0, ne = 1, re = 2, ie = 3, S = {
102
+ var te = 0, ne = 1, re = 2, ie = 3, ae = 4;
103
+ function oe(e) {
104
+ return e[3] !== 0;
105
+ }
106
+ var S = {
103
107
  type: Uint32Array,
104
- size: 3,
108
+ size: 4,
105
109
  loadProperties: [
106
110
  "width",
107
111
  "height",
108
112
  "radius",
109
113
  "shape",
110
114
  "collideCategory",
111
- "collideMask"
115
+ "collideMask",
116
+ "sensor"
112
117
  ],
113
118
  load(e, t, n) {
114
119
  let r = t.create([
115
- ae(n),
120
+ se(n),
116
121
  n.collideCategory ?? 1,
117
- n.collideMask ?? 4294967295
122
+ n.collideMask ?? 4294967295,
123
+ +!!n.sensor
118
124
  ]), i = t.getBlock(r);
119
125
  return {
120
126
  index: r,
@@ -135,19 +141,41 @@ var te = 0, ne = 1, re = 2, ie = 3, S = {
135
141
  },
136
142
  set collideMask(e) {
137
143
  i[2] = e;
144
+ },
145
+ get sensor() {
146
+ return i[3] !== 0;
147
+ },
148
+ set sensor(e) {
149
+ i[3] = +!!e;
138
150
  }
139
151
  };
140
152
  }
141
153
  };
142
- function ae(e) {
154
+ function se(e) {
143
155
  let t = e.shape;
144
156
  if (t === void 0) return e.radius === void 0 ? 1 : 2;
145
157
  if (!y.includes(t)) throw Error(`Unknown body shape: ${t}`);
146
158
  return t;
147
159
  }
148
160
  //#endregion
149
- //#region src/components/interpolation-component.ts
150
- var oe = 0, se = 1, ce = 2, le = 3, ue = 4, de = 5, fe = 6, C = 7, pe = 8, w = {
161
+ //#region src/components/bounciness-component.ts
162
+ var ce = 0, le = 1, C = {
163
+ type: Float32Array,
164
+ size: 1,
165
+ loadProperties: ["bounciness"],
166
+ load(e, t, n) {
167
+ let r = t.create([n.bounciness ?? 0]), i = t.getBlock(r);
168
+ return {
169
+ index: r,
170
+ get bounciness() {
171
+ return i[0];
172
+ },
173
+ set bounciness(e) {
174
+ i[0] = e;
175
+ }
176
+ };
177
+ }
178
+ }, ue = 0, de = 1, fe = 2, pe = 3, me = 4, he = 5, ge = 6, _e = 7, ve = 8, w = {
151
179
  type: Float32Array,
152
180
  size: 8,
153
181
  loadProperties: ["interpolate"],
@@ -191,16 +219,17 @@ var oe = 0, se = 1, ce = 2, le = 3, ue = 4, de = 5, fe = 6, C = 7, pe = 8, w = {
191
219
  };
192
220
  }
193
221
  };
194
- function me(e) {
222
+ function ye(e) {
195
223
  let { transform: t, interpolation: n } = e.components;
196
224
  !t || !n || (n.prevX = n.x = t.x, n.prevY = n.y = t.y);
197
225
  }
198
226
  //#endregion
199
227
  //#region src/components/registry.ts
200
- var he = {
228
+ var be = {
201
229
  transform: d,
202
230
  velocity: h,
203
231
  body: S,
232
+ bounciness: C,
204
233
  interpolation: w
205
234
  };
206
235
  //#endregion
@@ -251,13 +280,13 @@ function F(e, t, n, r, i, a, o, s, c, l, u, d) {
251
280
  function I(e, t, n, r, i, a, o, s) {
252
281
  let c = n - e, l = r - t, u = o - i, d = s - a, f = e - i, p = t - a, m = c * c + l * l, h = u * u + d * d, g = u * f + d * p, _ = 0, v = 0;
253
282
  if (m <= 0 && h <= 0) return f * f + p * p;
254
- if (m <= 0) v = V(g / h);
283
+ if (m <= 0) v = B(g / h);
255
284
  else {
256
285
  let e = c * f + l * p;
257
- if (h <= 0) _ = V(-e / m);
286
+ if (h <= 0) _ = B(-e / m);
258
287
  else {
259
288
  let t = c * u + l * d, n = m * h - t * t;
260
- n !== 0 && (_ = V((t * g - e * h) / n)), v = (t * _ + g) / h, v < 0 ? (v = 0, _ = V(-e / m)) : v > 1 && (v = 1, _ = V((t - e) / m));
289
+ n !== 0 && (_ = B((t * g - e * h) / n)), v = (t * _ + g) / h, v < 0 ? (v = 0, _ = B(-e / m)) : v > 1 && (v = 1, _ = B((t - e) / m));
261
290
  }
262
291
  }
263
292
  let y = e + c * _ - (i + u * v), b = t + l * _ - (a + d * v);
@@ -265,27 +294,30 @@ function I(e, t, n, r, i, a, o, s) {
265
294
  }
266
295
  function L(e, t, n, r, i, a, o, s, c) {
267
296
  let l = Math.cos(c), u = Math.sin(c), d = o / 2, f = s / 2, p = e - i, m = t - a, h = n - i, g = r - a, _ = p * l + m * u, v = -p * u + m * l, y = h * l + g * u, b = -h * u + g * l;
268
- return z(_, v, y, b, d, f) ? Math.min(B(_, v, d, f), B(y, b, d, f), R(-d, -f, _, v, y, b), R(d, -f, _, v, y, b), R(d, f, _, v, y, b), R(-d, f, _, v, y, b)) : 0;
297
+ return xe(_, v, y, b, d, f) ? Math.min(z(_, v, d, f), z(y, b, d, f), R(-d, -f, _, v, y, b), R(d, -f, _, v, y, b), R(d, f, _, v, y, b), R(-d, f, _, v, y, b)) : 0;
269
298
  }
270
299
  function R(e, t, n, r, i, a) {
271
- let o = i - n, s = a - r, c = o * o + s * s, l = c > 0 ? V(((e - n) * o + (t - r) * s) / c) : 0, u = e - (n + o * l), d = t - (r + s * l);
300
+ let o = i - n, s = a - r, c = o * o + s * s, l = c > 0 ? B(((e - n) * o + (t - r) * s) / c) : 0, u = e - (n + o * l), d = t - (r + s * l);
272
301
  return u * u + d * d;
273
302
  }
274
- function z(e, t, n, r, i, a) {
303
+ function xe(e, t, n, r, i, a) {
275
304
  if (Math.max(e, n) < -i || Math.min(e, n) > i || Math.max(t, r) < -a || Math.min(t, r) > a) return !0;
276
305
  let o = -(r - t), s = n - e;
277
306
  return Math.abs(o * e + s * t) > i * Math.abs(o) + a * Math.abs(s);
278
307
  }
279
- function B(e, t, n, r) {
308
+ function z(e, t, n, r) {
280
309
  let i = Math.abs(e) - n, a = Math.abs(t) - r, o = i > 0 ? i : 0, s = a > 0 ? a : 0;
281
310
  return o * o + s * s;
282
311
  }
283
- function V(e) {
312
+ function B(e) {
284
313
  return e < 0 ? 0 : e > 1 ? 1 : e;
285
314
  }
286
315
  //#endregion
287
316
  //#region src/systems/collision.ts
288
- var H = 1e-4, ge = 24, U = "collidable", W = [], G = class {
317
+ var V = 1e-4, Se = 24, H = "collidable", U = [], W = {
318
+ fraction: 1,
319
+ blocking: U
320
+ }, G = class {
289
321
  buckets = [];
290
322
  constructor(t, n) {
291
323
  let r = /* @__PURE__ */ new Map();
@@ -327,25 +359,71 @@ var H = 1e-4, ge = 24, U = "collidable", W = [], G = class {
327
359
  let r = Math.sqrt(t * t + n * n), i = K(e);
328
360
  if (!i || r === 0) return {
329
361
  fraction: 1,
330
- blocking: W
362
+ blocking: U
331
363
  };
332
- let { x: a, y: o, halfWidth: s, halfHeight: c } = i, l = a + t, u = o + n, d = [];
333
- if (this.forEachCandidate(i, l - s, u - c, l + s, u + c, (e) => {
334
- q(i, l, u, e) && (q(i, a, o, e) || d.push(e));
335
- }), d.length === 0) return {
364
+ let a = this.gatherCandidates(i, t, n);
365
+ return a.length === 0 ? {
336
366
  fraction: 1,
337
- blocking: W
367
+ blocking: U
368
+ } : this.refine(i, a, t, n, r);
369
+ }
370
+ resolveMove(e, t, n, r) {
371
+ let i = Math.sqrt(t * t + n * n), a = K(e);
372
+ if (!a || i === 0) return {
373
+ moveX: t,
374
+ moveY: n,
375
+ blocking: U
338
376
  };
339
- let f = 0, p = 1, m = H / r;
340
- for (let e = 0; e < ge && p - f > m; e++) {
341
- let e = (f + p) / 2;
342
- this.blockedAt(i, d, t, n, e) ? p = e : f = e;
377
+ let o = this.gatherCandidates(a, t, n);
378
+ if (o.length === 0) return {
379
+ moveX: t,
380
+ moveY: n,
381
+ blocking: U
382
+ };
383
+ if (r && t !== 0 && n !== 0) {
384
+ let e = this.gatherCandidates(a, t, 0), r = this.gatherCandidates(a, 0, n);
385
+ if (e.length === 0 && r.length === 0) return Math.abs(t) >= Math.abs(n) ? {
386
+ moveX: t,
387
+ moveY: 0,
388
+ blocking: U
389
+ } : {
390
+ moveX: 0,
391
+ moveY: n,
392
+ blocking: U
393
+ };
394
+ let i = e.length === 0 ? W : this.refine(a, e, t, 0, Math.abs(t)), o = r.length === 0 ? W : this.refine(a, r, 0, n, Math.abs(n));
395
+ return {
396
+ moveX: t * i.fraction,
397
+ moveY: n * o.fraction,
398
+ blocking: Ce(i.blocking, o.blocking)
399
+ };
343
400
  }
344
- let h = [], g = a + t * p, _ = o + n * p;
345
- for (let e of d) q(i, g, _, e) && h.push(e);
401
+ let s = this.refine(a, o, t, n, i);
346
402
  return {
347
- fraction: f * r > H ? f : 0,
348
- blocking: h
403
+ moveX: t * s.fraction,
404
+ moveY: n * s.fraction,
405
+ blocking: s.blocking
406
+ };
407
+ }
408
+ gatherCandidates(e, t, n) {
409
+ let { x: r, y: i, halfWidth: a, halfHeight: o } = e;
410
+ if (e.sensor) return [];
411
+ let s = r + t, c = i + n, l = [];
412
+ return this.forEachCandidate(e, s - a, c - o, s + a, c + o, (t) => {
413
+ q(e, s, c, t) && t.components.body[3] === 0 && (q(e, r, i, t) || l.push(t));
414
+ }), l;
415
+ }
416
+ refine(e, t, n, r, i) {
417
+ let { x: a, y: o } = e, s = 0, c = 1, l = V / i;
418
+ for (let i = 0; i < Se && c - s > l; i++) {
419
+ let i = (s + c) / 2;
420
+ this.blockedAt(e, t, n, r, i) ? c = i : s = i;
421
+ }
422
+ let u = [], d = a + n * c, f = o + r * c;
423
+ for (let n of t) q(e, d, f, n) && u.push(n);
424
+ return {
425
+ fraction: s * i > V ? s : 0,
426
+ blocking: u
349
427
  };
350
428
  }
351
429
  blockedAt(e, t, n, r, i) {
@@ -360,6 +438,13 @@ var H = 1e-4, ge = 24, U = "collidable", W = [], G = class {
360
438
  }
361
439
  }
362
440
  };
441
+ function Ce(e, t) {
442
+ if (e.length === 0) return t;
443
+ if (t.length === 0) return e;
444
+ let n = [...e];
445
+ for (let e of t) n.some((t) => t.entityId === e.entityId) || n.push(e);
446
+ return n;
447
+ }
363
448
  function K(e) {
364
449
  let t = e.components.body;
365
450
  if (!t) return;
@@ -379,7 +464,8 @@ function K(e) {
379
464
  halfWidth: O(i, a, o, s),
380
465
  halfHeight: k(i, a, o, s),
381
466
  category: t[1],
382
- mask: n
467
+ mask: n,
468
+ sensor: t[3] !== 0
383
469
  };
384
470
  }
385
471
  function q(e, t, n, r) {
@@ -388,7 +474,7 @@ function q(e, t, n, r) {
388
474
  }
389
475
  //#endregion
390
476
  //#region src/systems/spatial-index.ts
391
- var _e = class {
477
+ var we = class {
392
478
  entries = [];
393
479
  index;
394
480
  constructor(t) {
@@ -428,23 +514,61 @@ var _e = class {
428
514
  let o = this.entries;
429
515
  return (i ? a.neighbors(e, t, n, r, (e) => i(o[e])) : a.neighbors(e, t, n, r)).map((e) => o[e]);
430
516
  }
431
- }, J = "position-updated";
432
- function ve(e = {}) {
517
+ }, J = {
518
+ x: 0,
519
+ y: 0
520
+ }, Y = {
521
+ x: 0,
522
+ y: 0
523
+ }, X = {
524
+ x: 0,
525
+ y: 0
526
+ };
527
+ function Z(e, t) {
528
+ let n = e.components.bounciness;
529
+ if (!n || De(e.components.body) || De(t.components.body) || !Te(e, t, J)) return;
530
+ let r = e.components.velocity, i = r[0], a = r[1], o = i * J.x + a * J.y;
531
+ if (o >= 0) return;
532
+ let s = (1 + n[0]) * o;
533
+ r[0] = i - s * J.x, r[1] = a - s * J.y;
534
+ }
535
+ function Te(e, t, n) {
536
+ let r = e.components.transform, i = t.components.transform, a = r[0] - i[0], o = r[1] - i[1], s = Ee(e.components.body), c = Ee(t.components.body);
537
+ if (s === 2 && c === 2) {
538
+ let e = Math.sqrt(a * a + o * o);
539
+ return e === 0 ? !1 : (n.x = a / e, n.y = o / e, !0);
540
+ }
541
+ return Oe(r, s, Y), Oe(i, c, X), Y.x + X.x - Math.abs(a) < Y.y + X.y - Math.abs(o) ? (n.x = a < 0 ? -1 : 1, n.y = 0) : (n.x = 0, n.y = o < 0 ? -1 : 1), !0;
542
+ }
543
+ function Ee(e) {
544
+ return e ? e[0] : 1;
545
+ }
546
+ function De(e) {
547
+ return e !== void 0 && e[3] !== 0;
548
+ }
549
+ function Oe(e, t, n) {
550
+ let r = e[2], i = e[3], a = e[4];
551
+ n.x = O(t, r, i, a), n.y = k(t, r, i, a);
552
+ }
553
+ //#endregion
554
+ //#region src/systems/physics-update.ts
555
+ var ke = "position-updated";
556
+ function Ae(e = {}) {
433
557
  let { onCollision: t, optional: n = [] } = e, r, i = Object.assign((e, n, i, a, o) => {
434
558
  let s = {
435
559
  entityId: n,
436
560
  components: i
437
561
  }, c = i.interpolation, l = e.elapsedTime / 1e3, u = i.velocity[0] * l, d = i.velocity[1] * l;
438
- if (X(c, i.transform, e.elapsedTime), !r) {
439
- Q(n, i.transform, u, d, o, e.reportMoves), Z(c, e.tick);
562
+ if (Me(c, i.transform, e.elapsedTime), !r) {
563
+ $(n, i.transform, u, d, o, e.reportMoves), Q(c, e.tick);
440
564
  return;
441
565
  }
442
- let f = r.sweep(s, u, d);
443
- if (Q(n, i.transform, u * f.fraction, d * f.fraction, o, e.reportMoves), Z(c, e.tick), t) {
566
+ let f = i.bounciness !== void 0, p = r.resolveMove(s, u, d, !f);
567
+ if ($(n, i.transform, p.moveX, p.moveY, o, e.reportMoves), Q(c, e.tick), !(!f && !t)) {
444
568
  r.forEachOverlapping(s, (n) => {
445
- t(e, s, n, a, o);
569
+ f && Z(s, n), t && t(e, s, n, a, o);
446
570
  });
447
- for (let n of f.blocking) t(e, s, n, a, o);
571
+ for (let n of p.blocking) f && Z(s, n), t && t(e, s, n, a, o);
448
572
  }
449
573
  }, { physics: {
450
574
  collision: !0,
@@ -454,39 +578,43 @@ function ve(e = {}) {
454
578
  r = new G(n.collidable ?? [], e.elapsedTime / 1e3);
455
579
  }, i;
456
580
  }
457
- var Y = (e, t, n, r, i) => {
581
+ var je = (e, t, n, r, i) => {
458
582
  let a = e.elapsedTime / 1e3, o = n.interpolation;
459
- X(o, n.transform, e.elapsedTime), Q(t, n.transform, n.velocity[0] * a, n.velocity[1] * a, i, e.reportMoves), Z(o, e.tick);
583
+ Me(o, n.transform, e.elapsedTime), $(t, n.transform, n.velocity[0] * a, n.velocity[1] * a, i, e.reportMoves), Q(o, e.tick);
460
584
  };
461
- function X(e, t, n) {
585
+ function Me(e, t, n) {
462
586
  e && (e[2] = t[0], e[3] = t[1], e[6] = n);
463
587
  }
464
- function Z(e, t) {
588
+ function Q(e, t) {
465
589
  e && r(e, 7, t);
466
590
  }
467
- function Q(e, n, r, i, a, o) {
468
- r === 0 && i === 0 || (r !== 0 && t(n, 0, r, Infinity), i !== 0 && t(n, 1, i, Infinity), o !== !1 && a.emitSystemEvent(J, e));
591
+ function $(e, n, r, i, a, o) {
592
+ r === 0 && i === 0 || (r !== 0 && t(n, 0, r, Infinity), i !== 0 && t(n, 1, i, Infinity), o !== !1 && a.emitSystemEvent(ke, e));
469
593
  }
470
594
  //#endregion
471
595
  //#region src/systems/physics-system.ts
472
- var ye = 50, be = class extends i {
596
+ var Ne = 50, Pe = class extends i {
473
597
  tick = 0;
474
598
  reportMoves;
475
599
  constructor(e, t = {}) {
476
- let n = t.updateFunction ?? Y, r = t.optional ?? n.physics?.optional ?? [], i = t.collision ?? n.physics?.collision ?? !1, a = [];
477
- i && !r.includes("body") && a.push("body"), r.includes("interpolation") || a.push("interpolation");
478
- let o = a.length ? [...a, ...r] : r;
600
+ let n = t.updateFunction ?? je, r = t.optional ?? n.physics?.optional ?? [], i = t.collision ?? n.physics?.collision ?? !1, a = [];
601
+ i && !r.includes("body") && a.push("body"), i && !r.includes("bounciness") && a.push("bounciness"), r.includes("interpolation") || a.push("interpolation");
602
+ let o = a.length ? [...a, ...r] : r, s = i ? { [H]: {
603
+ required: ["transform", "body"],
604
+ optional: ["velocity", ...r]
605
+ } } : void 0, c = s || t.queries ? {
606
+ ...s,
607
+ ...t.queries
608
+ } : void 0;
479
609
  super(e, {
480
610
  name: t.name ?? "PhysicsSystem",
481
611
  deltaBetweenRuns: t.deltaBetweenRuns ?? 50,
482
612
  firstRun: t.firstRun,
483
613
  required: ["transform", "velocity"],
484
614
  optional: o,
615
+ filter: t.filter,
485
616
  updateFunction: n,
486
- queries: i ? { [U]: {
487
- required: ["transform", "body"],
488
- optional: ["velocity", ...r]
489
- } } : void 0,
617
+ queries: c,
490
618
  forceMainThread: t.forceMainThread ?? !t.getWorker,
491
619
  getWorker: t.getWorker ?? (() => {
492
620
  throw Error("PhysicsSystem cannot start a worker: no getWorker was supplied");
@@ -496,7 +624,7 @@ var ye = 50, be = class extends i {
496
624
  addDataToWorld(e) {
497
625
  e.tick = ++this.tick, e.reportMoves = this.reportMoves ?? this.listenerCount("position-updated") > 0;
498
626
  }
499
- }, $ = (e, t, r) => {
627
+ }, Fe = (e, t, r) => {
500
628
  let i = r.interpolation, a = r.transform, o = n(i, 7), s = i[2], c = i[3], l = i[6], u = a[0], d = a[1], f = n(i, 7);
501
629
  if (o !== f) return;
502
630
  if (l <= 0) {
@@ -505,14 +633,14 @@ var ye = 50, be = class extends i {
505
633
  }
506
634
  let p = i[4];
507
635
  f !== i[5] && (p = 0, i[5] = f), p += e.elapsedTime / l, p > 1 && (p = 1), i[4] = p, i[0] = s + (u - s) * p, i[1] = c + (d - c) * p;
508
- }, xe = class extends i {
636
+ }, Ie = class extends i {
509
637
  constructor(e, t = {}) {
510
638
  super(e, {
511
639
  name: t.name ?? "InterpolationSystem",
512
640
  deltaBetweenRuns: 0,
513
641
  firstRun: t.firstRun,
514
642
  required: ["transform", "interpolation"],
515
- updateFunction: $,
643
+ updateFunction: Fe,
516
644
  forceMainThread: t.forceMainThread ?? !t.getWorker,
517
645
  getWorker: t.getWorker ?? (() => {
518
646
  throw Error("InterpolationSystem cannot start a worker: no getWorker was supplied");
@@ -521,6 +649,6 @@ var ye = 50, be = class extends i {
521
649
  }
522
650
  };
523
651
  //#endregion
524
- export { ne as BODY_CATEGORY_INDEX, re as BODY_MASK_INDEX, te as BODY_SHAPE_INDEX, ie as BODY_SIZE, U as COLLIDABLE_QUERY, G as CollisionBroadphase, b as DEFAULT_COLLIDE_CATEGORY, x as DEFAULT_COLLIDE_MASK, ye as DEFAULT_PHYSICS_STEP_MS, fe as INTERPOLATION_DURATION_INDEX, ce as INTERPOLATION_PREV_X_INDEX, le as INTERPOLATION_PREV_Y_INDEX, ue as INTERPOLATION_PROGRESS_INDEX, pe as INTERPOLATION_SIZE, de as INTERPOLATION_SYNCED_TICK_INDEX, C as INTERPOLATION_TICK_INDEX, oe as INTERPOLATION_X_INDEX, se as INTERPOLATION_Y_INDEX, xe as InterpolationSystem, J as POSITION_UPDATED_EVENT, be as PhysicsSystem, v as SHAPE_CAPSULE, _ as SHAPE_CIRCLE, g as SHAPE_RECTANGLE, _e as SpatialIndex, l as TRANSFORM_ANGLE_INDEX, c as TRANSFORM_HEIGHT_INDEX, u as TRANSFORM_SIZE, s as TRANSFORM_WIDTH_INDEX, a as TRANSFORM_X_INDEX, o as TRANSFORM_Y_INDEX, m as VELOCITY_SIZE, f as VELOCITY_X_INDEX, p as VELOCITY_Y_INDEX, S as bodyDefinition, N as boundsHalfHeight, M as boundsHalfWidth, ee as canCollide, T as capsuleHalfLength, ve as createPhysicsUpdate, w as interpolationDefinition, $ as interpolationUpdate, P as orientedBoxesOverlap, he as physicsRegistry, Y as physicsUpdate, R as pointSegmentDistanceSquared, L as segmentBoxDistanceSquared, I as segmentSegmentDistanceSquared, k as shapeHalfHeight, O as shapeHalfWidth, D as shapeIsEmpty, E as shapeRadius, A as shapesOverlap, me as snapEntity, d as transformDefinition, h as velocityDefinition };
652
+ export { ne as BODY_CATEGORY_INDEX, re as BODY_MASK_INDEX, ie as BODY_SENSOR_INDEX, te as BODY_SHAPE_INDEX, ae as BODY_SIZE, ce as BOUNCINESS_INDEX, le as BOUNCINESS_SIZE, H as COLLIDABLE_QUERY, G as CollisionBroadphase, b as DEFAULT_COLLIDE_CATEGORY, x as DEFAULT_COLLIDE_MASK, Ne as DEFAULT_PHYSICS_STEP_MS, ge as INTERPOLATION_DURATION_INDEX, fe as INTERPOLATION_PREV_X_INDEX, pe as INTERPOLATION_PREV_Y_INDEX, me as INTERPOLATION_PROGRESS_INDEX, ve as INTERPOLATION_SIZE, he as INTERPOLATION_SYNCED_TICK_INDEX, _e as INTERPOLATION_TICK_INDEX, ue as INTERPOLATION_X_INDEX, de as INTERPOLATION_Y_INDEX, Ie as InterpolationSystem, ke as POSITION_UPDATED_EVENT, Pe as PhysicsSystem, v as SHAPE_CAPSULE, _ as SHAPE_CIRCLE, g as SHAPE_RECTANGLE, we as SpatialIndex, l as TRANSFORM_ANGLE_INDEX, c as TRANSFORM_HEIGHT_INDEX, u as TRANSFORM_SIZE, s as TRANSFORM_WIDTH_INDEX, a as TRANSFORM_X_INDEX, o as TRANSFORM_Y_INDEX, m as VELOCITY_SIZE, f as VELOCITY_X_INDEX, p as VELOCITY_Y_INDEX, S as bodyDefinition, C as bouncinessDefinition, N as boundsHalfHeight, M as boundsHalfWidth, ee as canCollide, T as capsuleHalfLength, Ae as createPhysicsUpdate, w as interpolationDefinition, Fe as interpolationUpdate, oe as isSensor, P as orientedBoxesOverlap, be as physicsRegistry, je as physicsUpdate, R as pointSegmentDistanceSquared, L as segmentBoxDistanceSquared, I as segmentSegmentDistanceSquared, k as shapeHalfHeight, O as shapeHalfWidth, D as shapeIsEmpty, E as shapeRadius, A as shapesOverlap, ye as snapEntity, d as transformDefinition, h as velocityDefinition };
525
653
 
526
654
  //# sourceMappingURL=index.js.map