@adatechnology/game-weapons-three 0.21.7 → 0.22.1

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.
@@ -79,6 +79,7 @@ var GameWeaponsThree = (() => {
79
79
  createWeaponProps: () => createWeaponProps,
80
80
  createWeaponsTestModule: () => createWeaponsTestModule,
81
81
  createWorldEffects: () => createWorldEffects,
82
+ createWorldExplosiveShells: () => createWorldExplosiveShells,
82
83
  defaultWeaponProps: () => defaultWeaponProps,
83
84
  deriveFrames: () => deriveFrames,
84
85
  explosivesTextOf: () => explosivesTextOf,
@@ -24858,6 +24859,58 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
24858
24859
  if (ductility >= 0.3) return 1;
24859
24860
  return (1 + 4 * (0.3 - ductility) / 0.3) * Math.min(25, Math.max(1, (0.02 / Math.max(thickness, 1e-4)) ** 2));
24860
24861
  };
24862
+ var SWEEP_BROAD_SLACK = 1e-3;
24863
+ var sweptBounds = (origins, direction, length2) => {
24864
+ if (origins.length === 0 || !Number.isFinite(length2)) return null;
24865
+ const min2 = [Infinity, Infinity, Infinity];
24866
+ const max2 = [-Infinity, -Infinity, -Infinity];
24867
+ for (const origin of origins) {
24868
+ for (let k = 0; k < 3; k++) {
24869
+ const end3 = origin[k] + direction[k] * length2;
24870
+ min2[k] = Math.min(min2[k], origin[k], end3);
24871
+ max2[k] = Math.max(max2[k], origin[k], end3);
24872
+ }
24873
+ }
24874
+ for (let k = 0; k < 3; k++) {
24875
+ if (!Number.isFinite(min2[k]) || !Number.isFinite(max2[k])) return null;
24876
+ min2[k] -= SWEEP_BROAD_SLACK;
24877
+ max2[k] += SWEEP_BROAD_SLACK;
24878
+ }
24879
+ return { min: min2, max: max2 };
24880
+ };
24881
+ var sphereTouchesBounds = (bounds, centre, radius) => {
24882
+ let distanceSquared = 0;
24883
+ for (let k = 0; k < 3; k++) {
24884
+ const below = bounds.min[k] - centre[k];
24885
+ const above2 = centre[k] - bounds.max[k];
24886
+ if (below > 0) distanceSquared += below * below;
24887
+ else if (above2 > 0) distanceSquared += above2 * above2;
24888
+ }
24889
+ return distanceSquared <= radius * radius;
24890
+ };
24891
+ var boundsTouch = (a, b) => a.min[0] <= b.max[0] && a.max[0] >= b.min[0] && a.min[1] <= b.max[1] && a.max[1] >= b.min[1] && a.min[2] <= b.max[2] && a.max[2] >= b.min[2];
24892
+ var boundsInFrame = (bounds, position, rotation2) => {
24893
+ const inverse = quat.conjugate(rotation2);
24894
+ const centre = [(bounds.min[0] + bounds.max[0]) / 2 - position[0], (bounds.min[1] + bounds.max[1]) / 2 - position[1], (bounds.min[2] + bounds.max[2]) / 2 - position[2]];
24895
+ const size = [bounds.max[0] - bounds.min[0], bounds.max[1] - bounds.min[1], bounds.max[2] - bounds.min[2]];
24896
+ return aabbOf({ kind: "box", size }, rotateVec(inverse, centre), inverse);
24897
+ };
24898
+ var rayMissesBounds = (origin, direction, maxDistance, bounds) => {
24899
+ let near = 0;
24900
+ let far = maxDistance;
24901
+ for (let k = 0; k < 3; k++) {
24902
+ if (direction[k] === 0) {
24903
+ if (origin[k] < bounds.min[k] || origin[k] > bounds.max[k]) return true;
24904
+ continue;
24905
+ }
24906
+ const a = (bounds.min[k] - origin[k]) / direction[k];
24907
+ const b = (bounds.max[k] - origin[k]) / direction[k];
24908
+ near = Math.max(near, Math.min(a, b));
24909
+ far = Math.min(far, Math.max(a, b));
24910
+ if (near > far) return true;
24911
+ }
24912
+ return false;
24913
+ };
24861
24914
  var THIN_SHEET_DISHING = 5e-3;
24862
24915
  var SWEEP_BACK = 0.01;
24863
24916
  function sweepOrigins(box5, d, spacing) {
@@ -25042,6 +25095,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25042
25095
  const ignitionRules = resolveIgnitionRules(options.ignition);
25043
25096
  const breachBlastFactor = options.breach?.blastFactor ?? BREACH_BLAST_FACTOR;
25044
25097
  const chipEnergy = options.breach?.chipEnergy ?? CHIP_ENERGY;
25098
+ const broadPhase = options.broadPhase ?? true;
25045
25099
  const chainLinkCap = options.chainLinksPerUpdate !== void 0 && options.chainLinksPerUpdate >= 1 ? Math.floor(options.chainLinksPerUpdate) : Infinity;
25046
25100
  const rng2 = createRng2(options.seed ?? 1);
25047
25101
  const rnd2 = () => rng2.next();
@@ -25147,6 +25201,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
25147
25201
  unsup: [],
25148
25202
  anyAnchor: false,
25149
25203
  order: ++orderCounter,
25204
+ loose: carry?.loose ?? false,
25150
25205
  base: { pos: [pos[0], pos[1], pos[2]], rot: [rot[0], rot[1], rot[2], rot[3]] }
25151
25206
  };
25152
25207
  for (const ps of spec.parts) {
@@ -26634,17 +26689,90 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26634
26689
  if (disc < 0) return true;
26635
26690
  return -b - Math.sqrt(disc) > maxDist;
26636
26691
  };
26637
- const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false) => {
26692
+ const worldCentres = /* @__PURE__ */ new WeakMap();
26693
+ const worldCentreOf = (o) => {
26694
+ const p = o.st.position, q = o.st.rotation, c = o.bc;
26695
+ const known = worldCentres.get(o);
26696
+ if (known) {
26697
+ const k = known.key;
26698
+ if (k[0] === p[0] && k[1] === p[1] && k[2] === p[2] && k[3] === q[0] && k[4] === q[1] && k[5] === q[2] && k[6] === q[3] && k[7] === c[0] && k[8] === c[1] && k[9] === c[2]) return known.centre;
26699
+ }
26700
+ const centre = toWorld(p, q, c);
26701
+ worldCentres.set(o, { key: [p[0], p[1], p[2], q[0], q[1], q[2], q[3], c[0], c[1], c[2]], centre });
26702
+ return centre;
26703
+ };
26704
+ const implPartBox = (im, ps) => {
26705
+ const ov = im.poses.get(ps.id);
26706
+ return aabbOf(ps.shape, toWorld(im.position, im.rotation, ov?.pos ?? ps.position), quat.mul(im.rotation, ov?.q ?? quatFromEuler(...ps.rotation ?? [0, 0, 0])));
26707
+ };
26708
+ const implBounds = /* @__PURE__ */ new WeakMap();
26709
+ const implBoundsOf = (im) => {
26710
+ const spec = im.impl.describe();
26711
+ const p = im.position, q = im.rotation;
26712
+ const known = implBounds.get(im);
26713
+ if (known && known.spec === spec) {
26714
+ const k = known.key;
26715
+ if (k[0] === p[0] && k[1] === p[1] && k[2] === p[2] && k[3] === q[0] && k[4] === q[1] && k[5] === q[2] && k[6] === q[3] && k[7] === im.posesVersion) return known.bounds;
26716
+ }
26717
+ const min2 = [Infinity, Infinity, Infinity];
26718
+ const max2 = [-Infinity, -Infinity, -Infinity];
26719
+ for (const ps of spec.parts) {
26720
+ const box5 = implPartBox(im, ps);
26721
+ for (let k = 0; k < 3; k++) {
26722
+ min2[k] = Math.min(min2[k], box5.min[k] - SWEEP_BROAD_SLACK);
26723
+ max2[k] = Math.max(max2[k], box5.max[k] + SWEEP_BROAD_SLACK);
26724
+ }
26725
+ }
26726
+ const bounds = { min: min2, max: max2 };
26727
+ implBounds.set(im, { spec, key: [p[0], p[1], p[2], q[0], q[1], q[2], q[3], im.posesVersion], bounds });
26728
+ return bounds;
26729
+ };
26730
+ const sweepScope = (origins, d, length2, ignore) => {
26731
+ const bounds = sweptBounds(origins, d, length2);
26732
+ if (!bounds) return null;
26733
+ const scoped = [];
26734
+ const parts = /* @__PURE__ */ new Map();
26735
+ for (const o of objects.values()) {
26736
+ if (!sphereTouchesBounds(bounds, worldCentreOf(o), o.br + SWEEP_BROAD_SLACK)) continue;
26737
+ const local2 = boundsInFrame(bounds, o.st.position, o.st.rotation);
26738
+ const near = o.parts.filter((p) => !isLost(p) && !ignore.has(`${o.id}\0${p.spec.id}`) && sphereTouchesBounds(local2, p.pos, p.bound + PART_BOUND_SLACK + SWEEP_BROAD_SLACK));
26739
+ if (near.length === 0) continue;
26740
+ scoped.push(o);
26741
+ parts.set(o, near);
26742
+ }
26743
+ const scopedImpls = [];
26744
+ const implParts2 = /* @__PURE__ */ new Map();
26745
+ for (const im of impls.values()) {
26746
+ if (!boundsTouch(bounds, implBoundsOf(im))) continue;
26747
+ const near = im.impl.describe().parts.filter((ps) => !ignore.has(`${im.impl.id}\0${ps.id}`) && boundsTouch(bounds, implPartBox(im, ps)));
26748
+ if (near.length === 0) continue;
26749
+ scopedImpls.push(im);
26750
+ implParts2.set(im, near);
26751
+ }
26752
+ return { objects: scoped, parts, impls: scopedImpls, implParts: implParts2 };
26753
+ };
26754
+ let sweepCounts = null;
26755
+ let lastSweep = { objectVisits: 0, partVisits: 0, shapeTests: 0, shapeTested: [] };
26756
+ const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false, skip = {}, scope2) => {
26638
26757
  const d = vec.normalize(dir);
26758
+ const minRadius = skip.minObjectRadius ?? 0;
26639
26759
  let best = null;
26640
- for (const o of objects.values()) {
26641
- if (raySphereMiss(origin, d, toWorld(o.st.position, o.st.rotation, o.bc), o.br, best ? Math.min(maxDist, best.distance) : maxDist)) continue;
26760
+ const counts = sweepCounts;
26761
+ for (const o of scope2 ? scope2.objects : objects.values()) {
26762
+ if (counts) counts.objectVisits++;
26763
+ if (skip.skipLoose && o.loose || o.br < minRadius) continue;
26764
+ if (raySphereMiss(origin, d, worldCentreOf(o), o.br, best ? Math.min(maxDist, best.distance) : maxDist)) continue;
26642
26765
  const qi = quat.conjugate(o.st.rotation);
26643
26766
  const lo = rotateVec(qi, vec.sub(origin, o.st.position));
26644
26767
  const ld = rotateVec(qi, d);
26645
- for (const p of o.parts) {
26768
+ for (const p of scope2?.parts.get(o) ?? o.parts) {
26769
+ if (counts) counts.partVisits++;
26646
26770
  if (isLost(p) || ignore?.has(`${o.id}\0${p.spec.id}`)) continue;
26647
26771
  if (partSphereMiss(lo, ld, p, maxDist)) continue;
26772
+ if (counts) {
26773
+ counts.shapeTests++;
26774
+ counts.shapeTested.add(o.id);
26775
+ }
26648
26776
  const r = rayPart(o, p, origin, d);
26649
26777
  if (!r || r.t0 < 0 || r.t0 > maxDist) continue;
26650
26778
  if (p.st.opening && insideOpening(o, p, objLocal(o, vec.madd(origin, d, r.t0)))) continue;
@@ -26653,10 +26781,17 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26653
26781
  if (!best || r.t0 < best.distance) best = { object: o.id, part: p.spec.id, point: vec.madd(origin, d, r.t0), normal: r.n, distance: r.t0, pathLen: r.t1 - r.t0 };
26654
26782
  }
26655
26783
  }
26656
- for (const im of worldOnly ? [] : impls.values()) {
26784
+ for (const im of worldOnly ? [] : scope2 ? scope2.impls : impls.values()) {
26785
+ if (counts) counts.objectVisits++;
26786
+ if (!scope2 && broadPhase && rayMissesBounds(origin, d, maxDist, implBoundsOf(im))) continue;
26657
26787
  let boxHit = null;
26658
- for (const ps of im.impl.describe().parts) {
26788
+ for (const ps of scope2?.implParts.get(im) ?? im.impl.describe().parts) {
26789
+ if (counts) counts.partVisits++;
26659
26790
  if (ignore?.has(`${im.impl.id}\0${ps.id}`)) continue;
26791
+ if (counts) {
26792
+ counts.shapeTests++;
26793
+ counts.shapeTested.add(im.impl.id);
26794
+ }
26660
26795
  const ov = im.poses.get(ps.id);
26661
26796
  const r = rayPartRaw(im.position, im.rotation, ps, ov?.q ?? quatFromEuler(...ps.rotation ?? [0, 0, 0]), origin, d, ov?.pos);
26662
26797
  if (!r || r.t1 < 0 || r.t0 > maxDist) continue;
@@ -26864,6 +26999,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26864
26999
  return covered / length2;
26865
27000
  };
26866
27001
  const isTrim = (p) => (p.spec.structure?.role ?? "none") === "none";
27002
+ const fixesTrim = (o, j) => isTrim(o.parts[j.ia]) !== isTrim(o.parts[j.ib]);
26867
27003
  const wearJoints = (o, p, amount, near, radius = 0.06, src, split = false, span, blast) => {
26868
27004
  if (amount <= 0) return;
26869
27005
  const mine = (o.byPart.get(p.spec.id) ?? []).filter((j) => !j.st.open);
@@ -26872,7 +27008,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
26872
27008
  if (j.st.open) continue;
26873
27009
  if (j.spec.kind === "rebar" && (isReinforced(o.parts[j.ia].spec) || isReinforced(o.parts[j.ib].spec))) continue;
26874
27010
  if (near && jointReach(o, j, near) > Math.max(radius, jointReachLimit(o, j))) continue;
26875
- if (blast && (isTrim(o.parts[j.ia]) || isTrim(o.parts[j.ib])) && jointReach(o, j, blast.point) > Math.max(blast.reach, jointReachLimit(o, j))) continue;
27011
+ if (blast && fixesTrim(o, j) && jointReach(o, j, blast.point) > Math.max(blast.reach, jointReachLimit(o, j))) continue;
26876
27012
  j.st.hp -= span === void 0 ? amount : Math.min(amount, j.st.maxHp) * Math.min(1, span / Math.max(jointLength(o, j), 1e-6));
26877
27013
  if (j.st.hp <= 0 && blast && span !== void 0 && onFoundation(o, j) && wornShare(o, j, blast.point, span) < JOINT_OPEN_SHARE) j.st.hp = Math.min(j.st.maxHp, 1);
26878
27014
  if (j.st.hp <= 0) {
@@ -28607,7 +28743,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28607
28743
  register(impl, opts = {}) {
28608
28744
  const id = opts.id ?? impl.id;
28609
28745
  if (taken(id)) throw new Error(`object "${id}" already exists`);
28610
- impls.set(id, { impl, position: opts.position ?? [0, 0, 0], rotation: opts.rotation ?? [0, 0, 0, 1], poses: /* @__PURE__ */ new Map() });
28746
+ impls.set(id, { impl, position: opts.position ?? [0, 0, 0], rotation: opts.rotation ?? [0, 0, 0, 1], poses: /* @__PURE__ */ new Map(), posesVersion: 0 });
28611
28747
  return id;
28612
28748
  },
28613
28749
  setPartPose(objectId, partId, position, rotation2) {
@@ -28616,6 +28752,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28616
28752
  if (im) {
28617
28753
  im.impl.setPartPose?.(partId, position, rotation2);
28618
28754
  im.poses.set(partId, { pos: [position[0], position[1], position[2]], q });
28755
+ im.posesVersion++;
28619
28756
  return;
28620
28757
  }
28621
28758
  const o = getObj(objectId);
@@ -28671,7 +28808,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28671
28808
  const inNew = (pid) => moved.has(pid);
28672
28809
  const inOld = (pid) => !moved.has(pid);
28673
28810
  const pos = o.st.position, rot = o.st.rotation;
28674
- const fresh = build(sub2(inNew), nid, pos, rot, carryFor(inNew, (a, b) => inNew(a) && inNew(b)));
28811
+ const fresh = build(sub2(inNew), nid, pos, rot, { ...carryFor(inNew, (a, b) => inNew(a) && inNew(b)), loose: true });
28675
28812
  const restCarry = carryFor(inOld, (a, b) => !(inNew(a) && inNew(b)));
28676
28813
  if (o.st.soil) restCarry.soil = o.st.soil;
28677
28814
  if (o.soil?.sets.size) restCarry.soilSets = Object.fromEntries(o.soil.sets);
@@ -28743,8 +28880,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28743
28880
  if (!(loss.radius > 0) || !(loss.depth > 0) || !Number.isFinite(loss.x) || !Number.isFinite(loss.z)) return;
28744
28881
  pendingLosses.push({ ...loss });
28745
28882
  },
28746
- raycast(origin, direction, maxDistance = Infinity) {
28747
- const r = raycastInternal(origin, direction, maxDistance, void 0, false, true);
28883
+ raycast(origin, direction, maxDistance = Infinity, options2) {
28884
+ const r = raycastInternal(origin, direction, maxDistance, void 0, false, true, options2);
28748
28885
  return r ? { object: r.object, part: r.part, point: r.point, normal: r.normal, distance: r.distance } : null;
28749
28886
  },
28750
28887
  sweepBox(box5, direction, distance4, options2 = {}) {
@@ -28758,13 +28895,26 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28758
28895
  else if (hosted) for (const p of hosted.impl.describe().parts) ignore.add(`${hosted.impl.id}\0${p.id}`);
28759
28896
  }
28760
28897
  let best = null;
28761
- for (const origin of sweepOrigins(box5, d, options2.spacing ?? 0.2)) {
28762
- const r = raycastInternal(origin, d, distance4 + SWEEP_BACK, ignore.size > 0 ? ignore : void 0);
28763
- if (!r || best && r.distance >= best.distance) continue;
28764
- best = { object: r.object, part: r.part, point: r.point, normal: r.normal, distance: Math.max(0, r.distance - SWEEP_BACK) };
28898
+ const origins = sweepOrigins(box5, d, options2.spacing ?? 0.2);
28899
+ const length2 = distance4 + SWEEP_BACK;
28900
+ const scope2 = broadPhase ? sweepScope(origins, d, length2, ignore) ?? void 0 : void 0;
28901
+ const counts = { objectVisits: 0, partVisits: 0, shapeTests: 0, shapeTested: /* @__PURE__ */ new Set() };
28902
+ sweepCounts = counts;
28903
+ try {
28904
+ for (const origin of origins) {
28905
+ const r = raycastInternal(origin, d, length2, ignore.size > 0 ? ignore : void 0, false, false, {}, scope2);
28906
+ if (!r || best && r.distance >= best.distance) continue;
28907
+ best = { object: r.object, part: r.part, point: r.point, normal: r.normal, distance: Math.max(0, r.distance - SWEEP_BACK) };
28908
+ }
28909
+ } finally {
28910
+ sweepCounts = null;
28911
+ lastSweep = { objectVisits: counts.objectVisits, partVisits: counts.partVisits, shapeTests: counts.shapeTests, shapeTested: [...counts.shapeTested] };
28765
28912
  }
28766
28913
  return best;
28767
28914
  },
28915
+ sweepProbe() {
28916
+ return lastSweep;
28917
+ },
28768
28918
  shoot(origin, direction, energy, caliber, source, round5) {
28769
28919
  const extras = typeof round5 === "number" ? { piercing: round5 } : round5 ?? {};
28770
28920
  return withCollapses(run(withBlow("ballistic", () => {
@@ -28997,7 +29147,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
28997
29147
  rng: rng2.state(),
28998
29148
  counter,
28999
29149
  objects: [...objects.values()].map((o) => {
29000
- const runtime = { parts: {}, joints: {}, collapsed: [...o.collapsed], ...o.unanchored.size ? { unanchored: [...o.unanchored] } : {}, ...o.soil?.sets.size ? { soil: Object.fromEntries(o.soil.sets) } : {}, ...o.wind ? { wind: [o.wind.dyn.x, o.wind.dyn.v, o.wind.dyn.y, o.wind.dyn.w, o.wind.dyn.peak] } : {} };
29150
+ const runtime = { parts: {}, joints: {}, collapsed: [...o.collapsed], ...o.loose ? { loose: true } : {}, ...o.unanchored.size ? { unanchored: [...o.unanchored] } : {}, ...o.soil?.sets.size ? { soil: Object.fromEntries(o.soil.sets) } : {}, ...o.wind ? { wind: [o.wind.dyn.x, o.wind.dyn.v, o.wind.dyn.y, o.wind.dyn.w, o.wind.dyn.peak] } : {} };
29001
29151
  for (const p of o.parts) runtime.parts[p.spec.id] = clone(p.rt);
29002
29152
  for (const j of o.joints) runtime.joints[j.spec.id] = j.step;
29003
29153
  return { id: o.id, spec: clone(o.spec), state: clone(o.st), runtime };
@@ -29020,7 +29170,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
29020
29170
  joints: new Map(state.joints.map((st) => [st.id, { st, step: e.runtime?.joints[st.id] ?? 0 }])),
29021
29171
  collapsed: e.runtime?.collapsed,
29022
29172
  ...e.runtime?.unanchored ? { unanchored: e.runtime.unanchored } : {},
29023
- ...e.runtime?.wind ? { wind: e.runtime.wind } : {}
29173
+ ...e.runtime?.wind ? { wind: e.runtime.wind } : {},
29174
+ ...e.runtime?.loose ? { loose: true } : {}
29024
29175
  };
29025
29176
  let pos = state.position, rot = state.rotation;
29026
29177
  if (state.soil) {
@@ -32358,7 +32509,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
32358
32509
  }
32359
32510
  var residentialTower = residentialTowerTemplate();
32360
32511
 
32361
- // ../game-floorplan-three/dist/chunk-RZF4G6CY.js
32512
+ // ../game-floorplan-three/dist/chunk-XOLKY3ZJ.js
32362
32513
  var __defProp4 = Object.defineProperty;
32363
32514
  var __defNormalProp2 = (obj, key2, value) => key2 in obj ? __defProp4(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
32364
32515
  var __publicField2 = (obj, key2, value) => __defNormalProp2(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
@@ -39570,9 +39721,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
39570
39721
  dropped.length = 0;
39571
39722
  },
39572
39723
  flush,
39573
- /** Takes this house's painting out of the renderer's queue (the house goes away); `claim` puts it back. */
39724
+ /** Takes this house's painting out of the renderer's queue (the house goes away) and frees the unit shapes on the GPU; `claim` puts it back (three.js uploads the shapes again when drawn). */
39574
39725
  release() {
39575
39726
  paintQueues.delete(queue);
39727
+ unitGeometry.dispose();
39728
+ lumpShape?.dispose();
39576
39729
  },
39577
39730
  /** The painting of this house alone. */
39578
39731
  deferredQueue: () => queue,
@@ -39839,6 +39992,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
39839
39992
  D.deactivate = () => {
39840
39993
  if (off) off();
39841
39994
  off = null;
39995
+ if (R && D.id && D.active) R.release?.(D.id);
39842
39996
  D.restore();
39843
39997
  if (R && D.id && D.active) R.unbind(D.id);
39844
39998
  if (D.active && D.world.has(D.id)) D.world.remove(D.id);
@@ -39921,7 +40075,10 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
39921
40075
  D.piece = (id) => D.active ? D.world.part(D.id, id) : null;
39922
40076
  D.state = () => D.active ? D.world.state(D.id) : null;
39923
40077
  D.reset = () => {
39924
- if (D.active) D.world.reset(D.id);
40078
+ if (D.active) {
40079
+ R?.releasePieces?.(D.id);
40080
+ D.world.reset(D.id);
40081
+ }
39925
40082
  D.restore();
39926
40083
  };
39927
40084
  D.strike = (pid, point, type, amount, d) => {
@@ -47941,7 +48098,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
47941
48098
  var MAGAZINE_DROP_DEFAULTS = defaultsOf(SAMPLE_LEVELS.magazine);
47942
48099
  var droppedPartDefaults = (id) => id.startsWith("casing_drop_") ? CASING_DEFAULTS : id.startsWith("mag_drop_") ? MAGAZINE_DROP_DEFAULTS : void 0;
47943
48100
 
47944
- // ../game-audio/dist/chunk-KGYMFUK7.js
48101
+ // ../game-audio/dist/chunk-ZFNHDQRV.js
47945
48102
  var DISTANCE_CURVES = {
47946
48103
  /** The game's `sfx`: `vol / (1 + d² × 0.004)`, cutoff `/ (1 + d × 0.01)`, silent below 0.01 (jogo L62091–62092, L62101). */
47947
48104
  game_sfx: { model: "inverse_square", k: 4e-3, cutoffK: 0.01, minGain: 0.01 },
@@ -48701,6 +48858,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48701
48858
  cutoffDbPerDecade: 30,
48702
48859
  interval: 0.15,
48703
48860
  budget: 3,
48861
+ budgetMs: 1,
48704
48862
  smoothing: 0.08,
48705
48863
  audibleLevel: 2e-3
48706
48864
  };
@@ -48727,6 +48885,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48727
48885
  }
48728
48886
  var NEIGHBOUR_RADIUS = 2;
48729
48887
  var REMEMBERED = 64;
48888
+ var COST_WEIGHT = 0.5;
48730
48889
  var MOVED = 0.05;
48731
48890
  var CHANGED_DB = 0.5;
48732
48891
  var distance3 = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
@@ -48736,12 +48895,20 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48736
48895
  const entries2 = /* @__PURE__ */ new Map();
48737
48896
  let served = 0;
48738
48897
  let spent = 0;
48898
+ let spentMs = 0;
48899
+ let costMs;
48739
48900
  const remembered = /* @__PURE__ */ new Map();
48740
48901
  const interval = setup.interval ?? OCCLUSION_DEFAULTS.interval;
48741
48902
  const budget = Math.max(1, setup.budget ?? OCCLUSION_DEFAULTS.budget);
48742
48903
  const audibleLevel = setup.audibleLevel ?? OCCLUSION_DEFAULTS.audibleLevel;
48904
+ const budgetMs = setup.budgetMs ?? OCCLUSION_DEFAULTS.budgetMs;
48905
+ const clock = setup.clock ?? (() => performance.now());
48743
48906
  const measure = (source, listener) => {
48907
+ const started = clock();
48744
48908
  const state = occlusionState(totalLossDb(setup.query(source, listener), setup), setup);
48909
+ const cost = clock() - started;
48910
+ spentMs += cost;
48911
+ costMs = costMs === void 0 ? cost : costMs + (cost - costMs) * COST_WEIGHT;
48745
48912
  const key2 = keyOf(source);
48746
48913
  remembered.delete(key2);
48747
48914
  remembered.set(key2, state);
@@ -48762,7 +48929,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48762
48929
  add({ id, source, level, listener, now }) {
48763
48930
  const from = copy(source);
48764
48931
  const at4 = copy(listener);
48765
- if (spent >= budget) {
48932
+ if (spent >= budget || spentMs >= budgetMs || spentMs + (costMs ?? 0) > budgetMs) {
48766
48933
  const provisional = guess(from);
48767
48934
  entries2.set(id, { source: from, level, state: provisional, pending: true, checkedAt: now, checkedFrom: at4, served: served++ });
48768
48935
  return provisional;
@@ -48777,18 +48944,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48777
48944
  state: (id) => entries2.get(id)?.state,
48778
48945
  update(listener, now) {
48779
48946
  spent = 0;
48947
+ spentMs = 0;
48780
48948
  const at4 = copy(listener);
48781
48949
  const changes = [];
48782
48950
  let queries = 0;
48951
+ const canQuery = () => queries < budget && (queries === 0 || spentMs < budgetMs);
48783
48952
  for (const [id, voice2] of entries2) {
48784
- if (!voice2.pending || queries >= budget) continue;
48953
+ if (!voice2.pending) continue;
48954
+ if (!canQuery()) break;
48785
48955
  queries++;
48786
48956
  const state = measure(voice2.source, at4);
48787
48957
  voice2.pending = false;
48788
48958
  voice2.checkedAt = now;
48789
48959
  voice2.checkedFrom = at4;
48790
48960
  voice2.served = served++;
48791
- if (Math.abs(state.lossDb - voice2.state.lossDb) < CHANGED_DB) continue;
48961
+ if (state.lossDb === voice2.state.lossDb) continue;
48792
48962
  voice2.state = state;
48793
48963
  changes.push({ id, state });
48794
48964
  }
@@ -48804,7 +48974,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
48804
48974
  voice2.checkedAt = now;
48805
48975
  continue;
48806
48976
  }
48807
- if (queries >= budget) break;
48977
+ if (!canQuery()) break;
48808
48978
  queries++;
48809
48979
  const state = measure(voice2.source, at4);
48810
48980
  voice2.checkedAt = now;
@@ -50407,6 +50577,21 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
50407
50577
  const chosen = (ids ?? registry.sampleIds()).map((id) => registry.sample(id)).filter((sample) => sample !== void 0);
50408
50578
  return loadSounds(chosen);
50409
50579
  },
50580
+ preload(ids) {
50581
+ const chosen = /* @__PURE__ */ new Map();
50582
+ const seen = /* @__PURE__ */ new Set();
50583
+ const visit = (id) => {
50584
+ if (seen.has(id)) return;
50585
+ seen.add(id);
50586
+ const sample = registry.sample(id);
50587
+ const set2 = registry.set(id);
50588
+ if (sample) chosen.set(sample.id, sample);
50589
+ else if (set2) for (const variant of set2.variants) visit(variant);
50590
+ else wanted.add(id);
50591
+ };
50592
+ for (const id of ids) visit(id);
50593
+ return loadSounds([...chosen.values()]);
50594
+ },
50410
50595
  sampleStatus(id) {
50411
50596
  const sample = registry.sample(id);
50412
50597
  if (!sample) return "none";
@@ -64307,7 +64492,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64307
64492
  trail: 0,
64308
64493
  glow: null,
64309
64494
  rng: placeholder,
64310
- outColor: [0, 0, 0]
64495
+ outColor: [0, 0, 0],
64496
+ source: void 0
64311
64497
  }),
64312
64498
  freezeFollowingGlow
64313
64499
  );
@@ -64409,7 +64595,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64409
64595
  outY: 0,
64410
64596
  outZ: 0,
64411
64597
  outSize: 0,
64412
- outIntensity: 0
64598
+ outIntensity: 0,
64599
+ source: void 0
64413
64600
  }));
64414
64601
  }
64415
64602
  function spawnGlow(pool, init) {
@@ -64429,6 +64616,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64429
64616
  glow.fx = init.fx ?? 0;
64430
64617
  glow.fy = init.fy ?? 0;
64431
64618
  glow.fz = init.fz ?? 0;
64619
+ glow.source = init.source;
64432
64620
  return glow;
64433
64621
  }
64434
64622
  function ageOrKeep(glow, dt) {
@@ -64712,7 +64900,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64712
64900
  rng: placeholder,
64713
64901
  age: 0,
64714
64902
  heat: 0,
64715
- size: 0
64903
+ size: 0,
64904
+ source: void 0
64716
64905
  }));
64717
64906
  }
64718
64907
  function spawnPuff(pool, random, init) {
@@ -64745,6 +64934,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64745
64934
  puff3.age = 0;
64746
64935
  puff3.heat = 0;
64747
64936
  puff3.size = 0;
64937
+ puff3.source = init.source;
64748
64938
  return puff3;
64749
64939
  }
64750
64940
  function ageOrKeep2(puff3, dt) {
@@ -64803,7 +64993,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64803
64993
  var GROUND_LIFT = 0.02;
64804
64994
  var BOUNCE_SLIDE = 0.55;
64805
64995
  function createSparkPool(capacity) {
64806
- return new OrderedPool(capacity, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, t: 0, life: 0.8, w: 0.04, st: 0.035, kind: 0, drag: 0.6, g: 9.8, bounce: 0.35, age: 0 }));
64996
+ return new OrderedPool(capacity, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, t: 0, life: 0.8, w: 0.04, st: 0.035, kind: 0, drag: 0.6, g: 9.8, bounce: 0.35, age: 0, source: void 0 }));
64807
64997
  }
64808
64998
  function spawnSpark(pool, init) {
64809
64999
  const spark = pool.acquire();
@@ -64822,6 +65012,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64822
65012
  spark.g = init.g ?? 9.8;
64823
65013
  spark.bounce = init.bounce ?? 0.35;
64824
65014
  spark.age = 0;
65015
+ spark.source = init.source;
64825
65016
  return spark;
64826
65017
  }
64827
65018
  function ageOrKeep3(spark, dt) {
@@ -64855,22 +65046,26 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64855
65046
  function addPuff(core, random, init) {
64856
65047
  core.spawned.puffs++;
64857
65048
  const puff3 = spawnPuff(core.puffs, random, init);
65049
+ puff3.source = init.source ?? core.source;
64858
65050
  core.trace?.puff?.(puff3);
64859
65051
  return puff3;
64860
65052
  }
64861
65053
  function addSpark(core, init) {
64862
65054
  core.spawned.sparks++;
64863
65055
  const spark = spawnSpark(core.sparks, init);
65056
+ spark.source = init.source ?? core.source;
64864
65057
  core.trace?.spark?.(spark);
64865
65058
  return spark;
64866
65059
  }
64867
65060
  function addGlow(core, init) {
64868
65061
  const glow = spawnGlow(core.glows, init);
65062
+ glow.source = init.source ?? core.source;
64869
65063
  core.trace?.glow?.(glow);
64870
65064
  return glow;
64871
65065
  }
64872
65066
  function addChunk(core, random, init) {
64873
65067
  const chunk = spawnChunk(core.chunks, random, init);
65068
+ chunk.source = core.source;
64874
65069
  core.spawned.chunks++;
64875
65070
  if (chunk.hot && core.layers.shrapnel) {
64876
65071
  chunk.glow = addGlow(core, { follow: chunk, s: 0.35 + chunk.sx, i: 2.2, life: random.between(1, 2.2), color: HOT_GLOW_COLOR, curve: 1.5 });
@@ -64899,7 +65094,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64899
65094
  fz: 0,
64900
65095
  color: SMOKE_COLORS.black,
64901
65096
  rng: placeholder,
64902
- handle: 0
65097
+ handle: 0,
65098
+ source: void 0
64903
65099
  }));
64904
65100
  }
64905
65101
  function spawnFire(pool, random, init, handle) {
@@ -64924,6 +65120,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64924
65120
  fire.color = init.color ?? SMOKE_COLORS.black;
64925
65121
  fire.rng = random;
64926
65122
  fire.handle = handle;
65123
+ fire.source = init.source;
64927
65124
  return fire;
64928
65125
  }
64929
65126
  function addFire(core, random, init, handle) {
@@ -64958,7 +65155,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64958
65155
  buoy: 3.2,
64959
65156
  color: fire.color,
64960
65157
  kind: 0,
64961
- wind: 0.4
65158
+ wind: 0.4,
65159
+ source: fire.source
64962
65160
  });
64963
65161
  }
64964
65162
  }
@@ -64981,7 +65179,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
64981
65179
  drag: 0.6,
64982
65180
  buoy: 0.55,
64983
65181
  color: fire.color,
64984
- kind: 0
65182
+ kind: 0,
65183
+ source: fire.source
64985
65184
  });
64986
65185
  }
64987
65186
  }
