@daneren2005/shared-memory-physics 1.2.2 → 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,7 +1,7 @@
1
- import e from "flatbush";
2
- import { ComponentSystem as t, DEAD_INDEX as n } from "@daneren2005/shared-memory-ecs";
3
- import { addAtomicFloat32 as r } from "@daneren2005/shared-memory-objects/utils/atomic-math";
4
- import { loadFloat32 as i, storeFloat32 as a } from "@daneren2005/shared-memory-objects/utils/float32-atomics";
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
6
  var o = 0, s = 1, c = 2, l = 3, u = 4, d = 5, f = {
7
7
  type: Float32Array,
@@ -61,7 +61,8 @@ var o = 0, s = 1, c = 2, l = 3, u = 4, d = 5, f = {
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
68
  }, p = 0, m = 1, h = 2, g = {
@@ -100,13 +101,19 @@ var o = 0, s = 1, c = 2, l = 3, u = 4, d = 5, f = {
100
101
  function C(e, t, n, r) {
101
102
  return (t & n) !== 0 && (r & e) !== 0;
102
103
  }
103
- var w = 0, T = 1, E = 2, D = 3, O = 4;
104
- function k(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 A = {
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 A = {
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
- ee(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,15 +151,25 @@ var A = {
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 ee(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
175
  if (!b.includes(t)) throw Error(`Unknown body shape: ${t}`);
@@ -160,7 +177,7 @@ function ee(e) {
160
177
  }
161
178
  //#endregion
162
179
  //#region src/components/bounciness-component.ts
163
- var te = 0, ne = 1, re = {
180
+ var ie = 0, ae = 1, oe = {
164
181
  type: Float32Array,
165
182
  size: 1,
166
183
  loadProperties: ["bounciness"],
@@ -176,280 +193,337 @@ var te = 0, ne = 1, re = {
176
193
  }
177
194
  };
178
195
  }
179
- }, ie = 0, ae = 1, oe = 2, se = 3, ce = 4, le = 5, ue = 6, de = 7, fe = 8, pe = {
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 me(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 he = {
276
+ var ye = {
230
277
  transform: f,
231
278
  velocity: g,
232
- body: A,
233
- bounciness: re,
234
- interpolation: pe
235
- }, j = {
279
+ body: te,
280
+ bounciness: oe,
281
+ interpolation: ge
282
+ }, N = {
236
283
  x: 0,
237
284
  y: 0
238
- }, M = {
285
+ }, P = {
239
286
  x: 0,
240
287
  y: 0
241
288
  };
242
- function N(e, t) {
289
+ function F(e, t) {
243
290
  return Math.max(0, (e - t) / 2);
244
291
  }
245
- function P(e, t, n) {
292
+ function I(e, t, n) {
246
293
  return e === 2 ? t / 2 : e === 3 ? n / 2 : 0;
247
294
  }
248
- function F(e, t, n) {
295
+ function L(e, t, n) {
249
296
  return e === 2 ? t <= 0 : e === 3 ? n <= 0 : t <= 0 || n <= 0;
250
297
  }
251
- function I(e, t, n, r) {
252
- return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.cos(r)) * N(t, n) + n / 2 : Se(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);
253
300
  }
254
- function L(e, t, n, r) {
255
- return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.sin(r)) * N(t, n) + n / 2 : Ce(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);
256
303
  }
257
- function R(e, t, n, r, i, a, o, s, c, l, u, d) {
258
- if (F(e, r, i) || F(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;
259
306
  let f = e !== 1, p = o !== 1;
260
- if (!f && !p) return we(t, n, r, i, a, s, c, l, u, d);
261
- if (f && !p) return R(o, s, c, l, u, d, e, t, n, r, i, a);
262
- let m = z(o, l, u), h = Math.cos(d) * m, g = Math.sin(d) * m, _ = P(o, l, u);
263
- if (!f) return U(s - h, c - g, s + h, c + g, t, n, r, i, a) < _ * _;
264
- let v = z(e, r, i), y = Math.cos(a) * v, b = Math.sin(a) * v, x = P(e, r, i) + _;
265
- return H(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;
266
313
  }
267
- function z(e, t, n) {
268
- return e === 3 ? N(t, n) : 0;
314
+ function V(e, t, n) {
315
+ return e === 3 ? F(t, n) : 0;
269
316
  }
270
- function ge(e, t, n, r, i, a, o, s, c, l, u, d, f) {
317
+ function be(e, t, n, r, i, a, o, s, c, l, u, d, f) {
271
318
  let p = e !== 1, m = o !== 1;
272
- return !p && !m ? _e(t, n, r, i, a, s, c, l, u, d, f) : p && m ? ve(e, t, n, r, i, a, o, s, c, l, u, d, f) : p ? ye(s, c, l, u, d, e, t, n, r, i, a, f) : ye(t, n, r, i, a, o, s, c, l, u, d, f) ? (f.x = -f.x, f.y = -f.y, !0) : !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;
273
320
  }
274
- function _e(e, t, n, r, i, a, o, s, c, l, u) {
275
- 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 = V(d, f, y, b, h, g, d, f, _, v, p, m);
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);
276
323
  u.x = d, u.y = f;
277
- let S = V(-f, d, y, b, h, g, d, f, _, v, p, m);
278
- return S < x && (x = S, u.x = -f, u.y = d), S = V(p, m, y, b, h, g, d, f, _, v, p, m), S < x && (x = S, u.x = p, u.y = m), S = V(-m, p, y, b, h, g, d, f, _, v, p, m), S < x && (u.x = -m, u.y = p), be(y, b, u), !0;
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;
279
326
  }
280
- function ve(e, t, n, r, i, a, o, s, c, l, u, d, f) {
281
- let p = z(e, r, i), m = Math.cos(a) * p, h = Math.sin(a) * p, g = z(o, l, u), _ = Math.cos(d) * g, v = Math.sin(d) * g, y = Math.sqrt(H(t - m, n - h, t + m, n + h, s - _, c - v, s + _, c + v, j));
282
- return y > 0 ? (f.x = j.x / y, f.y = j.y / y, !0) : xe(t - s, n - c, f);
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);
283
330
  }
284
- function ye(e, t, n, r, i, a, o, s, c, l, u, d) {
285
- let f = z(a, c, l), p = Math.cos(u) * f, m = Math.sin(u) * f, h = Math.sqrt(U(o - p, s - m, o + p, s + m, e, t, n, r, i, j));
286
- if (h > 0) return d.x = j.x / h, d.y = j.y / h, !0;
287
- 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 = P(a, c, l), T = n / 2, E = r / 2, D = B(1, 0, b, x, S, C, w, T, E);
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);
288
335
  d.x = 1, d.y = 0;
289
- let O = B(0, 1, b, x, S, C, w, T, E);
290
- O < D && (D = O, d.x = 0, d.y = 1), xe(-C, S, M) && (O = B(M.x, M.y, b, x, S, C, w, T, E), O < D && (d.x = M.x, d.y = M.y)), be(b, x, d);
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);
291
338
  let k = d.x, A = d.y;
292
339
  return d.x = k * g - A * _, d.y = k * _ + A * g, !0;
293
340
  }
294
- function B(e, t, n, r, i, a, o, s, c) {
341
+ function H(e, t, n, r, i, a, o, s, c) {
295
342
  return s * Math.abs(e) + c * Math.abs(t) + (Math.abs(i * e + a * t) + o) - Math.abs(n * e + r * t);
296
343
  }
297
- function be(e, t, n) {
344
+ function we(e, t, n) {
298
345
  e * n.x + t * n.y < 0 && (n.x = -n.x, n.y = -n.y);
299
346
  }
300
- function xe(e, t, n) {
347
+ function Te(e, t, n) {
301
348
  let r = Math.sqrt(e * e + t * t);
302
349
  return r === 0 ? !1 : (n.x = e / r, n.y = t / r, !0);
303
350
  }
304
- function Se(e, t, n) {
351
+ function Ee(e, t, n) {
305
352
  return (Math.abs(Math.cos(n)) * e + Math.abs(Math.sin(n)) * t) / 2;
306
353
  }
307
- function Ce(e, t, n) {
354
+ function De(e, t, n) {
308
355
  return (Math.abs(Math.sin(n)) * e + Math.abs(Math.cos(n)) * t) / 2;
309
356
  }
310
- function we(e, t, n, r, i, a, o, s, c, l) {
357
+ function Oe(e, t, n, r, i, a, o, s, c, l) {
311
358
  if (n <= 0 || r <= 0 || s <= 0 || c <= 0) return !1;
312
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;
313
- return V(u, d, v, y, m, h, u, d, g, _, f, p) > 0 && V(-d, u, v, y, m, h, u, d, g, _, f, p) > 0 && V(f, p, v, y, m, h, u, d, g, _, f, p) > 0 && V(-p, f, v, y, m, h, u, d, g, _, f, p) > 0;
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;
314
361
  }
315
- function V(e, t, n, r, i, a, o, s, c, l, u, d) {
362
+ function U(e, t, n, r, i, a, o, s, c, l, u, d) {
316
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);
317
364
  }
318
- function H(e, t, n, r, i, a, o, s, c) {
365
+ function W(e, t, n, r, i, a, o, s, c) {
319
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;
320
367
  if (h <= 0 && g <= 0) return c && (c.x = p, c.y = m), p * p + m * m;
321
- if (h <= 0) y = q(_ / g);
368
+ if (h <= 0) y = J(_ / g);
322
369
  else {
323
370
  let e = l * p + u * m;
324
- if (g <= 0) v = q(-e / h);
371
+ if (g <= 0) v = J(-e / h);
325
372
  else {
326
373
  let t = l * d + u * f, n = h * g - t * t;
327
- n !== 0 && (v = q((t * _ - e * g) / n)), y = (t * v + _) / g, y < 0 ? (y = 0, v = q(-e / h)) : y > 1 && (y = 1, v = q((t - e) / h));
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));
328
375
  }
329
376
  }
330
377
  let b = e + l * v - (i + d * y), x = t + u * v - (a + f * y);
331
378
  return c && (c.x = b, c.y = x), b * b + x * x;
332
379
  }
333
- function U(e, t, n, r, i, a, o, s, c, l) {
380
+ function ke(e, t, n, r, i, a, o, s, c, l) {
334
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;
335
- if (!Te(v, y, b, x, f, p)) return l && (l.x = 0, l.y = 0), 0;
336
- if (!l) return Math.min(K(v, y, f, p), K(b, x, f, p), G(-f, -p, v, y, b, x), G(f, -p, v, y, b, x), G(f, p, v, y, b, x), G(-f, p, v, y, b, x));
337
- let S = K(v, y, f, p, l);
338
- S = W(S, K(b, x, f, p, M), M, l, !1), S = W(S, G(-f, -p, v, y, b, x, M), M, l, !0), S = W(S, G(f, -p, v, y, b, x, M), M, l, !0), S = W(S, G(f, p, v, y, b, x, M), M, l, !0), S = W(S, G(-f, p, v, y, b, x, M), M, l, !0);
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);
339
386
  let C = l.x, w = l.y;
340
387
  return l.x = C * u - w * d, l.y = C * d + w * u, S;
341
388
  }
342
- function W(e, t, n, r, i) {
389
+ function G(e, t, n, r, i) {
343
390
  return t >= e ? e : (r.x = i ? -n.x : n.x, r.y = i ? -n.y : n.y, t);
344
391
  }
345
- function G(e, t, n, r, i, a, o) {
346
- let s = i - n, c = a - r, l = s * s + c * c, u = l > 0 ? q(((e - n) * s + (t - r) * c) / l) : 0, d = e - (n + s * u), f = t - (r + c * u);
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);
347
394
  return o && (o.x = d, o.y = f), d * d + f * f;
348
395
  }
349
- function Te(e, t, n, r, i, a) {
396
+ function Ae(e, t, n, r, i, a) {
350
397
  if (Math.max(e, n) < -i || Math.min(e, n) > i || Math.max(t, r) < -a || Math.min(t, r) > a) return !0;
351
398
  let o = -(r - t), s = n - e;
352
399
  return Math.abs(o * e + s * t) > i * Math.abs(o) + a * Math.abs(s);
353
400
  }
354
- function K(e, t, n, r, i) {
401
+ function q(e, t, n, r, i) {
355
402
  let a = Math.abs(e) - n, o = Math.abs(t) - r, s = a > 0 ? a : 0, c = o > 0 ? o : 0;
356
403
  return i && (i.x = e < 0 ? -s : s, i.y = t < 0 ? -c : c), s * s + c * c;
357
404
  }
358
- function q(e) {
405
+ function J(e) {
359
406
  return e < 0 ? 0 : e > 1 ? 1 : e;
360
407
  }
361
408
  //#endregion
362
409
  //#region src/systems/collision.ts
363
- var Ee = 1e-4, De = 24, Oe = "collidable", J = [], ke = 2 ** 26, Ae = {
410
+ var Y = 1e-4, je = 24, Me = "collidable", X = [], Ne = 2 ** 26, Pe = {
364
411
  fraction: 1,
365
- blocking: J
366
- }, je = class {
412
+ blocking: X
413
+ }, Fe = class {
367
414
  buckets = [];
368
415
  hasBounciness = !1;
369
416
  resolved = /* @__PURE__ */ new Set();
370
- constructor(t, n) {
417
+ constructor(e, t) {
371
418
  let r = /* @__PURE__ */ new Map();
372
- for (let e of t) {
373
- 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;
374
421
  if (!i || !a) continue;
375
422
  let o = a[1];
376
423
  if (o === 0) continue;
377
- let s = a[0], c = i[2], l = i[3];
378
- if (F(s, c, l)) continue;
379
- let u = i[4], d = I(s, c, l, u), f = L(s, c, l, u);
380
- t.bounciness && (this.hasBounciness = !0);
381
- let 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);
382
429
  v || (v = {
383
430
  entries: [],
384
431
  bounds: []
385
432
  }, r.set(o, v)), v.entries.push({
386
- entityId: e.entityId,
387
- components: t
433
+ entityId: n.entityId,
434
+ components: e
388
435
  }), v.bounds.push(g - d - m, _ - f - h, g + d + m, _ + f + h);
389
436
  }
390
- for (let [t, { entries: n, bounds: i }] of r) {
391
- let r = new e(n.length);
392
- 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]);
393
440
  r.finish(), this.buckets.push({
394
- category: t,
395
- entries: n,
441
+ category: e,
442
+ entries: t,
396
443
  index: r
397
444
  });
398
445
  }
399
446
  }
400
447
  claimContact(e, t) {
401
- let n = e < t ? e * ke + t : t * ke + e;
448
+ let n = e < t ? e * Ne + t : t * Ne + e;
402
449
  return this.resolved.has(n) ? !1 : (this.resolved.add(n), !0);
403
450
  }
404
- forEachOverlapping(e, t) {
405
- let n = Y(e);
406
- if (!n) return;
407
- let { x: r, y: i, halfWidth: a, halfHeight: o } = n;
408
- this.forEachCandidate(n, r - a, i - o, r + a, i + o, (e) => {
409
- X(n, r, i, e) && t(e);
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);
410
464
  });
411
465
  }
412
466
  sweep(e, t, n) {
413
- let r = Math.sqrt(t * t + n * n), i = Y(e);
467
+ let r = Math.sqrt(t * t + n * n), i = Le(e);
414
468
  if (!i || r === 0) return {
415
469
  fraction: 1,
416
- blocking: J
470
+ blocking: X
417
471
  };
472
+ if (i.ccd) return this.sweepContinuous(i, t, n, r);
418
473
  let a = this.gatherCandidates(i, t, n);
419
474
  return a.length === 0 ? {
420
475
  fraction: 1,
421
- blocking: J
476
+ blocking: X
422
477
  } : this.refine(i, a, t, n, r);
423
478
  }
424
479
  resolveMove(e, t, n, r) {
425
- let i = Math.sqrt(t * t + n * n), a = Y(e);
480
+ let i = Math.sqrt(t * t + n * n), a = Le(e);
426
481
  if (!a || i === 0) return {
427
482
  moveX: t,
428
483
  moveY: n,
429
- blocking: J
484
+ blocking: X
430
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
+ }
431
494
  let o = this.gatherCandidates(a, t, n);
432
495
  if (o.length === 0) return {
433
496
  moveX: t,
434
497
  moveY: n,
435
- blocking: J
498
+ blocking: X
436
499
  };
437
500
  if (r && t !== 0 && n !== 0) {
438
501
  let e = this.gatherCandidates(a, t, 0), r = this.gatherCandidates(a, 0, n);
439
502
  if (e.length === 0 && r.length === 0) return Math.abs(t) >= Math.abs(n) ? {
440
503
  moveX: t,
441
504
  moveY: 0,
442
- blocking: J
505
+ blocking: X
443
506
  } : {
444
507
  moveX: 0,
445
508
  moveY: n,
446
- blocking: J
509
+ blocking: X
447
510
  };
448
- let i = e.length === 0 ? Ae : this.refine(a, e, t, 0, Math.abs(t)), o = r.length === 0 ? Ae : 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
+ }
449
523
  return {
450
- moveX: t * i.fraction,
451
- moveY: n * o.fraction,
452
- blocking: Me(i.blocking, o.blocking)
524
+ moveX: s,
525
+ moveY: c,
526
+ blocking: Ie(i.blocking, o.blocking)
453
527
  };
454
528
  }
455
529
  let s = this.refine(a, o, t, n, i);
@@ -464,48 +538,89 @@ var Ee = 1e-4, De = 24, Oe = "collidable", J = [], ke = 2 ** 26, Ae = {
464
538
  if (e.sensor) return [];
465
539
  let s = r + t, c = i + n, l = [];
466
540
  return this.forEachCandidate(e, s - a, c - o, s + a, c + o, (t) => {
467
- X(e, s, c, t) && t.components.body[3] === 0 && (X(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));
468
542
  }), l;
469
543
  }
470
544
  refine(e, t, n, r, i) {
471
- let { x: a, y: o } = e, s = 0, c = 1, l = Ee / i;
472
- for (let i = 0; i < De && 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++) {
473
547
  let i = (s + c) / 2;
474
548
  this.blockedAt(e, t, n, r, i) ? c = i : s = i;
475
549
  }
476
550
  let u = [], d = a + n * c, f = o + r * c;
477
- for (let n of t) X(e, d, f, n) && u.push(n);
551
+ for (let n of t) Z(e, d, f, n) && u.push(n);
478
552
  return {
479
- fraction: s * i > Ee ? s : 0,
553
+ fraction: s * i > Y ? s : 0,
480
554
  blocking: u
481
555
  };
482
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
+ }
483
598
  blockedAt(e, t, n, r, i) {
484
- let a = e.x + n * i, o = e.y + r * i;
485
- for (let n of t) if (X(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;
486
601
  return !1;
487
602
  }
488
- forEachCandidate(e, t, r, i, a, o) {
489
- for (let s of this.buckets) if ((e.mask & s.category) !== 0) for (let c of s.index.search(t, r, i, a)) {
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)) {
490
605
  let t = s.entries[c];
491
- t.entityId !== e.entityId && (t.components.body[2] & e.category) !== 0 && t.components.entity?.[n] !== 1 && o(t);
606
+ t.entityId !== e.entityId && (t.components.body[2] & e.category) !== 0 && t.components.entity?.[i] !== 1 && o(t);
492
607
  }
493
608
  }
494
609
  };
495
- function Me(e, t) {
610
+ function Ie(e, t) {
496
611
  if (e.length === 0) return t;
497
612
  if (t.length === 0) return e;
498
613
  let n = [...e];
499
614
  for (let e of t) n.some((t) => t.entityId === e.entityId) || n.push(e);
500
615
  return n;
501
616
  }
502
- function Y(e) {
617
+ function Le(e) {
503
618
  let t = e.components.body;
504
619
  if (!t) return;
505
620
  let n = t[2];
506
621
  if (n === 0) return;
507
- let r = e.components.transform, i = t[0], a = r[2], o = r[3];
508
- if (F(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;
509
624
  let s = r[4];
510
625
  return {
511
626
  entityId: e.entityId,
@@ -515,36 +630,49 @@ function Y(e) {
515
630
  width: a,
516
631
  height: o,
517
632
  angle: s,
518
- halfWidth: I(i, a, o, s),
519
- halfHeight: L(i, a, o, s),
633
+ halfWidth: R(i, a, o, s),
634
+ halfHeight: z(i, a, o, s),
520
635
  category: t[1],
521
636
  mask: n,
522
- sensor: t[3] !== 0
637
+ sensor: M(t),
638
+ ccd: ee(t)
523
639
  };
524
640
  }
525
- function X(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) {
526
654
  let i = r.components.transform;
527
- return R(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]);
528
656
  }
529
657
  //#endregion
530
658
  //#region src/systems/spatial-index.ts
531
- var Ne = class {
659
+ var Be = class {
532
660
  entries = [];
533
661
  index;
534
- constructor(t) {
535
- let n = [];
536
- for (let e of t) {
537
- 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;
538
666
  if (!r) continue;
539
- 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 = I(a, o, s, c), f = L(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);
540
668
  this.entries.push({
541
- entityId: e.entityId,
542
- components: t
543
- }), 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);
544
672
  }
545
673
  if (this.entries.length === 0) return;
546
- let r = new e(this.entries.length);
547
- 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]);
548
676
  r.finish(), this.index = r;
549
677
  }
550
678
  get size() {
@@ -568,14 +696,14 @@ var Ne = class {
568
696
  let o = this.entries;
569
697
  return (i ? a.neighbors(e, t, n, r, (e) => i(o[e])) : a.neighbors(e, t, n, r)).map((e) => o[e]);
570
698
  }
571
- }, Z = {
699
+ }, Q = {
572
700
  x: 0,
573
701
  y: 0
574
702
  };
575
- function Pe(e, t) {
576
- !Ie(e) && !Ie(t) || Le(e, t) && Re(e, t, Z) && (Fe(e, Z.x, Z.y), Fe(t, -Z.x, -Z.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));
577
705
  }
578
- function Fe(e, t, n) {
706
+ function He(e, t, n) {
579
707
  let r = e.components.bounciness, i = e.components.velocity;
580
708
  if (!r || !i) return;
581
709
  let a = i[0], o = i[1], s = a * t + o * n;
@@ -583,95 +711,96 @@ function Fe(e, t, n) {
583
711
  let c = (1 + r[0]) * s;
584
712
  i[0] = a - c * t, i[1] = o - c * n;
585
713
  }
586
- function Ie(e) {
714
+ function Ue(e) {
587
715
  return e.components.bounciness !== void 0 && e.components.velocity !== void 0;
588
716
  }
589
- function Le(e, t) {
590
- return !Be(e.components.body) && !Be(t.components.body);
717
+ function We(e, t) {
718
+ return !qe(e.components.body) && !qe(t.components.body);
591
719
  }
592
- function Re(e, t, n) {
720
+ function Ge(e, t, n) {
593
721
  let r = e.components.transform, i = t.components.transform;
594
- return ge(ze(e.components.body), r[0], r[1], r[2], r[3], r[4], ze(t.components.body), i[0], i[1], i[2], i[3], i[4], n);
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);
595
723
  }
596
- function ze(e) {
597
- return e ? e[0] : 1;
724
+ function Ke(e) {
725
+ return e ? j(e) : 1;
598
726
  }
599
- function Be(e) {
600
- return e !== void 0 && e[3] !== 0;
727
+ function qe(e) {
728
+ return e !== void 0 && M(e);
601
729
  }
602
730
  //#endregion
603
731
  //#region src/systems/physics-update.ts
604
- var Ve = "position-updated";
605
- function He(e = {}) {
606
- let { onCollision: t, optional: r = [] } = e, i, a = Object.assign((e, r, a, o, s) => {
607
- if (a.entity?.[n] === 1) return;
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;
608
736
  let c = {
609
- entityId: r,
737
+ entityId: n,
610
738
  components: a
611
739
  }, l = a.interpolation, u = e.elapsedTime / 1e3, d = a.velocity[0] * u, f = a.velocity[1] * u;
612
- Ge(l, a.transform, e.elapsedTime);
613
- let p = i;
740
+ Qe(l, a.transform, e.elapsedTime);
741
+ let p = r;
614
742
  if (!p) {
615
- $(r, a.transform, d, f, s, e.reportMoves), Q(l, e.tick);
743
+ $(n, a.transform, d, f, s, e.reportMoves), $e(l, e.tick);
616
744
  return;
617
745
  }
618
746
  let m = a.bounciness !== void 0, h = p.resolveMove(c, d, f, !m);
619
- if ($(r, a.transform, h.moveX, h.moveY, s, e.reportMoves), Q(l, e.tick), !(!p.hasBounciness && !t)) {
620
- p.forEachOverlapping(c, (n) => {
621
- p.claimContact(r, n.entityId) && Ue(e, c, n, o, s, t);
622
- });
623
- for (let n of h.blocking) p.claimContact(r, n.entityId) && Ue(e, c, n, o, s, t);
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);
624
752
  }
625
753
  }, { physics: {
626
754
  collision: !0,
627
- optional: r
755
+ optional: n
628
756
  } });
629
757
  return a.preRun = (e, t, n) => {
630
- i = new je(n.collidable ?? [], e.elapsedTime / 1e3);
758
+ r = new Fe(n.collidable ?? [], e.elapsedTime / 1e3);
631
759
  }, a;
632
760
  }
633
- function Ue(e, t, n, r, i, a) {
634
- Pe(t, n), a && a(e, t, n, r, i);
761
+ function Xe(e, t, n, r, i, a) {
762
+ Ve(t, n), a && a(e, t, n, r, i);
635
763
  }
636
- function We(e, t, n, r, i) {
764
+ function Ze(e, t, n, r, i) {
637
765
  let a = e.elapsedTime / 1e3, o = n.interpolation;
638
- Ge(o, n.transform, e.elapsedTime), $(t, n.transform, n.velocity[0] * a, n.velocity[1] * a, i, e.reportMoves), Q(o, e.tick);
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);
639
767
  }
640
- function Ge(e, t, n) {
768
+ function Qe(e, t, n) {
641
769
  e && (e[2] = t[0], e[3] = t[1], e[6] = n);
642
770
  }
643
- function Q(e, t) {
644
- e && a(e, 7, t);
771
+ function $e(e, n) {
772
+ e && t(e, 7, n);
645
773
  }
646
- function $(e, t, n, i, a, o) {
647
- n === 0 && i === 0 || (n !== 0 && r(t, 0, n, Infinity), i !== 0 && r(t, 1, i, Infinity), o !== !1 && a.emitSystemEvent(Ve, 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));
648
776
  }
649
777
  //#endregion
650
778
  //#region src/systems/physics-system.ts
651
- var Ke = 50, qe = class extends t {
779
+ var et = 50, tt = class extends r {
652
780
  tick = 0;
653
781
  reportMoves;
654
782
  constructor(e, t = {}) {
655
- let n = t.updateFunction ?? We, r = t.optional ?? n.physics?.optional ?? [], i = t.collision ?? n.physics?.collision ?? !1, a = [];
783
+ let n = t.updateFunction ?? Ze, r = t.optional ?? n.physics?.optional ?? [], i = t.collision ?? n.physics?.collision ?? !1, a = [];
656
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");
657
- let o = a.length ? [...a, ...r] : r, s = r.includes("bounciness") ? r : ["bounciness", ...r], c = i ? { [Oe]: {
785
+ let o = a.length ? [...a, ...r] : r, s = r.includes("bounciness") ? r : ["bounciness", ...r], c = i ? { [Me]: {
658
786
  required: ["transform", "body"],
659
787
  optional: [
660
788
  "velocity",
661
789
  "entity",
662
790
  ...s
663
- ]
791
+ ],
792
+ filter: t.scope
664
793
  } } : void 0, l = c || t.queries ? {
665
794
  ...c,
666
795
  ...t.queries
667
- } : void 0;
796
+ } : void 0, u = nt(t.scope, t.filter);
668
797
  super(e, {
669
798
  name: t.name ?? "PhysicsSystem",
670
799
  deltaBetweenRuns: t.deltaBetweenRuns ?? 50,
671
800
  firstRun: t.firstRun,
672
801
  required: ["transform", "velocity"],
673
802
  optional: o,
674
- filter: t.filter,
803
+ filter: u,
675
804
  updateFunction: n,
676
805
  queries: l,
677
806
  forceMainThread: t.forceMainThread ?? !t.getWorker,
@@ -680,26 +809,40 @@ var Ke = 50, qe = class extends t {
680
809
  })
681
810
  }), this.reportMoves = t.reportMoves;
682
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
+ }
683
820
  addDataToWorld(e) {
684
821
  e.tick = ++this.tick, e.reportMoves = this.reportMoves ?? this.listenerCount("position-updated") > 0;
685
822
  }
686
- }, Je = (e, t, n) => {
687
- let r = n.interpolation, a = n.transform, o = i(r, 7), s = r[2], c = r[3], l = r[6], u = a[0], d = a[1], f = i(r, 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);
688
831
  if (o !== f) return;
689
832
  if (l <= 0) {
690
- r[4] = 1, r[5] = f, r[0] = u, r[1] = d;
833
+ i[4] = 1, i[5] = f, i[0] = u, i[1] = d;
691
834
  return;
692
835
  }
693
- let p = r[4];
694
- f !== r[5] && (p = 0, r[5] = f), p += e.elapsedTime / l, p > 1 && (p = 1), r[4] = p, r[0] = s + (u - s) * p, r[1] = c + (d - c) * p;
695
- }, Ye = class extends t {
836
+ let p = i[4];
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 {
696
839
  constructor(e, t = {}) {
697
840
  super(e, {
698
841
  name: t.name ?? "InterpolationSystem",
699
842
  deltaBetweenRuns: 0,
700
843
  firstRun: t.firstRun,
701
844
  required: ["transform", "interpolation"],
702
- updateFunction: Je,
845
+ updateFunction: rt,
703
846
  forceMainThread: t.forceMainThread ?? !t.getWorker,
704
847
  getWorker: t.getWorker ?? (() => {
705
848
  throw Error("InterpolationSystem cannot start a worker: no getWorker was supplied");
@@ -708,6 +851,6 @@ var Ke = 50, qe = class extends t {
708
851
  }
709
852
  };
710
853
  //#endregion
711
- export { T as BODY_CATEGORY_INDEX, E as BODY_MASK_INDEX, D as BODY_SENSOR_INDEX, w as BODY_SHAPE_INDEX, O as BODY_SIZE, te as BOUNCINESS_INDEX, ne as BOUNCINESS_SIZE, Oe as COLLIDABLE_QUERY, je as CollisionBroadphase, x as DEFAULT_COLLIDE_CATEGORY, S as DEFAULT_COLLIDE_MASK, Ke as DEFAULT_PHYSICS_STEP_MS, ue as INTERPOLATION_DURATION_INDEX, oe as INTERPOLATION_PREV_X_INDEX, se as INTERPOLATION_PREV_Y_INDEX, ce as INTERPOLATION_PROGRESS_INDEX, fe as INTERPOLATION_SIZE, le as INTERPOLATION_SYNCED_TICK_INDEX, de as INTERPOLATION_TICK_INDEX, ie as INTERPOLATION_X_INDEX, ae as INTERPOLATION_Y_INDEX, Ye as InterpolationSystem, Ve as POSITION_UPDATED_EVENT, qe as PhysicsSystem, y as SHAPE_CAPSULE, v as SHAPE_CIRCLE, _ as SHAPE_RECTANGLE, Ne 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, A as bodyDefinition, re as bouncinessDefinition, Ce as boundsHalfHeight, Se as boundsHalfWidth, C as canCollide, N as capsuleHalfLength, ge as contactNormal, He as createPhysicsUpdate, pe as interpolationDefinition, Je as interpolationUpdate, k as isSensor, we as orientedBoxesOverlap, he as physicsRegistry, We as physicsUpdate, G as pointSegmentDistanceSquared, U as segmentBoxDistanceSquared, H as segmentSegmentDistanceSquared, L as shapeHalfHeight, I as shapeHalfWidth, F as shapeIsEmpty, P as shapeRadius, R as shapesOverlap, me as snapEntity, f as transformDefinition, g 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 };
712
855
 
713
856
  //# sourceMappingURL=index.js.map