@adatechnology/game-vfx 0.20.0 → 0.20.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.
package/dist/index.js CHANGED
@@ -1675,8 +1675,9 @@ function slideAlong(out, vx2, vy2, vz2) {
1675
1675
  }
1676
1676
 
1677
1677
  // src/pools/puff-cuts.ts
1678
+ var PUFF_CUTS = 3;
1678
1679
  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 = [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
1681
  var PROBES_PER_SECOND = 60;
1681
1682
  var FRAMES_PER_PROBE = 3;
1682
1683
  var GROUND_FACING = 0.7;
@@ -1695,41 +1696,44 @@ function createCut() {
1695
1696
  return new KeptCut();
1696
1697
  }
1697
1698
  function clearCuts(puff3) {
1698
- puff3.cuts[0].on = false;
1699
- puff3.cuts[1].on = false;
1699
+ for (let i = 0; i < PUFF_CUTS; i++) puff3.cuts[i].on = false;
1700
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();
1701
+ var WAY = new Float64Array(3);
1702
+ var PASSED = 0.02;
1709
1703
  function probe(confiner, puff3, way) {
1710
- const reach = puff3.size * PUFF_REACH;
1704
+ const reach = puff3.size * (puff3.reachOfSize ?? PUFF_REACH);
1711
1705
  if (!(reach > 0)) return false;
1712
1706
  PROBE.x0 = puff3.x;
1713
1707
  PROBE.y0 = puff3.y;
1714
1708
  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;
1709
+ PROBE.x1 = puff3.x + way[0] * reach;
1710
+ PROBE.y1 = puff3.y + way[1] * reach;
1711
+ PROBE.z1 = puff3.z + way[2] * reach;
1712
+ PROBE.pad = 0;
1713
+ return confiner.confineMove(PROBE, 0) && confiner.out.ny <= GROUND_FACING;
1714
+ }
1715
+ function probeAgain(confiner, puff3, way) {
1716
+ const reach = puff3.size * (puff3.reachOfSize ?? PUFF_REACH);
1717
+ if (!(reach > 0)) return false;
1718
+ PROBE.x0 = puff3.x - way[0] * PASSED;
1719
+ PROBE.y0 = puff3.y - way[1] * PASSED;
1720
+ PROBE.z0 = puff3.z - way[2] * PASSED;
1721
+ PROBE.x1 = puff3.x + way[0] * reach;
1722
+ PROBE.y1 = puff3.y + way[1] * reach;
1723
+ PROBE.z1 = puff3.z + way[2] * reach;
1718
1724
  PROBE.pad = 0;
1719
1725
  return confiner.confineMove(PROBE, 0) && confiner.out.ny <= GROUND_FACING;
1720
1726
  }
1721
1727
  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;
1728
+ var isBehind = (puff3, face) => face.nx * puff3.x + face.ny * puff3.y + face.nz * puff3.z < face.d - PASSED;
1723
1729
  var sameWall = (cut, face) => cut.on && cut.nx * face.nx + cut.ny * face.ny + cut.nz * face.nz > SAME_WALL;
1724
1730
  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;
1731
+ const cuts = puff3.cuts;
1732
+ for (let i = 0; i < PUFF_CUTS; i++) if (sameWall(cuts[i], face)) return cuts[i];
1733
+ for (let i = 0; i < PUFF_CUTS; i++) if (!cuts[i].on) return cuts[i];
1734
+ let farthest = cuts[0];
1735
+ for (let i = 1; i < PUFF_CUTS; i++) if (isFartherFrom(puff3, cuts[i], farthest)) farthest = cuts[i];
1736
+ return isFartherFrom(puff3, farthest, face) ? farthest : void 0;
1733
1737
  }
1734
1738
  function cutAtFace(puff3, face) {
1735
1739
  if (face.ny > GROUND_FACING) return;
@@ -1752,28 +1756,35 @@ function cutAt(confiner, puff3, way) {
1752
1756
  function backward(puff3) {
1753
1757
  const speed = Math.sqrt(puff3.vx * puff3.vx + puff3.vy * puff3.vy + puff3.vz * puff3.vz);
1754
1758
  if (!(speed > 0)) return null;
1755
- WAY.x = -puff3.vx / speed;
1756
- WAY.y = -puff3.vy / speed;
1757
- WAY.z = -puff3.vz / speed;
1759
+ WAY[0] = -puff3.vx / speed;
1760
+ WAY[1] = -puff3.vy / speed;
1761
+ WAY[2] = -puff3.vz / speed;
1758
1762
  return WAY;
1759
1763
  }
1760
1764
  function along(cut, sign) {
1761
- WAY.x = sign * cut.nx;
1762
- WAY.y = sign * cut.ny;
1763
- WAY.z = sign * cut.nz;
1765
+ WAY[0] = sign * cut.nx;
1766
+ WAY[1] = sign * cut.ny;
1767
+ WAY[2] = sign * cut.nz;
1764
1768
  return WAY;
1765
1769
  }
1766
1770
  function dropPassed(confiner, puff3) {
1767
- for (let i = 0; i < 2; i++) {
1771
+ for (let i = 0; i < PUFF_CUTS; i++) {
1768
1772
  const cut = puff3.cuts[i];
1769
1773
  if (!cut.on || !isBehind(puff3, cut)) continue;
1770
1774
  cut.on = false;
1775
+ const nx = cut.nx;
1776
+ const ny = cut.ny;
1777
+ const nz = cut.nz;
1771
1778
  cutAt(confiner, puff3, along(cut, 1));
1779
+ WAY[0] = -nx;
1780
+ WAY[1] = -ny;
1781
+ WAY[2] = -nz;
1782
+ cutAt(confiner, puff3, WAY);
1772
1783
  }
1773
1784
  }
1774
1785
  function keep(confiner, puff3, cut) {
1775
1786
  if (!cut.on) return;
1776
- if (!probe(confiner, puff3, along(cut, -1))) {
1787
+ if (!probeAgain(confiner, puff3, along(cut, -1))) {
1777
1788
  cut.on = false;
1778
1789
  return;
1779
1790
  }
@@ -1789,12 +1800,12 @@ function lookForWalls(confiner, puff3) {
1789
1800
  return;
1790
1801
  }
1791
1802
  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) {
1803
+ const slot = (turn / FRAMES_PER_PROBE | 0) % (PROBES.length + PUFF_CUTS + 1);
1804
+ if (slot < PUFF_CUTS) keep(confiner, puff3, puff3.cuts[slot]);
1805
+ else if (slot === PUFF_CUTS) {
1795
1806
  const back = backward(puff3);
1796
1807
  if (back) cutAt(confiner, puff3, back);
1797
- } else cutAt(confiner, puff3, PROBES[slot - 3]);
1808
+ } else cutAt(confiner, puff3, PROBES[slot - PUFF_CUTS - 1]);
1798
1809
  }
1799
1810
 
1800
1811
  // src/pools/puffs.ts
@@ -1838,7 +1849,7 @@ function createPuffPool(capacity) {
1838
1849
  heat: 0,
1839
1850
  size: 0,
1840
1851
  source: void 0,
1841
- cuts: [createCut(), createCut()]
1852
+ cuts: [createCut(), createCut(), createCut()]
1842
1853
  }));
1843
1854
  }
1844
1855
  function spawnPuff(pool, random, init) {
@@ -1890,7 +1901,9 @@ function moveOnRing(puff3, ring2, wind) {
1890
1901
  puff3.z = ring2.z + Math.sin(puff3.ph) * radius + wind.z * ringTime * 0.6;
1891
1902
  puff3.y = centerY + minorRadius * Math.sin(theta);
1892
1903
  }
1893
- function moveFree(puff3, dt, age, heat, wind) {
1904
+ function moveFree(puff3, dt, wind) {
1905
+ const age = puff3.age;
1906
+ const heat = puff3.heat;
1894
1907
  const damping = Math.exp(-puff3.drag * dt);
1895
1908
  puff3.vx *= damping;
1896
1909
  puff3.vy *= damping;
@@ -1915,13 +1928,13 @@ function updatePuffs(pool, dt, wind, confiner) {
1915
1928
  pool.compact(ageOrKeep2, dt);
1916
1929
  const confining = confiner !== void 0 && !confiner.empty;
1917
1930
  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;
1931
+ puff3.age = puff3.t / puff3.life;
1932
+ puff3.heat = puff3.h0 > 0 ? puff3.h0 * Math.pow(Math.max(0, 1 - puff3.t / puff3.hl), 1.25) : 0;
1920
1933
  MOVE.x0 = puff3.x;
1921
1934
  MOVE.y0 = puff3.y;
1922
1935
  MOVE.z0 = puff3.z;
1923
1936
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
1924
- else moveFree(puff3, dt, age, heat, wind);
1937
+ else moveFree(puff3, dt, wind);
1925
1938
  const carried = confining && CARRIED_KINDS[puff3.kind];
1926
1939
  if (carried && confine(confiner, puff3, dt)) {
1927
1940
  const out = confiner.out;
@@ -1933,8 +1946,6 @@ function updatePuffs(pool, dt, wind, confiner) {
1933
1946
  }
1934
1947
  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
1948
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
1936
- puff3.age = age;
1937
- puff3.heat = heat;
1938
1949
  if (carried) lookForWalls(confiner, puff3);
1939
1950
  else clearCuts(puff3);
1940
1951
  }
@@ -6495,6 +6506,23 @@ var PAD_OF_SIZE2 = 0.35;
6495
6506
  var STEP = { x0: 0.5, y0: 0.5, z0: 0.5, x1: 0.5, y1: 0.5, z1: 0.5, pad: 0.5 };
6496
6507
  var GROUND_RESAMPLE = 0.1;
6497
6508
  var VELOCITY = { vx: 0.5, vy: 0.5, vz: 0.5 };
6509
+ var SPRITE_REACH = 1;
6510
+ var NO_CUT = -1e9;
6511
+ var SpriteCutView = class {
6512
+ constructor() {
6513
+ __publicField(this, "x", 0.5);
6514
+ __publicField(this, "y", 0.5);
6515
+ __publicField(this, "z", 0.5);
6516
+ __publicField(this, "vx", 0.5);
6517
+ __publicField(this, "vy", 0.5);
6518
+ __publicField(this, "vz", 0.5);
6519
+ __publicField(this, "t", 0.5);
6520
+ __publicField(this, "size", 0.5);
6521
+ __publicField(this, "reachOfSize", SPRITE_REACH);
6522
+ __publicField(this, "cuts", [createCut(), createCut(), createCut()]);
6523
+ }
6524
+ };
6525
+ var VIEW = new SpriteCutView();
6498
6526
  var clamp4 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
6499
6527
  var lerp4 = (a, b, t) => a + (b - a) * t;
6500
6528
  function rgb(hex) {
@@ -6523,6 +6551,14 @@ var SpriteKindPool = class {
6523
6551
  __publicField(this, "color");
6524
6552
  __publicField(this, "alpha");
6525
6553
  __publicField(this, "size");
6554
+ /**
6555
+ * 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
6556
+ * (`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
6557
+ * shows nothing on the wall's other side, as a puff's ball does (`Puff.cuts`).
6558
+ */
6559
+ __publicField(this, "cutA");
6560
+ __publicField(this, "cutB");
6561
+ __publicField(this, "cutC");
6526
6562
  __publicField(this, "next", 0);
6527
6563
  __publicField(this, "high", 0);
6528
6564
  __publicField(this, "velocity");
@@ -6549,6 +6585,10 @@ var SpriteKindPool = class {
6549
6585
  this.color = new Float32Array(n * 3);
6550
6586
  this.alpha = new Float32Array(n);
6551
6587
  this.size = new Float32Array(n);
6588
+ this.cutA = new Float32Array(n * 4);
6589
+ this.cutB = new Float32Array(n * 4);
6590
+ this.cutC = new Float32Array(n * 4);
6591
+ for (let i = 0; i < n; i++) this.uncut(i);
6552
6592
  this.velocity = new Float32Array(n * 3);
6553
6593
  this.age = new Float32Array(n);
6554
6594
  this.life = new Float32Array(n);
@@ -6597,6 +6637,51 @@ var SpriteKindPool = class {
6597
6637
  this.ground[i * 3] = Number.NaN;
6598
6638
  this.size[i] = this.size0[i];
6599
6639
  this.alpha[i] = 0;
6640
+ this.uncut(i);
6641
+ }
6642
+ /** Sprite `i` cut at no wall. */
6643
+ uncut(i) {
6644
+ this.cutA.fill(0, i * 4, i * 4 + 3);
6645
+ this.cutA[i * 4 + 3] = NO_CUT;
6646
+ this.cutB.fill(0, i * 4, i * 4 + 3);
6647
+ this.cutB[i * 4 + 3] = NO_CUT;
6648
+ this.cutC.fill(0, i * 4, i * 4 + 3);
6649
+ this.cutC[i * 4 + 3] = NO_CUT;
6650
+ }
6651
+ /**
6652
+ * 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`.
6653
+ * The sprite's faces go into the reused `VIEW` and come back out: no object a sprite.
6654
+ */
6655
+ cutAtWalls(i, confiner, met) {
6656
+ const o = i * 4;
6657
+ const i3 = i * 3;
6658
+ VIEW.x = this.position[i3];
6659
+ VIEW.y = this.position[i3 + 1];
6660
+ VIEW.z = this.position[i3 + 2];
6661
+ VIEW.vx = this.velocity[i3];
6662
+ VIEW.vy = this.velocity[i3 + 1];
6663
+ VIEW.vz = this.velocity[i3 + 2];
6664
+ VIEW.t = this.age[i];
6665
+ VIEW.size = this.size[i];
6666
+ for (let k = 0; k < PUFF_CUTS; k++) {
6667
+ const cut = VIEW.cuts[k];
6668
+ const faces = k === 0 ? this.cutA : k === 1 ? this.cutB : this.cutC;
6669
+ cut.on = faces[o + 3] !== NO_CUT;
6670
+ cut.nx = faces[o];
6671
+ cut.ny = faces[o + 1];
6672
+ cut.nz = faces[o + 2];
6673
+ cut.d = faces[o + 3];
6674
+ }
6675
+ if (met) cutFrom(VIEW, met);
6676
+ lookForWalls(confiner, VIEW);
6677
+ for (let k = 0; k < PUFF_CUTS; k++) {
6678
+ const cut = VIEW.cuts[k];
6679
+ const faces = k === 0 ? this.cutA : k === 1 ? this.cutB : this.cutC;
6680
+ faces[o] = cut.on ? cut.nx : 0;
6681
+ faces[o + 1] = cut.on ? cut.ny : 0;
6682
+ faces[o + 2] = cut.on ? cut.nz : 0;
6683
+ faces[o + 3] = cut.on ? cut.d : NO_CUT;
6684
+ }
6600
6685
  }
6601
6686
  ownerIndex(name) {
6602
6687
  let index = this.owners.indexOf(name);
@@ -6687,7 +6772,9 @@ var SpriteKindPool = class {
6687
6772
  let y = this.position[i3 + 1] + vy2 * dt;
6688
6773
  let z = this.position[i3 + 2] + vz2 * dt;
6689
6774
  const confiner = host.confiner;
6690
- if (def.carried && confiner && !confiner.empty) {
6775
+ const confining = def.carried && confiner !== void 0 && !confiner.empty;
6776
+ let met = false;
6777
+ if (confining) {
6691
6778
  STEP.x0 = this.position[i3];
6692
6779
  STEP.y0 = this.position[i3 + 1];
6693
6780
  STEP.z0 = this.position[i3 + 2];
@@ -6696,6 +6783,7 @@ var SpriteKindPool = class {
6696
6783
  STEP.z1 = z;
6697
6784
  STEP.pad = this.size0[i] * (1 + (def.grow - 1) * t) * PAD_OF_SIZE2;
6698
6785
  if (confiner.confineMove(STEP, dt)) {
6786
+ met = true;
6699
6787
  const out = confiner.out;
6700
6788
  x = out.x;
6701
6789
  y = out.y;
@@ -6744,6 +6832,8 @@ var SpriteKindPool = class {
6744
6832
  this.position[i3 + 1] = y;
6745
6833
  this.position[i3 + 2] = z;
6746
6834
  this.size[i] = this.size0[i] * lerp4(1, def.grow, t);
6835
+ if (confining) this.cutAtWalls(i, confiner, met ? confiner.out : null);
6836
+ 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
6837
  this.color[i3] = lerp4(this.rgbStart[i3], this.rgbEnd[i3], t);
6748
6838
  this.color[i3 + 1] = lerp4(this.rgbStart[i3 + 1], this.rgbEnd[i3 + 1], t);
6749
6839
  this.color[i3 + 2] = lerp4(this.rgbStart[i3 + 2], this.rgbEnd[i3 + 2], t);
@@ -10310,12 +10400,14 @@ export {
10310
10400
  OrderedPool,
10311
10401
  PIECES_DRAWN_VARIABLE,
10312
10402
  PROFILES,
10403
+ PUFF_CUTS,
10313
10404
  PUFF_REACH,
10314
10405
  RAIN_CAPACITY,
10315
10406
  RainField,
10316
10407
  SCRAPE_LIMIT,
10317
10408
  SMOKE_COLORS,
10318
10409
  SPRITE_KINDS,
10410
+ NO_CUT as SPRITE_NO_CUT,
10319
10411
  SpriteKindPool,
10320
10412
  SpriteKindSystem,
10321
10413
  VFX_LAYERS,