@@ -65000,7 +65199,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
65000
65199
  st: 0.02,
65001
65200
  kind: 4,
65002
65201
  g: -0.6,
65003
- drag: 1.2
65202
+ drag: 1.2,
65203
+ source: fire.source
65004
65204
  });
65005
65205
  }
65006
65206
  function updateFires(core, dt) {
@@ -68930,10 +69130,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
68930
69130
  st: 0.05,
68931
69131
  kind: 0,
68932
69132
  g: 0,
68933
- drag: 1
69133
+ drag: 1,
69134
+ source: chunk.source
68934
69135
  });
68935
69136
  if (random.next() < 0.25) {
68936
- addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0 });
69137
+ addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0, source: chunk.source });
68937
69138
  }
68938
69139
  }
68939
69140
  function updateChunks(core, dt) {
@@ -68989,10 +69190,11 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
68989
69190
  };
68990
69191
  }
68991
69192
  var SpriteKindPool = class {
68992
- constructor(capacity, defs, owners) {
69193
+ constructor(capacity, defs, owners, sources = { ids: /* @__PURE__ */ new Map(), next: 0 }) {
68993
69194
  __publicField3(this, "capacity", capacity);
68994
69195
  __publicField3(this, "defs", defs);
68995
69196
  __publicField3(this, "owners", owners);
69197
+ __publicField3(this, "sources", sources);
68996
69198
  __publicField3(this, "live", 0);
68997
69199
  __publicField3(this, "drawCount", 0);
68998
69200
  __publicField3(this, "position");
@@ -69011,6 +69213,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
69011
69213
  __publicField3(this, "alphaMul");
69012
69214
  __publicField3(this, "tag");
69013
69215
  __publicField3(this, "owner");
69216
+ __publicField3(this, "source");
69014
69217
  __publicField3(this, "colorHex");
69015
69218
  __publicField3(this, "rgbStart");
69016
69219
  __publicField3(this, "rgbEnd");
@@ -69032,6 +69235,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
69032
69235
  this.alphaMul = new Float32Array(n);
69033
69236
  this.tag = new Int32Array(n);
69034
69237
  this.owner = new Int32Array(n);
69238
+ this.source = new Int32Array(n);
69035
69239
  this.colorHex = new Int32Array(n);
69036
69240
  this.rgbStart = new Float32Array(n * 3);
69037
69241
  this.rgbEnd = new Float32Array(n * 3);
@@ -69058,6 +69262,7 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
69058
69262
  this.alphaMul[i] = options?.alpha ?? 1;
69059
69263
  this.tag[i] = options?.tag ?? 0;
69060
69264
  this.owner[i] = options?.owner === void 0 ? -1 : this.ownerIndex(options.owner);
69265
+ this.source[i] = options?.source === void 0 ? -1 : this.sourceIndex(options.source);
69061
69266
  this.colorHex[i] = options?.color ?? -1;
69062
69267
  this.rgbStart.set(rgb(options?.color ?? def.c0), i * 3);
69063
69268
  this.rgbEnd.set(rgb(options?.color ?? def.c1), i * 3);
@@ -69072,6 +69277,26 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
69072
69277
  if (index < 0) index = this.owners.push(name) - 1;
69073
69278
  return index;
69074
69279
  }
69280
+ sourceIndex(name) {
69281
+ let index = this.sources.ids.get(name);
69282
+ if (index === void 0) {
69283
+ index = this.sources.next++;
69284
+ this.sources.ids.set(name, index);
69285
+ }
69286
+ return index;
69287
+ }
69288
+ /** Kills the live sprites made for `source`; returns how many went. */
69289
+ clearSource(source) {
69290
+ const index = this.sources.ids.get(source);
69291
+ if (index === void 0) return 0;
69292
+ let killed = 0;
69293
+ for (let i = 0; i < this.high; i++) {
69294
+ if (!this.alive[i] || this.source[i] !== index) continue;
69295
+ this.kill(i);
69296
+ killed++;
69297
+ }
69298
+ return killed;
69299
+ }
69075
69300
  kill(i) {
69076
69301
  if (!this.alive[i]) return;
69077
69302
  this.alive[i] = 0;
@@ -69517,14 +69742,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
69517
69742
  __publicField3(this, "defs");
69518
69743
  __publicField3(this, "index", /* @__PURE__ */ new Map());
69519
69744
  __publicField3(this, "owners", []);
69745
+ __publicField3(this, "sources", { ids: /* @__PURE__ */ new Map(), next: 0 });
69520
69746
  __publicField3(this, "listeners", /* @__PURE__ */ new Map());
69521
69747
  const kinds = options.kinds ?? SPRITE_KINDS;
69522
69748
  this.ids = Object.keys(kinds);
69523
69749
  this.defs = this.ids.map((id) => kinds[id]);
69524
69750
  this.ids.forEach((id, at32) => this.index.set(id, at32));
69525
69751
  const additiveCapacity = Math.floor(options.capacity * 0.4);
69526
- this.additive = new SpriteKindPool(additiveCapacity, this.defs, this.owners);
69527
- this.normal = new SpriteKindPool(options.capacity - additiveCapacity, this.defs, this.owners);
69752
+ this.additive = new SpriteKindPool(additiveCapacity, this.defs, this.owners, this.sources);
69753
+ this.normal = new SpriteKindPool(options.capacity - additiveCapacity, this.defs, this.owners, this.sources);
69528
69754
  this.random = spriteRandom(options.seed);
69529
69755
  }
69530
69756
  get capacity() {
@@ -69598,9 +69824,16 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
69598
69824
  if (this.additive.live > 0 || this.additive.drawCount > 0) this.additive.update(dt, host);
69599
69825
  if (this.normal.live > 0 || this.normal.drawCount > 0) this.normal.update(dt, host);
69600
69826
  }
69827
+ /** Kills the live sprites made for `source` (`SpriteSpawnOptions.source`); returns how many went. */
69828
+ clearSource(source) {
69829
+ const killed = this.additive.clearSource(source) + this.normal.clearSource(source);
69830
+ this.sources.ids.delete(source);
69831
+ return killed;
69832
+ }
69601
69833
  clear() {
69602
69834
  this.additive.clear();
69603
69835
  this.normal.clear();
69836
+ this.sources.ids.clear();
69604
69837
  }
69605
69838
  };
69606
69839
  var TWO_PI_ROUNDED = 6.2832;
@@ -70628,7 +70861,8 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
70628
70861
  groundAt,
70629
70862
  ...options.marklessAt ? { marklessAt: options.marklessAt } : {},
70630
70863
  ...options.cratersAt ? { cratersAt: options.cratersAt } : {},
70631
- emit: (request) => options.onRequest?.(request)
70864
+ emit: (request) => options.onRequest?.(request),
70865
+ source: void 0
70632
70866
  };
