@adatechnology/game-vfx 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1106,11 +1106,11 @@ var OrderedPool = class {
1106
1106
  this.spare.push(record);
1107
1107
  }
1108
1108
  /** Keeps the records `keep` accepts, in the same order, without allocating. `context` goes to `keep` so no closure is needed per frame. */
1109
- compact(keep, context) {
1109
+ compact(keep2, context) {
1110
1110
  let write = 0;
1111
1111
  for (let read = 0; read < this.items.length; read++) {
1112
1112
  const record = this.items[read];
1113
- if (keep(record, context)) {
1113
+ if (keep2(record, context)) {
1114
1114
  this.items[write++] = record;
1115
1115
  continue;
1116
1116
  }
@@ -1395,9 +1395,74 @@ function streamFor(eventSeed) {
1395
1395
  return lehmer(mixEventSeed(eventSeed));
1396
1396
  }
1397
1397
 
1398
- // src/enclosures.ts
1399
- var SKIN = 5e-3;
1398
+ // src/solids.ts
1400
1399
  var MAX_PAD = 0.45;
1400
+ var SKIN = 5e-3;
1401
+ var Solids = class {
1402
+ constructor() {
1403
+ __publicField(this, "queries", /* @__PURE__ */ new Map());
1404
+ __publicField(this, "list", []);
1405
+ // fractions from the start: the fields hold fractions, and a field that held a whole number first boxes each fraction written to it
1406
+ __publicField(this, "hit", { x: 0.5, y: 0.5, z: 0.5, nx: 0.5, ny: 0.5, nz: 0.5, d: 0.5 });
1407
+ }
1408
+ get empty() {
1409
+ return this.list.length === 0;
1410
+ }
1411
+ /** Declares or (with `null`) ends the solids `id` answers for. */
1412
+ set(id, query2) {
1413
+ if (query2) this.queries.set(id, query2);
1414
+ else this.queries.delete(id);
1415
+ this.list = [...this.queries.values()];
1416
+ }
1417
+ clear() {
1418
+ this.queries.clear();
1419
+ this.list = [];
1420
+ }
1421
+ /**
1422
+ * Stops a step that goes into a solid: `out` gets the nearest hit, put back the step's `pad` metres (at most `MAX_PAD`) off the surface (never behind where the step began) and
1423
+ * the surface's normal. Answers whether the step was stopped.
1424
+ */
1425
+ stop(move, out) {
1426
+ const dx = move.x1 - move.x0;
1427
+ const dy = move.y1 - move.y0;
1428
+ const dz = move.z1 - move.z0;
1429
+ const length = Math.sqrt(dx * dx + dy * dy + dz * dz);
1430
+ if (!(length > 0)) return false;
1431
+ let nearest = Infinity;
1432
+ const list = this.list;
1433
+ for (let index = 0; index < list.length; index++) {
1434
+ if (!list[index](move, this.hit)) continue;
1435
+ const reached = ((this.hit.x - move.x0) * dx + (this.hit.y - move.y0) * dy + (this.hit.z - move.z0) * dz) / length;
1436
+ if (reached >= nearest) continue;
1437
+ nearest = reached;
1438
+ out.x = this.hit.x;
1439
+ out.y = this.hit.y;
1440
+ out.z = this.hit.z;
1441
+ out.nx = this.hit.nx;
1442
+ out.ny = this.hit.ny;
1443
+ out.nz = this.hit.nz;
1444
+ }
1445
+ if (nearest === Infinity) return false;
1446
+ const hitX2 = out.x;
1447
+ const hitY2 = out.y;
1448
+ const hitZ = out.z;
1449
+ out.d = out.nx * hitX2 + out.ny * hitY2 + out.nz * hitZ;
1450
+ const back = Math.min(Math.min(Math.max(move.pad, 0), MAX_PAD) + SKIN, Math.max(nearest, 0));
1451
+ out.x -= dx / length * back;
1452
+ out.y -= dy / length * back;
1453
+ out.z -= dz / length * back;
1454
+ const off = (out.x - hitX2) * out.nx + (out.y - hitY2) * out.ny + (out.z - hitZ) * out.nz;
1455
+ if (off < SKIN) {
1456
+ out.x += out.nx * (SKIN - off);
1457
+ out.y += out.ny * (SKIN - off);
1458
+ out.z += out.nz * (SKIN - off);
1459
+ }
1460
+ return true;
1461
+ }
1462
+ };
1463
+
1464
+ // src/enclosures.ts
1465
+ var SKIN2 = 5e-3;
1401
1466
  function rotation(q) {
1402
1467
  const [x, y, z, w] = q ?? [0, 0, 0, 1];
1403
1468
  const n = Math.hypot(x, y, z, w) || 1;
@@ -1422,16 +1487,21 @@ var Enclosures = class {
1422
1487
  __publicField(this, "spaces", /* @__PURE__ */ new Map());
1423
1488
  __publicField(this, "list", []);
1424
1489
  __publicField(this, "random");
1425
- __publicField(this, "out", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
1490
+ __publicField(this, "out", { x: 0.5, y: 0.5, z: 0.5, nx: 0.5, ny: 0.5, nz: 0.5, d: 0.5 });
1426
1491
  __publicField(this, "l0", new Float64Array(3));
1427
1492
  __publicField(this, "l1", new Float64Array(3));
1428
1493
  __publicField(this, "q", new Float64Array(3));
1429
1494
  __publicField(this, "h", new Float64Array(3));
1430
1495
  __publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 });
1496
+ __publicField(this, "solids", new Solids());
1431
1497
  this.random = lehmer(seed);
1432
1498
  }
1433
1499
  get empty() {
1434
- return this.list.length === 0;
1500
+ return this.list.length === 0 && this.solids.empty;
1501
+ }
1502
+ /** Declares or (with `null`) ends the host solids `id` answers for (a destruction world's walls): what is carried stops at them and passes only their holes. */
1503
+ solid(id, query2) {
1504
+ this.solids.set(id, query2);
1435
1505
  }
1436
1506
  get size() {
1437
1507
  return this.list.length;
@@ -1492,7 +1562,7 @@ var Enclosures = class {
1492
1562
  }
1493
1563
  /** Passes at `rate` per second. */
1494
1564
  chance(rate, dt) {
1495
- return rate > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
1565
+ return rate > 0 && dt > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
1496
1566
  }
1497
1567
  /** The opening the wall point `q` (local) is in lets it through now. */
1498
1568
  through(s, q, dt) {
@@ -1514,6 +1584,10 @@ var Enclosures = class {
1514
1584
  return this.confineMove(move, dt);
1515
1585
  }
1516
1586
  confineMove(move, dt) {
1587
+ if (this.confineSpaces(move, dt)) return true;
1588
+ return !this.solids.empty && this.solids.stop(move, this.out);
1589
+ }
1590
+ confineSpaces(move, dt) {
1517
1591
  const list = this.list;
1518
1592
  if (list.length === 0) return false;
1519
1593
  const { x0, y0, z0, x1, y1, z1 } = move;
@@ -1554,7 +1628,7 @@ var Enclosures = class {
1554
1628
  }
1555
1629
  }
1556
1630
  sign = l1[axis2] < 0 ? -1 : 1;
1557
- for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN, Math.max(-(h[a] - SKIN), l1[a]));
1631
+ for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN2, Math.max(-(h[a] - SKIN2), l1[a]));
1558
1632
  sign = -sign;
1559
1633
  } else {
1560
1634
  const padded0 = Math.abs(l0[0]) <= s.hx + p && Math.abs(l0[1]) <= s.hy + p && Math.abs(l0[2]) <= s.hz + p;
@@ -1571,7 +1645,7 @@ var Enclosures = class {
1571
1645
  }
1572
1646
  }
1573
1647
  sign = l0[axis2] < 0 ? -1 : 1;
1574
- l1[axis2] = sign * (h[axis2] + bound + SKIN);
1648
+ l1[axis2] = sign * (h[axis2] + bound + SKIN2);
1575
1649
  }
1576
1650
  const r = s.r;
1577
1651
  const out = this.out;
@@ -1581,6 +1655,7 @@ var Enclosures = class {
1581
1655
  out.nx = r[axis2] * sign;
1582
1656
  out.ny = r[3 + axis2] * sign;
1583
1657
  out.nz = r[6 + axis2] * sign;
1658
+ out.d = out.nx * s.cx + out.ny * s.cy + out.nz * s.cz + (in0 ? -h[axis2] : h[axis2]);
1584
1659
  return true;
1585
1660
  }
1586
1661
  return false;
@@ -1599,6 +1674,129 @@ function slideAlong(out, vx2, vy2, vz2) {
1599
1674
  return [vx2 - into * out.nx, vy2 - into * out.ny, vz2 - into * out.nz];
1600
1675
  }
1601
1676
 
1677
+ // src/pools/puff-cuts.ts
1678
+ var PUFF_REACH = 1.28;
1679
+ var PROBES = [{ x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }, { x: 0, y: 1, z: 0 }];
1680
+ var PROBES_PER_SECOND = 60;
1681
+ var FRAMES_PER_PROBE = 3;
1682
+ var GROUND_FACING = 0.7;
1683
+ var SAME_WALL = 0.9;
1684
+ var PROBE = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
1685
+ var KeptCut = class {
1686
+ constructor() {
1687
+ __publicField(this, "on", false);
1688
+ __publicField(this, "nx", 0.5);
1689
+ __publicField(this, "ny", 0.5);
1690
+ __publicField(this, "nz", 0.5);
1691
+ __publicField(this, "d", 0.5);
1692
+ }
1693
+ };
1694
+ function createCut() {
1695
+ return new KeptCut();
1696
+ }
1697
+ function clearCuts(puff3) {
1698
+ puff3.cuts[0].on = false;
1699
+ puff3.cuts[1].on = false;
1700
+ }
1701
+ var WrittenWay = class {
1702
+ constructor() {
1703
+ __publicField(this, "x", 0.5);
1704
+ __publicField(this, "y", 0.5);
1705
+ __publicField(this, "z", 0.5);
1706
+ }
1707
+ };
1708
+ var WAY = new WrittenWay();
1709
+ function probe(confiner, puff3, way) {
1710
+ const reach = puff3.size * PUFF_REACH;
1711
+ if (!(reach > 0)) return false;
1712
+ PROBE.x0 = puff3.x;
1713
+ PROBE.y0 = puff3.y;
1714
+ PROBE.z0 = puff3.z;
1715
+ PROBE.x1 = puff3.x + way.x * reach;
1716
+ PROBE.y1 = puff3.y + way.y * reach;
1717
+ PROBE.z1 = puff3.z + way.z * reach;
1718
+ PROBE.pad = 0;
1719
+ return confiner.confineMove(PROBE, 0) && confiner.out.ny <= GROUND_FACING;
1720
+ }
1721
+ var isFartherFrom = (puff3, a, b) => a.nx * puff3.x + a.ny * puff3.y + a.nz * puff3.z - a.d > b.nx * puff3.x + b.ny * puff3.y + b.nz * puff3.z - b.d;
1722
+ var isBehind = (puff3, face) => face.nx * puff3.x + face.ny * puff3.y + face.nz * puff3.z < face.d;
1723
+ var sameWall = (cut, face) => cut.on && cut.nx * face.nx + cut.ny * face.ny + cut.nz * face.nz > SAME_WALL;
1724
+ function cutFor(puff3, face) {
1725
+ const first = puff3.cuts[0];
1726
+ const second = puff3.cuts[1];
1727
+ if (sameWall(first, face)) return first;
1728
+ if (sameWall(second, face)) return second;
1729
+ if (!first.on) return first;
1730
+ if (!second.on) return second;
1731
+ const farther = isFartherFrom(puff3, first, second) ? first : second;
1732
+ return isFartherFrom(puff3, farther, face) ? farther : void 0;
1733
+ }
1734
+ function cutAtFace(puff3, face) {
1735
+ if (face.ny > GROUND_FACING) return;
1736
+ const cut = cutFor(puff3, face);
1737
+ if (!cut) return;
1738
+ cut.on = true;
1739
+ cut.nx = face.nx;
1740
+ cut.ny = face.ny;
1741
+ cut.nz = face.nz;
1742
+ cut.d = face.d;
1743
+ }
1744
+ function cutFrom(puff3, out) {
1745
+ cutAtFace(puff3, out);
1746
+ }
1747
+ function cutAt(confiner, puff3, way) {
1748
+ if (!probe(confiner, puff3, way)) return false;
1749
+ cutAtFace(puff3, confiner.out);
1750
+ return true;
1751
+ }
1752
+ function backward(puff3) {
1753
+ const speed = Math.sqrt(puff3.vx * puff3.vx + puff3.vy * puff3.vy + puff3.vz * puff3.vz);
1754
+ if (!(speed > 0)) return null;
1755
+ WAY.x = -puff3.vx / speed;
1756
+ WAY.y = -puff3.vy / speed;
1757
+ WAY.z = -puff3.vz / speed;
1758
+ return WAY;
1759
+ }
1760
+ function along(cut, sign) {
1761
+ WAY.x = sign * cut.nx;
1762
+ WAY.y = sign * cut.ny;
1763
+ WAY.z = sign * cut.nz;
1764
+ return WAY;
1765
+ }
1766
+ function dropPassed(confiner, puff3) {
1767
+ for (let i = 0; i < 2; i++) {
1768
+ const cut = puff3.cuts[i];
1769
+ if (!cut.on || !isBehind(puff3, cut)) continue;
1770
+ cut.on = false;
1771
+ cutAt(confiner, puff3, along(cut, 1));
1772
+ }
1773
+ }
1774
+ function keep(confiner, puff3, cut) {
1775
+ if (!cut.on) return;
1776
+ if (!probe(confiner, puff3, along(cut, -1))) {
1777
+ cut.on = false;
1778
+ return;
1779
+ }
1780
+ cut.d = confiner.out.d;
1781
+ }
1782
+ function lookForWalls(confiner, puff3) {
1783
+ dropPassed(confiner, puff3);
1784
+ const turn = Math.round(puff3.t * PROBES_PER_SECOND);
1785
+ if (turn <= 1) {
1786
+ const back = backward(puff3);
1787
+ if (back) cutAt(confiner, puff3, back);
1788
+ for (let i = 0; i < PROBES.length; i++) cutAt(confiner, puff3, PROBES[i]);
1789
+ return;
1790
+ }
1791
+ if (turn % FRAMES_PER_PROBE !== 0) return;
1792
+ const slot = turn / FRAMES_PER_PROBE % (PROBES.length + 3);
1793
+ if (slot < 2) keep(confiner, puff3, puff3.cuts[slot]);
1794
+ else if (slot === 2) {
1795
+ const back = backward(puff3);
1796
+ if (back) cutAt(confiner, puff3, back);
1797
+ } else cutAt(confiner, puff3, PROBES[slot - 3]);
1798
+ }
1799
+
1602
1800
  // src/pools/puffs.ts
1603
1801
  var FLOOR_FRACTION = 0.4;
1604
1802
  var FLOOR_BOUNCE = -0.2;
@@ -1639,7 +1837,8 @@ function createPuffPool(capacity) {
1639
1837
  age: 0,
1640
1838
  heat: 0,
1641
1839
  size: 0,
1642
- source: void 0
1840
+ source: void 0,
1841
+ cuts: [createCut(), createCut()]
1643
1842
  }));
