@adatechnology/game-vfx-three 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1233,11 +1233,11 @@ var GameVfxThree = (() => {
1233
1233
  this.spare.push(record);
1234
1234
  }
1235
1235
  /** Keeps the records `keep` accepts, in the same order, without allocating. `context` goes to `keep` so no closure is needed per frame. */
1236
- compact(keep, context) {
1236
+ compact(keep2, context) {
1237
1237
  let write = 0;
1238
1238
  for (let read = 0; read < this.items.length; read++) {
1239
1239
  const record = this.items[read];
1240
- if (keep(record, context)) {
1240
+ if (keep2(record, context)) {
1241
1241
  this.items[write++] = record;
1242
1242
  continue;
1243
1243
  }
@@ -1487,8 +1487,70 @@ var GameVfxThree = (() => {
1487
1487
  function streamFor(eventSeed) {
1488
1488
  return lehmer(mixEventSeed(eventSeed));
1489
1489
  }
1490
- var SKIN = 5e-3;
1491
1490
  var MAX_PAD = 0.45;
1491
+ var SKIN = 5e-3;
1492
+ var Solids = class {
1493
+ constructor() {
1494
+ __publicField(this, "queries", /* @__PURE__ */ new Map());
1495
+ __publicField(this, "list", []);
1496
+ __publicField(this, "hit", { x: 0.5, y: 0.5, z: 0.5, nx: 0.5, ny: 0.5, nz: 0.5, d: 0.5 });
1497
+ }
1498
+ get empty() {
1499
+ return this.list.length === 0;
1500
+ }
1501
+ /** Declares or (with `null`) ends the solids `id` answers for. */
1502
+ set(id, query2) {
1503
+ if (query2) this.queries.set(id, query2);
1504
+ else this.queries.delete(id);
1505
+ this.list = [...this.queries.values()];
1506
+ }
1507
+ clear() {
1508
+ this.queries.clear();
1509
+ this.list = [];
1510
+ }
1511
+ /**
1512
+ * 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
1513
+ * the surface's normal. Answers whether the step was stopped.
1514
+ */
1515
+ stop(move, out) {
1516
+ const dx = move.x1 - move.x0;
1517
+ const dy = move.y1 - move.y0;
1518
+ const dz = move.z1 - move.z0;
1519
+ const length = Math.sqrt(dx * dx + dy * dy + dz * dz);
1520
+ if (!(length > 0)) return false;
1521
+ let nearest = Infinity;
1522
+ const list = this.list;
1523
+ for (let index = 0; index < list.length; index++) {
1524
+ if (!list[index](move, this.hit)) continue;
1525
+ const reached = ((this.hit.x - move.x0) * dx + (this.hit.y - move.y0) * dy + (this.hit.z - move.z0) * dz) / length;
1526
+ if (reached >= nearest) continue;
1527
+ nearest = reached;
1528
+ out.x = this.hit.x;
1529
+ out.y = this.hit.y;
1530
+ out.z = this.hit.z;
1531
+ out.nx = this.hit.nx;
1532
+ out.ny = this.hit.ny;
1533
+ out.nz = this.hit.nz;
1534
+ }
1535
+ if (nearest === Infinity) return false;
1536
+ const hitX2 = out.x;
1537
+ const hitY2 = out.y;
1538
+ const hitZ = out.z;
1539
+ out.d = out.nx * hitX2 + out.ny * hitY2 + out.nz * hitZ;
1540
+ const back = Math.min(Math.min(Math.max(move.pad, 0), MAX_PAD) + SKIN, Math.max(nearest, 0));
1541
+ out.x -= dx / length * back;
1542
+ out.y -= dy / length * back;
1543
+ out.z -= dz / length * back;
1544
+ const off = (out.x - hitX2) * out.nx + (out.y - hitY2) * out.ny + (out.z - hitZ) * out.nz;
1545
+ if (off < SKIN) {
1546
+ out.x += out.nx * (SKIN - off);
1547
+ out.y += out.ny * (SKIN - off);
1548
+ out.z += out.nz * (SKIN - off);
1549
+ }
1550
+ return true;
1551
+ }
1552
+ };
1553
+ var SKIN2 = 5e-3;
1492
1554
  function rotation(q) {
1493
1555
  const [x, y, z, w] = q ?? [0, 0, 0, 1];
1494
1556
  const n = Math.hypot(x, y, z, w) || 1;
@@ -1513,16 +1575,21 @@ var GameVfxThree = (() => {
1513
1575
  __publicField(this, "spaces", /* @__PURE__ */ new Map());
1514
1576
  __publicField(this, "list", []);
1515
1577
  __publicField(this, "random");
1516
- __publicField(this, "out", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
1578
+ __publicField(this, "out", { x: 0.5, y: 0.5, z: 0.5, nx: 0.5, ny: 0.5, nz: 0.5, d: 0.5 });
1517
1579
  __publicField(this, "l0", new Float64Array(3));
1518
1580
  __publicField(this, "l1", new Float64Array(3));
1519
1581
  __publicField(this, "q", new Float64Array(3));
1520
1582
  __publicField(this, "h", new Float64Array(3));
1521
1583
  __publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 });
1584
+ __publicField(this, "solids", new Solids());
1522
1585
  this.random = lehmer(seed);
1523
1586
  }
1524
1587
  get empty() {
1525
- return this.list.length === 0;
1588
+ return this.list.length === 0 && this.solids.empty;
1589
+ }
1590
+ /** 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. */
1591
+ solid(id, query2) {
1592
+ this.solids.set(id, query2);
1526
1593
  }
1527
1594
  get size() {
1528
1595
  return this.list.length;
@@ -1583,7 +1650,7 @@ var GameVfxThree = (() => {
1583
1650
  }
1584
1651
  /** Passes at `rate` per second. */
1585
1652
  chance(rate, dt) {
1586
- return rate > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
1653
+ return rate > 0 && dt > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
1587
1654
  }
1588
1655
  /** The opening the wall point `q` (local) is in lets it through now. */
1589
1656
  through(s, q, dt) {
@@ -1605,6 +1672,10 @@ var GameVfxThree = (() => {
1605
1672
  return this.confineMove(move, dt);
1606
1673
  }
1607
1674
  confineMove(move, dt) {
1675
+ if (this.confineSpaces(move, dt)) return true;
1676
+ return !this.solids.empty && this.solids.stop(move, this.out);
1677
+ }
1678
+ confineSpaces(move, dt) {
1608
1679
  const list = this.list;
1609
1680
  if (list.length === 0) return false;
1610
1681
  const { x0, y0, z0, x1, y1, z1 } = move;
@@ -1645,7 +1716,7 @@ var GameVfxThree = (() => {
1645
1716
  }
1646
1717
  }
1647
1718
  sign = l1[axis2] < 0 ? -1 : 1;
1648
- for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN, Math.max(-(h[a] - SKIN), l1[a]));
1719
+ for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN2, Math.max(-(h[a] - SKIN2), l1[a]));
1649
1720
  sign = -sign;
1650
1721
  } else {
1651
1722
  const padded0 = Math.abs(l0[0]) <= s.hx + p && Math.abs(l0[1]) <= s.hy + p && Math.abs(l0[2]) <= s.hz + p;
@@ -1662,7 +1733,7 @@ var GameVfxThree = (() => {
1662
1733
  }
1663
1734
  }
1664
1735
  sign = l0[axis2] < 0 ? -1 : 1;
1665
- l1[axis2] = sign * (h[axis2] + bound + SKIN);
1736
+ l1[axis2] = sign * (h[axis2] + bound + SKIN2);
1666
1737
  }
1667
1738
  const r = s.r;
1668
1739
  const out = this.out;
@@ -1672,6 +1743,7 @@ var GameVfxThree = (() => {
1672
1743
  out.nx = r[axis2] * sign;
1673
1744
  out.ny = r[3 + axis2] * sign;
1674
1745
  out.nz = r[6 + axis2] * sign;
1746
+ out.d = out.nx * s.cx + out.ny * s.cy + out.nz * s.cz + (in0 ? -h[axis2] : h[axis2]);
1675
1747
  return true;
1676
1748
  }
1677
1749
  return false;
@@ -1689,6 +1761,127 @@ var GameVfxThree = (() => {
1689
1761
  if (into >= 0) return [vx2, vy2, vz2];
1690
1762
  return [vx2 - into * out.nx, vy2 - into * out.ny, vz2 - into * out.nz];
1691
1763
  }
1764
+ var PUFF_REACH = 1.28;
1765
+ 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 }];
1766
+ var PROBES_PER_SECOND = 60;
1767
+ var FRAMES_PER_PROBE = 3;
1768
+ var GROUND_FACING = 0.7;
1769
+ var SAME_WALL = 0.9;
1770
+ var PROBE = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
1771
+ var KeptCut = class {
1772
+ constructor() {
1773
+ __publicField(this, "on", false);
1774
+ __publicField(this, "nx", 0.5);
1775
+ __publicField(this, "ny", 0.5);
1776
+ __publicField(this, "nz", 0.5);
1777
+ __publicField(this, "d", 0.5);
1778
+ }
1779
+ };
1780
+ function createCut() {
1781
+ return new KeptCut();
1782
+ }
1783
+ function clearCuts(puff3) {
1784
+ puff3.cuts[0].on = false;
1785
+ puff3.cuts[1].on = false;
1786
+ }
1787
+ var WrittenWay = class {
1788
+ constructor() {
1789
+ __publicField(this, "x", 0.5);
1790
+ __publicField(this, "y", 0.5);
1791
+ __publicField(this, "z", 0.5);
1792
+ }
1793
+ };
1794
+ var WAY = new WrittenWay();
1795
+ function probe(confiner, puff3, way) {
1796
+ const reach = puff3.size * PUFF_REACH;
1797
+ if (!(reach > 0)) return false;
1798
+ PROBE.x0 = puff3.x;
1799
+ PROBE.y0 = puff3.y;
1800
+ PROBE.z0 = puff3.z;
1801
+ PROBE.x1 = puff3.x + way.x * reach;
1802
+ PROBE.y1 = puff3.y + way.y * reach;
1803
+ PROBE.z1 = puff3.z + way.z * reach;
1804
+ PROBE.pad = 0;
1805
+ return confiner.confineMove(PROBE, 0) && confiner.out.ny <= GROUND_FACING;
1806
+ }
1807
+ 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;
1808
+ var isBehind = (puff3, face) => face.nx * puff3.x + face.ny * puff3.y + face.nz * puff3.z < face.d;
1809
+ var sameWall = (cut, face) => cut.on && cut.nx * face.nx + cut.ny * face.ny + cut.nz * face.nz > SAME_WALL;
1810
+ function cutFor(puff3, face) {
1811
+ const first = puff3.cuts[0];
1812
+ const second = puff3.cuts[1];
1813
+ if (sameWall(first, face)) return first;
1814
+ if (sameWall(second, face)) return second;
1815
+ if (!first.on) return first;
1816
+ if (!second.on) return second;
1817
+ const farther = isFartherFrom(puff3, first, second) ? first : second;
1818
+ return isFartherFrom(puff3, farther, face) ? farther : void 0;
1819
+ }
1820
+ function cutAtFace(puff3, face) {
1821
+ if (face.ny > GROUND_FACING) return;
1822
+ const cut = cutFor(puff3, face);
1823
+ if (!cut) return;
1824
+ cut.on = true;
1825
+ cut.nx = face.nx;
1826
+ cut.ny = face.ny;
1827
+ cut.nz = face.nz;
1828
+ cut.d = face.d;
1829
+ }
1830
+ function cutFrom(puff3, out) {
1831
+ cutAtFace(puff3, out);
1832
+ }
1833
+ function cutAt(confiner, puff3, way) {
1834
+ if (!probe(confiner, puff3, way)) return false;
1835
+ cutAtFace(puff3, confiner.out);
1836
+ return true;
1837
+ }
1838
+ function backward(puff3) {
1839
+ const speed = Math.sqrt(puff3.vx * puff3.vx + puff3.vy * puff3.vy + puff3.vz * puff3.vz);
1840
+ if (!(speed > 0)) return null;
1841
+ WAY.x = -puff3.vx / speed;
1842
+ WAY.y = -puff3.vy / speed;
1843
+ WAY.z = -puff3.vz / speed;
1844
+ return WAY;
1845
+ }
1846
+ function along(cut, sign) {
1847
+ WAY.x = sign * cut.nx;
1848
+ WAY.y = sign * cut.ny;
1849
+ WAY.z = sign * cut.nz;
1850
+ return WAY;
1851
+ }
1852
+ function dropPassed(confiner, puff3) {
1853
+ for (let i = 0; i < 2; i++) {
1854
+ const cut = puff3.cuts[i];
1855
+ if (!cut.on || !isBehind(puff3, cut)) continue;
1856
+ cut.on = false;
1857
+ cutAt(confiner, puff3, along(cut, 1));
1858
+ }
1859
+ }
1860
+ function keep(confiner, puff3, cut) {
1861
+ if (!cut.on) return;
1862
+ if (!probe(confiner, puff3, along(cut, -1))) {
1863
+ cut.on = false;
1864
+ return;
1865
+ }
1866
+ cut.d = confiner.out.d;
1867
+ }
1868
+ function lookForWalls(confiner, puff3) {
1869
+ dropPassed(confiner, puff3);
1870
+ const turn = Math.round(puff3.t * PROBES_PER_SECOND);
1871
+ if (turn <= 1) {
1872
+ const back = backward(puff3);
1873
+ if (back) cutAt(confiner, puff3, back);
1874
+ for (let i = 0; i < PROBES.length; i++) cutAt(confiner, puff3, PROBES[i]);
1875
+ return;
1876
+ }
1877
+ if (turn % FRAMES_PER_PROBE !== 0) return;
1878
+ const slot = turn / FRAMES_PER_PROBE % (PROBES.length + 3);
1879
+ if (slot < 2) keep(confiner, puff3, puff3.cuts[slot]);
1880
+ else if (slot === 2) {
1881
+ const back = backward(puff3);
1882
+ if (back) cutAt(confiner, puff3, back);
1883
+ } else cutAt(confiner, puff3, PROBES[slot - 3]);
1884
+ }
1692
1885
  var FLOOR_FRACTION = 0.4;
1693
1886
  var FLOOR_BOUNCE = -0.2;
1694
1887
  var ARRIVAL_FRAME = 30;
@@ -1728,7 +1921,8 @@ var GameVfxThree = (() => {
1728
1921
  age: 0,
1729
1922
  heat: 0,
1730
1923
  size: 0,
1731
- source: void 0
1924
+ source: void 0,
1925
+ cuts: [createCut(), createCut()]
1732
1926
  }));
1733
1927
  }
1734
1928
  function spawnPuff(pool, random, init) {
@@ -1762,6 +1956,7 @@ var GameVfxThree = (() => {
1762
1956
  puff3.heat = 0;
1763
1957
  puff3.size = 0;
1764
1958
  puff3.source = init.source;
1959
+ clearCuts(puff3);
1765
1960
  return puff3;
1766
1961
  }
1767
1962
  function ageOrKeep2(puff3, dt) {
@@ -1811,17 +2006,21 @@ var GameVfxThree = (() => {
1811
2006
  MOVE.z0 = puff3.z;
1812
2007
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
1813
2008
  else moveFree(puff3, dt, age, heat, wind);
1814
- if (confining && CARRIED_KINDS[puff3.kind] && confine(confiner, puff3, dt)) {
2009
+ const carried = confining && CARRIED_KINDS[puff3.kind];
2010
+ if (carried && confine(confiner, puff3, dt)) {
1815
2011
  const out = confiner.out;
1816
2012
  puff3.x = out.x;
1817
2013
  puff3.y = out.y;
1818
2014
  puff3.z = out.z;
1819
2015
  slideInto(out, puff3);
2016
+ cutFrom(puff3, out);
1820
2017
  }
1821
2018
  const size = puff3.s0 + (puff3.s1 - puff3.s0) * (1 - Math.exp(-puff3.t * puff3.gk)) + puff3.sg * Math.min(puff3.t, GROWTH_CAP_SECONDS);
1822
2019
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
1823
2020
  puff3.age = age;
1824
2021
  puff3.heat = heat;
2022
+ if (carried) lookForWalls(confiner, puff3);
2023
+ else clearCuts(puff3);
1825
2024
  }
1826
2025
  }
1827
2026
  var GROUND_LIFT = 0.02;
@@ -4792,10 +4991,10 @@ var GameVfxThree = (() => {
4792
4991
  var MAX_SCALE = 3;
4793
4992
  var MIN_SCALE = 0.6;
4794
4993
  function reflected(direction, normal) {
4795
- const along = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
4796
- const out = [direction[0] - 2 * along * normal[0], direction[1] - 2 * along * normal[1], direction[2] - 2 * along * normal[2]];
4994
+ const along2 = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
4995
+ const out = [direction[0] - 2 * along2 * normal[0], direction[1] - 2 * along2 * normal[1], direction[2] - 2 * along2 * normal[2]];
4797
4996
  const length = Math.hypot(out[0], out[1], out[2]);
4798
- if (length < 1e-6 || Math.abs(along) > 0.98) return normal;
4997
+ if (length < 1e-6 || Math.abs(along2) > 0.98) return normal;
4799
4998
  return [out[0] / length, out[1] / length, out[2] / length];
4800
4999
  }
4801
5000
  var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
@@ -5649,6 +5848,24 @@ var GameVfxThree = (() => {
5649
5848
  screen2.flashDecay = 0.5;
5650
5849
  }
5651
5850
  }
5851
+ var BIRTH = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
5852
+ function bornFrom(core, puff3, ox, oy, oz) {
5853
+ const confiner = core.confiner;
5854
+ if (confiner.empty) return;
5855
+ BIRTH.x0 = ox;
5856
+ BIRTH.y0 = oy;
5857
+ BIRTH.z0 = oz;
5858
+ BIRTH.x1 = puff3.x;
5859
+ BIRTH.y1 = puff3.y;
5860
+ BIRTH.z1 = puff3.z;
5861
+ BIRTH.pad = puff3.s0 * PAD_OF_SIZE;
5862
+ if (!confiner.confineMove(BIRTH, 0)) return;
5863
+ const out = confiner.out;
5864
+ puff3.x = out.x;
5865
+ puff3.y = out.y;
5866
+ puff3.z = out.z;
5867
+ slideInto(out, puff3);
5868
+ }
5652
5869
  function composeFireballs(context) {
5653
5870
  const { core, def, random, x, y, z, size, scale, direction } = context;
5654
5871
  if (!core.layers.fire || !def.fireballs) return;
@@ -5665,7 +5882,7 @@ var GameVfxThree = (() => {
5665
5882
  const life = random.between(def.smoke.life * 0.7, def.smoke.life);
5666
5883
  const h0 = random.between(1.05, 1.35) * heat;
5667
5884
  const hl = fuel ? random.between(0.8, 1.4) * (def.heatLifeScale ?? 1) : random.between(0.22, 0.42);
5668
- addPuff(core, random, {
5885
+ const fireball = addPuff(core, random, {
5669
5886
  x: x + d.x * size * 0.15,
5670
5887
  y: y + size * 0.25 + d.y * size * 0.1,
5671
5888
  z: z + d.z * size * 0.15,
@@ -5684,6 +5901,7 @@ var GameVfxThree = (() => {
5684
5901
  color: context.smokeColor,
5685
5902
  kind: 0
5686
5903
  });
5904
+ bornFrom(core, fireball, x, y, z);
5687
5905
  }
5688
5906
  }
5689
5907
  function composeSmoke(context) {
@@ -5697,7 +5915,7 @@ var GameVfxThree = (() => {
5697
5915
  const s1 = size * random.between(0.55, 0.85);
5698
5916
  const sg = size * random.between(0.18, 0.3);
5699
5917
  const life = random.between(def.smoke.life * 0.7, def.smoke.life * 1.1);
5700
- addPuff(core, random, {
5918
+ const smoke = addPuff(core, random, {
5701
5919
  x: x + d.x * size * 0.6,
5702
5920
  y: y + size * 0.4 + d.y * size * 0.5,
5703
5921
  z: z + d.z * size * 0.6,
@@ -5716,6 +5934,7 @@ var GameVfxThree = (() => {
5716
5934
  color: context.smokeColor,
5717
5935
  kind: def.smoke.kind ?? 0
5718
5936
  });
5937
+ bornFrom(core, smoke, x, y, z);
5719
5938
  }
5720
5939
  }
5721
5940
  function composeShock(context) {
@@ -5727,7 +5946,7 @@ var GameVfxThree = (() => {
5727
5946
  spawnShock(core.shocks, spec);
5728
5947
  }
5729
5948
  function composeDust(context) {
5730
- const { core, def, random, x, z, size, scale } = context;
5949
+ const { core, def, random, x, y, z, size, scale } = context;
5731
5950
  if (!core.layers.smoke || !def.dust.count || !(scale > 0.15)) return;
5732
5951
  const count = Math.round(def.dust.count * scale);
5733
5952
  const color = hexToLinearRgb(def.dust.color);
@@ -5740,7 +5959,7 @@ var GameVfxThree = (() => {
5740
5959
  const s1 = size * random.between(0.5, 0.8);
5741
5960
  const sg = size * random.between(0.2, 0.35);
5742
5961
  const life = random.between(2.2, 4);
5743
- addPuff(core, random, {
5962
+ const dust = addPuff(core, random, {
5744
5963
  x: x + Math.cos(angle) * 0.3,
5745
5964
  y: 0.15,
5746
5965
  z: z + Math.sin(angle) * 0.3,
@@ -5757,6 +5976,7 @@ var GameVfxThree = (() => {
5757
5976
  color,
5758
5977
  kind: 1
5759
5978
  });
5979
+ bornFrom(core, dust, x, y, z);
5760
5980
  }
5761
5981
  }
5762
5982
  function coneAngle(context) {
@@ -6087,6 +6307,9 @@ var GameVfxThree = (() => {
6087
6307
  state.beat *= Math.exp(-DECAY.beat * dt);
6088
6308
  }
6089
6309
  var PAD_OF_SIZE2 = 0.35;
6310
+ var STEP = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
6311
+ var GROUND_RESAMPLE = 0.1;
6312
+ var VELOCITY = { vx: 0.5, vy: 0.5, vz: 0.5 };
6090
6313
  var clamp4 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
6091
6314
  var lerp4 = (a, b, t) => a + (b - a) * t;
6092
6315
  function rgb(hex) {
@@ -6133,6 +6356,7 @@ var GameVfxThree = (() => {
6133
6356
  __publicField(this, "bounced");
6134
6357
  __publicField(this, "floor");
6135
6358
  __publicField(this, "riseMul");
6359
+ __publicField(this, "ground");
6136
6360
  const n = Math.max(1, capacity);
6137
6361
  this.position = new Float32Array(n * 3);
6138
6362
  this.color = new Float32Array(n * 3);
@@ -6155,6 +6379,7 @@ var GameVfxThree = (() => {
6155
6379
  this.bounced = new Uint8Array(n);
6156
6380
  this.floor = new Float32Array(n);
6157
6381
  this.riseMul = new Float32Array(n);
6382
+ this.ground = new Float32Array(n * 3);
6158
6383
  }
6159
6384
  spawn(kind, p, v, random, options) {
6160
6385
  if (this.capacity <= 0) return;
@@ -6182,6 +6407,7 @@ var GameVfxThree = (() => {
6182
6407
  this.bounced[i] = 0;
6183
6408
  this.floor[i] = options?.floor ?? Number.NaN;
6184
6409
  this.riseMul[i] = options?.rise ?? 1;
6410
+ this.ground[i * 3] = Number.NaN;
6185
6411
  this.size[i] = this.size0[i];
6186
6412
  this.alpha[i] = 0;
6187
6413
  }
@@ -6275,18 +6501,36 @@ var GameVfxThree = (() => {
6275
6501
  let z = this.position[i3 + 2] + vz2 * dt;
6276
6502
  const confiner = host.confiner;
6277
6503
  if (def.carried && confiner && !confiner.empty) {
6278
- const pad = this.size0[i] * lerp4(1, def.grow, t) * PAD_OF_SIZE2;
6279
- if (confiner.confine(this.position[i3], this.position[i3 + 1], this.position[i3 + 2], x, y, z, pad, dt)) {
6504
+ STEP.x0 = this.position[i3];
6505
+ STEP.y0 = this.position[i3 + 1];
6506
+ STEP.z0 = this.position[i3 + 2];
6507
+ STEP.x1 = x;
6508
+ STEP.y1 = y;
6509
+ STEP.z1 = z;
6510
+ STEP.pad = this.size0[i] * (1 + (def.grow - 1) * t) * PAD_OF_SIZE2;
6511
+ if (confiner.confineMove(STEP, dt)) {
6280
6512
  const out = confiner.out;
6281
6513
  x = out.x;
6282
6514
  y = out.y;
6283
6515
  z = out.z;
6284
- [vx2, vy2, vz2] = slideAlong(out, vx2, vy2, vz2);
6516
+ VELOCITY.vx = vx2;
6517
+ VELOCITY.vy = vy2;
6518
+ VELOCITY.vz = vz2;
6519
+ slideInto(out, VELOCITY);
6520
+ vx2 = VELOCITY.vx;
6521
+ vy2 = VELOCITY.vy;
6522
+ vz2 = VELOCITY.vz;
6285
6523
  }
6286
6524
  }
6287
6525
  if (def.ground !== "none") {
6288
6526
  const own = this.floor[i];
6289
- const gy = Number.isNaN(own) ? host.groundAt(x, z) + 5e-3 : own;
6527
+ const ground = this.ground;
6528
+ if (Number.isNaN(own) && !(Math.abs(x - ground[i3]) < GROUND_RESAMPLE && Math.abs(z - ground[i3 + 1]) < GROUND_RESAMPLE)) {
6529
+ ground[i3] = x;
6530
+ ground[i3 + 1] = z;
6531
+ ground[i3 + 2] = host.groundAt(x, z);
6532
+ }
6533
+ const gy = Number.isNaN(own) ? ground[i3 + 2] + 5e-3 : own;
6290
6534
  if (y < gy) {
6291
6535
  if (def.ground === "land") {
6292
6536
  const tag = this.tag[i];
@@ -7132,10 +7376,10 @@ var GameVfxThree = (() => {
7132
7376
  if (particle.fade) particle.opacity = Math.max(0, particle.startOpacity * (1 - particle.age / particle.life));
7133
7377
  particle.vy -= particle.gravity * dt;
7134
7378
  if (particle.drag) {
7135
- const keep = Math.max(0, 1 - particle.drag * dt);
7136
- particle.vx *= keep;
7137
- particle.vy *= keep;
7138
- particle.vz *= keep;
7379
+ const keep2 = Math.max(0, 1 - particle.drag * dt);
7380
+ particle.vx *= keep2;
7381
+ particle.vy *= keep2;
7382
+ particle.vz *= keep2;
7139
7383
  }
7140
7384
  if (particle.carried) this.ride(particle, dt);
7141
7385
  else {
@@ -7828,6 +8072,7 @@ var GameVfxThree = (() => {
7828
8072
  });
7829
8073
  const core = {
7830
8074
  profile,
8075
+ confiner: enclosures,
7831
8076
  puffs: createPuffPool(profile.puffs),
7832
8077
  sparks: createSparkPool(profile.sparks),
7833
8078
  glows: createGlowPool(profile.glows),
@@ -7968,6 +8213,9 @@ var GameVfxThree = (() => {
7968
8213
  enclose(id, enclosure) {
7969
8214
  enclosures.set(id, enclosure);
7970
8215
  },
8216
+ solid(id, query2) {
8217
+ enclosures.solid(id, query2);
8218
+ },
7971
8219
  enclosures: () => enclosures,
7972
8220
  stop(handle) {
7973
8221
  player?.stop(handle);
@@ -7975,10 +8223,10 @@ var GameVfxThree = (() => {
7975
8223
  for (let index = fires.items.length - 1; index >= 0; index--) if (fires.items[index].handle === handle) fires.removeAt(index);
7976
8224
  },
7977
8225
  clearSource(source) {
7978
- const keep = (record, gone) => record.source !== gone;
8226
+ const keep2 = (record, gone) => record.source !== gone;
7979
8227
  const drop = (pool) => {
7980
8228
  const before = pool.count;
7981
- pool.compact(keep, source);
8229
+ pool.compact(keep2, source);
7982
8230
  return before - pool.count;
7983
8231
  };
7984
8232
  return drop(core.fires) + drop(core.puffs) + drop(core.sparks) + drop(core.chunks) + drop(core.glows) + spriteSystem.clearSource(source);
@@ -8904,23 +9152,24 @@ float vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
8904
9152
  `;
8905
9153
 
8906
9154
  // src/shaders/puff.ts
9155
+ var PUFF_BASE = (PUFF_REACH - 0.5).toFixed(2);
8907
9156
  var PUFF_VERTEX = `${GL_NOISE}
8908
- attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
9157
+ attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;attribute vec4 aK;attribute vec4 aK2;varying vec4 vK;varying vec4 vK2;
8909
9158
  varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
8910
9159
  void main(){
8911
9160
  vec3 p=position;
8912
9161
  float s=aD.z;
8913
9162
  float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
8914
- p*=0.78+0.5*n;
9163
+ p*=${PUFF_BASE}+0.5*n;
8915
9164
  float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;
8916
9165
  vL=p;
8917
9166
  vec3 wp=aP.xyz+p*aP.w;
8918
- vWP=wp;vD=aD;vC=aC;
9167
+ vWP=wp;vD=aD;vC=aC;vK=aK;vK2=aK2;
8919
9168
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
8920
9169
  }`;
8921
9170
  var PUFF_FRAGMENT = `${GL_NOISE}
8922
9171
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
8923
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
9172
+ varying vec4 vK;varying vec4 vK2;varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
8924
9173
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
8925
9174
  vec3 ramp(float h){
8926
9175
  vec3 c0=L(vec3(.36,.07,.03)),c1=L(vec3(.76,.21,.1)),c2=L(vec3(1.,.54,.16)),c3=L(vec3(1.,.83,.42)),c4=L(vec3(1.,.96,.84));
@@ -8930,6 +9179,8 @@ vec3 ramp(float h){
8930
9179
  return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
8931
9180
  }
8932
9181
  void main(){
9182
+ // cut at the face of a wall within reach (Puff.cuts): smoke flattens on the wall, it does not show through on its other side
9183
+ if(dot(vWP,vK.xyz)<vK.w||dot(vWP,vK2.xyz)<vK2.w)discard;
8933
9184
  vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));
8934
9185
  float age=vD.x,heat=vD.y,kind=vD.w;
8935
9186
  float n=vn(vL*2.4+vD.z*13.0);
@@ -8958,23 +9209,23 @@ void main(){
8958
9209
  #include <colorspace_fragment>
8959
9210
  }`;
8960
9211
  var SOFT_PUFF_VERTEX = `${GL_NOISE}
8961
- attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
9212
+ attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;attribute vec4 aK;attribute vec4 aK2;varying vec4 vK;varying vec4 vK2;
8962
9213
  varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
8963
9214
  void main(){
8964
9215
  vec3 p=position;
8965
9216
  vec3 q=normalize(position);
8966
9217
  float s=aD.z;
8967
9218
  float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
8968
- p*=0.78+0.5*n;
9219
+ p*=${PUFF_BASE}+0.5*n;
8969
9220
  float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;q.xz=mat2(c,-si,si,c)*q.xz;
8970
9221
  vL=p;vN=q;
8971
9222
  vec3 wp=aP.xyz+p*aP.w;
8972
- vWP=wp;vD=aD;vC=aC;
9223
+ vWP=wp;vD=aD;vC=aC;vK=aK;vK2=aK2;
8973
9224
  gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
8974
9225
  }`;
8975
9226
  var SOFT_PUFF_FRAGMENT = `${GL_NOISE}
8976
9227
  uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
8977
- varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
9228
+ varying vec4 vK;varying vec4 vK2;varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
8978
9229
  vec3 L(vec3 c){return pow(c,vec3(2.2));}
8979
9230
  vec3 ramp(float h){
8980
9231
  vec3 c0=L(vec3(.36,.07,.03)),c1=L(vec3(.76,.21,.1)),c2=L(vec3(1.,.54,.16)),c3=L(vec3(1.,.83,.42)),c4=L(vec3(1.,.96,.84));
@@ -8984,6 +9235,8 @@ vec3 ramp(float h){
8984
9235
  return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
8985
9236
  }
8986
9237
  void main(){
9238
+ // cut at the face of a wall within reach (Puff.cuts): smoke flattens on the wall, it does not show through on its other side
9239
+ if(dot(vWP,vK.xyz)<vK.w||dot(vWP,vK2.xyz)<vK2.w)discard;
8987
9240
  float age=vD.x,heat=vD.y,kind=vD.w;
8988
9241
  float n=vn(vL*2.4+vD.z*13.0);
8989
9242
  // the sphere's own normal, roughened by the noise: a billowing cloud, never facets
@@ -9051,6 +9304,13 @@ void main(){
9051
9304
  function dynamic(THREE, array, size) {
9052
9305
  return new THREE.InstancedBufferAttribute(array, size).setUsage(THREE.DynamicDrawUsage);
9053
9306
  }
9307
+ var NO_CUT = -1e9;
9308
+ function writeCut(into, n, cut) {
9309
+ into[n * 4] = cut.on ? cut.nx : 0;
9310
+ into[n * 4 + 1] = cut.on ? cut.ny : 0;
9311
+ into[n * 4 + 2] = cut.on ? cut.nz : 0;
9312
+ into[n * 4 + 3] = cut.on ? cut.d : NO_CUT;
9313
+ }
9054
9314
  var PUFF_DETAIL = { faceted: 1, soft: 2 };
9055
9315
  function createPuffLayer(THREE, pool, uniforms, style = "faceted") {
9056
9316
  const capacity = pool.capacity;
@@ -9059,10 +9319,14 @@ void main(){
9059
9319
  const a = new Float32Array(capacity * 4);
9060
9320
  const d = new Float32Array(capacity * 4);
9061
9321
  const c = new Float32Array(capacity * 3);
9062
- const attributes = [dynamic(THREE, a, 4), dynamic(THREE, d, 4), dynamic(THREE, c, 3)];
9322
+ const k = new Float32Array(capacity * 4);
9323
+ const k2 = new Float32Array(capacity * 4);
9324
+ const attributes = [dynamic(THREE, a, 4), dynamic(THREE, d, 4), dynamic(THREE, c, 3), dynamic(THREE, k, 4), dynamic(THREE, k2, 4)];
9063
9325
  geometry.setAttribute("aP", attributes[0]);
9064
9326
  geometry.setAttribute("aD", attributes[1]);
9065
9327
  geometry.setAttribute("aC", attributes[2]);
9328
+ geometry.setAttribute("aK", attributes[3]);
9329
+ geometry.setAttribute("aK2", attributes[4]);
9066
9330
  geometry.instanceCount = 0;
9067
9331
  const material2 = style === "faceted" ? new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT }) : new THREE.ShaderMaterial({ uniforms, vertexShader: SOFT_PUFF_VERTEX, fragmentShader: SOFT_PUFF_FRAGMENT, transparent: true, depthWrite: false });
9068
9332
  const mesh2 = new THREE.Mesh(geometry, material2);
@@ -9084,6 +9348,8 @@ void main(){
9084
9348
  c[n * 3] = p.color[0];
9085
9349
  c[n * 3 + 1] = p.color[1];
9086
9350
  c[n * 3 + 2] = p.color[2];
9351
+ writeCut(k, n, p.cuts[0]);
9352
+ writeCut(k2, n, p.cuts[1]);
9087
9353
  n++;
9088
9354
  }
9089
9355
  geometry.instanceCount = n;
@@ -9752,6 +10018,7 @@ void main(){
9752
10018
  }
9753
10019
 
9754
10020
  // src/screen-overlay.ts
10021
+ var SHOWN_FIELDS = 6;
9755
10022
  var clamp5 = (value, min2, max2) => value < min2 ? min2 : value > max2 ? max2 : value;
9756
10023
  function layer(container, name, blend) {
9757
10024
  const element = container.ownerDocument.createElement("div");
@@ -9769,8 +10036,20 @@ void main(){
9769
10036
  const sides = layer(container, "sides");
9770
10037
  const gas = layer(container, "gas");
9771
10038
  const elements = [flash2, white, red, sides, gas];
10039
+ const shown = new Float64Array(SHOWN_FIELDS).fill(Number.NaN);
10040
+ const isShown = (state) => {
10041
+ const same = shown[0] === state.flash && shown[1] === state.white && shown[2] === state.red && shown[3] === state.directionLeft && shown[4] === state.directionRight && shown[5] === state.gas;
10042
+ shown[0] = state.flash;
10043
+ shown[1] = state.white;
10044
+ shown[2] = state.red;
10045
+ shown[3] = state.directionLeft;
10046
+ shown[4] = state.directionRight;
10047
+ shown[5] = state.gas;
10048
+ return same;
10049
+ };
9772
10050
  return {
9773
10051
  update(state) {
10052
+ if (isShown(state)) return;
9774
10053
  flash2.style.opacity = clamp5(state.flash, 0, 1).toFixed(3);
9775
10054
  white.style.opacity = "1";
9776
10055
  white.style.background = `rgba(235,240,255,${clamp5(state.white, 0, 1).toFixed(2)})`;