70633
70867
  function definitionOf(id) {
70634
70868
  return explosions[id] ?? explosions[aliases[id] ?? ""];
@@ -70639,7 +70873,13 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
70639
70873
  return streamFor3(seed ?? Math.imul(handles.events, AUTO_SEED) + (options.seed ?? 0));
70640
70874
  }
70641
70875
  function detonate(def, point, call3) {
70642
- composeExplosion(core, def, { x: point[0], y: point[1], z: point[2], direction: call3.direction, random: call3.random, handle: call3.handle });
70876
+ const outer = core.source;
70877
+ core.source = call3.source;
70878
+ try {
70879
+ composeExplosion(core, def, { x: point[0], y: point[1], z: point[2], direction: call3.direction, random: call3.random, handle: call3.handle });
70880
+ } finally {
70881
+ core.source = outer;
70882
+ }
70643
70883
  }
70644
70884
  let engine;
70645
70885
  let player;
@@ -70680,8 +70920,9 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
70680
70920
  const handle = ++handles.next;
70681
70921
  const direction = explosionOptions.direction && { x: explosionOptions.direction[0], y: explosionOptions.direction[1], z: explosionOptions.direction[2] };
70682
70922
  const random = streamOf(explosionOptions.seed);
70683
- if (explosionOptions.delay) core.schedule.at(core.clock.time + explosionOptions.delay, () => detonate(def, point, { direction, random, handle }));
70684
- else detonate(def, point, { direction, random, handle });
70923
+ const source = explosionOptions.source;
70924
+ if (explosionOptions.delay) core.schedule.at(core.clock.time + explosionOptions.delay, () => detonate(def, point, { direction, random, handle, source }));
70925
+ else detonate(def, point, { direction, random, handle, source });
70685
70926
  return handle;
