@daneren2005/shared-memory-physics 1.7.1 → 1.7.3

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
@@ -13,29 +13,29 @@ var l = 16, u = 0, d = 1, f = 33, p = class extends t {
13
13
  size: 33,
14
14
  loadProperties: ["vertices"],
15
15
  toBlock(e) {
16
- let t = h(e.vertices);
16
+ let t = h(e.vertices, e.width, e.height);
17
17
  return [t.vertices.length / 2, ...t.vertices];
18
18
  },
19
19
  attach(e, t, n) {
20
20
  return new p(t.getBlock(n), n);
21
21
  }
22
22
  };
23
- function h(e) {
23
+ function h(e, t, n) {
24
24
  if (!e || e.length < 3 || e.length > 16) throw Error("A polygon needs between 3 and 16 vertices");
25
- let t = Infinity, n = Infinity, r = -Infinity, i = -Infinity;
26
- for (let [a, o] of e) {
27
- if (!Number.isFinite(a) || !Number.isFinite(o)) throw Error("Polygon vertices must be finite numbers");
28
- t = Math.min(t, a), n = Math.min(n, o), r = Math.max(r, a), i = Math.max(i, o);
29
- }
30
- let a = r - t, o = i - n;
31
- if (a <= 0 || o <= 0) throw Error("A polygon must have nonzero width and height");
32
- let s = 0;
25
+ let r = Infinity, i = Infinity, a = -Infinity, o = -Infinity;
26
+ for (let [t, n] of e) {
27
+ if (!Number.isFinite(t) || !Number.isFinite(n)) throw Error("Polygon vertices must be finite numbers");
28
+ r = Math.min(r, t), i = Math.min(i, n), a = Math.max(a, t), o = Math.max(o, n);
29
+ }
30
+ let s = a - r, c = o - i;
31
+ if (s <= 0 || c <= 0) throw Error("A polygon must have nonzero width and height");
32
+ let l = 0;
33
33
  for (let t = 0; t < e.length; t++) {
34
34
  let n = e[(t + e.length - 1) % e.length], r = e[t], i = e[(t + 1) % e.length], a = (r[0] - n[0]) * (i[1] - r[1]) - (r[1] - n[1]) * (i[0] - r[0]);
35
35
  if (a === 0) throw Error("A polygon cannot contain duplicate or collinear adjacent vertices");
36
36
  let o = Math.sign(a);
37
- if (s === 0) s = o;
38
- else if (o !== s) throw Error("Polygon vertices must describe a convex polygon in boundary order");
37
+ if (l === 0) l = o;
38
+ else if (o !== l) throw Error("Polygon vertices must describe a convex polygon in boundary order");
39
39
  }
40
40
  for (let t = 0; t < e.length; t++) {
41
41
  let n = e[t], r = e[(t + 1) % e.length];
@@ -45,12 +45,18 @@ function h(e) {
45
45
  if (g(n, r, a, o)) throw Error("Polygon edges cannot cross or share non-adjacent vertices");
46
46
  }
47
47
  }
48
- let c = (t + r) / 2, l = (n + i) / 2, u = [], d = s > 0 ? e : e.toReversed();
49
- for (let [e, t] of d) u.push((e - c) / a, (t - l) / o);
48
+ if (t === void 0 != (n === void 0)) throw Error("A sized polygon needs both a width and a height");
49
+ let u = t !== void 0 && n !== void 0;
50
+ if (u) {
51
+ if (!(t > 0) || !(n > 0)) throw Error("A sized polygon needs a positive width and height");
52
+ if (r < -t / 2 || a > t / 2 || i < -n / 2 || o > n / 2) throw Error("Polygon vertices must fit inside the width and height they are given with");
53
+ }
54
+ let d = u ? t : s, f = u ? n : c, p = u ? 0 : (r + a) / 2, m = u ? 0 : (i + o) / 2, h = [], _ = l > 0 ? e : e.toReversed();
55
+ for (let [e, t] of _) h.push((e - p) / d, (t - m) / f);
50
56
  return {
51
- width: a,
52
- height: o,
53
- vertices: u
57
+ width: d,
58
+ height: f,
59
+ vertices: h
54
60
  };
55
61
  }
56
62
  function g(e, t, n, r) {
@@ -105,8 +111,8 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = class extends t {
105
111
  toBlock(e) {
106
112
  let t = e.radius, n = e.vertices, r = e.width, i = e.height;
107
113
  if (n !== void 0) {
108
- if (t !== void 0 || r !== void 0 || i !== void 0) throw Error("A transform takes polygon vertices, a radius, or a width and height");
109
- let e = h(n);
114
+ if (t !== void 0) throw Error("A transform takes polygon vertices or a radius, not both");
115
+ let e = h(n, r, i);
110
116
  r = e.width, i = e.height;
111
117
  }
112
118
  if (t !== void 0) {
@@ -125,11 +131,11 @@ var v = 0, y = 1, b = 2, x = 3, S = 4, C = 5, w = class extends t {
125
131
  return new w(t.getBlock(n), n);
126
132
  },
127
133
  save(e) {
128
- return {
134
+ let t = {
129
135
  x: e.x,
130
- y: e.y,
131
- angle: e.angle
132
- };
136
+ y: e.y
137
+ }, n = e.angle;
138
+ return n !== 0 && (t.angle = n), t;
133
139
  }
134
140
  }, E = 0, D = 1, O = 2, k = 3, A = class extends t {
135
141
  get velocityX() {
@@ -182,7 +188,7 @@ function M(e) {
182
188
  }
183
189
  //#endregion
184
190
  //#region src/components/dynamics-component.ts
185
- var N = 0, ee = 1, P = 2, F = 3, I = class extends t {
191
+ var N = 0, P = 1, ee = 2, F = 3, I = class extends t {
186
192
  get accelerationX() {
187
193
  return this.block[0];
188
194
  }
@@ -494,128 +500,131 @@ var tt = {
494
500
  y: 0
495
501
  };
496
502
  function V(e, t) {
497
- return Math.max(0, (e - t) / 2);
503
+ return Math.abs(e - t) / 2;
498
504
  }
499
505
  function H(e, t, n) {
500
- return e === 2 ? t / 2 : e === 3 ? n / 2 : 0;
506
+ return t > e ? n + Math.PI / 2 : n;
501
507
  }
502
508
  function U(e, t, n) {
503
- return e === 2 ? t <= 0 : e === 3 ? n <= 0 : t <= 0 || n <= 0;
509
+ return e === 2 ? t / 2 : e === 3 ? Math.min(t, n) / 2 : 0;
510
+ }
511
+ function W(e, t, n) {
512
+ return e === 2 ? t <= 0 : t <= 0 || n <= 0;
504
513
  }
505
- function W(e, t, n, r) {
506
- return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.cos(r)) * V(t, n) + n / 2 : ut(t, n, r);
514
+ function nt(e, t, n, r) {
515
+ return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.cos(H(t, n, r))) * V(t, n) + Math.min(t, n) / 2 : pt(t, n, r);
507
516
  }
508
- function G(e, t, n, r) {
509
- return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.sin(r)) * V(t, n) + n / 2 : dt(t, n, r);
517
+ function rt(e, t, n, r) {
518
+ return e === 2 ? t / 2 : e === 3 ? Math.abs(Math.sin(H(t, n, r))) * V(t, n) + Math.min(t, n) / 2 : mt(t, n, r);
510
519
  }
511
- function nt(e, t, n, r, i, a, o, s, c, l, u, d) {
512
- if (U(e, r, i) || U(o, l, u)) return !1;
520
+ function it(e, t, n, r, i, a, o, s, c, l, u, d) {
521
+ if (W(e, r, i) || W(o, l, u)) return !1;
513
522
  let f = e !== 1, p = o !== 1;
514
- if (!f && !p) return ft(t, n, r, i, a, s, c, l, u, d);
515
- if (f && !p) return nt(o, s, c, l, u, d, e, t, n, r, i, a);
516
- let m = K(o, l, u), h = Math.cos(d) * m, g = Math.sin(d) * m, _ = H(o, l, u);
517
- if (!f) return mt(s - h, c - g, s + h, c + g, t, n, r, i, a) < _ * _;
518
- let v = K(e, r, i), y = Math.cos(a) * v, b = Math.sin(a) * v, x = H(e, r, i) + _;
519
- return pt(t - y, n - b, t + y, n + b, s - h, c - g, s + h, c + g) < x * x;
520
- }
521
- function K(e, t, n) {
523
+ if (!f && !p) return ht(t, n, r, i, a, s, c, l, u, d);
524
+ if (f && !p) return it(o, s, c, l, u, d, e, t, n, r, i, a);
525
+ let m = at(o, l, u), h = H(l, u, d), g = Math.cos(h) * m, _ = Math.sin(h) * m, v = U(o, l, u);
526
+ if (!f) return _t(s - g, c - _, s + g, c + _, t, n, r, i, a) < v * v;
527
+ let y = at(e, r, i), b = H(r, i, a), x = Math.cos(b) * y, S = Math.sin(b) * y, C = U(e, r, i) + v;
528
+ return gt(t - x, n - S, t + x, n + S, s - g, c - _, s + g, c + _) < C * C;
529
+ }
530
+ function at(e, t, n) {
522
531
  return e === 3 ? V(t, n) : 0;
523
532
  }
524
- function rt(e, t, n, r, i, a, o, s, c, l, u, d, f) {
533
+ function ot(e, t, n, r, i, a, o, s, c, l, u, d, f) {
525
534
  let p = e !== 1, m = o !== 1;
526
- return !p && !m ? it(t, n, r, i, a, s, c, l, u, d, f) : p && m ? at(e, t, n, r, i, a, o, s, c, l, u, d, f) : p ? ot(s, c, l, u, d, e, t, n, r, i, a, f) : ot(t, n, r, i, a, o, s, c, l, u, d, f) ? (f.x = -f.x, f.y = -f.y, !0) : !1;
535
+ return !p && !m ? st(t, n, r, i, a, s, c, l, u, d, f) : p && m ? ct(e, t, n, r, i, a, o, s, c, l, u, d, f) : p ? lt(s, c, l, u, d, e, t, n, r, i, a, f) : lt(t, n, r, i, a, o, s, c, l, u, d, f) ? (f.x = -f.x, f.y = -f.y, !0) : !1;
527
536
  }
528
- function it(e, t, n, r, i, a, o, s, c, l, u) {
529
- 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 = q(d, f, y, b, h, g, d, f, _, v, p, m);
537
+ function st(e, t, n, r, i, a, o, s, c, l, u) {
538
+ 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 = G(d, f, y, b, h, g, d, f, _, v, p, m);
530
539
  u.x = d, u.y = f;
531
- let S = q(-f, d, y, b, h, g, d, f, _, v, p, m);
532
- return S < x && (x = S, u.x = -f, u.y = d), S = q(p, m, y, b, h, g, d, f, _, v, p, m), S < x && (x = S, u.x = p, u.y = m), S = q(-m, p, y, b, h, g, d, f, _, v, p, m), S < x && (u.x = -m, u.y = p), ct(y, b, u), !0;
540
+ let S = G(-f, d, y, b, h, g, d, f, _, v, p, m);
541
+ return S < x && (x = S, u.x = -f, u.y = d), S = G(p, m, y, b, h, g, d, f, _, v, p, m), S < x && (x = S, u.x = p, u.y = m), S = G(-m, p, y, b, h, g, d, f, _, v, p, m), S < x && (u.x = -m, u.y = p), dt(y, b, u), !0;
533
542
  }
534
- function at(e, t, n, r, i, a, o, s, c, l, u, d, f) {
535
- let p = K(e, r, i), m = Math.cos(a) * p, h = Math.sin(a) * p, g = K(o, l, u), _ = Math.cos(d) * g, v = Math.sin(d) * g, y = Math.sqrt(pt(t - m, n - h, t + m, n + h, s - _, c - v, s + _, c + v, z));
536
- return y > 0 ? (f.x = z.x / y, f.y = z.y / y, !0) : lt(t - s, n - c, f);
543
+ function ct(e, t, n, r, i, a, o, s, c, l, u, d, f) {
544
+ let p = at(e, r, i), m = H(r, i, a), h = Math.cos(m) * p, g = Math.sin(m) * p, _ = at(o, l, u), v = H(l, u, d), y = Math.cos(v) * _, b = Math.sin(v) * _, x = Math.sqrt(gt(t - h, n - g, t + h, n + g, s - y, c - b, s + y, c + b, z));
545
+ return x > 0 ? (f.x = z.x / x, f.y = z.y / x, !0) : ft(t - s, n - c, f);
537
546
  }
538
- function ot(e, t, n, r, i, a, o, s, c, l, u, d) {
539
- let f = K(a, c, l), p = Math.cos(u) * f, m = Math.sin(u) * f, h = Math.sqrt(mt(o - p, s - m, o + p, s + m, e, t, n, r, i, z));
540
- if (h > 0) return d.x = z.x / h, d.y = z.y / h, !0;
541
- 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 = H(a, c, l), T = n / 2, E = r / 2, D = st(1, 0, b, x, S, C, w, T, E);
547
+ function lt(e, t, n, r, i, a, o, s, c, l, u, d) {
548
+ let f = at(a, c, l), p = H(c, l, u), m = Math.cos(p) * f, h = Math.sin(p) * f, g = Math.sqrt(_t(o - m, s - h, o + m, s + h, e, t, n, r, i, z));
549
+ if (g > 0) return d.x = z.x / g, d.y = z.y / g, !0;
550
+ let _ = Math.cos(i), v = Math.sin(i), y = o - e, b = s - t, x = y * _ + b * v, S = -y * v + b * _, C = m * _ + h * v, w = -m * v + h * _, T = U(a, c, l), E = n / 2, D = r / 2, O = ut(1, 0, x, S, C, w, T, E, D);
542
551
  d.x = 1, d.y = 0;
543
- let O = st(0, 1, b, x, S, C, w, T, E);
544
- O < D && (D = O, d.x = 0, d.y = 1), lt(-C, S, B) && (O = st(B.x, B.y, b, x, S, C, w, T, E), O < D && (d.x = B.x, d.y = B.y)), ct(b, x, d);
545
- let k = d.x, A = d.y;
546
- return d.x = k * g - A * _, d.y = k * _ + A * g, !0;
552
+ let k = ut(0, 1, x, S, C, w, T, E, D);
553
+ k < O && (O = k, d.x = 0, d.y = 1), ft(-w, C, B) && (k = ut(B.x, B.y, x, S, C, w, T, E, D), k < O && (d.x = B.x, d.y = B.y)), dt(x, S, d);
554
+ let A = d.x, j = d.y;
555
+ return d.x = A * _ - j * v, d.y = A * v + j * _, !0;
547
556
  }
548
- function st(e, t, n, r, i, a, o, s, c) {
557
+ function ut(e, t, n, r, i, a, o, s, c) {
549
558
  return s * Math.abs(e) + c * Math.abs(t) + (Math.abs(i * e + a * t) + o) - Math.abs(n * e + r * t);
550
559
  }
551
- function ct(e, t, n) {
560
+ function dt(e, t, n) {
552
561
  e * n.x + t * n.y < 0 && (n.x = -n.x, n.y = -n.y);
553
562
  }
554
- function lt(e, t, n) {
563
+ function ft(e, t, n) {
555
564
  let r = Math.sqrt(e * e + t * t);
556
565
  return r !== 0 && (n.x = e / r, n.y = t / r, !0);
557
566
  }
558
- function ut(e, t, n) {
567
+ function pt(e, t, n) {
559
568
  return (Math.abs(Math.cos(n)) * e + Math.abs(Math.sin(n)) * t) / 2;
560
569
  }
561
- function dt(e, t, n) {
570
+ function mt(e, t, n) {
562
571
  return (Math.abs(Math.sin(n)) * e + Math.abs(Math.cos(n)) * t) / 2;
563
572
  }
564
- function ft(e, t, n, r, i, a, o, s, c, l) {
573
+ function ht(e, t, n, r, i, a, o, s, c, l) {
565
574
  if (n <= 0 || r <= 0 || s <= 0 || c <= 0) return !1;
566
575
  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;
567
- return q(u, d, v, y, m, h, u, d, g, _, f, p) > 0 && q(-d, u, v, y, m, h, u, d, g, _, f, p) > 0 && q(f, p, v, y, m, h, u, d, g, _, f, p) > 0 && q(-p, f, v, y, m, h, u, d, g, _, f, p) > 0;
576
+ return G(u, d, v, y, m, h, u, d, g, _, f, p) > 0 && G(-d, u, v, y, m, h, u, d, g, _, f, p) > 0 && G(f, p, v, y, m, h, u, d, g, _, f, p) > 0 && G(-p, f, v, y, m, h, u, d, g, _, f, p) > 0;
568
577
  }
569
- function q(e, t, n, r, i, a, o, s, c, l, u, d) {
578
+ function G(e, t, n, r, i, a, o, s, c, l, u, d) {
570
579
  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);
571
580
  }
572
- function pt(e, t, n, r, i, a, o, s, c) {
581
+ function gt(e, t, n, r, i, a, o, s, c) {
573
582
  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;
574
583
  if (h <= 0 && g <= 0) return c && (c.x = p, c.y = m), p * p + m * m;
575
- if (h <= 0) y = Y(_ / g);
584
+ if (h <= 0) y = J(_ / g);
576
585
  else {
577
586
  let e = l * p + u * m;
578
- if (g <= 0) v = Y(-e / h);
587
+ if (g <= 0) v = J(-e / h);
579
588
  else {
580
589
  let t = l * d + u * f, n = h * g - t * t;
581
- n !== 0 && (v = Y((t * _ - e * g) / n)), y = (t * v + _) / g, y < 0 ? (y = 0, v = Y(-e / h)) : y > 1 && (y = 1, v = Y((t - e) / h));
590
+ 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));
582
591
  }
583
592
  }
584
593
  let b = e + l * v - (i + d * y), x = t + u * v - (a + f * y);
585
594
  return c && (c.x = b, c.y = x), b * b + x * x;
586
595
  }
587
- function mt(e, t, n, r, i, a, o, s, c, l) {
596
+ function _t(e, t, n, r, i, a, o, s, c, l) {
588
597
  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;
589
- if (!gt(v, y, b, x, f, p)) return l && (l.x = 0, l.y = 0), 0;
590
- if (!l) return Math.min(_t(v, y, f, p), _t(b, x, f, p), J(-f, -p, v, y, b, x), J(f, -p, v, y, b, x), J(f, p, v, y, b, x), J(-f, p, v, y, b, x));
591
- let S = _t(v, y, f, p, l);
592
- S = ht(S, _t(b, x, f, p, B), B, l, !1), S = ht(S, J(-f, -p, v, y, b, x, B), B, l, !0), S = ht(S, J(f, -p, v, y, b, x, B), B, l, !0), S = ht(S, J(f, p, v, y, b, x, B), B, l, !0), S = ht(S, J(-f, p, v, y, b, x, B), B, l, !0);
598
+ if (!vt(v, y, b, x, f, p)) return l && (l.x = 0, l.y = 0), 0;
599
+ if (!l) return Math.min(yt(v, y, f, p), yt(b, x, f, p), q(-f, -p, v, y, b, x), q(f, -p, v, y, b, x), q(f, p, v, y, b, x), q(-f, p, v, y, b, x));
600
+ let S = yt(v, y, f, p, l);
601
+ S = K(S, yt(b, x, f, p, B), B, l, !1), S = K(S, q(-f, -p, v, y, b, x, B), B, l, !0), S = K(S, q(f, -p, v, y, b, x, B), B, l, !0), S = K(S, q(f, p, v, y, b, x, B), B, l, !0), S = K(S, q(-f, p, v, y, b, x, B), B, l, !0);
593
602
  let C = l.x, w = l.y;
594
603
  return l.x = C * u - w * d, l.y = C * d + w * u, S;
595
604
  }
596
- function ht(e, t, n, r, i) {
605
+ function K(e, t, n, r, i) {
597
606
  return t >= e ? e : (r.x = i ? -n.x : n.x, r.y = i ? -n.y : n.y, t);
598
607
  }
599
- function J(e, t, n, r, i, a, o) {
600
- let s = i - n, c = a - r, l = s * s + c * c, u = l > 0 ? Y(((e - n) * s + (t - r) * c) / l) : 0, d = e - (n + s * u), f = t - (r + c * u);
608
+ function q(e, t, n, r, i, a, o) {
609
+ 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);
601
610
  return o && (o.x = d, o.y = f), d * d + f * f;
602
611
  }
603
- function gt(e, t, n, r, i, a) {
612
+ function vt(e, t, n, r, i, a) {
604
613
  if (Math.max(e, n) < -i || Math.min(e, n) > i || Math.max(t, r) < -a || Math.min(t, r) > a) return !0;
605
614
  let o = -(r - t), s = n - e;
606
615
  return Math.abs(o * e + s * t) > i * Math.abs(o) + a * Math.abs(s);
607
616
  }
608
- function _t(e, t, n, r, i) {
617
+ function yt(e, t, n, r, i) {
609
618
  let a = Math.abs(e) - n, o = Math.abs(t) - r, s = a > 0 ? a : 0, c = o > 0 ? o : 0;
610
619
  return i && (i.x = e < 0 ? -s : s, i.y = t < 0 ? -c : c), s * s + c * c;
611
620
  }
612
- function Y(e) {
621
+ function J(e) {
613
622
  return e < 0 ? 0 : e > 1 ? 1 : e;
614
623
  }
615
624
  //#endregion
616
625
  //#region src/systems/spatial-bounds.ts
617
- function X(e) {
618
- let t = e.transform, n = e.body ? L(e.body) : 1, r = t[2], i = t[3], a = t[4], o = W(n, r, i, a), s = G(n, r, i, a), c = t[0], l = t[1];
626
+ function Y(e) {
627
+ let t = e.transform, n = e.body ? L(e.body) : 1, r = t[2], i = t[3], a = t[4], o = nt(n, r, i, a), s = rt(n, r, i, a), c = t[0], l = t[1];
619
628
  return {
620
629
  minX: c - o,
621
630
  minY: l - s,
@@ -623,23 +632,23 @@ function X(e) {
623
632
  maxY: l + s
624
633
  };
625
634
  }
626
- function vt(e, t, n, r, i) {
635
+ function bt(e, t, n, r, i) {
627
636
  return e.minX <= r && e.maxX >= t && e.minY <= i && e.maxY >= n;
628
637
  }
629
- function yt(e, t) {
638
+ function xt(e, t) {
630
639
  return t > e ? t - e : Math.max(1, Math.abs(e)) * 2 ** -52;
631
640
  }
632
641
  //#endregion
633
642
  //#region src/world.ts
634
- function bt(e, t) {
643
+ function St(e, t) {
635
644
  t.spatialMapMemory = e.spatialMap.getSharedMemory();
636
645
  }
637
- function xt(e) {
646
+ function Ct(e) {
638
647
  if (e.spatialMap) return e.spatialMap;
639
648
  if (!e.heap || !e.spatialMapMemory) throw Error("Spatial system world is missing its shared MemoryHeap or spatial map");
640
649
  return e.spatialMap = new o(e.heap, e.spatialMapMemory), e.spatialMap;
641
650
  }
642
- var St = class extends e {
651
+ var wt = class extends e {
643
652
  spatialMap;
644
653
  spatialIds = /* @__PURE__ */ new Set();
645
654
  constructor(e, t = {}) {
@@ -662,7 +671,7 @@ var St = class extends e {
662
671
  this.spatialIds.delete(t.eid), this.spatialMap.remove(t.eid);
663
672
  return;
664
673
  }
665
- let i = X({
674
+ let i = Y({
666
675
  transform: r,
667
676
  body: n.body?.block
668
677
  });
@@ -670,12 +679,12 @@ var St = class extends e {
670
679
  }
671
680
  searchSpatial(e, t, n, r, i) {
672
681
  if (n < e || r < t) return [];
673
- let a = [], o = Number.isFinite(e) && Number.isFinite(t) && Number.isFinite(n) && Number.isFinite(r) ? this.spatialMap.search(e, t, yt(e, n), yt(t, r)) : this.spatialIds;
682
+ let a = [], o = Number.isFinite(e) && Number.isFinite(t) && Number.isFinite(n) && Number.isFinite(r) ? this.spatialMap.search(e, t, xt(e, n), xt(t, r)) : this.spatialIds;
674
683
  for (let s of o) {
675
684
  let o = this.getEntityByEid(s);
676
685
  if (!o || i && !i(o)) continue;
677
686
  let c = o.components, l = c.transform?.block;
678
- l && vt(X({
687
+ l && bt(Y({
679
688
  transform: l,
680
689
  body: c.body?.block
681
690
  }), e, t, n, r) && a.push(o);
@@ -697,60 +706,60 @@ var St = class extends e {
697
706
  return t ? [t] : [];
698
707
  });
699
708
  }
700
- }, Ct = {
709
+ }, Tt = {
701
710
  min: 0,
702
711
  max: 0
703
- }, wt = {
712
+ }, Et = {
704
713
  min: 0,
705
714
  max: 0
706
- }, Z = {
715
+ }, X = {
707
716
  overlap: !0,
708
717
  depth: Infinity,
709
718
  x: 0,
710
719
  y: 0
711
720
  };
712
- function Tt(e, t, n, r, i, a, o, s, c, l, u, d, f, p) {
713
- return Dt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, !1);
721
+ function Dt(e, t, n, r, i, a, o, s, c, l, u, d, f, p) {
722
+ return kt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, !1);
714
723
  }
715
- function Et(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) {
716
- return Z.depth = Infinity, !Dt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, !0) || Z.depth === Infinity ? !1 : (m.x = Z.x, m.y = Z.y, !0);
724
+ function Ot(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) {
725
+ return X.depth = Infinity, !kt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, !0) || X.depth === Infinity ? !1 : (m.x = X.x, m.y = X.y, !0);
717
726
  }
718
- function Dt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) {
719
- return !(e === 4 && (!t || !Ot(t, n, r, i, a, o, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m)) || s === 4 && (!c || !Ot(c, l, u, d, f, p, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m)) || e === 1 && !kt(o, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) || s === 1 && !kt(p, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) || It(e) && c && !At(e, n, r, i, a, o, c, l, u, d, f, p, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) || It(s) && t && !At(s, l, u, d, f, p, t, n, r, i, a, o, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m));
727
+ function kt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) {
728
+ return !(e === 4 && (!t || !At(t, n, r, i, a, o, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m)) || s === 4 && (!c || !At(c, l, u, d, f, p, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m)) || e === 1 && !jt(o, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) || s === 1 && !jt(p, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) || Rt(e) && c && !Mt(e, n, r, i, a, o, c, l, u, d, f, p, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m) || Rt(s) && t && !Mt(s, l, u, d, f, p, t, n, r, i, a, o, e, t, n, r, i, a, o, s, c, l, u, d, f, p, m));
720
729
  }
721
- function Ot(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g, _, v, y, b) {
730
+ function At(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g, _, v, y, b) {
722
731
  let x = e[0], S = Math.cos(a), C = Math.sin(a);
723
732
  for (let a = 0; a < x; a++) {
724
- let w = (a + 1) % x, T = Nt(e, a, t, r, i, S, C), E = Pt(e, a, n, r, i, S, C), D = Nt(e, w, t, r, i, S, C);
725
- if (!jt(E - Pt(e, w, n, r, i, S, C), D - T, o, s, c, l, u, d, f, p, m, h, g, _, v, y, b)) return !1;
733
+ let w = (a + 1) % x, T = Ft(e, a, t, r, i, S, C), E = It(e, a, n, r, i, S, C), D = Ft(e, w, t, r, i, S, C);
734
+ if (!Nt(E - It(e, w, n, r, i, S, C), D - T, o, s, c, l, u, d, f, p, m, h, g, _, v, y, b)) return !1;
726
735
  }
727
736
  return !0;
728
737
  }
729
- function kt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h) {
738
+ function jt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h) {
730
739
  let g = Math.cos(e), _ = Math.sin(e);
731
- return jt(g, _, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h) && jt(-_, g, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h);
740
+ return Nt(g, _, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h) && Nt(-_, g, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h);
732
741
  }
733
- function At(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g, _, v, y, b, x, S, C, w, T, E) {
734
- let D = e === 3 ? V(r, i) : 0, O = Math.cos(a) * D, k = Math.sin(a) * D, A = t - O, j = n - k, M = t + O, N = n + k, ee = o[0], P = Math.cos(d), F = Math.sin(d);
742
+ function Mt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g, _, v, y, b, x, S, C, w, T, E) {
743
+ let D = e === 3 ? V(r, i) : 0, O = H(r, i, a), k = Math.cos(O) * D, A = Math.sin(O) * D, j = t - k, M = n - A, N = t + k, P = n + A, ee = o[0], F = Math.cos(d), I = Math.sin(d);
735
744
  for (let e = 0; e < ee; e++) {
736
- let t = Nt(o, e, s, l, u, P, F), n = Pt(o, e, c, l, u, P, F), r = Ft(A, j, M, N, t, n), i = A + (M - A) * r, a = j + (N - j) * r;
737
- if (!jt(t - i, n - a, f, p, m, h, g, _, v, y, b, x, S, C, w, T, E)) return !1;
745
+ let t = Ft(o, e, s, l, u, F, I), n = It(o, e, c, l, u, F, I), r = Lt(j, M, N, P, t, n), i = j + (N - j) * r, a = M + (P - M) * r;
746
+ if (!Nt(t - i, n - a, f, p, m, h, g, _, v, y, b, x, S, C, w, T, E)) return !1;
738
747
  }
739
748
  return !0;
740
749
  }
741
- function jt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g) {
750
+ function Nt(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g) {
742
751
  let _ = Math.hypot(e, t);
743
752
  if (_ === 0) return !0;
744
- e /= _, t /= _, Mt(n, r, i, a, o, s, c, e, t, Ct), Mt(l, u, d, f, p, m, h, e, t, wt);
745
- let v = Ct.max - wt.min, y = wt.max - Ct.min;
753
+ e /= _, t /= _, Pt(n, r, i, a, o, s, c, e, t, Tt), Pt(l, u, d, f, p, m, h, e, t, Et);
754
+ let v = Tt.max - Et.min, y = Et.max - Tt.min;
746
755
  if (!g && (v <= 0 || y <= 0)) return !1;
747
756
  if (g) {
748
757
  let n, r;
749
- v <= 0 ? (n = -v, r = -1) : y <= 0 ? (n = -y, r = 1) : v < y ? (n = v, r = -1) : (n = y, r = 1), n < Z.depth && (Z.depth = n, Z.x = e * r, Z.y = t * r);
758
+ v <= 0 ? (n = -v, r = -1) : y <= 0 ? (n = -y, r = 1) : v < y ? (n = v, r = -1) : (n = y, r = 1), n < X.depth && (X.depth = n, X.x = e * r, X.y = t * r);
750
759
  }
751
760
  return !0;
752
761
  }
753
- function Mt(e, t, n, r, i, a, o, s, c, l) {
762
+ function Pt(e, t, n, r, i, a, o, s, c, l) {
754
763
  let u = n * s + r * c;
755
764
  if (e === 2) {
756
765
  let e = i / 2;
@@ -758,8 +767,8 @@ function Mt(e, t, n, r, i, a, o, s, c, l) {
758
767
  return;
759
768
  }
760
769
  if (e === 3) {
761
- let e = V(i, a), t = Math.abs(s * Math.cos(o) + c * Math.sin(o)) * e + a / 2;
762
- l.min = u - t, l.max = u + t;
770
+ let e = V(i, a), t = H(i, a, o), n = Math.abs(s * Math.cos(t) + c * Math.sin(t)) * e + Math.min(i, a) / 2;
771
+ l.min = u - n, l.max = u + n;
763
772
  return;
764
773
  }
765
774
  if (e === 1) {
@@ -774,48 +783,48 @@ function Mt(e, t, n, r, i, a, o, s, c, l) {
774
783
  let d = t[0], f = Math.cos(o), p = Math.sin(o);
775
784
  l.min = Infinity, l.max = -Infinity;
776
785
  for (let e = 0; e < d; e++) {
777
- let o = Nt(t, e, n, i, a, f, p), u = Pt(t, e, r, i, a, f, p), d = o * s + u * c;
786
+ let o = Ft(t, e, n, i, a, f, p), u = It(t, e, r, i, a, f, p), d = o * s + u * c;
778
787
  l.min = Math.min(l.min, d), l.max = Math.max(l.max, d);
779
788
  }
780
789
  }
781
- function Nt(e, t, n, r, i, a, o) {
790
+ function Ft(e, t, n, r, i, a, o) {
782
791
  let s = 1 + t * 2;
783
792
  return n + e[s] * r * a - e[s + 1] * i * o;
784
793
  }
785
- function Pt(e, t, n, r, i, a, o) {
794
+ function It(e, t, n, r, i, a, o) {
786
795
  let s = 1 + t * 2;
787
796
  return n + e[s] * r * o + e[s + 1] * i * a;
788
797
  }
789
- function Ft(e, t, n, r, i, a) {
798
+ function Lt(e, t, n, r, i, a) {
790
799
  let o = n - e, s = r - t, c = o * o + s * s;
791
800
  return c === 0 ? 0 : Math.min(1, Math.max(0, ((i - e) * o + (a - t) * s) / c));
792
801
  }
793
- function It(e) {
802
+ function Rt(e) {
794
803
  return e === 2 || e === 3;
795
804
  }
796
- function Lt(e, t, n, r, i, a) {
797
- if (Gt(n, r, "Force"), Gt(i, a, "Impulse"), n === 0 && r === 0 && i === 0 && a === 0) return;
798
- let o = e.get(t) ?? Wt(), s = {
805
+ function zt(e, t, n, r, i, a) {
806
+ if (qt(n, r, "Force"), qt(i, a, "Impulse"), n === 0 && r === 0 && i === 0 && a === 0) return;
807
+ let o = e.get(t) ?? Kt(), s = {
799
808
  ...o,
800
809
  forceX: o.forceX + n,
801
810
  forceY: o.forceY + r,
802
811
  impulseX: o.impulseX + i,
803
812
  impulseY: o.impulseY + a
804
813
  };
805
- Gt(s.forceX, s.forceY, "Accumulated force"), Gt(s.impulseX, s.impulseY, "Accumulated impulse"), e.set(t, s);
814
+ qt(s.forceX, s.forceY, "Accumulated force"), qt(s.impulseX, s.impulseY, "Accumulated impulse"), e.set(t, s);
806
815
  }
807
- function Rt(e, t, n) {
808
- Kt(n), (n.velocityX !== void 0 || n.velocityY !== void 0) && e.set(t, {
809
- ...e.get(t) ?? Wt(),
816
+ function Bt(e, t, n) {
817
+ Jt(n), (n.velocityX !== void 0 || n.velocityY !== void 0) && e.set(t, {
818
+ ...e.get(t) ?? Kt(),
810
819
  ...n
811
820
  });
812
821
  }
813
- function zt(e, t) {
822
+ function Vt(e, t) {
814
823
  if (e.size === 0) return t;
815
824
  let n = /* @__PURE__ */ new Map();
816
825
  for (let [t, r] of e) n.set(t, { ...r });
817
- return Ut(t, (e, t) => {
818
- let r = n.get(e) ?? Wt();
826
+ return Gt(t, (e, t) => {
827
+ let r = n.get(e) ?? Kt();
819
828
  n.set(e, {
820
829
  forceX: r.forceX + t.forceX,
821
830
  forceY: r.forceY + t.forceY,
@@ -829,13 +838,13 @@ function zt(e, t) {
829
838
  ...t
830
839
  })).sort((e, t) => e.entityId - t.entityId);
831
840
  }
832
- function Bt(e, t, n, r) {
833
- let i = e.dynamicsCommands, a = i instanceof Float64Array ? i : void 0, o = Vt(i && !(i instanceof Float64Array) ? i : void 0, t), s = a ? Ht(a, t) : -1, c = n[2];
841
+ function Ht(e, t, n, r) {
842
+ let i = e.dynamicsCommands, a = i instanceof Float64Array ? i : void 0, o = Ut(i && !(i instanceof Float64Array) ? i : void 0, t), s = a ? Wt(a, t) : -1, c = n[2];
834
843
  if (!r && !o && s < 0 && c === 0) return;
835
844
  let l = e.elapsedTime / 1e3, u = r?.[2] ?? 1, d = s < 0 ? o?.forceX ?? 0 : a[s + 1], f = s < 0 ? o?.forceY ?? 0 : a[s + 2], p = s < 0 ? o?.impulseX ?? 0 : a[s + 3], m = s < 0 ? o?.impulseY ?? 0 : a[s + 4], h = s < 0 ? 0 : a[s + 5], g = s < 0 ? o?.velocityX : h & 1 ? a[s + 6] : void 0, _ = s < 0 ? o?.velocityY : h & 2 ? a[s + 7] : void 0, v = c > 0 ? 1 / (1 + c * l) : 1, y = (n[0] + (r?.[0] ?? 0) * l + d * u * l + p * u) * v, b = (n[1] + (r?.[1] ?? 0) * l + f * u * l + m * u) * v;
836
845
  n[0] = g ?? y, n[1] = _ ?? b;
837
846
  }
838
- function Vt(e, t) {
847
+ function Ut(e, t) {
839
848
  if (!e) return;
840
849
  let n = 0, r = e.length - 1;
841
850
  for (; n <= r;) {
@@ -844,7 +853,7 @@ function Vt(e, t) {
844
853
  a.entityId < t ? n = i + 1 : r = i - 1;
845
854
  }
846
855
  }
847
- function Ht(e, t) {
856
+ function Wt(e, t) {
848
857
  let n = 0, r = e.length / 8 - 1;
849
858
  for (; n <= r;) {
850
859
  let i = n + r >>> 1, a = i * 8, o = e[a + 0];
@@ -853,7 +862,7 @@ function Ht(e, t) {
853
862
  }
854
863
  return -1;
855
864
  }
856
- function Ut(e, t) {
865
+ function Gt(e, t) {
857
866
  if (e) {
858
867
  if (!(e instanceof Float64Array)) {
859
868
  for (let { entityId: n, ...r } of e) t(n, r);
@@ -872,7 +881,7 @@ function Ut(e, t) {
872
881
  }
873
882
  }
874
883
  }
875
- function Wt() {
884
+ function Kt() {
876
885
  return {
877
886
  forceX: 0,
878
887
  forceY: 0,
@@ -880,18 +889,18 @@ function Wt() {
880
889
  impulseY: 0
881
890
  };
882
891
  }
883
- function Gt(e, t, n) {
892
+ function qt(e, t, n) {
884
893
  if (!Number.isFinite(e) || !Number.isFinite(t)) throw Error(`${n} must contain finite numbers`);
885
894
  }
886
- function Kt(e) {
895
+ function Jt(e) {
887
896
  if (e.velocityX !== void 0 && !Number.isFinite(e.velocityX) || e.velocityY !== void 0 && !Number.isFinite(e.velocityY)) throw Error("Velocity assignment must contain finite numbers");
888
897
  }
889
898
  //#endregion
890
899
  //#region src/systems/collision.ts
891
- var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
900
+ var Yt = 1e-4, Xt = 24, Zt = "collidable", Z = [], Qt = 2 ** 26, $t = {
892
901
  fraction: 1,
893
- blocking: Q
894
- }, Qt = class {
902
+ blocking: Z
903
+ }, en = class {
895
904
  buckets = [];
896
905
  hasBounciness = !1;
897
906
  resolved = /* @__PURE__ */ new Set();
@@ -903,17 +912,17 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
903
912
  let c = s[1];
904
913
  if (c === 0) continue;
905
914
  let l = L(s), u = o[2], d = o[3];
906
- if (U(l, u, d)) continue;
907
- let f = o[4], p = W(l, u, d, f), m = G(l, u, d, f);
915
+ if (W(l, u, d)) continue;
916
+ let f = o[4], p = nt(l, u, d, f), m = rt(l, u, d, f);
908
917
  e.bounciness && (this.hasBounciness = !0);
909
- let h = e.velocity, g = e.dynamics, _ = Vt(a, n.entityId), v = i ? Ht(i, n.entityId) : -1, y = g?.[2] ?? 1, b = v < 0 ? _?.forceX ?? 0 : i[v + 1], x = v < 0 ? _?.forceY ?? 0 : i[v + 2], S = v < 0 ? _?.impulseX ?? 0 : i[v + 3], C = v < 0 ? _?.impulseY ?? 0 : i[v + 4], w = v < 0 ? 0 : i[v + 5], T = v < 0 ? _?.velocityX : w & 1 ? i[v + 6] : void 0, E = v < 0 ? _?.velocityY : w & 2 ? i[v + 7] : void 0, D = h?.[0] ?? 0, O = h?.[1] ?? 0, k = D + (g?.[0] ?? 0) * t + b * y * t + S * y, A = O + (g?.[1] ?? 0) * t + x * y * t + C * y, j = T ?? k, M = E ?? A, N = Math.max(Math.abs(D), Math.abs(j)) * t, ee = Math.max(Math.abs(O), Math.abs(M)) * t, P = o[0], F = o[1], I = r.get(c);
918
+ let h = e.velocity, g = e.dynamics, _ = Ut(a, n.entityId), v = i ? Wt(i, n.entityId) : -1, y = g?.[2] ?? 1, b = v < 0 ? _?.forceX ?? 0 : i[v + 1], x = v < 0 ? _?.forceY ?? 0 : i[v + 2], S = v < 0 ? _?.impulseX ?? 0 : i[v + 3], C = v < 0 ? _?.impulseY ?? 0 : i[v + 4], w = v < 0 ? 0 : i[v + 5], T = v < 0 ? _?.velocityX : w & 1 ? i[v + 6] : void 0, E = v < 0 ? _?.velocityY : w & 2 ? i[v + 7] : void 0, D = h?.[0] ?? 0, O = h?.[1] ?? 0, k = D + (g?.[0] ?? 0) * t + b * y * t + S * y, A = O + (g?.[1] ?? 0) * t + x * y * t + C * y, j = T ?? k, M = E ?? A, N = Math.max(Math.abs(D), Math.abs(j)) * t, P = Math.max(Math.abs(O), Math.abs(M)) * t, ee = o[0], F = o[1], I = r.get(c);
910
919
  I || (I = {
911
920
  entries: [],
912
921
  bounds: []
913
922
  }, r.set(c, I)), I.entries.push({
914
923
  entityId: n.entityId,
915
924
  components: e
916
- }), I.bounds.push(P - p - N, F - m - ee, P + p + N, F + m + ee);
925
+ }), I.bounds.push(ee - p - N, F - m - P, ee + p + N, F + m + P);
917
926
  }
918
927
  for (let [e, { entries: t, bounds: n }] of r) {
919
928
  let r = new s(t.length);
@@ -926,17 +935,17 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
926
935
  }
927
936
  }
928
937
  claimContact(e, t) {
929
- let n = e < t ? e * Xt + t : t * Xt + e;
938
+ let n = e < t ? e * Qt + t : t * Qt + e;
930
939
  return !this.resolved.has(n) && (this.resolved.add(n), !0);
931
940
  }
932
941
  forEachOverlapping(e, t, n = 0, r = 0) {
933
- let i = tn(e);
942
+ let i = Q(e);
934
943
  if (!i) return;
935
944
  let { x: a, y: o, halfWidth: s, halfHeight: c } = i;
936
945
  if (i.ccd && (n !== 0 || r !== 0)) {
937
946
  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;
938
947
  this.forEachCandidate(i, u, d, f, p, (a) => {
939
- nn(i, e, l, n, r, a) && t(a);
948
+ rn(i, e, l, n, r, a) && t(a);
940
949
  });
941
950
  return;
942
951
  }
@@ -945,7 +954,7 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
945
954
  });
946
955
  }
947
956
  contactPoint(e, t, n, r) {
948
- let i = e.components.transform, a = i[0], o = i[1], s = Math.sqrt(n * n + r * r), c = tn(e);
957
+ let i = e.components.transform, a = i[0], o = i[1], s = Math.sqrt(n * n + r * r), c = Q(e);
949
958
  if (!c || s === 0) return {
950
959
  x: a,
951
960
  y: o
@@ -958,33 +967,33 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
958
967
  };
959
968
  }
960
969
  contactNormal(e, t, n, r, i) {
961
- let a = tn(e);
970
+ let a = Q(e);
962
971
  if (!a) return !1;
963
972
  let o = n === 0 && r === 0 ? {
964
973
  x: a.x,
965
974
  y: a.y
966
975
  } : this.contactPoint(e, t, n, r);
967
- return $t(a, o.x, o.y, t, i);
976
+ return tn(a, o.x, o.y, t, i);
968
977
  }
969
978
  sweep(e, t, n) {
970
- let r = Math.sqrt(t * t + n * n), i = tn(e);
979
+ let r = Math.sqrt(t * t + n * n), i = Q(e);
971
980
  if (!i || r === 0) return {
972
981
  fraction: 1,
973
- blocking: Q
982
+ blocking: Z
974
983
  };
975
984
  if (i.ccd) return this.sweepContinuous(i, t, n, r);
976
985
  let a = this.gatherCandidates(i, t, n);
977
986
  return a.length === 0 ? {
978
987
  fraction: 1,
979
- blocking: Q
988
+ blocking: Z
980
989
  } : this.refine(i, a, t, n, r);
981
990
  }
982
991
  resolveMove(e, t, n, r) {
983
- let i = Math.sqrt(t * t + n * n), a = tn(e);
992
+ let i = Math.sqrt(t * t + n * n), a = Q(e);
984
993
  if (!a || i === 0) return {
985
994
  moveX: t,
986
995
  moveY: n,
987
- blocking: Q
996
+ blocking: Z
988
997
  };
989
998
  if (a.ccd) {
990
999
  let e = this.sweepContinuous(a, t, n, i);
@@ -998,20 +1007,20 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
998
1007
  if (o.length === 0) return {
999
1008
  moveX: t,
1000
1009
  moveY: n,
1001
- blocking: Q
1010
+ blocking: Z
1002
1011
  };
1003
1012
  if (r && t !== 0 && n !== 0) {
1004
1013
  let e = this.gatherCandidates(a, t, 0), r = this.gatherCandidates(a, 0, n);
1005
1014
  if (e.length === 0 && r.length === 0) return Math.abs(t) >= Math.abs(n) ? {
1006
1015
  moveX: t,
1007
1016
  moveY: 0,
1008
- blocking: Q
1017
+ blocking: Z
1009
1018
  } : {
1010
1019
  moveX: 0,
1011
1020
  moveY: n,
1012
- blocking: Q
1021
+ blocking: Z
1013
1022
  };
1014
- let i = e.length === 0 ? Zt : this.refine(a, e, t, 0, Math.abs(t)), o = r.length === 0 ? Zt : this.refine(a, r, 0, n, Math.abs(n)), s = t * i.fraction, c = n * o.fraction;
1023
+ let i = e.length === 0 ? $t : this.refine(a, e, t, 0, Math.abs(t)), o = r.length === 0 ? $t : this.refine(a, r, 0, n, Math.abs(n)), s = t * i.fraction, c = n * o.fraction;
1015
1024
  if (s !== 0 && c !== 0) {
1016
1025
  let e = this.gatherCandidates(a, s, c);
1017
1026
  if (e.length > 0) {
@@ -1026,7 +1035,7 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
1026
1035
  return {
1027
1036
  moveX: s,
1028
1037
  moveY: c,
1029
- blocking: en(i.blocking, o.blocking)
1038
+ blocking: nn(i.blocking, o.blocking)
1030
1039
  };
1031
1040
  }
1032
1041
  let s = this.refine(a, o, t, n, i);
@@ -1045,15 +1054,15 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
1045
1054
  }), l;
1046
1055
  }
1047
1056
  refine(e, t, n, r, i) {
1048
- let { x: a, y: o } = e, s = 0, c = 1, l = qt / i;
1049
- for (let i = 0; i < Jt && c - s > l; i++) {
1057
+ let { x: a, y: o } = e, s = 0, c = 1, l = Yt / i;
1058
+ for (let i = 0; i < Xt && c - s > l; i++) {
1050
1059
  let i = (s + c) / 2;
1051
1060
  this.blockedAt(e, t, n, r, i) ? c = i : s = i;
1052
1061
  }
1053
1062
  let u = [], d = a + n * c, f = o + r * c;
1054
1063
  for (let n of t) $(e, d, f, n) && u.push(n);
1055
1064
  return {
1056
- fraction: s * i > qt ? s : 0,
1065
+ fraction: s * i > Yt ? s : 0,
1057
1066
  blocking: u
1058
1067
  };
1059
1068
  }
@@ -1061,22 +1070,22 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
1061
1070
  if (e.sensor) return [];
1062
1071
  let { x: r, y: i, halfWidth: a, halfHeight: o } = e, s = r + t, c = i + n, l = [];
1063
1072
  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) => {
1064
- R(a.components.body) || $(e, r, i, a) || nn(e, r, i, t, n, a) && l.push(a);
1073
+ R(a.components.body) || $(e, r, i, a) || rn(e, r, i, t, n, a) && l.push(a);
1065
1074
  }), l;
1066
1075
  }
1067
1076
  sweepContinuous(e, t, n, r) {
1068
1077
  let i = this.gatherContinuousCandidates(e, t, n);
1069
1078
  if (i.length === 0) return {
1070
1079
  fraction: 1,
1071
- blocking: Q
1080
+ blocking: Z
1072
1081
  };
1073
- let a = 1, o = [], s = qt / r;
1082
+ let a = 1, o = [], s = Yt / r;
1074
1083
  for (let c of i) {
1075
1084
  let i = this.entryFraction(e, c, t, n, r);
1076
1085
  i < a - s ? (a = i, o = [c]) : i <= a + s && o.push(c);
1077
1086
  }
1078
1087
  return {
1079
- fraction: a * r > qt ? a : 0,
1088
+ fraction: a * r > Yt ? a : 0,
1080
1089
  blocking: o
1081
1090
  };
1082
1091
  }
@@ -1084,12 +1093,12 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
1084
1093
  let a;
1085
1094
  if (this.blockedAtOne(e, t, n, r, 1)) a = 1;
1086
1095
  else {
1087
- let o = t.components.transform, s = o[0] - e.x, c = o[1] - e.y, l = rn((s * n + c * r) / (i * i));
1096
+ let o = t.components.transform, s = o[0] - e.x, c = o[1] - e.y, l = an((s * n + c * r) / (i * i));
1088
1097
  if (!this.blockedAtOne(e, t, n, r, l)) return l;
1089
1098
  a = l;
1090
1099
  }
1091
- let o = 0, s = qt / i;
1092
- for (let i = 0; i < Jt && a - o > s; i++) {
1100
+ let o = 0, s = Yt / i;
1101
+ for (let i = 0; i < Xt && a - o > s; i++) {
1093
1102
  let i = (o + a) / 2;
1094
1103
  this.blockedAtOne(e, t, n, r, i) ? a = i : o = i;
1095
1104
  }
@@ -1110,24 +1119,24 @@ var qt = 1e-4, Jt = 24, Yt = "collidable", Q = [], Xt = 2 ** 26, Zt = {
1110
1119
  }
1111
1120
  }
1112
1121
  };
1113
- function $t(e, t, n, r, i) {
1122
+ function tn(e, t, n, r, i) {
1114
1123
  let a = r.components.transform, o = L(r.components.body), s = a[0], c = a[1], l = a[2], u = a[3], d = a[4];
1115
- return e.shape === 4 || o === 4 ? Et(e.shape, e.polygon, t, n, e.width, e.height, e.angle, o, r.components.polygon, s, c, l, u, d, i) : rt(e.shape, t, n, e.width, e.height, e.angle, o, s, c, l, u, d, i);
1124
+ return e.shape === 4 || o === 4 ? Ot(e.shape, e.polygon, t, n, e.width, e.height, e.angle, o, r.components.polygon, s, c, l, u, d, i) : ot(e.shape, t, n, e.width, e.height, e.angle, o, s, c, l, u, d, i);
1116
1125
  }
1117
- function en(e, t) {
1126
+ function nn(e, t) {
1118
1127
  if (e.length === 0) return t;
1119
1128
  if (t.length === 0) return e;
1120
1129
  let n = [...e];
1121
1130
  for (let e of t) n.some((t) => t.entityId === e.entityId) || n.push(e);
1122
1131
  return n;
1123
1132
  }
1124
- function tn(e) {
1133
+ function Q(e) {
1125
1134
  let t = e.components.body;
1126
1135
  if (!t) return;
1127
1136
  let n = t[2];
1128
1137
  if (n === 0) return;
1129
1138
  let r = e.components.transform, i = L(t), a = r[2], o = r[3];
1130
- if (U(i, a, o)) return;
1139
+ if (W(i, a, o)) return;
1131
1140
  let s = r[4], c = e.components.polygon;
1132
1141
  if (i !== 4 || c) return {
1133
1142
  entityId: e.entityId,
@@ -1138,36 +1147,36 @@ function tn(e) {
1138
1147
  width: a,
1139
1148
  height: o,
1140
1149
  angle: s,
1141
- halfWidth: W(i, a, o, s),
1142
- halfHeight: G(i, a, o, s),
1150
+ halfWidth: nt(i, a, o, s),
1151
+ halfHeight: rt(i, a, o, s),
1143
1152
  category: t[1],
1144
1153
  mask: n,
1145
1154
  sensor: R(t),
1146
1155
  ccd: xe(t)
1147
1156
  };
1148
1157
  }
1149
- function nn(e, t, n, r, i, a) {
1158
+ function rn(e, t, n, r, i, a) {
1150
1159
  let o = t + r, s = n + i, c = a.components.transform, l = L(a.components.body), u = c[0], d = c[1], f = c[2], p = c[3], m = c[4];
1151
1160
  if (e.shape === 1 || e.shape === 4) {
1152
1161
  let c = Math.cos(e.angle), h = Math.sin(e.angle), g = r * c + i * h, _ = -r * h + i * c;
1153
- return an(1, void 0, (t + o) / 2, (n + s) / 2, e.width + Math.abs(g), e.height + Math.abs(_), e.angle, l, a.components.polygon, u, d, f, p, m);
1162
+ return on(1, void 0, (t + o) / 2, (n + s) / 2, e.width + Math.abs(g), e.height + Math.abs(_), e.angle, l, a.components.polygon, u, d, f, p, m);
1154
1163
  }
1155
- let h = H(e.shape, e.width, e.height), g = Math.sqrt(r * r + i * i), _ = g > 0 ? Math.atan2(i, r) : e.angle;
1156
- return an(3, void 0, (t + o) / 2, (n + s) / 2, g + h * 2, h * 2, _, l, a.components.polygon, u, d, f, p, m) ? !0 : an(e.shape, e.polygon, o, s, e.width, e.height, e.angle, l, a.components.polygon, u, d, f, p, m);
1164
+ let h = U(e.shape, e.width, e.height), g = Math.sqrt(r * r + i * i), _ = g > 0 ? Math.atan2(i, r) : e.angle;
1165
+ return on(3, void 0, (t + o) / 2, (n + s) / 2, g + h * 2, h * 2, _, l, a.components.polygon, u, d, f, p, m) ? !0 : on(e.shape, e.polygon, o, s, e.width, e.height, e.angle, l, a.components.polygon, u, d, f, p, m);
1157
1166
  }
1158
- function rn(e) {
1167
+ function an(e) {
1159
1168
  return e < 0 ? 0 : e > 1 ? 1 : e;
1160
1169
  }
1161
1170
  function $(e, t, n, r) {
1162
1171
  let i = r.components.transform;
1163
- return an(e.shape, e.polygon, t, n, e.width, e.height, e.angle, L(r.components.body), r.components.polygon, i[0], i[1], i[2], i[3], i[4]);
1172
+ return on(e.shape, e.polygon, t, n, e.width, e.height, e.angle, L(r.components.body), r.components.polygon, i[0], i[1], i[2], i[3], i[4]);
1164
1173
  }
1165
- function an(e, t, n, r, i, a, o, s, c, l, u, d, f, p) {
1166
- return e !== 4 && s !== 4 ? nt(e, n, r, i, a, o, s, l, u, d, f, p) : Tt(e, t, n, r, i, a, o, s, c, l, u, d, f, p);
1174
+ function on(e, t, n, r, i, a, o, s, c, l, u, d, f, p) {
1175
+ return e !== 4 && s !== 4 ? it(e, n, r, i, a, o, s, l, u, d, f, p) : Dt(e, t, n, r, i, a, o, s, c, l, u, d, f, p);
1167
1176
  }
1168
1177
  //#endregion
1169
1178
  //#region src/systems/spatial-index.ts
1170
- var on = class {
1179
+ var sn = class {
1171
1180
  entries = [];
1172
1181
  index;
1173
1182
  constructor(e) {
@@ -1175,7 +1184,7 @@ var on = class {
1175
1184
  for (let n of e) {
1176
1185
  let e = n.components, r = e.transform;
1177
1186
  if (!r) continue;
1178
- let i = e.body, a = i ? L(i) : 1, o = r[2], s = r[3], c = r[4], l = r[0], u = r[1], d = W(a, o, s, c), f = G(a, o, s, c);
1187
+ let i = e.body, a = i ? L(i) : 1, o = r[2], s = r[3], c = r[4], l = r[0], u = r[1], d = nt(a, o, s, c), f = rt(a, o, s, c);
1179
1188
  this.entries.push({
1180
1189
  entityId: n.entityId,
1181
1190
  components: e
@@ -1207,14 +1216,14 @@ var on = class {
1207
1216
  let o = this.entries;
1208
1217
  return (i ? a.neighbors(e, t, n, r, (e) => i(o[e])) : a.neighbors(e, t, n, r)).map((e) => o[e]);
1209
1218
  }
1210
- }, sn = {
1219
+ }, cn = {
1211
1220
  x: 0,
1212
1221
  y: 0
1213
1222
  };
1214
- function cn(e, t, n = !1) {
1215
- (dn(e, n) || dn(t, n)) && fn(e, t) && pn(e, t, sn) && (un(e, sn.x, sn.y, n), un(t, -sn.x, -sn.y, n));
1223
+ function ln(e, t, n = !1) {
1224
+ (fn(e, n) || fn(t, n)) && pn(e, t) && mn(e, t, cn) && (dn(e, cn.x, cn.y, n), dn(t, -cn.x, -cn.y, n));
1216
1225
  }
1217
- function ln(e, t, n) {
1226
+ function un(e, t, n) {
1218
1227
  let r = e.components.bounciness, i = e.components.velocity;
1219
1228
  if (!r || !i) return;
1220
1229
  let a = i[0], o = i[1], s = a * t + o * n;
@@ -1222,9 +1231,9 @@ function ln(e, t, n) {
1222
1231
  let c = (1 + r[0]) * s;
1223
1232
  i[0] = a - c * t, i[1] = o - c * n;
1224
1233
  }
1225
- function un(e, t, n, r) {
1234
+ function dn(e, t, n, r) {
1226
1235
  if (e.components.bounciness) {
1227
- ln(e, t, n);
1236
+ un(e, t, n);
1228
1237
  return;
1229
1238
  }
1230
1239
  let i = e.components.velocity;
@@ -1232,60 +1241,60 @@ function un(e, t, n, r) {
1232
1241
  let a = i[0], o = i[1], s = a * t + o * n;
1233
1242
  s < 0 && (i[0] = a - s * t, i[1] = o - s * n);
1234
1243
  }
1235
- function dn(e, t) {
1244
+ function fn(e, t) {
1236
1245
  return e.components.velocity !== void 0 && (t || e.components.bounciness !== void 0);
1237
1246
  }
1238
- function fn(e, t) {
1239
- return !hn(e.components.body) && !hn(t.components.body);
1247
+ function pn(e, t) {
1248
+ return !gn(e.components.body) && !gn(t.components.body);
1240
1249
  }
1241
- function pn(e, t, n) {
1242
- let r = e.components.transform, i = t.components.transform, a = mn(e.components.body), o = mn(t.components.body);
1243
- return a === 4 || o === 4 ? Et(a, e.components.polygon, r[0], r[1], r[2], r[3], r[4], o, t.components.polygon, i[0], i[1], i[2], i[3], i[4], n) : rt(a, r[0], r[1], r[2], r[3], r[4], o, i[0], i[1], i[2], i[3], i[4], n);
1250
+ function mn(e, t, n) {
1251
+ let r = e.components.transform, i = t.components.transform, a = hn(e.components.body), o = hn(t.components.body);
1252
+ return a === 4 || o === 4 ? Ot(a, e.components.polygon, r[0], r[1], r[2], r[3], r[4], o, t.components.polygon, i[0], i[1], i[2], i[3], i[4], n) : ot(a, r[0], r[1], r[2], r[3], r[4], o, i[0], i[1], i[2], i[3], i[4], n);
1244
1253
  }
1245
- function mn(e) {
1254
+ function hn(e) {
1246
1255
  return e ? L(e) : 1;
1247
1256
  }
1248
- function hn(e) {
1257
+ function gn(e) {
1249
1258
  return e !== void 0 && R(e);
1250
1259
  }
1251
1260
  //#endregion
1252
1261
  //#region src/systems/physics-update.ts
1253
- function gn(e, t, n) {
1262
+ function _n(e, t, n) {
1254
1263
  if (!e.spatialMap && (!e.heap || !e.spatialMapMemory)) return;
1255
- let r = xt(e), i = X(n);
1264
+ let r = Ct(e), i = Y(n);
1256
1265
  r.update(t, i.minX, i.minY, i.maxX - i.minX, i.maxY - i.minY);
1257
1266
  }
1258
- var _n = "position-updated", vn = {
1267
+ var vn = "position-updated", yn = {
1259
1268
  x: 0,
1260
1269
  y: 0
1261
1270
  };
1262
- function yn(e = {}) {
1271
+ function bn(e = {}) {
1263
1272
  let { onCollision: t, optional: r = [], group: i, stopVelocityOnContact: a = !1 } = e, o, s, c = /* @__PURE__ */ new Map(), l = Object.assign((e, r, c, l, u) => {
1264
1273
  if (c.entity?.[n] === 1) return;
1265
1274
  if (c.body !== void 0 && Ce(c.body)) {
1266
1275
  u.entityDied(r);
1267
1276
  return;
1268
1277
  }
1269
- let d = i ? xn(c, i) : 0;
1278
+ let d = i ? Sn(c, i) : 0;
1270
1279
  if (i && e.skipGroup === d) return;
1271
1280
  let f = {
1272
1281
  entityId: r,
1273
1282
  components: c
1274
1283
  }, p = c.interpolation, m = e.elapsedTime / 1e3;
1275
- Bt(e, r, c.velocity, c.dynamics);
1284
+ Ht(e, r, c.velocity, c.dynamics);
1276
1285
  let h = c.velocity[0] * m, g = c.velocity[1] * m;
1277
- En(p, c.transform, e);
1286
+ Dn(p, c.transform, e);
1278
1287
  let _ = i ? s?.get(d) : o;
1279
1288
  if (!_) {
1280
- On(r, c.transform, h, g, u, e.reportMoves), gn(e, r, c), Dn(p, e.tick);
1289
+ kn(r, c.transform, h, g, u, e.reportMoves), _n(e, r, c), On(p, e.tick);
1281
1290
  return;
1282
1291
  }
1283
1292
  let v = c.bounciness !== void 0, y = _.resolveMove(f, h, g, !v);
1284
- if (On(r, c.transform, y.moveX, y.moveY, u, e.reportMoves), gn(e, r, c), Dn(p, e.tick), _.hasBounciness || a || t) {
1293
+ if (kn(r, c.transform, y.moveX, y.moveY, u, e.reportMoves), _n(e, r, c), On(p, e.tick), _.hasBounciness || a || t) {
1285
1294
  _.forEachOverlapping(f, (n) => {
1286
- _.claimContact(r, n.entityId) && Sn(e, _, f, n, l, u, y.moveX, y.moveY, a, t);
1295
+ _.claimContact(r, n.entityId) && Cn(e, _, f, n, l, u, y.moveX, y.moveY, a, t);
1287
1296
  }, y.moveX, y.moveY);
1288
- for (let n of y.blocking) _.claimContact(r, n.entityId) && Sn(e, _, f, n, l, u, y.moveX, y.moveY, a, t);
1297
+ for (let n of y.blocking) _.claimContact(r, n.entityId) && Cn(e, _, f, n, l, u, y.moveX, y.moveY, a, t);
1289
1298
  }
1290
1299
  }, { physics: {
1291
1300
  collision: !0,
@@ -1294,57 +1303,57 @@ function yn(e = {}) {
1294
1303
  group: i
1295
1304
  } });
1296
1305
  return l.preRun = (e, t, n) => {
1297
- bn(e, c), e.dieAtImpact = (t, n) => {
1298
- wn(e, i ? s?.get(xn(t.components, i)) : o, t, n);
1306
+ xn(e, c), e.dieAtImpact = (t, n) => {
1307
+ Tn(e, i ? s?.get(Sn(t.components, i)) : o, t, n);
1299
1308
  };
1300
1309
  let r = e.elapsedTime / 1e3, a = n.collidable ?? [];
1301
1310
  if (!i) {
1302
- o = new Qt(a, r, e.dynamicsCommands);
1311
+ o = new en(a, r, e.dynamicsCommands);
1303
1312
  return;
1304
1313
  }
1305
1314
  let l = /* @__PURE__ */ new Map();
1306
1315
  for (let t of a) {
1307
- let n = xn(t.components, i);
1316
+ let n = Sn(t.components, i);
1308
1317
  if (e.skipGroup === n) continue;
1309
1318
  let r = l.get(n);
1310
1319
  r || (r = [], l.set(n, r)), r.push(t);
1311
1320
  }
1312
1321
  s = /* @__PURE__ */ new Map();
1313
- for (let [t, n] of l) s.set(t, new Qt(n, r, e.dynamicsCommands));
1322
+ for (let [t, n] of l) s.set(t, new en(n, r, e.dynamicsCommands));
1314
1323
  }, l;
1315
1324
  }
1316
- function bn(e, t) {
1325
+ function xn(e, t) {
1317
1326
  let n = e, r = e.commandQueueId ?? 0, i = t.get(r);
1318
- i && (e.dynamicsCommands = zt(i, e.dynamicsCommands), t.delete(r));
1327
+ i && (e.dynamicsCommands = Vt(i, e.dynamicsCommands), t.delete(r));
1319
1328
  let a = () => {
1320
1329
  let e = t.get(r);
1321
1330
  return e || (e = /* @__PURE__ */ new Map(), t.set(r, e)), e;
1322
1331
  };
1323
1332
  n.queueForce = (e, t, n) => {
1324
- Lt(a(), e, t, n, 0, 0);
1333
+ zt(a(), e, t, n, 0, 0);
1325
1334
  }, n.queueImpulse = (e, t, n) => {
1326
- Lt(a(), e, 0, 0, t, n);
1335
+ zt(a(), e, 0, 0, t, n);
1327
1336
  }, n.queueVelocity = (e, t) => {
1328
- Rt(a(), e, t);
1337
+ Bt(a(), e, t);
1329
1338
  };
1330
1339
  }
1331
- function xn(e, t) {
1340
+ function Sn(e, t) {
1332
1341
  let n = e[t.component];
1333
1342
  return n ? n[t.index] : 0;
1334
1343
  }
1335
- function Sn(e, t, n, r, i, a, o, s, c, l) {
1336
- if (cn(n, r, c), !l) return;
1337
- let u = X(n.components), d = X(r.components);
1338
- vn.x = 0, vn.y = 0, t.contactNormal(n, r, o, s, vn), l(e, n, r, i, a, {
1339
- normalX: vn.x,
1340
- normalY: vn.y
1341
- }), Cn(e, n.entityId, n.components, u), Cn(e, r.entityId, r.components, d);
1342
- }
1343
- function Cn(e, t, n, r) {
1344
- let i = X(n);
1345
- (i.minX !== r.minX || i.minY !== r.minY || i.maxX !== r.maxX || i.maxY !== r.maxY) && gn(e, t, n);
1344
+ function Cn(e, t, n, r, i, a, o, s, c, l) {
1345
+ if (ln(n, r, c), !l) return;
1346
+ let u = Y(n.components), d = Y(r.components);
1347
+ yn.x = 0, yn.y = 0, t.contactNormal(n, r, o, s, yn), l(e, n, r, i, a, {
1348
+ normalX: yn.x,
1349
+ normalY: yn.y
1350
+ }), wn(e, n.entityId, n.components, u), wn(e, r.entityId, r.components, d);
1346
1351
  }
1347
1352
  function wn(e, t, n, r) {
1353
+ let i = Y(n);
1354
+ (i.minX !== r.minX || i.minY !== r.minY || i.maxX !== r.maxX || i.maxY !== r.maxY) && _n(e, t, n);
1355
+ }
1356
+ function Tn(e, t, n, r) {
1348
1357
  let i = n.components.body;
1349
1358
  if (!i || Ce(i)) return;
1350
1359
  we(i);
@@ -1364,50 +1373,50 @@ function wn(e, t, n, r) {
1364
1373
  } }, u, d);
1365
1374
  a[0] = f.x, a[1] = f.y;
1366
1375
  }
1367
- function Tn(e, t, n, r, i) {
1376
+ function En(e, t, n, r, i) {
1368
1377
  let a = e.elapsedTime / 1e3, o = n.interpolation;
1369
- Bt(e, t, n.velocity, n.dynamics), En(o, n.transform, e), On(t, n.transform, n.velocity[0] * a, n.velocity[1] * a, i, e.reportMoves), gn(e, t, n), Dn(o, e.tick);
1378
+ Ht(e, t, n.velocity, n.dynamics), Dn(o, n.transform, e), kn(t, n.transform, n.velocity[0] * a, n.velocity[1] * a, i, e.reportMoves), _n(e, t, n), On(o, e.tick);
1370
1379
  }
1371
- function En(e, t, n) {
1380
+ function Dn(e, t, n) {
1372
1381
  e && (a(e, 16, NaN), e[12] = t[0], e[13] = t[1], e[14] = e[3], e[15] = e[5], a(e, 16, i(e, 4)), a(e, 4, NaN), e[11] = n.interpolationChannel ?? 0, e[3] = n.elapsedTime, e[5] += n.elapsedTime);
1373
1382
  }
1374
- function Dn(e, t) {
1383
+ function On(e, t) {
1375
1384
  e && a(e, 4, t);
1376
1385
  }
1377
- function On(e, t, n, r, i, a) {
1378
- (n !== 0 || r !== 0) && (n !== 0 && c(t, 0, n, Infinity), r !== 0 && c(t, 1, r, Infinity), a !== !1 && i.emitSystemEvent(_n, e));
1386
+ function kn(e, t, n, r, i, a) {
1387
+ (n !== 0 || r !== 0) && (n !== 0 && c(t, 0, n, Infinity), r !== 0 && c(t, 1, r, Infinity), a !== !1 && i.emitSystemEvent(vn, e));
1379
1388
  }
1380
1389
  //#endregion
1381
1390
  //#region src/systems/interpolation-channels.ts
1382
- var kn = /* @__PURE__ */ new WeakMap();
1383
- function An(e, t) {
1384
- let n = kn.get(e);
1385
- return n || (n = [void 0], kn.set(e, n)), n.push(t), n.length - 1;
1386
- }
1391
+ var An = /* @__PURE__ */ new WeakMap();
1387
1392
  function jn(e, t) {
1388
- let n = kn.get(e);
1393
+ let n = An.get(e);
1394
+ return n || (n = [void 0], An.set(e, n)), n.push(t), n.length - 1;
1395
+ }
1396
+ function Mn(e, t) {
1397
+ let n = An.get(e);
1389
1398
  n && t > 0 && t < n.length && (n[t] = void 0);
1390
1399
  }
1391
- function Mn(e) {
1392
- let t = kn.get(e);
1400
+ function Nn(e) {
1401
+ let t = An.get(e);
1393
1402
  if (t) return t.map((e) => e ? e.committedTick : NaN);
1394
1403
  }
1395
1404
  //#endregion
1396
1405
  //#region src/systems/physics-system.ts
1397
- var Nn = 50, Pn = 1, Fn = class extends r {
1406
+ var Pn = 50, Fn = 1, In = class extends r {
1398
1407
  spatialWorld;
1399
1408
  pendingDynamicsCommands = /* @__PURE__ */ new Map();
1400
- commandQueueId = Pn++;
1409
+ commandQueueId = Fn++;
1401
1410
  tick = 0;
1402
1411
  interpolationChannel;
1403
1412
  reportMoves;
1404
1413
  skipGroup;
1405
1414
  constructor(e, t = {}) {
1406
- let n = t.updateFunction ?? Tn, r = t.optional ?? n.physics?.optional ?? [], i = t.collision ?? n.physics?.collision ?? !1, a = n === Tn || n.physics?.dynamics === !0, o = n.physics?.group, s = [];
1415
+ let n = t.updateFunction ?? En, r = t.optional ?? n.physics?.optional ?? [], i = t.collision ?? n.physics?.collision ?? !1, a = n === En || n.physics?.dynamics === !0, o = n.physics?.group, s = [];
1407
1416
  i && !r.includes("body") && s.push("body"), i && !r.includes("bounciness") && s.push("bounciness"), i && !r.includes("polygon") && s.push("polygon"), r.includes("interpolation") || s.push("interpolation"), a && !r.includes("dynamics") && s.push("dynamics"), i && s.push("entity"), o && !r.includes(o.component) && s.push(o.component);
1408
1417
  let c = s.length ? [...s, ...r] : r, l = r.includes("bounciness") ? [...r] : ["bounciness", ...r];
1409
1418
  l.includes("polygon") || l.push("polygon"), a && !l.includes("dynamics") && l.push("dynamics"), o && !l.includes(o.component) && l.push(o.component);
1410
- let u = i ? { [Yt]: {
1419
+ let u = i ? { [Zt]: {
1411
1420
  required: ["transform", "body"],
1412
1421
  optional: [
1413
1422
  "velocity",
@@ -1418,7 +1427,7 @@ var Nn = 50, Pn = 1, Fn = class extends r {
1418
1427
  } } : void 0, d = u || t.queries ? {
1419
1428
  ...u,
1420
1429
  ...t.queries
1421
- } : void 0, f = In(t.scope, t.filter);
1430
+ } : void 0, f = Ln(t.scope, t.filter);
1422
1431
  super(e, {
1423
1432
  name: t.name ?? "PhysicsSystem",
1424
1433
  deltaBetweenRuns: t.deltaBetweenRuns ?? 50,
@@ -1432,13 +1441,13 @@ var Nn = 50, Pn = 1, Fn = class extends r {
1432
1441
  getWorker: t.getWorker ?? (() => {
1433
1442
  throw Error("PhysicsSystem cannot start a worker: no getWorker was supplied");
1434
1443
  })
1435
- }), this.spatialWorld = e, this.reportMoves = t.reportMoves, this.skipGroup = t.skipGroup, this.interpolationChannel = An(e, this);
1444
+ }), this.spatialWorld = e, this.reportMoves = t.reportMoves, this.skipGroup = t.skipGroup, this.interpolationChannel = jn(e, this);
1436
1445
  }
1437
1446
  get committedTick() {
1438
1447
  return this.isCurrentlyRunning() ? this.tick - 1 : this.tick;
1439
1448
  }
1440
1449
  destroy() {
1441
- jn(this.world, this.interpolationChannel), super.destroy();
1450
+ Mn(this.world, this.interpolationChannel), super.destroy();
1442
1451
  }
1443
1452
  startInterpolation(e) {
1444
1453
  let t = this.deltaBetweenRuns;
@@ -1456,14 +1465,14 @@ var Nn = 50, Pn = 1, Fn = class extends r {
1456
1465
  }
1457
1466
  queueVelocity(e, t) {
1458
1467
  let n = typeof e == "number" ? e : e.eid;
1459
- Rt(this.pendingDynamicsCommands, n, t);
1468
+ Bt(this.pendingDynamicsCommands, n, t);
1460
1469
  }
1461
1470
  addDataToWorld(e) {
1462
- e.tick = ++this.tick, e.interpolationChannel = this.interpolationChannel, bt(this.spatialWorld, e), e.reportMoves = this.reportMoves ?? this.listenerCount("position-updated") > 0, e.skipGroup = this.skipGroup, e.commandQueueId = this.commandQueueId, e.dynamicsCommands = this.snapshotDynamicsCommands();
1471
+ e.tick = ++this.tick, e.interpolationChannel = this.interpolationChannel, St(this.spatialWorld, e), e.reportMoves = this.reportMoves ?? this.listenerCount("position-updated") > 0, e.skipGroup = this.skipGroup, e.commandQueueId = this.commandQueueId, e.dynamicsCommands = this.snapshotDynamicsCommands();
1463
1472
  }
1464
1473
  queueDynamics(e, t, n, r, i) {
1465
1474
  let a = typeof e == "number" ? e : e.eid;
1466
- Lt(this.pendingDynamicsCommands, a, t, n, r, i);
1475
+ zt(this.pendingDynamicsCommands, a, t, n, r, i);
1467
1476
  }
1468
1477
  snapshotDynamicsCommands() {
1469
1478
  if (this.pendingDynamicsCommands.size === 0) return;
@@ -1479,12 +1488,12 @@ var Nn = 50, Pn = 1, Fn = class extends r {
1479
1488
  return n;
1480
1489
  }
1481
1490
  };
1482
- function In(e, t) {
1491
+ function Ln(e, t) {
1483
1492
  return e ? t ? (n) => e(n) && t(n) : e : t;
1484
1493
  }
1485
1494
  //#endregion
1486
1495
  //#region src/systems/interpolation-update.ts
1487
- var Ln = 1.5, Rn = .5, zn = (e, t, n) => {
1496
+ var Rn = 1.5, zn = .5, Bn = (e, t, n) => {
1488
1497
  let r = n.interpolation, a = n.transform, o = i(r, 4), s = r[3], c = r[5], l = a[0], u = a[1], d = i(r, 4), f = o === d, p = e.committedTicks?.[r[11]];
1489
1498
  if (p !== void 0 && !Number.isNaN(p) && !(f && d <= p)) {
1490
1499
  let e = i(r, 16);
@@ -1508,18 +1517,18 @@ var Ln = 1.5, Rn = .5, zn = (e, t, n) => {
1508
1517
  r[7] = 0, r[0] = l, r[1] = u;
1509
1518
  return;
1510
1519
  }
1511
- let h = Math.min(Math.max(e.elapsedTime, 0), m), g = s * Ln, _ = m - h;
1512
- _ > g && (h += Math.min(_ - g, h * Rn));
1520
+ let h = Math.min(Math.max(e.elapsedTime, 0), m), g = s * Rn, _ = m - h;
1521
+ _ > g && (h += Math.min(_ - g, h * zn));
1513
1522
  let v = h / m, y = r[0], b = r[1];
1514
1523
  r[0] = y + (l - y) * v, r[1] = b + (u - b) * v, r[7] = m - h;
1515
- }, Bn = class extends r {
1524
+ }, Vn = class extends r {
1516
1525
  constructor(e, t = {}) {
1517
1526
  super(e, {
1518
1527
  name: t.name ?? "InterpolationSystem",
1519
1528
  deltaBetweenRuns: 0,
1520
1529
  firstRun: t.firstRun,
1521
1530
  required: ["transform", "interpolation"],
1522
- updateFunction: zn,
1531
+ updateFunction: Bn,
1523
1532
  forceMainThread: t.forceMainThread ?? !t.getWorker,
1524
1533
  getWorker: t.getWorker ?? (() => {
1525
1534
  throw Error("InterpolationSystem cannot start a worker: no getWorker was supplied");
@@ -1527,10 +1536,10 @@ var Ln = 1.5, Rn = .5, zn = (e, t, n) => {
1527
1536
  });
1528
1537
  }
1529
1538
  addDataToWorld(e) {
1530
- e.committedTicks = Mn(this.world);
1539
+ e.committedTicks = Nn(this.world);
1531
1540
  }
1532
1541
  };
1533
1542
  //#endregion
1534
- export { be as BODY_BLOCKS_PATH_FLAG, pe as BODY_CATEGORY_INDEX, ve as BODY_CCD_FLAG, ye as BODY_DYING_FLAG, fe as BODY_FLAGS_INDEX, me as BODY_MASK_INDEX, _e as BODY_SENSOR_FLAG, ge as BODY_SHAPE_MASK, he as BODY_SIZE, ke as BOUNCINESS_INDEX, Ae as BOUNCINESS_SIZE, Yt as COLLIDABLE_QUERY, Qt as CollisionBroadphase, le as DEFAULT_COLLIDE_CATEGORY, ue as DEFAULT_COLLIDE_MASK, Nn as DEFAULT_PHYSICS_STEP_MS, N as DYNAMICS_ACCELERATION_X_INDEX, ee as DYNAMICS_ACCELERATION_Y_INDEX, P as DYNAMICS_INVERSE_MASS_INDEX, F as DYNAMICS_SIZE, We as INTERPOLATION_CHANNEL_INDEX, Ie as INTERPOLATION_DURATION_INDEX, qe as INTERPOLATION_PREVIOUS_DURATION_INDEX, Ye as INTERPOLATION_PREVIOUS_TICK_INDEX, Je as INTERPOLATION_PREVIOUS_TOTAL_DURATION_INDEX, Ge as INTERPOLATION_PREVIOUS_X_INDEX, Ke as INTERPOLATION_PREVIOUS_Y_INDEX, Be as INTERPOLATION_REMAINING_DURATION_INDEX, Xe as INTERPOLATION_SIZE, ze as INTERPOLATION_SYNCED_DURATION_INDEX, Ue as INTERPOLATION_SYNCED_STEP_DURATION_INDEX, Fe as INTERPOLATION_SYNCED_TICK_INDEX, Ve as INTERPOLATION_TARGET_X_INDEX, He as INTERPOLATION_TARGET_Y_INDEX, Le as INTERPOLATION_TICK_INDEX, Re as INTERPOLATION_TOTAL_DURATION_INDEX, Ne as INTERPOLATION_X_INDEX, Pe as INTERPOLATION_Y_INDEX, Bn as InterpolationSystem, l as MAX_POLYGON_VERTICES, f as POLYGON_SIZE, u as POLYGON_VERTEX_COUNT_INDEX, d as POLYGON_VERTICES_INDEX, _n as POSITION_UPDATED_EVENT, St as PhysicalWorld, Fn as PhysicsSystem, oe as SHAPE_CAPSULE, ae as SHAPE_CIRCLE, se as SHAPE_POLYGON, ie as SHAPE_RECTANGLE, on as SpatialIndex, S as TRANSFORM_ANGLE_INDEX, x as TRANSFORM_HEIGHT_INDEX, C as TRANSFORM_SIZE, b as TRANSFORM_WIDTH_INDEX, v as TRANSFORM_X_INDEX, y as TRANSFORM_Y_INDEX, O as VELOCITY_DAMPING_INDEX, k as VELOCITY_SIZE, E as VELOCITY_X_INDEX, D as VELOCITY_Y_INDEX, bt as addPhysicalWorldData, Se as blocksPath, Ee as bodyDefinition, L as bodyShape, Me as bouncinessDefinition, dt as boundsHalfHeight, ut as boundsHalfWidth, de as canCollide, V as capsuleHalfLength, rt as contactNormal, yn as createPhysicsUpdate, te as dynamicsDefinition, xt as getSpatialMap, Bt as integrateDynamics, Qe as interpolationDefinition, zn as interpolationUpdate, xe as isContinuous, Ce as isDying, R as isSensor, we as markDying, ft as orientedBoxesOverlap, tt as physicsRegistry, Tn as physicsUpdate, J as pointSegmentDistanceSquared, Et as polygonContactNormal, m as polygonDefinition, Tt as polygonShapesOverlap, h as preparePolygon, mt as segmentBoxDistanceSquared, pt as segmentSegmentDistanceSquared, G as shapeHalfHeight, W as shapeHalfWidth, U as shapeIsEmpty, H as shapeRadius, nt as shapesOverlap, $e as snapEntity, et as startSpawnInterpolation, T as transformDefinition, gn as updateSpatialMap, j as velocityDefinition };
1543
+ export { be as BODY_BLOCKS_PATH_FLAG, pe as BODY_CATEGORY_INDEX, ve as BODY_CCD_FLAG, ye as BODY_DYING_FLAG, fe as BODY_FLAGS_INDEX, me as BODY_MASK_INDEX, _e as BODY_SENSOR_FLAG, ge as BODY_SHAPE_MASK, he as BODY_SIZE, ke as BOUNCINESS_INDEX, Ae as BOUNCINESS_SIZE, Zt as COLLIDABLE_QUERY, en as CollisionBroadphase, le as DEFAULT_COLLIDE_CATEGORY, ue as DEFAULT_COLLIDE_MASK, Pn as DEFAULT_PHYSICS_STEP_MS, N as DYNAMICS_ACCELERATION_X_INDEX, P as DYNAMICS_ACCELERATION_Y_INDEX, ee as DYNAMICS_INVERSE_MASS_INDEX, F as DYNAMICS_SIZE, We as INTERPOLATION_CHANNEL_INDEX, Ie as INTERPOLATION_DURATION_INDEX, qe as INTERPOLATION_PREVIOUS_DURATION_INDEX, Ye as INTERPOLATION_PREVIOUS_TICK_INDEX, Je as INTERPOLATION_PREVIOUS_TOTAL_DURATION_INDEX, Ge as INTERPOLATION_PREVIOUS_X_INDEX, Ke as INTERPOLATION_PREVIOUS_Y_INDEX, Be as INTERPOLATION_REMAINING_DURATION_INDEX, Xe as INTERPOLATION_SIZE, ze as INTERPOLATION_SYNCED_DURATION_INDEX, Ue as INTERPOLATION_SYNCED_STEP_DURATION_INDEX, Fe as INTERPOLATION_SYNCED_TICK_INDEX, Ve as INTERPOLATION_TARGET_X_INDEX, He as INTERPOLATION_TARGET_Y_INDEX, Le as INTERPOLATION_TICK_INDEX, Re as INTERPOLATION_TOTAL_DURATION_INDEX, Ne as INTERPOLATION_X_INDEX, Pe as INTERPOLATION_Y_INDEX, Vn as InterpolationSystem, l as MAX_POLYGON_VERTICES, f as POLYGON_SIZE, u as POLYGON_VERTEX_COUNT_INDEX, d as POLYGON_VERTICES_INDEX, vn as POSITION_UPDATED_EVENT, wt as PhysicalWorld, In as PhysicsSystem, oe as SHAPE_CAPSULE, ae as SHAPE_CIRCLE, se as SHAPE_POLYGON, ie as SHAPE_RECTANGLE, sn as SpatialIndex, S as TRANSFORM_ANGLE_INDEX, x as TRANSFORM_HEIGHT_INDEX, C as TRANSFORM_SIZE, b as TRANSFORM_WIDTH_INDEX, v as TRANSFORM_X_INDEX, y as TRANSFORM_Y_INDEX, O as VELOCITY_DAMPING_INDEX, k as VELOCITY_SIZE, E as VELOCITY_X_INDEX, D as VELOCITY_Y_INDEX, St as addPhysicalWorldData, Se as blocksPath, Ee as bodyDefinition, L as bodyShape, Me as bouncinessDefinition, mt as boundsHalfHeight, pt as boundsHalfWidth, de as canCollide, H as capsuleCoreAngle, V as capsuleHalfLength, ot as contactNormal, bn as createPhysicsUpdate, te as dynamicsDefinition, Ct as getSpatialMap, Ht as integrateDynamics, Qe as interpolationDefinition, Bn as interpolationUpdate, xe as isContinuous, Ce as isDying, R as isSensor, we as markDying, ht as orientedBoxesOverlap, tt as physicsRegistry, En as physicsUpdate, q as pointSegmentDistanceSquared, Ot as polygonContactNormal, m as polygonDefinition, Dt as polygonShapesOverlap, h as preparePolygon, _t as segmentBoxDistanceSquared, gt as segmentSegmentDistanceSquared, rt as shapeHalfHeight, nt as shapeHalfWidth, W as shapeIsEmpty, U as shapeRadius, it as shapesOverlap, $e as snapEntity, et as startSpawnInterpolation, T as transformDefinition, _n as updateSpatialMap, j as velocityDefinition };
1535
1544
 
1536
1545
  //# sourceMappingURL=index.js.map