@daneren2005/shared-memory-physics 1.9.0 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/index.js +84 -84
- package/dist/index.js.map +1 -1
- package/dist/world.d.ts +4 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -839,6 +839,11 @@ const clicked = world.findNearestSpatial(mouseX, mouseY, 0);
|
|
|
839
839
|
const nearby = world.searchSpatialAround(x, y, 100, 100);
|
|
840
840
|
```
|
|
841
841
|
|
|
842
|
+
The map defaults to `type: Float64Array`. Entity ids are never reused, so a `Float32` map, which only holds ids
|
|
843
|
+
below 2^24 (~16.7M), runs out after that many entities have *ever* been created. `Float64` covers the whole
|
|
844
|
+
uint32 eid range for about 1.4x the memory per entity. Pass `spatial: { type: Float32Array }` only if a world
|
|
845
|
+
will create fewer entities than that over its lifetime.
|
|
846
|
+
|
|
842
847
|
`searchSpatial`, `searchSpatialAround`, `findNearestSpatial`, and `findNearbySpatial` return live entities and
|
|
843
848
|
accept entity filters. Shape-aware axis-aligned bounds are stored: rotated rectangles and capsules occupy the
|
|
844
849
|
box around their actual outline. A direct transform/body edit outside the physics update must be followed by
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { loadFloat32 as i, storeFloat32 as a } from "@daneren2005/shared-memory-
|
|
|
3
3
|
import o from "@daneren2005/shared-memory-objects/spatial/shared-spatial-map";
|
|
4
4
|
import s from "flatbush";
|
|
5
5
|
import { addAtomicFloat32 as c } from "@daneren2005/shared-memory-objects/utils/atomic-math";
|
|
6
|
-
|
|
6
|
+
// src/constants.ts
|
|
7
7
|
var l = "position-updated", u = "collidable", d = 50, f = 1.5, p = .5, m = 0, h = 1, g = 2, _ = 3, v = 4, y = 5, b = 16, x = 0, S = 1, C = 33, w = class extends t {
|
|
8
8
|
get vertexCount() {
|
|
9
9
|
return this.block[0];
|
|
@@ -66,8 +66,7 @@ function D(e, t, n, r) {
|
|
|
66
66
|
function O(e, t, n) {
|
|
67
67
|
return (t[0] - e[0]) * (n[1] - e[1]) - (t[1] - e[1]) * (n[0] - e[0]);
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
//#region src/components/transform-component.ts
|
|
69
|
+
// src/components/transform-component.ts
|
|
71
70
|
var k = class extends t {
|
|
72
71
|
get x() {
|
|
73
72
|
return this.block[0];
|
|
@@ -186,8 +185,7 @@ var k = class extends t {
|
|
|
186
185
|
function N(e) {
|
|
187
186
|
if (!Number.isFinite(e) || e < 0) throw Error("Damping must be a finite number of at least zero");
|
|
188
187
|
}
|
|
189
|
-
|
|
190
|
-
//#region src/components/dynamics-component-constants.ts
|
|
188
|
+
// src/components/dynamics-component-constants.ts
|
|
191
189
|
var ie = 0, ae = 1, oe = 2, se = 3, ce = class extends t {
|
|
192
190
|
get accelerationX() {
|
|
193
191
|
return this.block[0];
|
|
@@ -240,8 +238,7 @@ function ue(e) {
|
|
|
240
238
|
function de(e, t) {
|
|
241
239
|
if (!Number.isFinite(e)) throw Error(`${t} must be a finite number`);
|
|
242
240
|
}
|
|
243
|
-
|
|
244
|
-
//#region src/components/body-component-constants.ts
|
|
241
|
+
// src/components/body-component-constants.ts
|
|
245
242
|
var fe = 1, pe = 2, me = 3, he = 4, ge = 1, _e = 4294967295, ve = 0, ye = 1, be = 2, xe = 3, Se = 7, Ce = 8, we = 16, Te = 32, Ee = 64, De = [
|
|
246
243
|
1,
|
|
247
244
|
2,
|
|
@@ -343,8 +340,7 @@ function Ie(e) {
|
|
|
343
340
|
if (t === 4 && e.vertices === void 0) throw Error("A polygon body requires vertices");
|
|
344
341
|
return t;
|
|
345
342
|
}
|
|
346
|
-
|
|
347
|
-
//#region src/components/bounciness-component-constants.ts
|
|
343
|
+
// src/components/bounciness-component-constants.ts
|
|
348
344
|
var Le = 0, Re = 1, ze = class extends t {
|
|
349
345
|
get bounciness() {
|
|
350
346
|
return this.block[0];
|
|
@@ -555,8 +551,7 @@ function At(e, t, n) {
|
|
|
555
551
|
for (let t = 0; t < i; t++) a(e, 8 + t * 2, n[t].x), a(e, 8 + t * 2 + 1, n[t].y);
|
|
556
552
|
e[4] = i, e[3] = 0, e[2] = r ? I.Incomplete : t;
|
|
557
553
|
}
|
|
558
|
-
|
|
559
|
-
//#region src/components/registry.ts
|
|
554
|
+
// src/components/registry.ts
|
|
560
555
|
var jt = {
|
|
561
556
|
transform: A,
|
|
562
557
|
velocity: M,
|
|
@@ -694,8 +689,7 @@ function Xt(e, t, n, r, i) {
|
|
|
694
689
|
function q(e) {
|
|
695
690
|
return e < 0 ? 0 : e > 1 ? 1 : e;
|
|
696
691
|
}
|
|
697
|
-
|
|
698
|
-
//#region src/systems/spatial-bounds.ts
|
|
692
|
+
// src/systems/spatial-bounds.ts
|
|
699
693
|
function J(e) {
|
|
700
694
|
let t = e.transform, n = e.body ? P(e.body) : 1, r = t[2], i = t[3], a = t[4], o = H(n, r, i, a), s = U(n, r, i, a), c = t[0], l = t[1];
|
|
701
695
|
return {
|
|
@@ -711,26 +705,42 @@ function Zt(e, t, n, r, i) {
|
|
|
711
705
|
function Qt(e, t) {
|
|
712
706
|
return t > e ? t - e : Math.max(1, Math.abs(e)) * 2 ** -52;
|
|
713
707
|
}
|
|
714
|
-
|
|
715
|
-
//#region src/world.ts
|
|
708
|
+
// src/world.ts
|
|
716
709
|
var $t = class extends e {
|
|
717
710
|
spatialMap;
|
|
718
711
|
spatialIds = /* @__PURE__ */ new Set();
|
|
712
|
+
pendingSpatial = /* @__PURE__ */ new Map();
|
|
719
713
|
constructor(e, t = {}) {
|
|
720
714
|
let { spatial: n, ...r } = t;
|
|
721
|
-
super(e, r), this.spatialMap = new o(this.heap,
|
|
715
|
+
super(e, r), this.spatialMap = new o(this.heap, {
|
|
716
|
+
type: Float64Array,
|
|
717
|
+
...n
|
|
718
|
+
}), this.on("entity-added", (e) => {
|
|
722
719
|
this.updateSpatialEntity(e), e.on("component-added", (t) => {
|
|
723
720
|
(t === "transform" || t === "body") && this.updateSpatialEntity(e);
|
|
724
721
|
}), e.on("component-removed", (t) => {
|
|
725
722
|
(t === "transform" || t === "body") && this.updateSpatialEntity(e);
|
|
726
723
|
});
|
|
727
724
|
}), this.on("entity-removed", (e) => {
|
|
728
|
-
this.spatialIds.delete(e.eid), this.spatialMap.remove(e.eid);
|
|
725
|
+
this.pendingSpatial.delete(e.eid), this.spatialIds.delete(e.eid), this.spatialMap.remove(e.eid);
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
load(e, t = {}) {
|
|
729
|
+
return this.pendingSpatial.clear(), super.load(e, {
|
|
730
|
+
...t,
|
|
731
|
+
onEntitiesReady: () => {
|
|
732
|
+
this.flushPendingSpatial(), t.onEntitiesReady?.();
|
|
733
|
+
}
|
|
729
734
|
});
|
|
730
735
|
}
|
|
731
736
|
updateSpatialEntity(e) {
|
|
732
737
|
let t = typeof e == "number" ? this.getEntityByEid(e) : e;
|
|
733
738
|
if (!t) return;
|
|
739
|
+
if (this.isBulkLoading) {
|
|
740
|
+
this.pendingSpatial.set(t.eid, t);
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
this.flushPendingSpatial();
|
|
734
744
|
let n = t.components, r = n.transform?.block;
|
|
735
745
|
if (!r) {
|
|
736
746
|
this.spatialIds.delete(t.eid), this.spatialMap.remove(t.eid);
|
|
@@ -742,8 +752,32 @@ var $t = class extends e {
|
|
|
742
752
|
});
|
|
743
753
|
this.spatialIds.add(t.eid), this.spatialMap.update(t.eid, i.minX, i.minY, i.maxX - i.minX, i.maxY - i.minY);
|
|
744
754
|
}
|
|
755
|
+
flushPendingSpatial() {
|
|
756
|
+
if (this.pendingSpatial.size === 0) return;
|
|
757
|
+
let e = [];
|
|
758
|
+
for (let t of this.pendingSpatial.values()) {
|
|
759
|
+
let n = t.components, r = n.transform?.block;
|
|
760
|
+
if (!r) {
|
|
761
|
+
this.spatialIds.delete(t.eid), this.spatialMap.remove(t.eid);
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
let i = J({
|
|
765
|
+
transform: r,
|
|
766
|
+
body: n.body?.block
|
|
767
|
+
});
|
|
768
|
+
this.spatialIds.add(t.eid), e.push({
|
|
769
|
+
id: t.eid,
|
|
770
|
+
x: i.minX,
|
|
771
|
+
y: i.minY,
|
|
772
|
+
width: i.maxX - i.minX,
|
|
773
|
+
height: i.maxY - i.minY
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
this.pendingSpatial.clear(), this.spatialMap.bulkInsert(e);
|
|
777
|
+
}
|
|
745
778
|
searchSpatial(e, t, n, r, i) {
|
|
746
779
|
if (n < e || r < t) return [];
|
|
780
|
+
this.flushPendingSpatial();
|
|
747
781
|
let a = [], o = Number.isFinite(e) && Number.isFinite(t) && Number.isFinite(n) && Number.isFinite(r) ? this.spatialMap.search(e, t, Qt(e, n), Qt(t, r)) : this.spatialIds;
|
|
748
782
|
for (let s of o) {
|
|
749
783
|
let o = this.getEntityByEid(s);
|
|
@@ -763,7 +797,7 @@ var $t = class extends e {
|
|
|
763
797
|
return this.findNearbySpatial(e, t, 1, n, r)[0];
|
|
764
798
|
}
|
|
765
799
|
findNearbySpatial(e, t, n, r = Infinity, i) {
|
|
766
|
-
return this.spatialMap.neighbors(e, t, n, r, (e) => {
|
|
800
|
+
return this.flushPendingSpatial(), this.spatialMap.neighbors(e, t, n, r, (e) => {
|
|
767
801
|
let t = this.getEntityByEid(e);
|
|
768
802
|
return !!t && (!i || i(t));
|
|
769
803
|
}).flatMap((e) => {
|
|
@@ -867,8 +901,7 @@ function pn(e, t, n, r, i, a) {
|
|
|
867
901
|
function mn(e) {
|
|
868
902
|
return e === 2 || e === 3;
|
|
869
903
|
}
|
|
870
|
-
|
|
871
|
-
//#region src/actions/dynamics-commands.ts
|
|
904
|
+
// src/actions/dynamics-commands.ts
|
|
872
905
|
function hn() {
|
|
873
906
|
return {
|
|
874
907
|
forceX: 0,
|
|
@@ -877,8 +910,7 @@ function hn() {
|
|
|
877
910
|
impulseY: 0
|
|
878
911
|
};
|
|
879
912
|
}
|
|
880
|
-
|
|
881
|
-
//#region src/actions/find-dynamics-command.ts
|
|
913
|
+
// src/actions/find-dynamics-command.ts
|
|
882
914
|
function gn(e, t) {
|
|
883
915
|
if (!e) return;
|
|
884
916
|
let n = 0, r = e.length - 1;
|
|
@@ -888,8 +920,7 @@ function gn(e, t) {
|
|
|
888
920
|
a.entityId < t ? n = i + 1 : r = i - 1;
|
|
889
921
|
}
|
|
890
922
|
}
|
|
891
|
-
|
|
892
|
-
//#region src/actions/find-dynamics-command-offset.ts
|
|
923
|
+
// src/actions/find-dynamics-command-offset.ts
|
|
893
924
|
function _n(e, t) {
|
|
894
925
|
let n = 0, r = e.length / 8 - 1;
|
|
895
926
|
for (; n <= r;) {
|
|
@@ -899,8 +930,7 @@ function _n(e, t) {
|
|
|
899
930
|
}
|
|
900
931
|
return -1;
|
|
901
932
|
}
|
|
902
|
-
|
|
903
|
-
//#region src/systems/collision.ts
|
|
933
|
+
// src/systems/collision.ts
|
|
904
934
|
var vn = 1e-4, yn = 24, X = [], bn = 2 ** 26, xn = {
|
|
905
935
|
fraction: 1,
|
|
906
936
|
blocking: X
|
|
@@ -951,9 +981,7 @@ var vn = 1e-4, yn = 24, X = [], bn = 2 ** 26, xn = {
|
|
|
951
981
|
this.forEachCandidate(i, u, d, f, p, (a) => {
|
|
952
982
|
En(i, e, l, n, r, a) && t(a);
|
|
953
983
|
});
|
|
954
|
-
|
|
955
|
-
}
|
|
956
|
-
this.forEachCandidate(i, a - s, o - c, a + s, o + c, (e) => {
|
|
984
|
+
} else this.forEachCandidate(i, a - s, o - c, a + s, o + c, (e) => {
|
|
957
985
|
Z(i, a, o, e) && t(e);
|
|
958
986
|
});
|
|
959
987
|
}
|
|
@@ -1178,8 +1206,7 @@ function Z(e, t, n, r) {
|
|
|
1178
1206
|
function On(e, t, n, r, i, a, o, s, c, l, u, d, f, p) {
|
|
1179
1207
|
return e !== 4 && s !== 4 ? Ft(e, n, r, i, a, o, s, l, u, d, f, p) : nn(e, t, n, r, i, a, o, s, c, l, u, d, f, p);
|
|
1180
1208
|
}
|
|
1181
|
-
|
|
1182
|
-
//#region src/systems/spatial-index.ts
|
|
1209
|
+
// src/systems/spatial-index.ts
|
|
1183
1210
|
var kn = class {
|
|
1184
1211
|
entries = [];
|
|
1185
1212
|
index;
|
|
@@ -1221,22 +1248,19 @@ var kn = class {
|
|
|
1221
1248
|
return (i ? a.neighbors(e, t, n, r, (e) => i(o[e])) : a.neighbors(e, t, n, r)).map((e) => o[e]);
|
|
1222
1249
|
}
|
|
1223
1250
|
};
|
|
1224
|
-
|
|
1225
|
-
//#region src/actions/get-spatial-map.ts
|
|
1251
|
+
// src/actions/get-spatial-map.ts
|
|
1226
1252
|
function An(e) {
|
|
1227
1253
|
if (e.spatialMap) return e.spatialMap;
|
|
1228
1254
|
if (!e.heap || !e.spatialMapMemory) throw Error("Spatial system world is missing its shared MemoryHeap or spatial map");
|
|
1229
1255
|
return e.spatialMap = new o(e.heap, e.spatialMapMemory), e.spatialMap;
|
|
1230
1256
|
}
|
|
1231
|
-
|
|
1232
|
-
//#region src/actions/update-spatial-map.ts
|
|
1257
|
+
// src/actions/update-spatial-map.ts
|
|
1233
1258
|
function Q(e, t, n) {
|
|
1234
1259
|
if (!e.spatialMap && (!e.heap || !e.spatialMapMemory)) return;
|
|
1235
1260
|
let r = An(e), i = J(n);
|
|
1236
1261
|
r.update(t, i.minX, i.minY, i.maxX - i.minX, i.maxY - i.minY);
|
|
1237
1262
|
}
|
|
1238
|
-
|
|
1239
|
-
//#region src/actions/set-entity-position.ts
|
|
1263
|
+
// src/actions/set-entity-position.ts
|
|
1240
1264
|
function jn(e, t, n) {
|
|
1241
1265
|
let r = t.components.transform;
|
|
1242
1266
|
if (!(r instanceof Float32Array)) return;
|
|
@@ -1247,35 +1271,30 @@ function jn(e, t, n) {
|
|
|
1247
1271
|
...i instanceof Uint32Array ? { body: i } : {}
|
|
1248
1272
|
});
|
|
1249
1273
|
}
|
|
1250
|
-
|
|
1251
|
-
//#region src/actions/add-physical-world-data.ts
|
|
1274
|
+
// src/actions/add-physical-world-data.ts
|
|
1252
1275
|
function Mn(e, t) {
|
|
1253
1276
|
t.spatialMapMemory = e.spatialMap.getSharedMemory();
|
|
1254
1277
|
}
|
|
1255
|
-
|
|
1256
|
-
//#region src/actions/snap-entity.ts
|
|
1278
|
+
// src/actions/snap-entity.ts
|
|
1257
1279
|
function Nn(e) {
|
|
1258
1280
|
let { transform: t, interpolation: n } = e.components;
|
|
1259
1281
|
t && n && (n.targetX = n.x = t.x, n.targetY = n.y = t.y, n.previousX = t.x, n.previousY = t.y, n.remainingDuration = 0, n.syncedStepDuration = 0, n.syncedDuration = n.totalDuration);
|
|
1260
1282
|
}
|
|
1261
|
-
|
|
1262
|
-
//#region src/actions/start-spawn-interpolation.ts
|
|
1283
|
+
// src/actions/start-spawn-interpolation.ts
|
|
1263
1284
|
function Pn(e, t) {
|
|
1264
1285
|
let { transform: n, velocity: r, interpolation: i } = e.components;
|
|
1265
1286
|
if (!n || !r || !i) return;
|
|
1266
1287
|
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;
|
|
1267
1288
|
n.x = s + l, n.y = c + u, i.x = s, i.y = c, i.duration = t.stepMs * a, i.syncedTick = t.tick, i.totalDuration += i.duration, i.syncedDuration = i.totalDuration, i.remainingDuration = i.duration, i.targetX = n.x, i.targetY = n.y, i.syncedStepDuration = i.duration, i.tick = t.tick;
|
|
1268
1289
|
}
|
|
1269
|
-
|
|
1270
|
-
//#region src/actions/integrate-dynamics.ts
|
|
1290
|
+
// src/actions/integrate-dynamics.ts
|
|
1271
1291
|
function Fn(e, t, n, r) {
|
|
1272
1292
|
let i = e.dynamicsCommands, a = i instanceof Float64Array ? i : void 0, o = gn(i && !(i instanceof Float64Array) ? i : void 0, t), s = a ? _n(a, t) : -1, c = n[2];
|
|
1273
1293
|
if (!r && !o && s < 0 && c === 0) return;
|
|
1274
1294
|
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;
|
|
1275
1295
|
n[0] = g ?? y, n[1] = _ ?? b;
|
|
1276
1296
|
}
|
|
1277
|
-
|
|
1278
|
-
//#region src/systems/bounce.ts
|
|
1297
|
+
// src/systems/bounce.ts
|
|
1279
1298
|
var In = {
|
|
1280
1299
|
x: 0,
|
|
1281
1300
|
y: 0
|
|
@@ -1317,8 +1336,7 @@ function Un(e) {
|
|
|
1317
1336
|
function Wn(e) {
|
|
1318
1337
|
return e !== void 0 && F(e);
|
|
1319
1338
|
}
|
|
1320
|
-
|
|
1321
|
-
//#region src/actions/combine-dynamics-commands.ts
|
|
1339
|
+
// src/actions/combine-dynamics-commands.ts
|
|
1322
1340
|
function Gn(e, t) {
|
|
1323
1341
|
if (e.size === 0) return t;
|
|
1324
1342
|
let n = /* @__PURE__ */ new Map();
|
|
@@ -1340,11 +1358,7 @@ function Gn(e, t) {
|
|
|
1340
1358
|
}
|
|
1341
1359
|
function Kn(e, t) {
|
|
1342
1360
|
if (e) {
|
|
1343
|
-
if (
|
|
1344
|
-
for (let { entityId: n, ...r } of e) t(n, r);
|
|
1345
|
-
return;
|
|
1346
|
-
}
|
|
1347
|
-
for (let n = 0; n < e.length; n += 8) {
|
|
1361
|
+
if (e instanceof Float64Array) for (let n = 0; n < e.length; n += 8) {
|
|
1348
1362
|
let r = e[n + 5];
|
|
1349
1363
|
t(e[n + 0], {
|
|
1350
1364
|
forceX: e[n + 1],
|
|
@@ -1355,10 +1369,10 @@ function Kn(e, t) {
|
|
|
1355
1369
|
velocityY: r & 2 ? e[n + 7] : void 0
|
|
1356
1370
|
});
|
|
1357
1371
|
}
|
|
1372
|
+
else for (let { entityId: n, ...r } of e) t(n, r);
|
|
1358
1373
|
}
|
|
1359
1374
|
}
|
|
1360
|
-
|
|
1361
|
-
//#region src/actions/queue-dynamics-vector.ts
|
|
1375
|
+
// src/actions/queue-dynamics-vector.ts
|
|
1362
1376
|
function qn(e, t, n, r, i, a) {
|
|
1363
1377
|
if (Jn(n, r, "Force"), Jn(i, a, "Impulse"), n === 0 && r === 0 && i === 0 && a === 0) return;
|
|
1364
1378
|
let o = e.get(t) ?? hn(), s = {
|
|
@@ -1373,8 +1387,7 @@ function qn(e, t, n, r, i, a) {
|
|
|
1373
1387
|
function Jn(e, t, n) {
|
|
1374
1388
|
if (!Number.isFinite(e) || !Number.isFinite(t)) throw Error(`${n} must contain finite numbers`);
|
|
1375
1389
|
}
|
|
1376
|
-
|
|
1377
|
-
//#region src/actions/queue-velocity-assignment.ts
|
|
1390
|
+
// src/actions/queue-velocity-assignment.ts
|
|
1378
1391
|
function Yn(e, t, n) {
|
|
1379
1392
|
Xn(n), (n.velocityX !== void 0 || n.velocityY !== void 0) && e.set(t, {
|
|
1380
1393
|
...e.get(t) ?? hn(),
|
|
@@ -1384,8 +1397,7 @@ function Yn(e, t, n) {
|
|
|
1384
1397
|
function Xn(e) {
|
|
1385
1398
|
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");
|
|
1386
1399
|
}
|
|
1387
|
-
|
|
1388
|
-
//#region src/systems/physics-update.ts
|
|
1400
|
+
// src/systems/physics-update.ts
|
|
1389
1401
|
var Zn = {
|
|
1390
1402
|
x: 0,
|
|
1391
1403
|
y: 0
|
|
@@ -1508,8 +1520,7 @@ function or(e, t) {
|
|
|
1508
1520
|
function sr(e, t, n, r, i, a) {
|
|
1509
1521
|
(n !== 0 || r !== 0) && (n !== 0 && c(t, 0, n, Infinity), r !== 0 && c(t, 1, r, Infinity), a !== !1 && i.emitSystemEvent(l, e));
|
|
1510
1522
|
}
|
|
1511
|
-
|
|
1512
|
-
//#region src/systems/interpolation-channels.ts
|
|
1523
|
+
// src/systems/interpolation-channels.ts
|
|
1513
1524
|
var cr = /* @__PURE__ */ new WeakMap();
|
|
1514
1525
|
function lr(e, t) {
|
|
1515
1526
|
let n = cr.get(e);
|
|
@@ -1523,8 +1534,7 @@ function dr(e) {
|
|
|
1523
1534
|
let t = cr.get(e);
|
|
1524
1535
|
if (t) return t.map((e) => e ? e.committedTick : NaN);
|
|
1525
1536
|
}
|
|
1526
|
-
|
|
1527
|
-
//#region src/systems/physics-system.ts
|
|
1537
|
+
// src/systems/physics-system.ts
|
|
1528
1538
|
var fr = 1, pr = class extends r {
|
|
1529
1539
|
spatialWorld;
|
|
1530
1540
|
pendingDynamicsCommands = /* @__PURE__ */ new Map();
|
|
@@ -1613,8 +1623,7 @@ var fr = 1, pr = class extends r {
|
|
|
1613
1623
|
function mr(e, t) {
|
|
1614
1624
|
return e ? t ? (n) => e(n) && t(n) : e : t;
|
|
1615
1625
|
}
|
|
1616
|
-
|
|
1617
|
-
//#region src/pathfinding/nav-grid.ts
|
|
1626
|
+
// src/pathfinding/nav-grid.ts
|
|
1618
1627
|
var hr = 0, gr = class e {
|
|
1619
1628
|
tilesWide;
|
|
1620
1629
|
tilesHigh;
|
|
@@ -1775,8 +1784,7 @@ var hr = 0, gr = class e {
|
|
|
1775
1784
|
t.set(this.ids), n.set(this.primary), r.set(this.secondary), this.ids = t, this.primary = n, this.secondary = r;
|
|
1776
1785
|
}
|
|
1777
1786
|
};
|
|
1778
|
-
|
|
1779
|
-
//#region src/pathfinding/line-of-sight.ts
|
|
1787
|
+
// src/pathfinding/line-of-sight.ts
|
|
1780
1788
|
function vr(e, t, n, r, i, a, o) {
|
|
1781
1789
|
let s = e.cellSize, c = r - t, l = i - n, u = o + s / 2, d = Math.floor((Math.min(n, i) - o) / s), f = Math.ceil((Math.max(n, i) + o) / s) - 1, p = 0;
|
|
1782
1790
|
for (let r = d; r <= f; r++) {
|
|
@@ -1798,8 +1806,7 @@ function vr(e, t, n, r, i, a, o) {
|
|
|
1798
1806
|
}
|
|
1799
1807
|
return p;
|
|
1800
1808
|
}
|
|
1801
|
-
|
|
1802
|
-
//#region src/pathfinding/smooth-path.ts
|
|
1809
|
+
// src/pathfinding/smooth-path.ts
|
|
1803
1810
|
var yr = 24;
|
|
1804
1811
|
function br(e, t, n, r, i) {
|
|
1805
1812
|
let a = Cr(t);
|
|
@@ -1831,12 +1838,11 @@ function Cr(e) {
|
|
|
1831
1838
|
let t = [];
|
|
1832
1839
|
for (let n of e) {
|
|
1833
1840
|
let e = t[t.length - 1];
|
|
1834
|
-
|
|
1841
|
+
e && e.x === n.x && e.y === n.y || t.push(n);
|
|
1835
1842
|
}
|
|
1836
1843
|
return t;
|
|
1837
1844
|
}
|
|
1838
|
-
|
|
1839
|
-
//#region src/pathfinding/grid-a-star.ts
|
|
1845
|
+
// src/pathfinding/grid-a-star.ts
|
|
1840
1846
|
var wr = 5e4, Tr = 0, Er = 16, Dr = [
|
|
1841
1847
|
[-1, 0],
|
|
1842
1848
|
[1, 0],
|
|
@@ -1992,8 +1998,7 @@ function jr(e, t, n) {
|
|
|
1992
1998
|
function Mr(e) {
|
|
1993
1999
|
return e.filter((t, n) => n === 0 || t.x !== e[n - 1].x || t.y !== e[n - 1].y);
|
|
1994
2000
|
}
|
|
1995
|
-
|
|
1996
|
-
//#region src/pathfinding/follow-path.ts
|
|
2001
|
+
// src/pathfinding/follow-path.ts
|
|
1997
2002
|
var $ = {
|
|
1998
2003
|
Waiting: 0,
|
|
1999
2004
|
Waypoint: 1,
|
|
@@ -2008,8 +2013,7 @@ function Nr(e, t, n, r, a) {
|
|
|
2008
2013
|
let c = e[2];
|
|
2009
2014
|
return c === I.Incomplete ? (wt(e), $.Waiting) : c === I.Found ? (a.x = i(e, 6), a.y = i(e, 7), $.Goal) : $.Stuck;
|
|
2010
2015
|
}
|
|
2011
|
-
|
|
2012
|
-
//#region src/pathfinding/path-blockers.ts
|
|
2016
|
+
// src/pathfinding/path-blockers.ts
|
|
2013
2017
|
var Pr = "pathBlockers", Fr = "pathGates";
|
|
2014
2018
|
function Ir(e = {}) {
|
|
2015
2019
|
let { gateCategories: t = 0, not: n, filter: r } = e, i = {
|
|
@@ -2066,8 +2070,7 @@ function zr(e) {
|
|
|
2066
2070
|
let t = Math.round(e / (Math.PI / 2)) * Math.PI / 2;
|
|
2067
2071
|
return Math.abs(e - t) < 1e-5 ? t : e;
|
|
2068
2072
|
}
|
|
2069
|
-
|
|
2070
|
-
//#region src/pathfinding/navigation-state.ts
|
|
2073
|
+
// src/pathfinding/navigation-state.ts
|
|
2071
2074
|
function Br(e, t, n, r = 0) {
|
|
2072
2075
|
return {
|
|
2073
2076
|
grid: new gr(e, t, n),
|
|
@@ -2124,8 +2127,7 @@ function Gr(e, t) {
|
|
|
2124
2127
|
function Kr(e, t, n) {
|
|
2125
2128
|
for (let [r, i] of e.gatedGrids) r & t && n(i);
|
|
2126
2129
|
}
|
|
2127
|
-
|
|
2128
|
-
//#region src/pathfinding/pathfinding-update.ts
|
|
2130
|
+
// src/pathfinding/pathfinding-update.ts
|
|
2129
2131
|
var qr = 16e3;
|
|
2130
2132
|
function Jr(e = {}) {
|
|
2131
2133
|
let t = e.search ?? new kr({ diagonal: !0 }), n = e.iterationBudget ?? 16e3, r = e.gateCategories ?? 0, a = (e, r, a) => {
|
|
@@ -2192,8 +2194,7 @@ function Zr(e, t, n) {
|
|
|
2192
2194
|
}
|
|
2193
2195
|
return !0;
|
|
2194
2196
|
}
|
|
2195
|
-
|
|
2196
|
-
//#region src/pathfinding/pathfinding-system.ts
|
|
2197
|
+
// src/pathfinding/pathfinding-system.ts
|
|
2197
2198
|
var Qr = class extends r {
|
|
2198
2199
|
iterationBudget;
|
|
2199
2200
|
constructor(e, t) {
|
|
@@ -2275,7 +2276,6 @@ var Qr = class extends r {
|
|
|
2275
2276
|
e.committedTicks = dr(this.world);
|
|
2276
2277
|
}
|
|
2277
2278
|
};
|
|
2278
|
-
//#endregion
|
|
2279
2279
|
export { Ee as BODY_BLOCKS_PATH_FLAG, ye as BODY_CATEGORY_INDEX, we as BODY_CCD_FLAG, Te as BODY_DYING_FLAG, ve as BODY_FLAGS_INDEX, be as BODY_MASK_INDEX, Ce as BODY_SENSOR_FLAG, Se as BODY_SHAPE_MASK, xe as BODY_SIZE, Le as BOUNCINESS_INDEX, Re as BOUNCINESS_SIZE, u as COLLIDABLE_QUERY, Sn as CollisionBroadphase, ge as DEFAULT_COLLIDE_CATEGORY, _e as DEFAULT_COLLIDE_MASK, qr as DEFAULT_PATH_SEARCH_ITERATION_BUDGET, d as DEFAULT_PHYSICS_STEP_MS, ie as DYNAMICS_ACCELERATION_X_INDEX, ae as DYNAMICS_ACCELERATION_Y_INDEX, oe as DYNAMICS_INVERSE_MASS_INDEX, se as DYNAMICS_SIZE, $ as FollowStep, kr as GridAStar, Qe as INTERPOLATION_CHANNEL_INDEX, We as INTERPOLATION_DURATION_INDEX, tt as INTERPOLATION_PREVIOUS_DURATION_INDEX, rt as INTERPOLATION_PREVIOUS_TICK_INDEX, nt as INTERPOLATION_PREVIOUS_TOTAL_DURATION_INDEX, $e as INTERPOLATION_PREVIOUS_X_INDEX, et as INTERPOLATION_PREVIOUS_Y_INDEX, Je as INTERPOLATION_REMAINING_DURATION_INDEX, it as INTERPOLATION_SIZE, qe as INTERPOLATION_SYNCED_DURATION_INDEX, Ze as INTERPOLATION_SYNCED_STEP_DURATION_INDEX, Ue as INTERPOLATION_SYNCED_TICK_INDEX, Ye as INTERPOLATION_TARGET_X_INDEX, Xe as INTERPOLATION_TARGET_Y_INDEX, Ge as INTERPOLATION_TICK_INDEX, Ke as INTERPOLATION_TOTAL_DURATION_INDEX, Ve as INTERPOLATION_X_INDEX, He as INTERPOLATION_Y_INDEX, ei as InterpolationSystem, b as MAX_POLYGON_VERTICES, _r as MinHeap, ft as NAVIGATION_ACTIVE_INDEX, pt as NAVIGATION_GOAL_X_INDEX, mt as NAVIGATION_GOAL_Y_INDEX, gt as NAVIGATION_MAX_WAYPOINTS, lt as NAVIGATION_OUTCOME_INDEX, st as NAVIGATION_REQUEST_INDEX, ct as NAVIGATION_RESULT_INDEX, _t as NAVIGATION_SIZE, ht as NAVIGATION_WAYPOINTS_INDEX, dt as NAVIGATION_WAYPOINT_COUNT_INDEX, ut as NAVIGATION_WAYPOINT_INDEX, gr as NavGrid, Pr as PATH_BLOCKERS_QUERY, Fr as PATH_GATES_QUERY, C as POLYGON_SIZE, x as POLYGON_VERTEX_COUNT_INDEX, S as POLYGON_VERTICES_INDEX, l as POSITION_UPDATED_EVENT, I as PathStatus, Qr as PathfindingSystem, $t as PhysicalWorld, pr as PhysicsSystem, me as SHAPE_CAPSULE, pe as SHAPE_CIRCLE, he as SHAPE_POLYGON, fe as SHAPE_RECTANGLE, kn as SpatialIndex, v as TRANSFORM_ANGLE_INDEX, _ as TRANSFORM_HEIGHT_INDEX, y as TRANSFORM_SIZE, g as TRANSFORM_WIDTH_INDEX, m as TRANSFORM_X_INDEX, h as TRANSFORM_Y_INDEX, te as VELOCITY_DAMPING_INDEX, ne as VELOCITY_SIZE, j as VELOCITY_X_INDEX, ee as VELOCITY_Y_INDEX, Mn as addPhysicalWorldData, Wr as applyPathBlockerChanges, Gr as applyPathGateChanges, Rr as applyRectChanges, Lr as blockerRect, Hr as blockingRects, Ae as blocksPath, Pe as bodyDefinition, P as bodyShape, Be as bouncinessDefinition, Gt as boundsHalfHeight, Wt as boundsHalfWidth, Oe as canCollide, V as capsuleCoreAngle, B as capsuleHalfLength, Lt as contactNormal, Br as createNavigationState, Jr as createPathfindingUpdate, Qn as createPhysicsUpdate, le as dynamicsDefinition, Nr as followPath, An as getSpatialMap, Fn as integrateDynamics, ot as interpolationDefinition, $r as interpolationUpdate, ke as isContinuous, je as isDying, Ct as isNavigating, Tt as isPathPending, F as isSensor, Et as isUnreachable, Me as markDying, bt as navigateTo, yt as navigationDefinition, Dt as navigationGoal, Vr as navigationGridFor, Mt as navigationRegistry, Kt as orientedBoxesOverlap, Ir as pathBlockerQueries, Yr as pathfindingUpdate, jt as physicsRegistry, ir as physicsUpdate, K as pointSegmentDistanceSquared, rn as polygonContactNormal, T as polygonDefinition, nn as polygonShapesOverlap, E as preparePolygon, wt as requestPath, Jt as segmentBoxDistanceSquared, qt as segmentSegmentDistanceSquared, jn as setEntityPosition, xt as setNavigationGoal, Ur as setNavigationTerrainSpeed, U as shapeHalfHeight, H as shapeHalfWidth, Pt as shapeIsEmpty, Nt as shapeRadius, Ft as shapesOverlap, br as smoothPath, Nn as snapEntity, Pn as startSpawnInterpolation, St as stopNavigating, vr as sweepCost, A as transformDefinition, Q as updateSpatialMap, M as velocityDefinition, Ot as waypoint, L as waypointX, kt as waypointY, At as writePath };
|
|
2280
2280
|
|
|
2281
2281
|
//# sourceMappingURL=index.js.map
|