70686
70927
  },
70687
70928
  fire(fireOptions) {
@@ -70723,6 +70964,15 @@ uniform mat4 uNodes[${nodes.length}]; attribute float aNodeIndex; attribute vec3
70723
70964
  const fires = core.fires;
70724
70965
  for (let index = fires.items.length - 1; index >= 0; index--) if (fires.items[index].handle === handle) fires.removeAt(index);
70725
70966
  },
70967
+ clearSource(source) {
70968
+ const keep = (record, gone) => record.source !== gone;
70969
+ const drop = (pool) => {
70970
+ const before = pool.count;
70971
+ pool.compact(keep, source);
70972
+ return before - pool.count;
70973
+ };
70974
+ return drop(core.fires) + drop(core.puffs) + drop(core.sparks) + drop(core.chunks) + drop(core.glows) + spriteSystem.clearSource(source);
70975
+ },
70726
70976
  setLayer(layer3, on) {
70727
70977
  layers[layer3] = on;
70728
70978
  },
@@ -74940,6 +75190,25 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
74940
75190
  model.name = `${WORLD_EXPLOSIVE_PREFIX}${defId}_shell`;
74941
75191
  return model;
74942
75192
  };
75193
+ var createWorldExplosiveShells = (THREE, defId, items) => {
75194
+ const model = worldExplosiveShell(THREE, defId, items);
75195
+ const geometries = /* @__PURE__ */ new Set();
75196
+ const materials = /* @__PURE__ */ new Set();
75197
+ model?.traverse((node) => {
75198
+ const mesh3 = node;
75199
+ if (!mesh3.isMesh) return;
75200
+ geometries.add(mesh3.geometry);
75201
+ for (const material of Array.isArray(mesh3.material) ? mesh3.material : [mesh3.material]) materials.add(material);
75202
+ });
75203
+ markShared(...geometries, ...materials);
75204
+ return {
75205
+ next: () => model?.clone(),
75206
+ dispose() {
75207
+ for (const geometry of geometries) geometry.dispose();
75208
+ for (const material of materials) material.dispose();
75209
+ }
75210
+ };
75211
+ };
74943
75212
  var worldExplosiveItem = (def, name, options = {}) => {
74944
75213
  const shape = SHAPES3[def.id];
74945
75214
  if (!shape) return void 0;
@@ -75714,6 +75983,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
75714
75983
  const vessels = /* @__PURE__ */ new Map();
75715
75984
  const wallParts = /* @__PURE__ */ new Set();
75716
75985
  const shells = [];
75986
+ let shellModel = null;
75717
75987
  const T2 = () => host?.THREE;
75718
75988
  const now = () => room?.world.time ?? 0;
75719
75989
  const say = (message, data = {}) => host?.log(message, { source: EXPLOSIVES_AREA_ID, ...data });
@@ -75820,7 +76090,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
75820
76090
  const launchShell = (vessel, point) => {
75821
76091
  const config = def.shell;
75822
76092
  if (!config || !host) return;
75823
- const mesh3 = worldExplosiveShell(T2(), def.id, options.items);
76093
+ const mesh3 = shellModel?.next();
75824
76094
  if (!mesh3) return;
75825
76095
  mesh3.position.set(point[0], Math.max(point[1], 0.3), point[2]);
75826
76096
  host.scene.add(mesh3);
@@ -76165,6 +76435,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
76165
76435
  ],
76166
76436
  attach(lent) {
76167
76437
  host = lent;
76438
+ if (def.shell) shellModel = createWorldExplosiveShells(T2(), def.id, options.items);
76168
76439
  const offs = [];
76169
76440
  if (room) {
76170
76441
  offs.push(room.world.on("*", onEvent));
@@ -76195,6 +76466,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
76195
76466
  for (const vessel of vessels.values()) clearRings(vessel);
76196
76467
  vessels.clear();
76197
76468
  clearShells();
76469
+ shellModel?.dispose();
76470
+ shellModel = null;
76198
76471
  host = null;
76199
76472
  };
76200
76473
  },
@@ -76209,6 +76482,38 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
76209
76482
  };