1644
1843
  }
1645
1844
  function spawnPuff(pool, random, init) {
@@ -1673,6 +1872,7 @@ function spawnPuff(pool, random, init) {
1673
1872
  puff3.heat = 0;
1674
1873
  puff3.size = 0;
1675
1874
  puff3.source = init.source;
1875
+ clearCuts(puff3);
1676
1876
  return puff3;
1677
1877
  }
1678
1878
  function ageOrKeep2(puff3, dt) {
@@ -1722,17 +1922,21 @@ function updatePuffs(pool, dt, wind, confiner) {
1722
1922
  MOVE.z0 = puff3.z;
1723
1923
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
1724
1924
  else moveFree(puff3, dt, age, heat, wind);
1725
- if (confining && CARRIED_KINDS[puff3.kind] && confine(confiner, puff3, dt)) {
1925
+ const carried = confining && CARRIED_KINDS[puff3.kind];
1926
+ if (carried && confine(confiner, puff3, dt)) {
1726
1927
  const out = confiner.out;
1727
1928
  puff3.x = out.x;
1728
1929
  puff3.y = out.y;
1729
1930
  puff3.z = out.z;
1730
1931
  slideInto(out, puff3);
1932
+ cutFrom(puff3, out);
1731
1933
  }
1732
1934
  const size = puff3.s0 + (puff3.s1 - puff3.s0) * (1 - Math.exp(-puff3.t * puff3.gk)) + puff3.sg * Math.min(puff3.t, GROWTH_CAP_SECONDS);
1733
1935
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
1734
1936
  puff3.age = age;
1735
1937
  puff3.heat = heat;
1938
+ if (carried) lookForWalls(confiner, puff3);
1939
+ else clearCuts(puff3);
1736
1940
  }
1737
1941
  }
1738
1942
 
@@ -4860,10 +5064,10 @@ var DEFAULT_DIRECTION = [0, 0, -1];
4860
5064
  var MAX_SCALE = 3;
4861
5065
  var MIN_SCALE = 0.6;
4862
5066
  function reflected(direction, normal) {
4863
- const along = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
4864
- const out = [direction[0] - 2 * along * normal[0], direction[1] - 2 * along * normal[1], direction[2] - 2 * along * normal[2]];
5067
+ const along2 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
5068
+ const out = [direction[0] - 2 * along2 * normal[0], direction[1] - 2 * along2 * normal[1], direction[2] - 2 * along2 * normal[2]];
4865
5069
  const length = Math.hypot(out[0], out[1], out[2]);
4866
- if (length < 1e-6 || Math.abs(along) > 0.98) return normal;
5070
+ if (length < 1e-6 || Math.abs(along2) > 0.98) return normal;
4867
5071
  return [out[0] / length, out[1] / length, out[2] / length];
4868
5072
  }
4869
5073
  var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
@@ -5742,6 +5946,24 @@ function composeFlash(context) {
5742
5946
  screen2.flashDecay = 0.5;
5743
5947
  }
5744
5948
  }
5949
+ var BIRTH = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
5950
+ function bornFrom(core, puff3, ox, oy, oz) {
5951
+ const confiner = core.confiner;
5952
+ if (confiner.empty) return;
5953
+ BIRTH.x0 = ox;
5954
+ BIRTH.y0 = oy;
5955
+ BIRTH.z0 = oz;
5956
+ BIRTH.x1 = puff3.x;
5957
+ BIRTH.y1 = puff3.y;
5958
+ BIRTH.z1 = puff3.z;
5959
+ BIRTH.pad = puff3.s0 * PAD_OF_SIZE;
5960
+ if (!confiner.confineMove(BIRTH, 0)) return;
5961
+ const out = confiner.out;
5962
+ puff3.x = out.x;
5963
+ puff3.y = out.y;
5964
+ puff3.z = out.z;
5965
+ slideInto(out, puff3);
5966
+ }
5745
5967
  function composeFireballs(context) {
5746
5968
  const { core, def, random, x, y, z, size, scale, direction } = context;
5747
5969
  if (!core.layers.fire || !def.fireballs) return;
@@ -5758,7 +5980,7 @@ function composeFireballs(context) {
5758
5980
  const life = random.between(def.smoke.life * 0.7, def.smoke.life);
5759
5981
  const h0 = random.between(1.05, 1.35) * heat;
5760
5982
  const hl = fuel ? random.between(0.8, 1.4) * (def.heatLifeScale ?? 1) : random.between(0.22, 0.42);
5761
- addPuff(core, random, {
5983
+ const fireball = addPuff(core, random, {
5762
5984
  x: x + d.x * size * 0.15,
5763
5985
  y: y + size * 0.25 + d.y * size * 0.1,
5764
5986
  z: z + d.z * size * 0.15,
@@ -5777,6 +5999,7 @@ function composeFireballs(context) {
5777
5999
  color: context.smokeColor,
5778
6000
  kind: 0
5779
6001
  });
6002
+ bornFrom(core, fireball, x, y, z);
5780
6003
  }
5781
6004
  }
5782
6005
  function composeSmoke(context) {
@@ -5790,7 +6013,7 @@ function composeSmoke(context) {
5790
6013
  const s1 = size * random.between(0.55, 0.85);
5791
6014
  const sg = size * random.between(0.18, 0.3);
5792
6015
  const life = random.between(def.smoke.life * 0.7, def.smoke.life * 1.1);
5793
- addPuff(core, random, {
6016
+ const smoke = addPuff(core, random, {
5794
6017
  x: x + d.x * size * 0.6,
5795
6018
  y: y + size * 0.4 + d.y * size * 0.5,
5796
6019
  z: z + d.z * size * 0.6,
@@ -5809,6 +6032,7 @@ function composeSmoke(context) {
5809
6032
  color: context.smokeColor,
5810
6033
  kind: def.smoke.kind ?? 0
5811
6034
  });
6035
+ bornFrom(core, smoke, x, y, z);
5812
6036
  }
5813
6037
  }
5814
6038
  function composeShock(context) {
@@ -5820,7 +6044,7 @@ function composeShock(context) {
5820
6044
  spawnShock(core.shocks, spec);
5821
6045
  }
5822
6046
  function composeDust(context) {
5823
- const { core, def, random, x, z, size, scale } = context;
6047
+ const { core, def, random, x, y, z, size, scale } = context;
5824
6048
  if (!core.layers.smoke || !def.dust.count || !(scale > 0.15)) return;
5825
6049
  const count = Math.round(def.dust.count * scale);
5826
6050
  const color = hexToLinearRgb(def.dust.color);
@@ -5833,7 +6057,7 @@ function composeDust(context) {
5833
6057
  const s1 = size * random.between(0.5, 0.8);
5834
6058
  const sg = size * random.between(0.2, 0.35);
5835
6059
  const life = random.between(2.2, 4);
5836
- addPuff(core, random, {
6060
+ const dust = addPuff(core, random, {
5837
6061
  x: x + Math.cos(angle) * 0.3,
5838
6062
  y: 0.15,
5839
6063
  z: z + Math.sin(angle) * 0.3,
@@ -5850,6 +6074,7 @@ function composeDust(context) {
5850
6074
  color,
5851
6075
  kind: 1
5852
6076
  });
6077
+ bornFrom(core, dust, x, y, z);
5853
6078
  }
5854
6079
  }
5855
6080
  function coneAngle(context) {
@@ -6186,6 +6411,9 @@ function updateScreen(state, dt) {
6186
6411
 
6187
6412
  // src/sprites/kind-pool.ts
6188
6413
  var PAD_OF_SIZE2 = 0.35;
6414
+ var STEP = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
6415
+ var GROUND_RESAMPLE = 0.1;
6416
+ var VELOCITY = { vx: 0.5, vy: 0.5, vz: 0.5 };
6189
6417
  var clamp4 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
6190
6418
  var lerp4 = (a, b, t) => a + (b - a) * t;
6191
6419
  function rgb(hex) {
@@ -6233,6 +6461,8 @@ var SpriteKindPool = class {
6233
6461
  __publicField(this, "bounced");
6234
6462
  __publicField(this, "floor");
6235
6463
  __publicField(this, "riseMul");
6464
+ /** The ground under each sprite as last asked (`GROUND_RESAMPLE`): x and z where it was asked, and its height. NaN x: not asked yet. */
6465
+ __publicField(this, "ground");
6236
6466
  const n = Math.max(1, capacity);
6237
6467
  this.position = new Float32Array(n * 3);
6238
6468
  this.color = new Float32Array(n * 3);
@@ -6255,6 +6485,7 @@ var SpriteKindPool = class {
6255
6485
  this.bounced = new Uint8Array(n);
6256
6486
  this.floor = new Float32Array(n);
6257
6487
  this.riseMul = new Float32Array(n);
6488
+ this.ground = new Float32Array(n * 3);
6258
6489
  }
6259
6490
  spawn(kind, p, v, random, options) {
6260
6491
  if (this.capacity <= 0) return;
@@ -6282,6 +6513,7 @@ var SpriteKindPool = class {
6282
6513
  this.bounced[i] = 0;
6283
6514
  this.floor[i] = options?.floor ?? Number.NaN;
6284
6515
  this.riseMul[i] = options?.rise ?? 1;
6516
+ this.ground[i * 3] = Number.NaN;
6285
6517
  this.size[i] = this.size0[i];
6286
6518
  this.alpha[i] = 0;
6287
6519
  }
@@ -6375,18 +6607,36 @@ var SpriteKindPool = class {
6375
6607
  let z = this.position[i3 + 2] + vz2 * dt;
6376
6608
  const confiner = host.confiner;
6377
6609
  if (def.carried && confiner && !confiner.empty) {
6378
- const pad = this.size0[i] * lerp4(1, def.grow, t) * PAD_OF_SIZE2;
6379
- if (confiner.confine(this.position[i3], this.position[i3 + 1], this.position[i3 + 2], x, y, z, pad, dt)) {
6610
+ STEP.x0 = this.position[i3];
6611
+ STEP.y0 = this.position[i3 + 1];
6612
+ STEP.z0 = this.position[i3 + 2];
6613
+ STEP.x1 = x;
6614
+ STEP.y1 = y;
6615
+ STEP.z1 = z;
6616
+ STEP.pad = this.size0[i] * (1 + (def.grow - 1) * t) * PAD_OF_SIZE2;
6617
+ if (confiner.confineMove(STEP, dt)) {
6380
6618
  const out = confiner.out;
6381
6619
  x = out.x;
6382
6620
  y = out.y;
6383
6621
  z = out.z;
6384
- [vx2, vy2, vz2] = slideAlong(out, vx2, vy2, vz2);
6622
+ VELOCITY.vx = vx2;
6623
+ VELOCITY.vy = vy2;
6624
+ VELOCITY.vz = vz2;
6625
+ slideInto(out, VELOCITY);
6626
+ vx2 = VELOCITY.vx;
6627
+ vy2 = VELOCITY.vy;
6628
+ vz2 = VELOCITY.vz;
6385
6629
  }
6386
6630
  }
6387
6631
  if (def.ground !== "none") {
6388
6632
  const own = this.floor[i];
6389
- const gy = Number.isNaN(own) ? host.groundAt(x, z) + 5e-3 : own;
6633
+ const ground = this.ground;
6634
+ if (Number.isNaN(own) && !(Math.abs(x - ground[i3]) < GROUND_RESAMPLE && Math.abs(z - ground[i3 + 1]) < GROUND_RESAMPLE)) {
6635
+ ground[i3] = x;
6636
+ ground[i3 + 1] = z;
6637
+ ground[i3 + 2] = host.groundAt(x, z);
6638
+ }
6639
+ const gy = Number.isNaN(own) ? ground[i3 + 2] + 5e-3 : own;
6390
6640
  if (y < gy) {
6391
6641
  if (def.ground === "land") {
6392
6642
  const tag = this.tag[i];
@@ -7258,10 +7508,10 @@ var MeshPool = class {
7258
7508
  if (particle.fade) particle.opacity = Math.max(0, particle.startOpacity * (1 - particle.age / particle.life));
7259
7509
  particle.vy -= particle.gravity * dt;
7260
7510
  if (particle.drag) {
7261
- const keep = Math.max(0, 1 - particle.drag * dt);
7262
- particle.vx *= keep;
7263
- particle.vy *= keep;
7264
- particle.vz *= keep;
7511
+ const keep2 = Math.max(0, 1 - particle.drag * dt);
7512
+ particle.vx *= keep2;
7513
+ particle.vy *= keep2;
7514
+ particle.vz *= keep2;
7265
7515
  }
7266
7516
  if (particle.carried) this.ride(particle, dt);
7267
7517
  else {
@@ -7969,6 +8219,7 @@ function createVfx(options = {}) {
7969
8219
  });
7970
8220
  const core = {
7971
8221
  profile,
8222
+ confiner: enclosures,
7972
8223
  puffs: createPuffPool(profile.puffs),
7973
8224
  sparks: createSparkPool(profile.sparks),
7974
8225
  glows: createGlowPool(profile.glows),
@@ -8109,6 +8360,9 @@ function createVfx(options = {}) {
8109
8360
  enclose(id, enclosure) {
8110
8361
  enclosures.set(id, enclosure);
8111
8362
  },
8363
+ solid(id, query2) {
8364
+ enclosures.solid(id, query2);
8365
+ },
8112
8366
  enclosures: () => enclosures,
8113
8367
  stop(handle) {
8114
8368
  player?.stop(handle);
@@ -8116,10 +8370,10 @@ function createVfx(options = {}) {
8116
8370
  for (let index = fires.items.length - 1; index >= 0; index--) if (fires.items[index].handle === handle) fires.removeAt(index);
8117
8371
  },
8118
8372
  clearSource(source) {
8119
- const keep = (record, gone) => record.source !== gone;
8373
+ const keep2 = (record, gone) => record.source !== gone;
8120
8374
  const drop = (pool) => {
8121
8375
  const before = pool.count;
8122
- pool.compact(keep, source);
8376
+ pool.compact(keep2, source);
8123
8377
  return before - pool.count;
8124
8378
  };
8125
8379
  return drop(core.fires) + drop(core.puffs) + drop(core.sparks) + drop(core.chunks) + drop(core.glows) + spriteSystem.clearSource(source);
@@ -9293,10 +9547,10 @@ var MIST_DRAG = 1.2;
9293
9547
  function moveDrop(drop, context) {
9294
9548
  const { dt } = context;
9295
9549
  drop.age += dt;
9296
- const keep = Math.exp(-DROP_DRAG * dt);
9297
- drop.vx *= keep;
9298
- drop.vz *= keep;
9299
- drop.vy = drop.vy * keep - WATER_GRAVITY * dt;
9550
+ const keep2 = Math.exp(-DROP_DRAG * dt);
9551
+ drop.vx *= keep2;
9552
+ drop.vz *= keep2;
9553
+ drop.vy = drop.vy * keep2 - WATER_GRAVITY * dt;
9300
9554
  drop.x += drop.vx * dt;
9301
9555
  drop.y += drop.vy * dt;
9302
9556
  drop.z += drop.vz * dt;
@@ -9356,10 +9610,10 @@ function ageBubble(bubble, dt) {
9356
9610
  }
9357
9611
  function ageMist(mist, dt) {
9358
9612
  mist.age += dt;
9359
- const keep = Math.exp(-MIST_DRAG * dt);
9360
- mist.vx *= keep;
9361
- mist.vy = mist.vy * keep - 0.15 * dt;
9362
- mist.vz *= keep;
9613
+ const keep2 = Math.exp(-MIST_DRAG * dt);
9614
+ mist.vx *= keep2;
9615
+ mist.vy = mist.vy * keep2 - 0.15 * dt;
9616
+ mist.vz *= keep2;
9363
9617
  mist.x += mist.vx * dt;
9364
9618
  mist.y += mist.vy * dt;
9365
9619
  mist.z += mist.vz * dt;
@@ -9732,10 +9986,10 @@ function spawnTrail(context, point, plan) {
9732
9986
  const count = Math.min(TRAIL_BUBBLES_MAX, Math.round(plan.profile.bubblesPerMetre * plan.trailLength * context.detail));
9733
9987
  const [ex, ey, ez] = plan.trailEnd;
9734
9988
  for (let index = 0; index < count; index++) {
9735
- const along = random.next() ** 1.6;
9736
- const jitter = 0.01 + 0.02 * along;
9737
- const at3 = [point[0] + (ex - point[0]) * along + random.between(-jitter, jitter), point[1] + (ey - point[1]) * along, point[2] + (ez - point[2]) * along + random.between(-jitter, jitter)];
9738
- addBubble(context, at3, point[1], along * 0.05, random.between(3e-3, 0.01));
9989
+ const along2 = random.next() ** 1.6;
9990
+ const jitter = 0.01 + 0.02 * along2;
9991
+ const at3 = [point[0] + (ex - point[0]) * along2 + random.between(-jitter, jitter), point[1] + (ey - point[1]) * along2, point[2] + (ez - point[2]) * along2 + random.between(-jitter, jitter)];
9992
+ addBubble(context, at3, point[1], along2 * 0.05, random.between(3e-3, 0.01));
9739
9993
  }
9740
9994
  }
9741
9995
  function spawnBlast(context, point, level, plan) {
@@ -9975,6 +10229,7 @@ export {
9975
10229
  OrderedPool,
9976
10230
  PIECES_DRAWN_VARIABLE,
9977
10231
  PROFILES,
10232
+ PUFF_REACH,
9978
10233
  RAIN_CAPACITY,
9979
10234
  RainField,
9980
10235
  SCRAPE_LIMIT,