@adatechnology/game-vfx 0.20.0 → 0.21.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
@@ -1462,6 +1462,13 @@ var Solids = class {
1462
1462
  };
1463
1463
 
1464
1464
  // src/enclosures.ts
1465
+ function ceilingAt(s, x) {
1466
+ const c = s.ceiling;
1467
+ if (!c) return s.hy;
1468
+ const t = Math.min(1, Math.max(0, (x + s.hx) / (2 * s.hx))) * (c.length - 1);
1469
+ const i = Math.min(c.length - 2, Math.floor(t));
1470
+ return c[i] + (c[i + 1] - c[i]) * (t - i);
1471
+ }
1465
1472
  var SKIN2 = 5e-3;
1466
1473
  function rotation(q) {
1467
1474
  const [x, y, z, w] = q ?? [0, 0, 0, 1];
@@ -1491,8 +1498,15 @@ var Enclosures = class {
1491
1498
  __publicField(this, "l0", new Float64Array(3));
1492
1499
  __publicField(this, "l1", new Float64Array(3));
1493
1500
  __publicField(this, "q", new Float64Array(3));
1501
+ /** Of the step being tested, per local axis: the walls (`wallLo`, `wallHi`) and how far a particle held inside may go (`lo`, `hi`). */
1502
+ __publicField(this, "wallLo", new Float64Array(3));
1503
+ __publicField(this, "wallHi", new Float64Array(3));
1504
+ __publicField(this, "lo", new Float64Array(3));
1505
+ __publicField(this, "hi", new Float64Array(3));
1506
+ /** The last `through` passed by a plain opening (no rate), not by a gap's or the leak's chance. */
1507
+ __publicField(this, "plain", false);
1494
1508
  __publicField(this, "h", new Float64Array(3));
1495
- __publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 });
1509
+ __publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0, inner: -1 });
1496
1510
  __publicField(this, "solids", new Solids());
1497
1511
  this.random = lehmer(seed);
1498
1512
  }
@@ -1523,7 +1537,9 @@ var Enclosures = class {
1523
1537
  r: rotation(enclosure.orientation),
1524
1538
  radius: Math.hypot(hx, hy, hz),
1525
1539
  openings: enclosure.openings ?? [],
1526
- leak: Math.max(0, enclosure.leak ?? 0)
1540
+ leak: Math.max(0, enclosure.leak ?? 0),
1541
+ // a roof no higher than the box, and never under its floor
1542
+ ceiling: enclosure.ceiling && enclosure.ceiling.length >= 2 && Math.abs(hx) > 0 ? Float64Array.from(enclosure.ceiling, (y) => Math.min(Math.abs(hy), Math.max(-Math.abs(hy), y))) : null
1527
1543
  };
1528
1544
  const old = this.spaces.get(id);
1529
1545
  this.spaces.set(id, space);