76210
76483
  }
76211
76484
 
76485
+ // src/test-area/torn-body.ts
76486
+ function boxesCentre(boxes) {
76487
+ if (boxes.length === 0) return void 0;
76488
+ const low = [Infinity, Infinity, Infinity];
76489
+ const high = [-Infinity, -Infinity, -Infinity];
76490
+ for (const box5 of boxes) {
76491
+ for (let axis2 = 0; axis2 < 3; axis2++) {
76492
+ low[axis2] = Math.min(low[axis2], box5[axis2]);
76493
+ high[axis2] = Math.max(high[axis2], box5[axis2 + 3]);
76494
+ }
76495
+ }
76496
+ return [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2];
76497
+ }
76498
+ function tornBodyShift(before, after2) {
76499
+ let mass = 0;
76500
+ const from = [0, 0];
76501
+ const to = [0, 0];
76502
+ for (const [key2, first] of before) {
76503
+ const second = after2.get(key2);
76504
+ const start = boxesCentre(first.boxes);
76505
+ const end3 = second ? boxesCentre(second.boxes) : void 0;
76506
+ if (!start || !end3 || first.mass <= 0) continue;
76507
+ mass += first.mass;
76508
+ from[0] += start[0] * first.mass;
76509
+ from[1] += start[2] * first.mass;
76510
+ to[0] += end3[0] * first.mass;
76511
+ to[1] += end3[2] * first.mass;
76512
+ }
76513
+ if (mass === 0) return void 0;
76514
+ return Math.hypot((to[0] - from[0]) / mass, (to[1] - from[1]) / mass);
76515
+ }
76516
+
76212
76517
  // src/test-area/explosives-scenarios.ts
