@daneren2005/shared-memory-physics 1.2.1 → 1.3.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/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import e from "flatbush";
2
- import { addAtomicFloat32 as t } from "@daneren2005/shared-memory-objects/utils/atomic-math";
3
- import { loadFloat32 as n, storeFloat32 as r } from "@daneren2005/shared-memory-objects/utils/float32-atomics";
4
- import { ComponentSystem as i } from "@daneren2005/shared-memory-ecs";
1
+ import { loadFloat32 as e, storeFloat32 as t } from "@daneren2005/shared-memory-objects/utils/float32-atomics";
2
+ import n from "flatbush";
3
+ import { ComponentSystem as r, DEAD_INDEX as i } from "@daneren2005/shared-memory-ecs";
4
+ import { addAtomicFloat32 as a } from "@daneren2005/shared-memory-objects/utils/atomic-math";
5
5
  //#region src/components/transform-component.ts
6
- var a = 0, o = 1, s = 2, c = 3, l = 4, u = 5, d = {
6
+ var o = 0, s = 1, c = 2, l = 3, u = 4, d = 5, f = {
7
7
  type: Float32Array,
8
8
  size: 5,
9
9
  loadProperties: [
@@ -61,10 +61,11 @@ var a = 0, o = 1, s = 2, c = 3, l = 4, u = 5, d = {
61
61
  save(e) {
62
62
  return {
63
63
  x: e.x,
64
- y: e.y
64
+ y: e.y,
65
+ angle: e.angle
65
66
  };
66
67
  }
67
- }, f = 0, p = 1, m = 2, h = {
68
+ }, p = 0, m = 1, h = 2, g = {
68
69
  type: Float32Array,
69
70
  size: 2,
70
71
  loadProperties: ["velocityX", "velocityY"],
@@ -92,21 +93,27 @@ var a = 0, o = 1, s = 2, c = 3, l = 4, u = 5, d = {
92
93
  velocityY: e.velocityY
93
94
  };
94
95
  }
95
- }, g = 1, _ = 2, v = 3, y = [
96
+ }, _ = 1, v = 2, y = 3, b = [
96
97
  1,
97
98
  2,
98
99
  3
99
- ], b = 1, x = 4294967295;
100
- function ee(e, t, n, r) {
100
+ ], x = 1, S = 4294967295;
101
+ function C(e, t, n, r) {
101
102
  return (t & n) !== 0 && (r & e) !== 0;
102
103
  }
103
- var te = 0, ne = 1, re = 2, ie = 3, ae = 4;
104
- function oe(e) {
105
- return e[3] !== 0;
104
+ var w = 0, T = 1, E = 2, D = 3, O = 3, k = 4, A = 8;
105
+ function j(e) {
106
+ return e[0] & 3;
106
107
  }
107
- var S = {
108
+ function M(e) {
109
+ return (e[0] & 4) != 0;
110
+ }
111
+ function ee(e) {
112
+ return (e[0] & 8) != 0;
113
+ }
114
+ var te = {
108
115
  type: Uint32Array,
109
- size: 4,
116
+ size: 3,
110
117
  loadProperties: [
111
118
  "width",
112
119
  "height",
@@ -114,22 +121,22 @@ var S = {
114
121
  "shape",
115
122
  "collideCategory",
116
123
  "collideMask",
117
- "sensor"
124
+ "sensor",
125
+ "continuousCollisionDetection"
118
126
  ],
119
127
  load(e, t, n) {
120
128
  let r = t.create([
121
- se(n),
129
+ ne(n),
122
130
  n.collideCategory ?? 1,
123
- n.collideMask ?? 4294967295,
124
- +!!n.sensor
131
+ n.collideMask ?? 4294967295
125
132
  ]), i = t.getBlock(r);
126
133
  return {
127
134
  index: r,
128
135
  get shape() {
129
- return i[0];
136
+ return i[0] & 3;
130
137
  },
131
138
  set shape(e) {
132
- i[0] = e;
139
+ i[0] = i[0] & -4 | e & 3;
133
140
  },
134
141
  get collideCategory() {
135
142
  return i[1];
@@ -144,23 +151,33 @@ var S = {
144
151
  i[2] = e;
145
152
  },
146
153
  get sensor() {
147
- return i[3] !== 0;
154
+ return (i[0] & 4) != 0;
148
155
  },
149
156
  set sensor(e) {
150
- i[3] = +!!e;
157
+ i[0] = e ? i[0] | 4 : i[0] & -5;
158
+ },
159
+ get continuousCollisionDetection() {
160
+ return (i[0] & 8) != 0;
161
+ },
162
+ set continuousCollisionDetection(e) {
163
+ i[0] = e ? i[0] | 8 : i[0] & -9;
151
164
  }
152
165
  };
153
166
  }
154
167
  };
155
- function se(e) {
168
+ function ne(e) {
169
+ let t = re(e);
170
+ return e.sensor && (t |= 4), e.continuousCollisionDetection && (t |= 8), t;
171
+ }
172
+ function re(e) {
156
173
  let t = e.shape;
157
174
  if (t === void 0) return e.radius === void 0 ? 1 : 2;
158
- if (!y.includes(t)) throw Error(`Unknown body shape: ${t}`);
175
+ if (!b.includes(t)) throw Error(`Unknown body shape: ${t}`);
159
176
  return t;
160
177
  }
161
178
  //#endregion
162
179
  //#region src/components/bounciness-component.ts
163
- var ce = 0, le = 1, C = {
180
+ var ie = 0, ae = 1, oe = {
164
181
  type: Float32Array,
165
182
  size: 1,
166
183
  loadProperties: ["bounciness"],
@@ -176,227 +193,337 @@ var ce = 0, le = 1, C = {
176
193
  }
177
194
  };
178
195
  }
179
- }, ue = 0, de = 1, fe = 2, pe = 3, me = 4, he = 5, ge = 6, _e = 7, ve = 8, w = {
196
+ }, se = 0, ce = 1, le = 2, ue = 3, de = 4, fe = 5, pe = 6, me = 7, he = 8, ge = {
180
197
  type: Float32Array,
181
198
  size: 8,
182
199
  loadProperties: ["interpolate"],
183
- load(e, t, n) {
184
- let r = n.x ?? 0, i = n.y ?? 0, a = t.create([
185
- r,
186
- i,
187
- r,
188
- i,
200
+ load(n, r, i) {
201
+ let a = i.x ?? 0, o = i.y ?? 0, s = r.create([
202
+ a,
203
+ o,
204
+ a,
205
+ o,
189
206
  0,
190
207
  0,
191
208
  0,
192
209
  0
193
- ]), o = t.getBlock(a);
210
+ ]), c = r.getBlock(s);
194
211
  return {
195
- index: a,
212
+ index: s,
196
213
  get x() {
197
- return o[0];
214
+ return c[0];
198
215
  },
199
216
  set x(e) {
200
- o[0] = e;
217
+ c[0] = e;
201
218
  },
202
219
  get y() {
203
- return o[1];
220
+ return c[1];
204
221
  },
205
222
  set y(e) {
206
- o[1] = e;
223
+ c[1] = e;
207
224
  },
208
225
  get prevX() {
209
- return o[2];
226
+ return c[2];
210
227
  },
211
228
  set prevX(e) {
212
- o[2] = e;
229
+ c[2] = e;
213
230
  },
214
231
  get prevY() {
215
- return o[3];
232
+ return c[3];
216
233
  },
217
234
  set prevY(e) {
218
- o[3] = e;
235
+ c[3] = e;
236
+ },
237
+ get progress() {
238
+ return c[4];
239
+ },
240
+ set progress(e) {
241
+ c[4] = e;
242
+ },
243
+ get syncedTick() {
244
+ return c[5];
245
+ },
246
+ set syncedTick(e) {
247
+ c[5] = e;
248
+ },
249
+ get duration() {
250
+ return c[6];
251
+ },
252
+ set duration(e) {
253
+ c[6] = e;
254
+ },
255
+ get tick() {
256
+ return e(c, 7);
257
+ },
258
+ set tick(e) {
259
+ t(c, 7, e);
219
260
  }
220
261
  };
221
262
  }
222
263
  };
223
- function ye(e) {
264
+ function _e(e) {
224
265
  let { transform: t, interpolation: n } = e.components;
225
266
  !t || !n || (n.prevX = n.x = t.x, n.prevY = n.y = t.y);
226
267
  }
268
+ function ve(e, t) {
269
+ let { transform: n, velocity: r, interpolation: i } = e.components;
270
+ if (!n || !r || !i) return;
271
+ let a = 1 - (t.stepFraction < 0 ? 0 : t.stepFraction > 1 ? 1 : t.stepFraction), o = t.stepMs / 1e3, s = n.x, c = n.y, l = r.velocityX * o * a, u = r.velocityY * o * a;
272
+ i.prevX = s, i.prevY = c, n.x = s + l, n.y = c + u, i.x = s, i.y = c, i.duration = t.stepMs * a, i.progress = 0, i.syncedTick = t.tick, i.tick = t.tick;
273
+ }
227
274
  //#endregion
228
275
  //#region src/components/registry.ts
229
- var be = {
230
- transform: d,
231
- velocity: h,
232
- body: S,
233
- bounciness: C,
234
- interpolation: w
276
+ var ye = {
277
+ transform: f,
278
+ velocity: g,
279
+ body: te,
280
+ bounciness: oe,
281
+ interpolation: ge
282
+ }, N = {
283
+ x: 0,
284
+ y: 0
285
+ }, P = {
286
+ x: 0,
287
+ y: 0
235
288
  };
236
- //#endregion
237
- //#region src/math/shapes.ts
238
- function T(e, t) {
289
+ function F(e, t) {
239
290
  return Math.max(0, (e - t) / 2);
240
291
  }
241
- function E(e, t, n) {
292
+ function I(e, t, n) {
242
293
  return e === 2 ? t / 2 : e === 3 ? n / 2 : 0;
243
294
  }
244
- function D(e, t, n) {
295
+ function L(e, t, n) {
245
296
  return e === 2 ? t <= 0 : e === 3 ? n <= 0 : t <= 0 || n <= 0;
246
297
  }
247
- function O(e, t, n, r) {
248
- return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.cos(r)) * T(t, n) + n / 2 : M(t, n, r);
298
+ function R(e, t, n, r) {
299
+ return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.cos(r)) * F(t, n) + n / 2 : Ee(t, n, r);
249
300
  }
250
- function k(e, t, n, r) {
251
- return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.sin(r)) * T(t, n) + n / 2 : N(t, n, r);
301
+ function z(e, t, n, r) {
302
+ return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.sin(r)) * F(t, n) + n / 2 : De(t, n, r);
252
303
  }
253
- function A(e, t, n, r, i, a, o, s, c, l, u, d) {
254
- if (D(e, r, i) || D(o, l, u)) return !1;
304
+ function B(e, t, n, r, i, a, o, s, c, l, u, d) {
305
+ if (L(e, r, i) || L(o, l, u)) return !1;
255
306
  let f = e !== 1, p = o !== 1;
256
- if (!f && !p) return P(t, n, r, i, a, s, c, l, u, d);
257
- if (f && !p) return A(o, s, c, l, u, d, e, t, n, r, i, a);
258
- let m = j(o, l, u), h = Math.cos(d) * m, g = Math.sin(d) * m, _ = E(o, l, u);
259
- if (!f) return L(s - h, c - g, s + h, c + g, t, n, r, i, a) < _ * _;
260
- let v = j(e, r, i), y = Math.cos(a) * v, b = Math.sin(a) * v, x = E(e, r, i) + _;
261
- return I(t - y, n - b, t + y, n + b, s - h, c - g, s + h, c + g) < x * x;
307
+ if (!f && !p) return Oe(t, n, r, i, a, s, c, l, u, d);
308
+ if (f && !p) return B(o, s, c, l, u, d, e, t, n, r, i, a);
309
+ let m = V(o, l, u), h = Math.cos(d) * m, g = Math.sin(d) * m, _ = I(o, l, u);
310
+ if (!f) return ke(s - h, c - g, s + h, c + g, t, n, r, i, a) < _ * _;
311
+ let v = V(e, r, i), y = Math.cos(a) * v, b = Math.sin(a) * v, x = I(e, r, i) + _;
312
+ return W(t - y, n - b, t + y, n + b, s - h, c - g, s + h, c + g) < x * x;
313
+ }
314
+ function V(e, t, n) {
315
+ return e === 3 ? F(t, n) : 0;
316
+ }
317
+ function be(e, t, n, r, i, a, o, s, c, l, u, d, f) {
318
+ let p = e !== 1, m = o !== 1;
319
+ return !p && !m ? xe(t, n, r, i, a, s, c, l, u, d, f) : p && m ? Se(e, t, n, r, i, a, o, s, c, l, u, d, f) : p ? Ce(s, c, l, u, d, e, t, n, r, i, a, f) : Ce(t, n, r, i, a, o, s, c, l, u, d, f) ? (f.x = -f.x, f.y = -f.y, !0) : !1;
320
+ }
321
+ function xe(e, t, n, r, i, a, o, s, c, l, u) {
322
+ let d = Math.cos(i), f = Math.sin(i), p = Math.cos(l), m = Math.sin(l), h = n / 2, g = r / 2, _ = s / 2, v = c / 2, y = e - a, b = t - o, x = U(d, f, y, b, h, g, d, f, _, v, p, m);
323
+ u.x = d, u.y = f;
324
+ let S = U(-f, d, y, b, h, g, d, f, _, v, p, m);
325
+ return S < x && (x = S, u.x = -f, u.y = d), S = U(p, m, y, b, h, g, d, f, _, v, p, m), S < x && (x = S, u.x = p, u.y = m), S = U(-m, p, y, b, h, g, d, f, _, v, p, m), S < x && (u.x = -m, u.y = p), we(y, b, u), !0;
326
+ }
327
+ function Se(e, t, n, r, i, a, o, s, c, l, u, d, f) {
328
+ let p = V(e, r, i), m = Math.cos(a) * p, h = Math.sin(a) * p, g = V(o, l, u), _ = Math.cos(d) * g, v = Math.sin(d) * g, y = Math.sqrt(W(t - m, n - h, t + m, n + h, s - _, c - v, s + _, c + v, N));
329
+ return y > 0 ? (f.x = N.x / y, f.y = N.y / y, !0) : Te(t - s, n - c, f);
330
+ }
331
+ function Ce(e, t, n, r, i, a, o, s, c, l, u, d) {
332
+ let f = V(a, c, l), p = Math.cos(u) * f, m = Math.sin(u) * f, h = Math.sqrt(ke(o - p, s - m, o + p, s + m, e, t, n, r, i, N));
333
+ if (h > 0) return d.x = N.x / h, d.y = N.y / h, !0;
334
+ let g = Math.cos(i), _ = Math.sin(i), v = o - e, y = s - t, b = v * g + y * _, x = -v * _ + y * g, S = p * g + m * _, C = -p * _ + m * g, w = I(a, c, l), T = n / 2, E = r / 2, D = H(1, 0, b, x, S, C, w, T, E);
335
+ d.x = 1, d.y = 0;
336
+ let O = H(0, 1, b, x, S, C, w, T, E);
337
+ O < D && (D = O, d.x = 0, d.y = 1), Te(-C, S, P) && (O = H(P.x, P.y, b, x, S, C, w, T, E), O < D && (d.x = P.x, d.y = P.y)), we(b, x, d);
338
+ let k = d.x, A = d.y;
339
+ return d.x = k * g - A * _, d.y = k * _ + A * g, !0;
340
+ }
341
+ function H(e, t, n, r, i, a, o, s, c) {
342
+ return s * Math.abs(e) + c * Math.abs(t) + (Math.abs(i * e + a * t) + o) - Math.abs(n * e + r * t);
343
+ }
344
+ function we(e, t, n) {
345
+ e * n.x + t * n.y < 0 && (n.x = -n.x, n.y = -n.y);
262
346
  }
263
- function j(e, t, n) {
264
- return e === 3 ? T(t, n) : 0;
347
+ function Te(e, t, n) {
348
+ let r = Math.sqrt(e * e + t * t);
349
+ return r === 0 ? !1 : (n.x = e / r, n.y = t / r, !0);
265
350
  }
266
- function M(e, t, n) {
351
+ function Ee(e, t, n) {
267
352
  return (Math.abs(Math.cos(n)) * e + Math.abs(Math.sin(n)) * t) / 2;
268
353
  }
269
- function N(e, t, n) {
354
+ function De(e, t, n) {
270
355
  return (Math.abs(Math.sin(n)) * e + Math.abs(Math.cos(n)) * t) / 2;
271
356
  }
272
- function P(e, t, n, r, i, a, o, s, c, l) {
357
+ function Oe(e, t, n, r, i, a, o, s, c, l) {
273
358
  if (n <= 0 || r <= 0 || s <= 0 || c <= 0) return !1;
274
359
  let u = Math.cos(i), d = Math.sin(i), f = Math.cos(l), p = Math.sin(l), m = n / 2, h = r / 2, g = s / 2, _ = c / 2, v = a - e, y = o - t;
275
- return !F(u, d, v, y, m, h, u, d, g, _, f, p) && !F(-d, u, v, y, m, h, u, d, g, _, f, p) && !F(f, p, v, y, m, h, u, d, g, _, f, p) && !F(-p, f, v, y, m, h, u, d, g, _, f, p);
360
+ return U(u, d, v, y, m, h, u, d, g, _, f, p) > 0 && U(-d, u, v, y, m, h, u, d, g, _, f, p) > 0 && U(f, p, v, y, m, h, u, d, g, _, f, p) > 0 && U(-p, f, v, y, m, h, u, d, g, _, f, p) > 0;
276
361
  }
277
- function F(e, t, n, r, i, a, o, s, c, l, u, d) {
278
- let f = i * Math.abs(o * e + s * t) + a * Math.abs(-s * e + o * t), p = c * Math.abs(u * e + d * t) + l * Math.abs(-d * e + u * t);
279
- return Math.abs(n * e + r * t) >= f + p;
362
+ function U(e, t, n, r, i, a, o, s, c, l, u, d) {
363
+ return i * Math.abs(o * e + s * t) + a * Math.abs(-s * e + o * t) + (c * Math.abs(u * e + d * t) + l * Math.abs(-d * e + u * t)) - Math.abs(n * e + r * t);
280
364
  }
281
- function I(e, t, n, r, i, a, o, s) {
282
- 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;
283
- if (m <= 0 && h <= 0) return f * f + p * p;
284
- if (m <= 0) v = B(g / h);
365
+ function W(e, t, n, r, i, a, o, s, c) {
366
+ let l = n - e, u = r - t, d = o - i, f = s - a, p = e - i, m = t - a, h = l * l + u * u, g = d * d + f * f, _ = d * p + f * m, v = 0, y = 0;
367
+ if (h <= 0 && g <= 0) return c && (c.x = p, c.y = m), p * p + m * m;
368
+ if (h <= 0) y = J(_ / g);
285
369
  else {
286
- let e = c * f + l * p;
287
- if (h <= 0) _ = B(-e / m);
370
+ let e = l * p + u * m;
371
+ if (g <= 0) v = J(-e / h);
288
372
  else {
289
- let t = c * u + l * d, n = m * h - t * t;
290
- 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));
373
+ let t = l * d + u * f, n = h * g - t * t;
374
+ n !== 0 && (v = J((t * _ - e * g) / n)), y = (t * v + _) / g, y < 0 ? (y = 0, v = J(-e / h)) : y > 1 && (y = 1, v = J((t - e) / h));
291
375
  }
292
376
  }
293
- let y = e + c * _ - (i + u * v), b = t + l * _ - (a + d * v);
294
- return y * y + b * b;
295
- }
296
- function L(e, t, n, r, i, a, o, s, c) {
297
- 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;
298
- 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;
299
- }
300
- function R(e, t, n, r, i, a) {
301
- 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);
302
- return u * u + d * d;
303
- }
304
- function xe(e, t, n, r, i, a) {
377
+ let b = e + l * v - (i + d * y), x = t + u * v - (a + f * y);
378
+ return c && (c.x = b, c.y = x), b * b + x * x;
379
+ }
380
+ function ke(e, t, n, r, i, a, o, s, c, l) {
381
+ let u = Math.cos(c), d = Math.sin(c), f = o / 2, p = s / 2, m = e - i, h = t - a, g = n - i, _ = r - a, v = m * u + h * d, y = -m * d + h * u, b = g * u + _ * d, x = -g * d + _ * u;
382
+ if (!Ae(v, y, b, x, f, p)) return l && (l.x = 0, l.y = 0), 0;
383
+ if (!l) return Math.min(q(v, y, f, p), q(b, x, f, p), K(-f, -p, v, y, b, x), K(f, -p, v, y, b, x), K(f, p, v, y, b, x), K(-f, p, v, y, b, x));
384
+ let S = q(v, y, f, p, l);
385
+ S = G(S, q(b, x, f, p, P), P, l, !1), S = G(S, K(-f, -p, v, y, b, x, P), P, l, !0), S = G(S, K(f, -p, v, y, b, x, P), P, l, !0), S = G(S, K(f, p, v, y, b, x, P), P, l, !0), S = G(S, K(-f, p, v, y, b, x, P), P, l, !0);
386
+ let C = l.x, w = l.y;
387
+ return l.x = C * u - w * d, l.y = C * d + w * u, S;
388
+ }
389
+ function G(e, t, n, r, i) {
390
+ return t >= e ? e : (r.x = i ? -n.x : n.x, r.y = i ? -n.y : n.y, t);
391
+ }
392
+ function K(e, t, n, r, i, a, o) {
393
+ let s = i - n, c = a - r, l = s * s + c * c, u = l > 0 ? J(((e - n) * s + (t - r) * c) / l) : 0, d = e - (n + s * u), f = t - (r + c * u);
394
+ return o && (o.x = d, o.y = f), d * d + f * f;
395
+ }
396
+ function Ae(e, t, n, r, i, a) {
305
397
  if (Math.max(e, n) < -i || Math.min(e, n) > i || Math.max(t, r) < -a || Math.min(t, r) > a) return !0;
306
398
  let o = -(r - t), s = n - e;
307
399
  return Math.abs(o * e + s * t) > i * Math.abs(o) + a * Math.abs(s);
308
400
  }
309
- function z(e, t, n, r) {
310
- let i = Math.abs(e) - n, a = Math.abs(t) - r, o = i > 0 ? i : 0, s = a > 0 ? a : 0;
311
- return o * o + s * s;
401
+ function q(e, t, n, r, i) {
402
+ let a = Math.abs(e) - n, o = Math.abs(t) - r, s = a > 0 ? a : 0, c = o > 0 ? o : 0;
403
+ return i && (i.x = e < 0 ? -s : s, i.y = t < 0 ? -c : c), s * s + c * c;
312
404
  }
313
- function B(e) {
405
+ function J(e) {
314
406
  return e < 0 ? 0 : e > 1 ? 1 : e;
315
407
  }
316
408
  //#endregion
317
409
  //#region src/systems/collision.ts
318
- var V = 1e-4, Se = 24, H = "collidable", U = [], W = {
410
+ var Y = 1e-4, je = 24, Me = "collidable", X = [], Ne = 2 ** 26, Pe = {
319
411
  fraction: 1,
320
- blocking: U
321
- }, G = class {
412
+ blocking: X
413
+ }, Fe = class {
322
414
  buckets = [];
323
- constructor(t, n) {
415
+ hasBounciness = !1;
416
+ resolved = /* @__PURE__ */ new Set();
417
+ constructor(e, t) {
324
418
  let r = /* @__PURE__ */ new Map();
325
- for (let e of t) {
326
- let t = e.components, i = t.transform, a = t.body;
419
+ for (let n of e) {
420
+ let e = n.components, i = e.transform, a = e.body;
327
421
  if (!i || !a) continue;
328
422
  let o = a[1];
329
423
  if (o === 0) continue;
330
- let s = a[0], c = i[2], l = i[3];
331
- if (D(s, c, l)) continue;
332
- let u = i[4], d = O(s, c, l, u), f = k(s, c, l, u), p = t.velocity, m = p ? Math.abs(p[0]) * n : 0, h = p ? Math.abs(p[1]) * n : 0, g = i[0], _ = i[1], v = r.get(o);
424
+ let s = j(a), c = i[2], l = i[3];
425
+ if (L(s, c, l)) continue;
426
+ let u = i[4], d = R(s, c, l, u), f = z(s, c, l, u);
427
+ e.bounciness && (this.hasBounciness = !0);
428
+ let p = e.velocity, m = p ? Math.abs(p[0]) * t : 0, h = p ? Math.abs(p[1]) * t : 0, g = i[0], _ = i[1], v = r.get(o);
333
429
  v || (v = {
334
430
  entries: [],
335
431
  bounds: []
336
432
  }, r.set(o, v)), v.entries.push({
337
- entityId: e.entityId,
338
- components: t
433
+ entityId: n.entityId,
434
+ components: e
339
435
  }), v.bounds.push(g - d - m, _ - f - h, g + d + m, _ + f + h);
340
436
  }
341
- for (let [t, { entries: n, bounds: i }] of r) {
342
- let r = new e(n.length);
343
- for (let e = 0; e < n.length; e++) r.add(i[e * 4], i[e * 4 + 1], i[e * 4 + 2], i[e * 4 + 3]);
437
+ for (let [e, { entries: t, bounds: i }] of r) {
438
+ let r = new n(t.length);
439
+ for (let e = 0; e < t.length; e++) r.add(i[e * 4], i[e * 4 + 1], i[e * 4 + 2], i[e * 4 + 3]);
344
440
  r.finish(), this.buckets.push({
345
- category: t,
346
- entries: n,
441
+ category: e,
442
+ entries: t,
347
443
  index: r
348
444
  });
349
445
  }
350
446
  }
351
- forEachOverlapping(e, t) {
352
- let n = K(e);
353
- if (!n) return;
354
- let { x: r, y: i, halfWidth: a, halfHeight: o } = n;
355
- this.forEachCandidate(n, r - a, i - o, r + a, i + o, (e) => {
356
- q(n, r, i, e) && t(e);
447
+ claimContact(e, t) {
448
+ let n = e < t ? e * Ne + t : t * Ne + e;
449
+ return this.resolved.has(n) ? !1 : (this.resolved.add(n), !0);
450
+ }
451
+ forEachOverlapping(e, t, n = 0, r = 0) {
452
+ let i = Le(e);
453
+ if (!i) return;
454
+ let { x: a, y: o, halfWidth: s, halfHeight: c } = i;
455
+ if (i.ccd && (n !== 0 || r !== 0)) {
456
+ let e = a - n, l = o - r, u = Math.min(e, a) - s, d = Math.min(l, o) - c, f = Math.max(e, a) + s, p = Math.max(l, o) + c;
457
+ this.forEachCandidate(i, u, d, f, p, (a) => {
458
+ Re(i, e, l, n, r, a) && t(a);
459
+ });
460
+ return;
461
+ }
462
+ this.forEachCandidate(i, a - s, o - c, a + s, o + c, (e) => {
463
+ Z(i, a, o, e) && t(e);
357
464
  });
358
465
  }
359
466
  sweep(e, t, n) {
360
- let r = Math.sqrt(t * t + n * n), i = K(e);
467
+ let r = Math.sqrt(t * t + n * n), i = Le(e);
361
468
  if (!i || r === 0) return {
362
469
  fraction: 1,
363
- blocking: U
470
+ blocking: X
364
471
  };
472
+ if (i.ccd) return this.sweepContinuous(i, t, n, r);
365
473
  let a = this.gatherCandidates(i, t, n);
366
474
  return a.length === 0 ? {
367
475
  fraction: 1,
368
- blocking: U
476
+ blocking: X
369
477
  } : this.refine(i, a, t, n, r);
370
478
  }
371
479
  resolveMove(e, t, n, r) {
372
- let i = Math.sqrt(t * t + n * n), a = K(e);
480
+ let i = Math.sqrt(t * t + n * n), a = Le(e);
373
481
  if (!a || i === 0) return {
374
482
  moveX: t,
375
483
  moveY: n,
376
- blocking: U
484
+ blocking: X
377
485
  };
486
+ if (a.ccd) {
487
+ let e = this.sweepContinuous(a, t, n, i);
488
+ return {
489
+ moveX: t * e.fraction,
490
+ moveY: n * e.fraction,
491
+ blocking: e.blocking
492
+ };
493
+ }
378
494
  let o = this.gatherCandidates(a, t, n);
379
495
  if (o.length === 0) return {
380
496
  moveX: t,
381
497
  moveY: n,
382
- blocking: U
498
+ blocking: X
383
499
  };
384
500
  if (r && t !== 0 && n !== 0) {
385
501
  let e = this.gatherCandidates(a, t, 0), r = this.gatherCandidates(a, 0, n);
386
502
  if (e.length === 0 && r.length === 0) return Math.abs(t) >= Math.abs(n) ? {
387
503
  moveX: t,
388
504
  moveY: 0,
389
- blocking: U
505
+ blocking: X
390
506
  } : {
391
507
  moveX: 0,
392
508
  moveY: n,
393
- blocking: U
509
+ blocking: X
394
510
  };
395
- 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));
511
+ let i = e.length === 0 ? Pe : this.refine(a, e, t, 0, Math.abs(t)), o = r.length === 0 ? Pe : this.refine(a, r, 0, n, Math.abs(n)), s = t * i.fraction, c = n * o.fraction;
512
+ if (s !== 0 && c !== 0) {
513
+ let e = this.gatherCandidates(a, s, c);
514
+ if (e.length > 0) {
515
+ let t = this.refine(a, e, s, c, Math.sqrt(s * s + c * c));
516
+ return {
517
+ moveX: s * t.fraction,
518
+ moveY: c * t.fraction,
519
+ blocking: t.blocking
520
+ };
521
+ }
522
+ }
396
523
  return {
397
- moveX: t * i.fraction,
398
- moveY: n * o.fraction,
399
- blocking: Ce(i.blocking, o.blocking)
524
+ moveX: s,
525
+ moveY: c,
526
+ blocking: Ie(i.blocking, o.blocking)
400
527
  };
401
528
  }
402
529
  let s = this.refine(a, o, t, n, i);
@@ -411,48 +538,89 @@ var V = 1e-4, Se = 24, H = "collidable", U = [], W = {
411
538
  if (e.sensor) return [];
412
539
  let s = r + t, c = i + n, l = [];
413
540
  return this.forEachCandidate(e, s - a, c - o, s + a, c + o, (t) => {
414
- q(e, s, c, t) && t.components.body[3] === 0 && (q(e, r, i, t) || l.push(t));
541
+ Z(e, s, c, t) && (M(t.components.body) || Z(e, r, i, t) || l.push(t));
415
542
  }), l;
416
543
  }
417
544
  refine(e, t, n, r, i) {
418
- let { x: a, y: o } = e, s = 0, c = 1, l = V / i;
419
- for (let i = 0; i < Se && c - s > l; i++) {
545
+ let { x: a, y: o } = e, s = 0, c = 1, l = Y / i;
546
+ for (let i = 0; i < je && c - s > l; i++) {
420
547
  let i = (s + c) / 2;
421
548
  this.blockedAt(e, t, n, r, i) ? c = i : s = i;
422
549
  }
423
550
  let u = [], d = a + n * c, f = o + r * c;
424
- for (let n of t) q(e, d, f, n) && u.push(n);
551
+ for (let n of t) Z(e, d, f, n) && u.push(n);
425
552
  return {
426
- fraction: s * i > V ? s : 0,
553
+ fraction: s * i > Y ? s : 0,
427
554
  blocking: u
428
555
  };
429
556
  }
557
+ gatherContinuousCandidates(e, t, n) {
558
+ if (e.sensor) return [];
559
+ let { x: r, y: i, halfWidth: a, halfHeight: o } = e, s = r + t, c = i + n, l = [];
560
+ return this.forEachCandidate(e, Math.min(r, s) - a, Math.min(i, c) - o, Math.max(r, s) + a, Math.max(i, c) + o, (a) => {
561
+ M(a.components.body) || Z(e, r, i, a) || Re(e, r, i, t, n, a) && l.push(a);
562
+ }), l;
563
+ }
564
+ sweepContinuous(e, t, n, r) {
565
+ let i = this.gatherContinuousCandidates(e, t, n);
566
+ if (i.length === 0) return {
567
+ fraction: 1,
568
+ blocking: X
569
+ };
570
+ let a = 1, o = [], s = Y / r;
571
+ for (let c of i) {
572
+ let i = this.entryFraction(e, c, t, n, r);
573
+ i < a - s ? (a = i, o = [c]) : i <= a + s && o.push(c);
574
+ }
575
+ return {
576
+ fraction: a * r > Y ? a : 0,
577
+ blocking: o
578
+ };
579
+ }
580
+ entryFraction(e, t, n, r, i) {
581
+ let a;
582
+ if (this.blockedAtOne(e, t, n, r, 1)) a = 1;
583
+ else {
584
+ let o = t.components.transform, s = o[0] - e.x, c = o[1] - e.y, l = ze((s * n + c * r) / (i * i));
585
+ if (!this.blockedAtOne(e, t, n, r, l)) return l;
586
+ a = l;
587
+ }
588
+ let o = 0, s = Y / i;
589
+ for (let i = 0; i < je && a - o > s; i++) {
590
+ let i = (o + a) / 2;
591
+ this.blockedAtOne(e, t, n, r, i) ? a = i : o = i;
592
+ }
593
+ return o;
594
+ }
595
+ blockedAtOne(e, t, n, r, i) {
596
+ return Z(e, Math.fround(e.x + n * i), Math.fround(e.y + r * i), t);
597
+ }
430
598
  blockedAt(e, t, n, r, i) {
431
- let a = e.x + n * i, o = e.y + r * i;
432
- for (let n of t) if (q(e, a, o, n)) return !0;
599
+ let a = Math.fround(e.x + n * i), o = Math.fround(e.y + r * i);
600
+ for (let n of t) if (Z(e, a, o, n)) return !0;
433
601
  return !1;
434
602
  }
435
- forEachCandidate(e, t, n, r, i, a) {
436
- for (let o of this.buckets) if ((e.mask & o.category) !== 0) for (let s of o.index.search(t, n, r, i)) {
437
- let t = o.entries[s];
438
- t.entityId !== e.entityId && (t.components.body[2] & e.category) !== 0 && a(t);
603
+ forEachCandidate(e, t, n, r, a, o) {
604
+ for (let s of this.buckets) if ((e.mask & s.category) !== 0) for (let c of s.index.search(t, n, r, a)) {
605
+ let t = s.entries[c];
606
+ t.entityId !== e.entityId && (t.components.body[2] & e.category) !== 0 && t.components.entity?.[i] !== 1 && o(t);
439
607
  }
440
608
  }
441
609
  };
442
- function Ce(e, t) {
610
+ function Ie(e, t) {
443
611
  if (e.length === 0) return t;
444
612
  if (t.length === 0) return e;
445
613
  let n = [...e];
446
614
  for (let e of t) n.some((t) => t.entityId === e.entityId) || n.push(e);
447
615
  return n;
448
616
  }
449
- function K(e) {
617
+ function Le(e) {
450
618
  let t = e.components.body;
451
619
  if (!t) return;
452
620
  let n = t[2];
453
621
  if (n === 0) return;
454
- let r = e.components.transform, i = t[0], a = r[2], o = r[3];
455
- if (D(i, a, o)) return;
622
+ let r = e.components.transform, i = j(t), a = r[2], o = r[3];
623
+ if (L(i, a, o)) return;
456
624
  let s = r[4];
457
625
  return {
458
626
  entityId: e.entityId,
@@ -462,36 +630,49 @@ function K(e) {
462
630
  width: a,
463
631
  height: o,
464
632
  angle: s,
465
- halfWidth: O(i, a, o, s),
466
- halfHeight: k(i, a, o, s),
633
+ halfWidth: R(i, a, o, s),
634
+ halfHeight: z(i, a, o, s),
467
635
  category: t[1],
468
636
  mask: n,
469
- sensor: t[3] !== 0
637
+ sensor: M(t),
638
+ ccd: ee(t)
470
639
  };
471
640
  }
472
- function q(e, t, n, r) {
641
+ function Re(e, t, n, r, i, a) {
642
+ let o = t + r, s = n + i, c = a.components.transform, l = j(a.components.body), u = c[0], d = c[1], f = c[2], p = c[3], m = c[4];
643
+ if (e.shape === 1) {
644
+ let a = Math.cos(e.angle), c = Math.sin(e.angle), h = r * a + i * c, g = -r * c + i * a;
645
+ return B(1, (t + o) / 2, (n + s) / 2, e.width + Math.abs(h), e.height + Math.abs(g), e.angle, l, u, d, f, p, m);
646
+ }
647
+ let h = I(e.shape, e.width, e.height), g = Math.sqrt(r * r + i * i), _ = g > 0 ? Math.atan2(i, r) : e.angle;
648
+ return B(3, (t + o) / 2, (n + s) / 2, g + h * 2, h * 2, _, l, u, d, f, p, m) ? !0 : B(e.shape, o, s, e.width, e.height, e.angle, l, u, d, f, p, m);
649
+ }
650
+ function ze(e) {
651
+ return e < 0 ? 0 : e > 1 ? 1 : e;
652
+ }
653
+ function Z(e, t, n, r) {
473
654
  let i = r.components.transform;
474
- return A(e.shape, t, n, e.width, e.height, e.angle, r.components.body[0], i[0], i[1], i[2], i[3], i[4]);
655
+ return B(e.shape, t, n, e.width, e.height, e.angle, j(r.components.body), i[0], i[1], i[2], i[3], i[4]);
475
656
  }
476
657
  //#endregion
477
658
  //#region src/systems/spatial-index.ts
478
- var we = class {
659
+ var Be = class {
479
660
  entries = [];
480
661
  index;
481
- constructor(t) {
482
- let n = [];
483
- for (let e of t) {
484
- let t = e.components, r = t.transform;
662
+ constructor(e) {
663
+ let t = [];
664
+ for (let n of e) {
665
+ let e = n.components, r = e.transform;
485
666
  if (!r) continue;
486
- let i = t.body, a = i ? i[0] : 1, o = r[2], s = r[3], c = r[4], l = r[0], u = r[1], d = O(a, o, s, c), f = k(a, o, s, c);
667
+ let i = e.body, a = i ? j(i) : 1, o = r[2], s = r[3], c = r[4], l = r[0], u = r[1], d = R(a, o, s, c), f = z(a, o, s, c);
487
668
  this.entries.push({
488
- entityId: e.entityId,
489
- components: t
490
- }), n.push(l - d, u - f, l + d, u + f);
669
+ entityId: n.entityId,
670
+ components: e
671
+ }), t.push(l - d, u - f, l + d, u + f);
491
672
  }
492
673
  if (this.entries.length === 0) return;
493
- let r = new e(this.entries.length);
494
- for (let e = 0; e < this.entries.length; e++) r.add(n[e * 4], n[e * 4 + 1], n[e * 4 + 2], n[e * 4 + 3]);
674
+ let r = new n(this.entries.length);
675
+ for (let e = 0; e < this.entries.length; e++) r.add(t[e * 4], t[e * 4 + 1], t[e * 4 + 2], t[e * 4 + 3]);
495
676
  r.finish(), this.index = r;
496
677
  }
497
678
  get size() {
@@ -515,133 +696,153 @@ var we = class {
515
696
  let o = this.entries;
516
697
  return (i ? a.neighbors(e, t, n, r, (e) => i(o[e])) : a.neighbors(e, t, n, r)).map((e) => o[e]);
517
698
  }
518
- }, J = {
519
- x: 0,
520
- y: 0
521
- }, Y = {
522
- x: 0,
523
- y: 0
524
- }, X = {
699
+ }, Q = {
525
700
  x: 0,
526
701
  y: 0
527
702
  };
528
- function Z(e, t) {
529
- let n = e.components.bounciness;
530
- if (!n || De(e.components.body) || De(t.components.body) || !Te(e, t, J)) return;
531
- let r = e.components.velocity, i = r[0], a = r[1], o = i * J.x + a * J.y;
532
- if (o >= 0) return;
533
- let s = (1 + n[0]) * o;
534
- r[0] = i - s * J.x, r[1] = a - s * J.y;
703
+ function Ve(e, t) {
704
+ !Ue(e) && !Ue(t) || We(e, t) && Ge(e, t, Q) && (He(e, Q.x, Q.y), He(t, -Q.x, -Q.y));
535
705
  }
536
- function Te(e, t, n) {
537
- 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);
538
- if (s === 2 && c === 2) {
539
- let e = Math.sqrt(a * a + o * o);
540
- return e === 0 ? !1 : (n.x = a / e, n.y = o / e, !0);
541
- }
542
- 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;
706
+ function He(e, t, n) {
707
+ let r = e.components.bounciness, i = e.components.velocity;
708
+ if (!r || !i) return;
709
+ let a = i[0], o = i[1], s = a * t + o * n;
710
+ if (s >= 0) return;
711
+ let c = (1 + r[0]) * s;
712
+ i[0] = a - c * t, i[1] = o - c * n;
713
+ }
714
+ function Ue(e) {
715
+ return e.components.bounciness !== void 0 && e.components.velocity !== void 0;
716
+ }
717
+ function We(e, t) {
718
+ return !qe(e.components.body) && !qe(t.components.body);
543
719
  }
544
- function Ee(e) {
545
- return e ? e[0] : 1;
720
+ function Ge(e, t, n) {
721
+ let r = e.components.transform, i = t.components.transform;
722
+ return be(Ke(e.components.body), r[0], r[1], r[2], r[3], r[4], Ke(t.components.body), i[0], i[1], i[2], i[3], i[4], n);
546
723
  }
547
- function De(e) {
548
- return e !== void 0 && e[3] !== 0;
724
+ function Ke(e) {
725
+ return e ? j(e) : 1;
549
726
  }
550
- function Oe(e, t, n) {
551
- let r = e[2], i = e[3], a = e[4];
552
- n.x = O(t, r, i, a), n.y = k(t, r, i, a);
727
+ function qe(e) {
728
+ return e !== void 0 && M(e);
553
729
  }
554
730
  //#endregion
555
731
  //#region src/systems/physics-update.ts
556
- var ke = "position-updated";
557
- function Ae(e = {}) {
558
- let { onCollision: t, optional: n = [] } = e, r, i = Object.assign((e, n, i, a, o) => {
559
- let s = {
732
+ var Je = "position-updated";
733
+ function Ye(e = {}) {
734
+ let { onCollision: t, optional: n = [] } = e, r, a = Object.assign((e, n, a, o, s) => {
735
+ if (a.entity?.[i] === 1) return;
736
+ let c = {
560
737
  entityId: n,
561
- components: i
562
- }, c = i.interpolation, l = e.elapsedTime / 1e3, u = i.velocity[0] * l, d = i.velocity[1] * l;
563
- if (Me(c, i.transform, e.elapsedTime), !r) {
564
- $(n, i.transform, u, d, o, e.reportMoves), Q(c, e.tick);
738
+ components: a
739
+ }, l = a.interpolation, u = e.elapsedTime / 1e3, d = a.velocity[0] * u, f = a.velocity[1] * u;
740
+ Qe(l, a.transform, e.elapsedTime);
741
+ let p = r;
742
+ if (!p) {
743
+ $(n, a.transform, d, f, s, e.reportMoves), $e(l, e.tick);
565
744
  return;
566
745
  }
567
- let f = i.bounciness !== void 0, p = r.resolveMove(s, u, d, !f);
568
- if ($(n, i.transform, p.moveX, p.moveY, o, e.reportMoves), Q(c, e.tick), !(!f && !t)) {
569
- r.forEachOverlapping(s, (n) => {
570
- f && Z(s, n), t && t(e, s, n, a, o);
571
- });
572
- for (let n of p.blocking) f && Z(s, n), t && t(e, s, n, a, o);
746
+ let m = a.bounciness !== void 0, h = p.resolveMove(c, d, f, !m);
747
+ if ($(n, a.transform, h.moveX, h.moveY, s, e.reportMoves), $e(l, e.tick), !(!p.hasBounciness && !t)) {
748
+ p.forEachOverlapping(c, (r) => {
749
+ p.claimContact(n, r.entityId) && Xe(e, c, r, o, s, t);
750
+ }, h.moveX, h.moveY);
751
+ for (let r of h.blocking) p.claimContact(n, r.entityId) && Xe(e, c, r, o, s, t);
573
752
  }
574
753
  }, { physics: {
575
754
  collision: !0,
576
755
  optional: n
577
756
  } });
578
- return i.preRun = (e, t, n) => {
579
- r = new G(n.collidable ?? [], e.elapsedTime / 1e3);
580
- }, i;
757
+ return a.preRun = (e, t, n) => {
758
+ r = new Fe(n.collidable ?? [], e.elapsedTime / 1e3);
759
+ }, a;
760
+ }
761
+ function Xe(e, t, n, r, i, a) {
762
+ Ve(t, n), a && a(e, t, n, r, i);
581
763
  }
582
- var je = (e, t, n, r, i) => {
764
+ function Ze(e, t, n, r, i) {
583
765
  let a = e.elapsedTime / 1e3, o = n.interpolation;
584
- Me(o, n.transform, e.elapsedTime), $(t, n.transform, n.velocity[0] * a, n.velocity[1] * a, i, e.reportMoves), Q(o, e.tick);
585
- };
586
- function Me(e, t, n) {
766
+ Qe(o, n.transform, e.elapsedTime), $(t, n.transform, n.velocity[0] * a, n.velocity[1] * a, i, e.reportMoves), $e(o, e.tick);
767
+ }
768
+ function Qe(e, t, n) {
587
769
  e && (e[2] = t[0], e[3] = t[1], e[6] = n);
588
770
  }
589
- function Q(e, t) {
590
- e && r(e, 7, t);
771
+ function $e(e, n) {
772
+ e && t(e, 7, n);
591
773
  }
592
- function $(e, n, r, i, a, o) {
593
- r === 0 && i === 0 || (r !== 0 && t(n, 0, r, Infinity), i !== 0 && t(n, 1, i, Infinity), o !== !1 && a.emitSystemEvent(ke, e));
774
+ function $(e, t, n, r, i, o) {
775
+ n === 0 && r === 0 || (n !== 0 && a(t, 0, n, Infinity), r !== 0 && a(t, 1, r, Infinity), o !== !1 && i.emitSystemEvent(Je, e));
594
776
  }
595
777
  //#endregion
596
778
  //#region src/systems/physics-system.ts
597
- var Ne = 50, Pe = class extends i {
779
+ var et = 50, tt = class extends r {
598
780
  tick = 0;
599
781
  reportMoves;
600
782
  constructor(e, t = {}) {
601
- let n = t.updateFunction ?? je, r = t.optional ?? n.physics?.optional ?? [], i = t.collision ?? n.physics?.collision ?? !1, a = [];
602
- i && !r.includes("body") && a.push("body"), i && !r.includes("bounciness") && a.push("bounciness"), r.includes("interpolation") || a.push("interpolation");
603
- let o = a.length ? [...a, ...r] : r, s = i ? { [H]: {
783
+ let n = t.updateFunction ?? Ze, r = t.optional ?? n.physics?.optional ?? [], i = t.collision ?? n.physics?.collision ?? !1, a = [];
784
+ i && !r.includes("body") && a.push("body"), i && !r.includes("bounciness") && a.push("bounciness"), r.includes("interpolation") || a.push("interpolation"), i && a.push("entity");
785
+ let o = a.length ? [...a, ...r] : r, s = r.includes("bounciness") ? r : ["bounciness", ...r], c = i ? { [Me]: {
604
786
  required: ["transform", "body"],
605
- optional: ["velocity", ...r]
606
- } } : void 0, c = s || t.queries ? {
607
- ...s,
787
+ optional: [
788
+ "velocity",
789
+ "entity",
790
+ ...s
791
+ ],
792
+ filter: t.scope
793
+ } } : void 0, l = c || t.queries ? {
794
+ ...c,
608
795
  ...t.queries
609
- } : void 0;
796
+ } : void 0, u = nt(t.scope, t.filter);
610
797
  super(e, {
611
798
  name: t.name ?? "PhysicsSystem",
612
799
  deltaBetweenRuns: t.deltaBetweenRuns ?? 50,
613
800
  firstRun: t.firstRun,
614
801
  required: ["transform", "velocity"],
615
802
  optional: o,
616
- filter: t.filter,
803
+ filter: u,
617
804
  updateFunction: n,
618
- queries: c,
805
+ queries: l,
619
806
  forceMainThread: t.forceMainThread ?? !t.getWorker,
620
807
  getWorker: t.getWorker ?? (() => {
621
808
  throw Error("PhysicsSystem cannot start a worker: no getWorker was supplied");
622
809
  })
623
810
  }), this.reportMoves = t.reportMoves;
624
811
  }
812
+ startInterpolation(e) {
813
+ let t = this.deltaBetweenRuns;
814
+ t <= 0 || ve(e, {
815
+ stepMs: t,
816
+ stepFraction: this.currentDelta / t,
817
+ tick: this.tick
818
+ });
819
+ }
625
820
  addDataToWorld(e) {
626
821
  e.tick = ++this.tick, e.reportMoves = this.reportMoves ?? this.listenerCount("position-updated") > 0;
627
822
  }
628
- }, Fe = (e, t, r) => {
629
- 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);
823
+ };
824
+ function nt(e, t) {
825
+ return e ? t ? (n) => e(n) && t(n) : e : t;
826
+ }
827
+ //#endregion
828
+ //#region src/systems/interpolation-update.ts
829
+ var rt = (t, n, r) => {
830
+ let i = r.interpolation, a = r.transform, o = e(i, 7), s = i[2], c = i[3], l = i[6], u = a[0], d = a[1], f = e(i, 7);
630
831
  if (o !== f) return;
631
832
  if (l <= 0) {
632
833
  i[4] = 1, i[5] = f, i[0] = u, i[1] = d;
633
834
  return;
634
835
  }
635
836
  let p = i[4];
636
- 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;
637
- }, Ie = class extends i {
837
+ f !== i[5] && (p = 0, i[5] = f), p += t.elapsedTime / l, p > 1 && (p = 1), i[4] = p, i[0] = s + (u - s) * p, i[1] = c + (d - c) * p;
838
+ }, it = class extends r {
638
839
  constructor(e, t = {}) {
639
840
  super(e, {
640
841
  name: t.name ?? "InterpolationSystem",
641
842
  deltaBetweenRuns: 0,
642
843
  firstRun: t.firstRun,
643
844
  required: ["transform", "interpolation"],
644
- updateFunction: Fe,
845
+ updateFunction: rt,
645
846
  forceMainThread: t.forceMainThread ?? !t.getWorker,
646
847
  getWorker: t.getWorker ?? (() => {
647
848
  throw Error("InterpolationSystem cannot start a worker: no getWorker was supplied");
@@ -650,6 +851,6 @@ var Ne = 50, Pe = class extends i {
650
851
  }
651
852
  };
652
853
  //#endregion
653
- 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 };
854
+ export { T as BODY_CATEGORY_INDEX, A as BODY_CCD_FLAG, w as BODY_FLAGS_INDEX, E as BODY_MASK_INDEX, k as BODY_SENSOR_FLAG, O as BODY_SHAPE_MASK, D as BODY_SIZE, ie as BOUNCINESS_INDEX, ae as BOUNCINESS_SIZE, Me as COLLIDABLE_QUERY, Fe as CollisionBroadphase, x as DEFAULT_COLLIDE_CATEGORY, S as DEFAULT_COLLIDE_MASK, et as DEFAULT_PHYSICS_STEP_MS, pe as INTERPOLATION_DURATION_INDEX, le as INTERPOLATION_PREV_X_INDEX, ue as INTERPOLATION_PREV_Y_INDEX, de as INTERPOLATION_PROGRESS_INDEX, he as INTERPOLATION_SIZE, fe as INTERPOLATION_SYNCED_TICK_INDEX, me as INTERPOLATION_TICK_INDEX, se as INTERPOLATION_X_INDEX, ce as INTERPOLATION_Y_INDEX, it as InterpolationSystem, Je as POSITION_UPDATED_EVENT, tt as PhysicsSystem, y as SHAPE_CAPSULE, v as SHAPE_CIRCLE, _ as SHAPE_RECTANGLE, Be as SpatialIndex, u as TRANSFORM_ANGLE_INDEX, l as TRANSFORM_HEIGHT_INDEX, d as TRANSFORM_SIZE, c as TRANSFORM_WIDTH_INDEX, o as TRANSFORM_X_INDEX, s as TRANSFORM_Y_INDEX, h as VELOCITY_SIZE, p as VELOCITY_X_INDEX, m as VELOCITY_Y_INDEX, te as bodyDefinition, j as bodyShape, oe as bouncinessDefinition, De as boundsHalfHeight, Ee as boundsHalfWidth, C as canCollide, F as capsuleHalfLength, be as contactNormal, Ye as createPhysicsUpdate, ge as interpolationDefinition, rt as interpolationUpdate, ee as isContinuous, M as isSensor, Oe as orientedBoxesOverlap, ye as physicsRegistry, Ze as physicsUpdate, K as pointSegmentDistanceSquared, ke as segmentBoxDistanceSquared, W as segmentSegmentDistanceSquared, z as shapeHalfHeight, R as shapeHalfWidth, L as shapeIsEmpty, I as shapeRadius, B as shapesOverlap, _e as snapEntity, ve as startSpawnInterpolation, f as transformDefinition, g as velocityDefinition };
654
855
 
655
856
  //# sourceMappingURL=index.js.map