@@ -1534,7 +1550,7 @@ var Enclosures = class {
1534
1550
  get(id) {
1535
1551
  const s = this.spaces.get(id);
1536
1552
  if (!s) return void 0;
1537
- return { center: [s.cx, s.cy, s.cz], halfSize: [s.hx, s.hy, s.hz], openings: s.openings, leak: s.leak };
1553
+ return { center: [s.cx, s.cy, s.cz], halfSize: [s.hx, s.hy, s.hz], openings: s.openings, leak: s.leak, ...s.ceiling ? { ceiling: [...s.ceiling] } : {} };
1538
1554
  }
1539
1555
  ids() {
1540
1556
  return [...this.spaces.keys()];
@@ -1547,7 +1563,7 @@ var Enclosures = class {
1547
1563
  inside(x, y, z) {
1548
1564
  for (const s of this.list) {
1549
1565
  this.toLocal(s, x, y, z, this.l0);
1550
- if (Math.abs(this.l0[0]) <= s.hx && Math.abs(this.l0[1]) <= s.hy && Math.abs(this.l0[2]) <= s.hz) return true;
1566
+ if (Math.abs(this.l0[0]) <= s.hx && this.l0[1] >= -s.hy && this.l0[1] <= ceilingAt(s, this.l0[0]) && Math.abs(this.l0[2]) <= s.hz) return true;
1551
1567
  }
1552
1568
  return false;
1553
1569
  }
@@ -1566,13 +1582,18 @@ var Enclosures = class {
1566
1582
  }
1567
1583
  /** The opening the wall point `q` (local) is in lets it through now. */
1568
1584
  through(s, q, dt) {
1585
+ this.plain = false;
1569
1586
  for (const o of s.openings) {
1570
1587
  if (Math.abs(q[0] - o.center[0]) > o.halfSize[0] || Math.abs(q[1] - o.center[1]) > o.halfSize[1] || Math.abs(q[2] - o.center[2]) > o.halfSize[2]) continue;
1571
- if (o.rate === void 0 || this.chance(o.rate, dt)) return true;
1588
+ if (o.rate === void 0) {
1589
+ this.plain = true;
1590
+ return true;
1591
+ }
1592
+ if (this.chance(o.rate, dt)) return true;
1572
1593
  }
1573
1594
  return this.chance(s.leak, dt);
1574
1595
  }
1575
- confine(x0, y0, z0, x1, y1, z1, pad, dt) {
1596
+ confine(x0, y0, z0, x1, y1, z1, pad, dt, inner = -1) {
1576
1597
  const move = this.move;
1577
1598
  move.x0 = x0;
1578
1599
  move.y0 = y0;
@@ -1581,6 +1602,7 @@ var Enclosures = class {
1581
1602
  move.y1 = y1;
1582
1603
  move.z1 = z1;
1583
1604
  move.pad = pad;
1605
+ move.inner = inner;
1584
1606
  return this.confineMove(move, dt);
1585
1607
  }
1586
1608
  confineMove(move, dt) {
@@ -1592,6 +1614,7 @@ var Enclosures = class {
1592
1614
  if (list.length === 0) return false;
1593
1615
  const { x0, y0, z0, x1, y1, z1 } = move;
1594
1616
  const p = Math.min(Math.max(0, move.pad), MAX_PAD);
1617
+ const inner = move.inner < 0 ? p : move.inner;
1595
1618
  const l0 = this.l0;
1596
1619
  const l1 = this.l1;
1597
1620
  const q = this.q;
@@ -1612,40 +1635,65 @@ var Enclosures = class {
1612
1635
  h[0] = s.hx;
1613
1636
  h[1] = s.hy;
1614
1637
  h[2] = s.hz;
1615
- const in0 = Math.abs(l0[0]) <= s.hx && Math.abs(l0[1]) <= s.hy && Math.abs(l0[2]) <= s.hz;
1638
+ const top0 = ceilingAt(s, l0[0]);
1639
+ const top = ceilingAt(s, l1[0]);
1640
+ const in0 = Math.abs(l0[0]) <= s.hx && l0[1] >= -s.hy && l0[1] <= top0 && Math.abs(l0[2]) <= s.hz;
1616
1641
  let axis2 = 0;
1617
1642
  let sign = 1;
1643
+ let outward = false;
1644
+ let face = 0;
1618
1645
  if (in0) {
1619
- if (Math.abs(l1[0]) <= s.hx && Math.abs(l1[1]) <= s.hy && Math.abs(l1[2]) <= s.hz) continue;
1620
- for (let a = 0; a < 3; a++) q[a] = Math.min(h[a], Math.max(-h[a], l1[a]));
1621
- if (this.through(s, q, dt)) continue;
1646
+ const { wallLo, wallHi, lo, hi } = this;
1647
+ let pressing = false;
1648
+ for (let a = 0; a < 3; a++) {
1649
+ wallLo[a] = -h[a];
1650
+ wallHi[a] = a === 1 ? top : h[a];
1651
+ const off = Math.min(inner, (wallHi[a] - wallLo[a]) * 0.25);
1652
+ lo[a] = wallLo[a] + off;
1653
+ hi[a] = wallHi[a] - off;
1654
+ if (l1[a] > hi[a] || l1[a] < lo[a]) pressing = true;
1655
+ }
1656
+ if (!pressing) continue;
1622
1657
  let worst = -Infinity;
1658
+ let gated = false;
1623
1659
  for (let a = 0; a < 3; a++) {
1624
- const over = Math.abs(l1[a]) - h[a];
1660
+ const over = Math.max(l1[a] - hi[a], lo[a] - l1[a]);
1661
+ q[a] = over > 0 ? l1[a] < lo[a] ? wallLo[a] : wallHi[a] : l1[a];
1625
1662
  if (over > worst) {
1626
1663
  worst = over;
1627
1664
  axis2 = a;
1628
1665
  }
1629
1666
  }
1630
- sign = l1[axis2] < 0 ? -1 : 1;
1631
- for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN2, Math.max(-(h[a] - SKIN2), l1[a]));
1632
- sign = -sign;
1667
+ sign = l1[axis2] < lo[axis2] ? -1 : 1;
1668
+ face = sign > 0 ? wallHi[axis2] : -wallLo[axis2];
1669
+ if (this.through(s, q, dt)) {
1670
+ if (this.plain) continue;
1671
+ gated = true;
1672
+ l1[axis2] = sign * (face + SKIN2);
1673
+ } else {
1674
+ for (let a = 0; a < 3; a++) l1[a] = Math.min(Math.min(hi[a], wallHi[a] - SKIN2), Math.max(Math.max(lo[a], wallLo[a] + SKIN2), l1[a]));
1675
+ sign = -sign;
1676
+ }
1677
+ outward = gated;
1633
1678
  } else {
1634
- const padded0 = Math.abs(l0[0]) <= s.hx + p && Math.abs(l0[1]) <= s.hy + p && Math.abs(l0[2]) <= s.hz + p;
1679
+ const padded0 = Math.abs(l0[0]) <= s.hx + p && l0[1] >= -s.hy - p && l0[1] <= top0 + p && Math.abs(l0[2]) <= s.hz + p;
1635
1680
  const bound = padded0 ? 0 : p;
1636
- if (!(Math.abs(l1[0]) <= s.hx + bound && Math.abs(l1[1]) <= s.hy + bound && Math.abs(l1[2]) <= s.hz + bound)) continue;
1637
- for (let a = 0; a < 3; a++) q[a] = Math.min(h[a], Math.max(-h[a], l1[a]));
1681
+ if (!(Math.abs(l1[0]) <= s.hx + bound && l1[1] >= -s.hy - bound && l1[1] <= top + bound && Math.abs(l1[2]) <= s.hz + bound)) continue;
1682
+ q[0] = Math.min(h[0], Math.max(-h[0], l1[0]));
1683
+ q[1] = Math.min(top, Math.max(-h[1], l1[1]));
1684
+ q[2] = Math.min(h[2], Math.max(-h[2], l1[2]));
1638
1685
  if (this.through(s, q, dt)) continue;
1639
1686
  let worst = -Infinity;
1640
1687
  for (let a = 0; a < 3; a++) {
1641
- const over = Math.abs(l0[a]) - (h[a] + bound);
1688
+ const over = a === 1 ? Math.max(l0[1] - (top0 + bound), -l0[1] - (h[1] + bound)) : Math.abs(l0[a]) - (h[a] + bound);
1642
1689
  if (over > worst) {
1643
1690
  worst = over;
1644
1691
  axis2 = a;
1645
1692
  }
1646
1693
  }
1647
- sign = l0[axis2] < 0 ? -1 : 1;
1648
- l1[axis2] = sign * (h[axis2] + bound + SKIN2);
1694
+ sign = axis2 === 1 ? l0[1] - top0 >= -l0[1] - h[1] ? 1 : -1 : l0[axis2] < 0 ? -1 : 1;
1695
+ face = axis2 === 1 && sign > 0 ? top : h[axis2];
1696
+ l1[axis2] = sign * (face + bound + SKIN2);
1649
1697
  }
1650
1698
  const r = s.r;
1651
1699
  const out = this.out;
@@ -1655,7 +1703,7 @@ var Enclosures = class {
1655
1703
  out.nx = r[axis2] * sign;
1656
1704
  out.ny = r[3 + axis2] * sign;
1657
1705
  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]);
1706
+ out.d = out.nx * s.cx + out.ny * s.cy + out.nz * s.cz + (in0 && !outward ? -face : face);
1659
1707
  return true;
1660
1708
  }
1661
1709
  return false;
@@ -1675,13 +1723,14 @@ function slideAlong(out, vx2, vy2, vz2) {
1675
1723
  }
1676
1724
 
1677
1725
  // src/pools/puff-cuts.ts
1726
+ var PUFF_CUTS = 3;
1678
1727
  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 }];
1728
+ var PROBES = [Float64Array.of(1, 0, 0), Float64Array.of(-1, 0, 0), Float64Array.of(0, 0, 1), Float64Array.of(0, 0, -1), Float64Array.of(0, 1, 0)];
1680
1729
  var PROBES_PER_SECOND = 60;
1681
1730
  var FRAMES_PER_PROBE = 3;
1682
1731
  var GROUND_FACING = 0.7;
1683
1732
  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 };
1733
+ var PROBE = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5, inner: -0.5 };
1685
1734
  var KeptCut = class {
1686
1735
  constructor() {
1687
1736
  __publicField(this, "on", false);
@@ -1695,41 +1744,44 @@ function createCut() {
1695
1744
  return new KeptCut();
1696
1745
  }
1697
1746
  function clearCuts(puff3) {
1698
- puff3.cuts[0].on = false;
1699
- puff3.cuts[1].on = false;
1747
+ for (let i = 0; i < PUFF_CUTS; i++) puff3.cuts[i].on = false;
1700
1748
  }
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();
1749
+ var WAY = new Float64Array(3);
1750
+ var PASSED = 0.02;
1709
1751
  function probe(confiner, puff3, way) {
1710
- const reach = puff3.size * PUFF_REACH;
1752
+ const reach = puff3.size * (puff3.reachOfSize ?? PUFF_REACH);
1711
1753
  if (!(reach > 0)) return false;
1712
1754
  PROBE.x0 = puff3.x;
1713
1755
  PROBE.y0 = puff3.y;
1714
1756
  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;
1757
+ PROBE.x1 = puff3.x + way[0] * reach;
1758
+ PROBE.y1 = puff3.y + way[1] * reach;
1759
+ PROBE.z1 = puff3.z + way[2] * reach;
1760
+ PROBE.pad = 0;
1761
+ return confiner.confineMove(PROBE, 0) && confiner.out.ny <= GROUND_FACING;
1762
+ }
1763
+ function probeAgain(confiner, puff3, way) {
1764
+ const reach = puff3.size * (puff3.reachOfSize ?? PUFF_REACH);
1765
+ if (!(reach > 0)) return false;
1766
+ PROBE.x0 = puff3.x - way[0] * PASSED;
1767
+ PROBE.y0 = puff3.y - way[1] * PASSED;
1768
+ PROBE.z0 = puff3.z - way[2] * PASSED;
1769
+ PROBE.x1 = puff3.x + way[0] * reach;
1770
+ PROBE.y1 = puff3.y + way[1] * reach;
1771
+ PROBE.z1 = puff3.z + way[2] * reach;
1718
1772
  PROBE.pad = 0;
1719
1773
  return confiner.confineMove(PROBE, 0) && confiner.out.ny <= GROUND_FACING;
1720
1774
  }
1721
1775
  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;
1776
+ var isBehind = (puff3, face) => face.nx * puff3.x + face.ny * puff3.y + face.nz * puff3.z < face.d - PASSED;
1723
1777
  var sameWall = (cut, face) => cut.on && cut.nx * face.nx + cut.ny * face.ny + cut.nz * face.nz > SAME_WALL;
1724
1778
  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;
1779
+ const cuts = puff3.cuts;
1780
+ for (let i = 0; i < PUFF_CUTS; i++) if (sameWall(cuts[i], face)) return cuts[i];
1781
+ for (let i = 0; i < PUFF_CUTS; i++) if (!cuts[i].on) return cuts[i];
1782
+ let farthest = cuts[0];
1783
+ for (let i = 1; i < PUFF_CUTS; i++) if (isFartherFrom(puff3, cuts[i], farthest)) farthest = cuts[i];
1784
+ return isFartherFrom(puff3, farthest, face) ? farthest : void 0;
1733
1785
  }
1734
1786
  function cutAtFace(puff3, face) {
1735
1787
  if (face.ny > GROUND_FACING) return;
@@ -1752,28 +1804,35 @@ function cutAt(confiner, puff3, way) {
1752
1804
  function backward(puff3) {
1753
1805
  const speed = Math.sqrt(puff3.vx * puff3.vx + puff3.vy * puff3.vy + puff3.vz * puff3.vz);
1754
1806
  if (!(speed > 0)) return null;
1755
- WAY.x = -puff3.vx / speed;
1756
- WAY.y = -puff3.vy / speed;
1757
- WAY.z = -puff3.vz / speed;
1807
+ WAY[0] = -puff3.vx / speed;
1808
+ WAY[1] = -puff3.vy / speed;
1809
+ WAY[2] = -puff3.vz / speed;
1758
1810
  return WAY;
1759
1811
  }
1760
1812
  function along(cut, sign) {
1761
- WAY.x = sign * cut.nx;
1762
- WAY.y = sign * cut.ny;
1763
- WAY.z = sign * cut.nz;
1813
+ WAY[0] = sign * cut.nx;
1814
+ WAY[1] = sign * cut.ny;
1815
+ WAY[2] = sign * cut.nz;
1764
1816
  return WAY;
1765
1817
  }
1766
1818
  function dropPassed(confiner, puff3) {
1767
- for (let i = 0; i < 2; i++) {
1819
+ for (let i = 0; i < PUFF_CUTS; i++) {
1768
1820
  const cut = puff3.cuts[i];
1769
1821
  if (!cut.on || !isBehind(puff3, cut)) continue;
1770
1822
  cut.on = false;
1823
+ const nx = cut.nx;
1824
+ const ny = cut.ny;
1825
+ const nz = cut.nz;
1771
1826
  cutAt(confiner, puff3, along(cut, 1));
1827
+ WAY[0] = -nx;
1828
+ WAY[1] = -ny;
1829
+ WAY[2] = -nz;
1830
+ cutAt(confiner, puff3, WAY);
1772
1831
  }
1773
1832
  }
1774
1833
  function keep(confiner, puff3, cut) {
1775
1834
  if (!cut.on) return;
1776
- if (!probe(confiner, puff3, along(cut, -1))) {
1835
+ if (!probeAgain(confiner, puff3, along(cut, -1))) {
1777
1836
  cut.on = false;
1778
1837
  return;
1779
1838
  }
@@ -1789,12 +1848,12 @@ function lookForWalls(confiner, puff3) {
1789
1848
  return;
1790
1849
  }
1791
1850
  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) {
1851
+ const slot = (turn / FRAMES_PER_PROBE | 0) % (PROBES.length + PUFF_CUTS + 1);
1852
+ if (slot < PUFF_CUTS) keep(confiner, puff3, puff3.cuts[slot]);
1853
+ else if (slot === PUFF_CUTS) {
1795
1854
  const back = backward(puff3);
1796
1855
  if (back) cutAt(confiner, puff3, back);
1797
- } else cutAt(confiner, puff3, PROBES[slot - 3]);
1856
+ } else cutAt(confiner, puff3, PROBES[slot - PUFF_CUTS - 1]);
1798
1857
  }
1799
1858
 
1800
1859
  // src/pools/puffs.ts
@@ -1805,7 +1864,7 @@ var ARRIVAL_BASE = 0.3;
1805
1864
  var GROWTH_CAP_SECONDS = 3.5;
1806
1865
  var CARRIED_KINDS = [true, true, false, true, false];
1807
1866
  var PAD_OF_SIZE = 0.35;
1808
- var MOVE = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
1867
+ var MOVE = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0, inner: 0 };
1809
1868
  function createPuffPool(capacity) {
1810
1869
  const placeholder = { next: () => 0, between: (min2) => min2, direction: (out) => out, state: 0 };
1811
1870
  return new OrderedPool(capacity, () => ({
@@ -1838,7 +1897,7 @@ function createPuffPool(capacity) {
1838
1897
  heat: 0,
1839
1898
  size: 0,
1840
1899
  source: void 0,
1841
- cuts: [createCut(), createCut()]
1900
+ cuts: [createCut(), createCut(), createCut()]
1842
1901
  }));
1843
1902
  }
1844
1903
  function spawnPuff(pool, random, init) {
@@ -1890,7 +1949,9 @@ function moveOnRing(puff3, ring2, wind) {
1890
1949
  puff3.z = ring2.z + Math.sin(puff3.ph) * radius + wind.z * ringTime * 0.6;
1891
1950
  puff3.y = centerY + minorRadius * Math.sin(theta);
1892
1951
  }
1893
- function moveFree(puff3, dt, age, heat, wind) {
1952
+ function moveFree(puff3, dt, wind) {
1953
+ const age = puff3.age;
1954
+ const heat = puff3.heat;
1894
1955
  const damping = Math.exp(-puff3.drag * dt);
1895
1956
  puff3.vx *= damping;
1896
1957
  puff3.vy *= damping;
@@ -1909,19 +1970,20 @@ function confine(confiner, puff3, dt) {
1909
1970
  MOVE.y1 = puff3.y;
1910
1971
  MOVE.z1 = puff3.z;
1911
1972
  MOVE.pad = puff3.size * PAD_OF_SIZE;
1973
+ MOVE.inner = puff3.size * 0.5;
1912
1974
  return confiner.confineMove(MOVE, dt);
1913
1975
  }
1914
1976
  function updatePuffs(pool, dt, wind, confiner) {
1915
1977
  pool.compact(ageOrKeep2, dt);
1916
1978
  const confining = confiner !== void 0 && !confiner.empty;
1917
1979
  for (const puff3 of pool.items) {
1918
- const age = puff3.t / puff3.life;
1919
- const heat = puff3.h0 > 0 ? puff3.h0 * Math.pow(Math.max(0, 1 - puff3.t / puff3.hl), 1.25) : 0;
1980
+ puff3.age = puff3.t / puff3.life;
1981
+ puff3.heat = puff3.h0 > 0 ? puff3.h0 * Math.pow(Math.max(0, 1 - puff3.t / puff3.hl), 1.25) : 0;
1920
1982
  MOVE.x0 = puff3.x;
1921
1983
  MOVE.y0 = puff3.y;
1922
1984
  MOVE.z0 = puff3.z;
1923
1985
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
1924
- else moveFree(puff3, dt, age, heat, wind);
1986
+ else moveFree(puff3, dt, wind);
1925
1987
  const carried = confining && CARRIED_KINDS[puff3.kind];
1926
1988
  if (carried && confine(confiner, puff3, dt)) {
1927
1989
  const out = confiner.out;
@@ -1933,8 +1995,6 @@ function updatePuffs(pool, dt, wind, confiner) {
1933
1995
  }
1934
1996
  const size = puff3.s0 + (puff3.s1 - puff3.s0) * (1 - Math.exp(-puff3.t * puff3.gk)) + puff3.sg * Math.min(puff3.t, GROWTH_CAP_SECONDS);
1935
1997
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
1936
- puff3.age = age;
1937
- puff3.heat = heat;
1938
1998
  if (carried) lookForWalls(confiner, puff3);
1939
1999
  else clearCuts(puff3);
1940
2000
  }
@@ -5867,7 +5927,7 @@ var TRAIL_SECONDS = 1.8;
5867
5927
  var TRAIL_STEP = 0.025;
5868
5928
  var QUARTER_TURN3 = Math.PI / 2;
5869
5929
  var TOP_FACING = 0.7;
5870
- var MOVE2 = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
5930
+ var MOVE2 = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5, inner: -0.5 };
5871
5931
  function bounce(core, chunk, floor2) {
5872
5932
  chunk.y = floor2;
5873
5933
  if (chunk.blood && !chunk.splat && core.layers.mark) {
@@ -6080,7 +6140,7 @@ function composeFlash(context) {
6080
6140
  screen2.flashDecay = 0.5;
6081
6141
  }
6082
6142
  }
6083
- var BIRTH = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
6143
+ var BIRTH = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0, inner: -1 };
6084
6144
  function bornFrom(core, puff3, ox, oy, oz) {
6085
6145
  const confiner = core.confiner;
6086
6146
  if (confiner.empty) return;
@@ -6492,9 +6552,26 @@ function updateScreen(state, dt) {
6492
6552
 
6493
6553
  // src/sprites/kind-pool.ts
6494
6554
  var PAD_OF_SIZE2 = 0.35;
6495
- var STEP = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
6555
+ var STEP = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5, inner: 0.5 };
6496
6556
  var GROUND_RESAMPLE = 0.1;
6497
6557
  var VELOCITY = { vx: 0.5, vy: 0.5, vz: 0.5 };
6558
+ var SPRITE_REACH = 1;
6559
+ var NO_CUT = -1e9;
6560
+ var SpriteCutView = class {
6561
+ constructor() {
6562
+ __publicField(this, "x", 0.5);
6563
+ __publicField(this, "y", 0.5);
6564
+ __publicField(this, "z", 0.5);
6565
+ __publicField(this, "vx", 0.5);
6566
+ __publicField(this, "vy", 0.5);
6567
+ __publicField(this, "vz", 0.5);
6568
+ __publicField(this, "t", 0.5);
6569
+ __publicField(this, "size", 0.5);
6570
+ __publicField(this, "reachOfSize", SPRITE_REACH);
6571
+ __publicField(this, "cuts", [createCut(), createCut(), createCut()]);
6572
+ }
6573
+ };
6574
+ var VIEW = new SpriteCutView();
6498
6575
  var clamp4 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
6499
6576
  var lerp4 = (a, b, t) => a + (b - a) * t;
6500
6577
  function rgb(hex) {
@@ -6523,6 +6600,14 @@ var SpriteKindPool = class {
6523
6600
  __publicField(this, "color");
6524
6601
  __publicField(this, "alpha");
6525
6602
  __publicField(this, "size");
6603
+ /**
6604
+ * The faces of the walls each carried sprite (smoke, steam, dust) is cut at, three of them (`PUFF_CUTS`: a corner), four numbers a sprite in each: unit normal towards the sprite and offset
6605
+ * (`n · point`), `(0, 0, 0, NO_CUT)` for none. The renderer drops the part of the drawn square behind a face: a puff against a wall flattens on it and
6606
+ * shows nothing on the wall's other side, as a puff's ball does (`Puff.cuts`).
6607
+ */
6608
+ __publicField(this, "cutA");
6609
+ __publicField(this, "cutB");
6610
+ __publicField(this, "cutC");
6526
6611
  __publicField(this, "next", 0);
6527
6612
  __publicField(this, "high", 0);
6528
6613
  __publicField(this, "velocity");
@@ -6549,6 +6634,10 @@ var SpriteKindPool = class {
6549
6634
  this.color = new Float32Array(n * 3);
6550
6635
  this.alpha = new Float32Array(n);
6551
6636
  this.size = new Float32Array(n);
6637
+ this.cutA = new Float32Array(n * 4);
6638
+ this.cutB = new Float32Array(n * 4);
6639
+ this.cutC = new Float32Array(n * 4);
6640
+ for (let i = 0; i < n; i++) this.uncut(i);
6552
6641
  this.velocity = new Float32Array(n * 3);
6553
6642
  this.age = new Float32Array(n);
6554
6643
  this.life = new Float32Array(n);
@@ -6597,6 +6686,51 @@ var SpriteKindPool = class {
6597
6686
  this.ground[i * 3] = Number.NaN;
6598
6687
  this.size[i] = this.size0[i];
6599
6688
  this.alpha[i] = 0;
6689
+ this.uncut(i);
6690
+ }
6691
+ /** Sprite `i` cut at no wall. */
6692
+ uncut(i) {
6693
+ this.cutA.fill(0, i * 4, i * 4 + 3);
6694
+ this.cutA[i * 4 + 3] = NO_CUT;
6695
+ this.cutB.fill(0, i * 4, i * 4 + 3);
6696
+ this.cutB[i * 4 + 3] = NO_CUT;
6697
+ this.cutC.fill(0, i * 4, i * 4 + 3);
6698
+ this.cutC[i * 4 + 3] = NO_CUT;
6699
+ }
6700
+ /**
6701
+ * Looks for the walls carried sprite `i` reaches (as a puff's ball does: `lookForWalls`), `met` the face its step was just stopped at, and keeps them in `cuts`.
6702
+ * The sprite's faces go into the reused `VIEW` and come back out: no object a sprite.
6703
+ */
6704
+ cutAtWalls(i, confiner, met) {
6705
+ const o = i * 4;
6706
+ const i3 = i * 3;
6707
+ VIEW.x = this.position[i3];
6708
+ VIEW.y = this.position[i3 + 1];
6709
+ VIEW.z = this.position[i3 + 2];
6710
+ VIEW.vx = this.velocity[i3];
6711
+ VIEW.vy = this.velocity[i3 + 1];
6712
+ VIEW.vz = this.velocity[i3 + 2];
6713
+ VIEW.t = this.age[i];
6714
+ VIEW.size = this.size[i];
6715
+ for (let k = 0; k < PUFF_CUTS; k++) {
6716
+ const cut = VIEW.cuts[k];
6717
+ const faces = k === 0 ? this.cutA : k === 1 ? this.cutB : this.cutC;
6718
+ cut.on = faces[o + 3] !== NO_CUT;
6719
+ cut.nx = faces[o];
6720
+ cut.ny = faces[o + 1];
6721
+ cut.nz = faces[o + 2];
6722
+ cut.d = faces[o + 3];
6723
+ }
6724
+ if (met) cutFrom(VIEW, met);
6725
+ lookForWalls(confiner, VIEW);
6726
+ for (let k = 0; k < PUFF_CUTS; k++) {
6727
+ const cut = VIEW.cuts[k];
6728
+ const faces = k === 0 ? this.cutA : k === 1 ? this.cutB : this.cutC;
6729
+ faces[o] = cut.on ? cut.nx : 0;
6730
+ faces[o + 1] = cut.on ? cut.ny : 0;
6731
+ faces[o + 2] = cut.on ? cut.nz : 0;
6732
+ faces[o + 3] = cut.on ? cut.d : NO_CUT;
6733
+ }
6600
6734
  }
6601
6735
  ownerIndex(name) {
6602
6736
  let index = this.owners.indexOf(name);
@@ -6687,7 +6821,9 @@ var SpriteKindPool = class {
6687
6821
  let y = this.position[i3 + 1] + vy2 * dt;
6688
6822
  let z = this.position[i3 + 2] + vz2 * dt;
6689
6823
  const confiner = host.confiner;
6690
- if (def.carried && confiner && !confiner.empty) {
6824
+ const confining = def.carried && confiner !== void 0 && !confiner.empty;
6825
+ let met = false;
6826
+ if (confining) {
6691
6827
  STEP.x0 = this.position[i3];
6692
6828
  STEP.y0 = this.position[i3 + 1];
6693
6829
  STEP.z0 = this.position[i3 + 2];
@@ -6695,7 +6831,9 @@ var SpriteKindPool = class {
6695
6831
  STEP.y1 = y;
6696
6832
  STEP.z1 = z;
6697
6833
  STEP.pad = this.size0[i] * (1 + (def.grow - 1) * t) * PAD_OF_SIZE2;
6834
+ STEP.inner = STEP.pad * (0.5 / PAD_OF_SIZE2);
6698
6835
  if (confiner.confineMove(STEP, dt)) {
6836
+ met = true;
6699
6837
  const out = confiner.out;
6700
6838
  x = out.x;
6701
6839
  y = out.y;
@@ -6744,6 +6882,8 @@ var SpriteKindPool = class {
6744
6882
  this.position[i3 + 1] = y;
6745
6883
  this.position[i3 + 2] = z;
6746
6884
  this.size[i] = this.size0[i] * lerp4(1, def.grow, t);
6885
+ if (confining) this.cutAtWalls(i, confiner, met ? confiner.out : null);
6886
+ else if (def.carried && (this.cutA[i * 4 + 3] !== NO_CUT || this.cutB[i * 4 + 3] !== NO_CUT || this.cutC[i * 4 + 3] !== NO_CUT)) this.uncut(i);
6747
6887
  this.color[i3] = lerp4(this.rgbStart[i3], this.rgbEnd[i3], t);
6748
6888
  this.color[i3 + 1] = lerp4(this.rgbStart[i3 + 1], this.rgbEnd[i3 + 1], t);
6749
6889
  this.color[i3 + 2] = lerp4(this.rgbStart[i3 + 2], this.rgbEnd[i3 + 2], t);
@@ -6780,7 +6920,8 @@ var sprite_kinds_default = {
6780
6920
  fadeIn: 0.12,
6781
6921
  cone: 0.7,
6782
6922
  ground: "none",
6783
- flicker: 0.35
6923
+ flicker: 0.35,
6924
+ carried: true
6784
6925
  },
6785
6926
  smoke: {
6786
6927
  id: "smoke",
@@ -7642,12 +7783,11 @@ var FLOATS_PER_VECTOR = 3;
7642
7783
  var BYTE_MAX2 = 255;
7643
7784
  var CARRIED_GRAVITY = 3;
7644
7785
  var PAD_OF_SIZE3 = 0.35;
7786
+ var INNER_OF_SIZE = 0.5;
7645
7787
  var SpritePool = class {
7646
- /** `carried`: the normal-blend pool (smoke, dust, steam), whose light sprites go round the closed spaces; the additive one (flames, sparks) does not. */
7647
- constructor(capacity, context, carried = false) {
7788
+ constructor(capacity, context) {
7648
7789
  __publicField(this, "capacity", capacity);
7649
7790
  __publicField(this, "context", context);
7650
- __publicField(this, "carried", carried);
7651
7791
  __publicField(this, "count", 0);
7652
7792
  __publicField(this, "position");
7653
7793
  __publicField(this, "velocity");
@@ -7768,9 +7908,9 @@ var SpritePool = class {
7768
7908
  position[offset] += velocity[offset] * dt;
7769
7909
  position[offset + 1] += velocity[offset + 1] * dt;
7770
7910
  position[offset + 2] += velocity[offset + 2] * dt;
7771
- if (this.carried && confiner && !confiner.empty && Math.abs(this.gravity[index]) < CARRIED_GRAVITY) {
7911
+ if (confiner && !confiner.empty && Math.abs(this.gravity[index]) < CARRIED_GRAVITY) {
7772
7912
  const size = this.startSize[index] * (1 + (this.growth[index] - 1) * age);
7773
- if (confiner.confine(x0, y0, z0, position[offset], position[offset + 1], position[offset + 2], size * PAD_OF_SIZE3, dt)) {
7913
+ if (confiner.confine(x0, y0, z0, position[offset], position[offset + 1], position[offset + 2], size * PAD_OF_SIZE3, dt, size * INNER_OF_SIZE)) {
7774
7914
  const out = confiner.out;
7775
7915
  position[offset] = out.x;
7776
7916
  position[offset + 1] = out.y;
@@ -8074,7 +8214,7 @@ var WorkshopEngine = class {
8074
8214
  const profile = options.profile ?? PROFILES.high;
8075
8215
  this.context = { random: options.random, groundAt: options.groundAt ?? workshopGround, quality: { level: 0, mult: 1 }, trace: options.trace, ...options.confiner ? { confiner: options.confiner } : {} };
8076
8216
  this.add = new SpritePool(profile.sprites.add, this.context);
8077
- this.normal = new SpritePool(profile.sprites.normal, this.context, true);
8217
+ this.normal = new SpritePool(profile.sprites.normal, this.context);
8078
8218
  this.streaks = new StreakPool(profile.streaks, this.context);
8079
8219
  this.debris = new DebrisPool(this.context);
8080
8220
  this.decals = new DecalPool(this.context);
@@ -10310,12 +10450,14 @@ export {
10310
10450
  OrderedPool,
10311
10451
  PIECES_DRAWN_VARIABLE,
10312
10452
  PROFILES,
10453
+ PUFF_CUTS,
10313
10454
  PUFF_REACH,
10314
10455
  RAIN_CAPACITY,
10315
10456
  RainField,
10316
10457
  SCRAPE_LIMIT,
10317
10458
  SMOKE_COLORS,
10318
10459
  SPRITE_KINDS,
10460
+ NO_CUT as SPRITE_NO_CUT,
10319
10461
  SpriteKindPool,
10320
10462
  SpriteKindSystem,
10321
10463
  VFX_LAYERS,