76213
76518
  var TORCH_WINDOW = [0.7, 1];
76214
76519
  var BLAST_WITHIN = 1.6;
@@ -76283,6 +76588,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
76283
76588
  origin.set(body.objectId, body.from);
76284
76589
  }
76285
76590
  const partsBefore = new Map(placed.map((body) => [body.objectId, partsOf(body.objectId)]));
76591
+ const partPlaces = (objectId, keep = () => true) => (room.world.state(objectId)?.parts ?? []).filter(keep).map((part) => [part, { mass: part.mass, boxes: room.renderer.shownBoxes?.(objectId, part.id) ?? [] }]);
76592
+ const heavyBefore = new Map(placed.filter((body) => HEAVY_ITEMS.includes(body.kind)).map((body) => [body.objectId, new Map(partPlaces(body.objectId))]));
76593
+ const heavyShift = (objectId) => {
76594
+ const before = heavyBefore.get(objectId);
76595
+ if (!before) return void 0;
76596
+ return tornBodyShift(before, new Map(room.world.ids().flatMap((id) => partPlaces(id, (part) => before.has(part)))));
76597
+ };
76286
76598
  expect(placed.length > 0, fillText2(text.push_found, { n: placed.length, kinds: [...new Set(placed.map((body) => body.kind))].join(", ") }), { placed: placed.map((body) => body.itemId) });
76287
76599
  const aimOf = new Map(
76288
76600
  placed.map((body) => {
@@ -76359,7 +76671,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
76359
76671
  expect(row.outward <= most, fillText2(text.push_person_wave, { who: things[row.kind] ?? row.kind, distance: row.distance.toFixed(1), moved: Math.max(0, row.outward).toFixed(2), most: most.toFixed(2) }), { row: { kind: row.kind, distance: row.distance, outward: row.outward, speed, most } });
76360
76672
  }
76361
76673
  const table = rows.find((row) => HEAVY_ITEMS.includes(row.kind) && row.distance < blast.radius * 0.85);
76362
- if (table) expect(table.moved >= MOVED2, fillText2(text.push_heavy, { what: things[table.itemId] ?? table.itemId, moved: table.moved.toFixed(2) }), { table });
76674
+ if (table) {
76675
+ const moved = heavyShift(table.objectId) ?? table.moved;
76676
+ expect(moved >= MOVED2, fillText2(text.push_heavy, { what: things[table.itemId] ?? table.itemId, moved: moved.toFixed(2) }), { table, moved, rootMoved: table.moved });
76677
+ }
76363
76678
  }
76364
76679
  };
76365
76680
  }
@@ -76458,7 +76773,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
76458
76773
  { item: "fridge", at: [-1.65, 0, -10.55] },
76459
76774
  { item: "kitchen_cabinet_base", at: [-0.78, 0, -10.6] },
76460
76775
  { item: "stove", at: [0.72, 0, -10.58] },
76461
- { item: "camp_table", at: [2.4, 0, -10.2] }
76776
+ // on open floor in the blast's sight, off the paving along the wall: the slabs a blast leaves fixed beyond the stretch it breaks (since #281) held the table's legs out of its reach
76777
+ { item: "camp_table", at: [1.82, 0, -8.52], rotationY: Math.PI / 2 }
76462
76778
  ],
76463
76779
  cylinder: [0.02, 0, -10.66],
76464
76780
  zombie: { item: "zombie_walker", at: [-1.6, 0, -8.1] },