@adatechnology/game-vfx-three 0.10.1 → 0.10.3

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.
@@ -1252,7 +1252,8 @@ var GameVfxThree = (() => {
1252
1252
  trail: 0,
1253
1253
  glow: null,
1254
1254
  rng: placeholder,
1255
- outColor: [0, 0, 0]
1255
+ outColor: [0, 0, 0],
1256
+ source: void 0
1256
1257
  }),
1257
1258
  freezeFollowingGlow
1258
1259
  );
@@ -1354,7 +1355,8 @@ var GameVfxThree = (() => {
1354
1355
  outY: 0,
1355
1356
  outZ: 0,
1356
1357
  outSize: 0,
1357
- outIntensity: 0
1358
+ outIntensity: 0,
1359
+ source: void 0
1358
1360
  }));
1359
1361
  }
1360
1362
  function spawnGlow(pool, init) {
@@ -1374,6 +1376,7 @@ var GameVfxThree = (() => {
1374
1376
  glow.fx = init.fx ?? 0;
1375
1377
  glow.fy = init.fy ?? 0;
1376
1378
  glow.fz = init.fz ?? 0;
1379
+ glow.source = init.source;
1377
1380
  return glow;
1378
1381
  }
1379
1382
  function ageOrKeep(glow, dt) {
@@ -1657,7 +1660,8 @@ var GameVfxThree = (() => {
1657
1660
  rng: placeholder,
1658
1661
  age: 0,
1659
1662
  heat: 0,
1660
- size: 0
1663
+ size: 0,
1664
+ source: void 0
1661
1665
  }));
1662
1666
  }
1663
1667
  function spawnPuff(pool, random, init) {
@@ -1690,6 +1694,7 @@ var GameVfxThree = (() => {
1690
1694
  puff3.age = 0;
1691
1695
  puff3.heat = 0;
1692
1696
  puff3.size = 0;
1697
+ puff3.source = init.source;
1693
1698
  return puff3;
1694
1699
  }
1695
1700
  function ageOrKeep2(puff3, dt) {
@@ -1748,7 +1753,7 @@ var GameVfxThree = (() => {
1748
1753
  var GROUND_LIFT = 0.02;
1749
1754
  var BOUNCE_SLIDE = 0.55;
1750
1755
  function createSparkPool(capacity) {
1751
- return new OrderedPool(capacity, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, t: 0, life: 0.8, w: 0.04, st: 0.035, kind: 0, drag: 0.6, g: 9.8, bounce: 0.35, age: 0 }));
1756
+ return new OrderedPool(capacity, () => ({ x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, t: 0, life: 0.8, w: 0.04, st: 0.035, kind: 0, drag: 0.6, g: 9.8, bounce: 0.35, age: 0, source: void 0 }));
1752
1757
  }
1753
1758
  function spawnSpark(pool, init) {
1754
1759
  const spark = pool.acquire();
@@ -1767,6 +1772,7 @@ var GameVfxThree = (() => {
1767
1772
  spark.g = init.g ?? 9.8;
1768
1773
  spark.bounce = init.bounce ?? 0.35;
1769
1774
  spark.age = 0;
1775
+ spark.source = init.source;
1770
1776
  return spark;
1771
1777
  }
1772
1778
  function ageOrKeep3(spark, dt) {
@@ -1800,22 +1806,26 @@ var GameVfxThree = (() => {
1800
1806
  function addPuff(core, random, init) {
1801
1807
  core.spawned.puffs++;
1802
1808
  const puff3 = spawnPuff(core.puffs, random, init);
1809
+ puff3.source = init.source ?? core.source;
1803
1810
  core.trace?.puff?.(puff3);
1804
1811
  return puff3;
1805
1812
  }
1806
1813
  function addSpark(core, init) {
1807
1814
  core.spawned.sparks++;
1808
1815
  const spark = spawnSpark(core.sparks, init);
1816
+ spark.source = init.source ?? core.source;
1809
1817
  core.trace?.spark?.(spark);
1810
1818
  return spark;
1811
1819
  }
1812
1820
  function addGlow(core, init) {
1813
1821
  const glow = spawnGlow(core.glows, init);
1822
+ glow.source = init.source ?? core.source;
1814
1823
  core.trace?.glow?.(glow);
1815
1824
  return glow;
1816
1825
  }
1817
1826
  function addChunk(core, random, init) {
1818
1827
  const chunk = spawnChunk(core.chunks, random, init);
1828
+ chunk.source = core.source;
1819
1829
  core.spawned.chunks++;
1820
1830
  if (chunk.hot && core.layers.shrapnel) {
1821
1831
  chunk.glow = addGlow(core, { follow: chunk, s: 0.35 + chunk.sx, i: 2.2, life: random.between(1, 2.2), color: HOT_GLOW_COLOR, curve: 1.5 });
@@ -1844,7 +1854,8 @@ var GameVfxThree = (() => {
1844
1854
  fz: 0,
1845
1855
  color: SMOKE_COLORS.black,
1846
1856
  rng: placeholder,
1847
- handle: 0
1857
+ handle: 0,
1858
+ source: void 0
1848
1859
  }));
1849
1860
  }
1850
1861
  function spawnFire(pool, random, init, handle) {
@@ -1869,6 +1880,7 @@ var GameVfxThree = (() => {
1869
1880
  fire.color = init.color ?? SMOKE_COLORS.black;
1870
1881
  fire.rng = random;
1871
1882
  fire.handle = handle;
1883
+ fire.source = init.source;
1872
1884
  return fire;
1873
1885
  }
1874
1886
  function addFire(core, random, init, handle) {
@@ -1903,7 +1915,8 @@ var GameVfxThree = (() => {
1903
1915
  buoy: 3.2,
1904
1916
  color: fire.color,
1905
1917
  kind: 0,
1906
- wind: 0.4
1918
+ wind: 0.4,
1919
+ source: fire.source
1907
1920
  });
1908
1921
  }
1909
1922
  }
@@ -1926,7 +1939,8 @@ var GameVfxThree = (() => {
1926
1939
  drag: 0.6,
1927
1940
  buoy: 0.55,
1928
1941
  color: fire.color,
1929
- kind: 0
1942
+ kind: 0,
1943
+ source: fire.source
1930
1944
  });
1931
1945
  }
1932
1946
  }
@@ -1945,7 +1959,8 @@ var GameVfxThree = (() => {
1945
1959
  st: 0.02,
1946
1960
  kind: 4,
1947
1961
  g: -0.6,
1948
- drag: 1.2
1962
+ drag: 1.2,
1963
+ source: fire.source
1949
1964
  });
1950
1965
  }
1951
1966
  function updateFires(core, dt) {
@@ -5875,10 +5890,11 @@ var GameVfxThree = (() => {
5875
5890
  st: 0.05,
5876
5891
  kind: 0,
5877
5892
  g: 0,
5878
- drag: 1
5893
+ drag: 1,
5894
+ source: chunk.source
5879
5895
  });
5880
5896
  if (random.next() < 0.25) {
5881
- addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0 });
5897
+ addPuff(core, random, { x: chunk.x, y: chunk.y, z: chunk.z, s0: 0.04, s1: 0.14 + chunk.sx * 0.3, sg: 0.15, life: random.between(1, 1.6), drag: 2, buoy: 0.6, color: SMOKE_COLORS.grey, kind: 0, source: chunk.source });
5882
5898
  }
5883
5899
  }
5884
5900
  function updateChunks(core, dt) {
@@ -5934,10 +5950,11 @@ var GameVfxThree = (() => {
5934
5950
  };
5935
5951
  }
5936
5952
  var SpriteKindPool = class {
5937
- constructor(capacity, defs, owners) {
5953
+ constructor(capacity, defs, owners, sources = { ids: /* @__PURE__ */ new Map(), next: 0 }) {
5938
5954
  __publicField(this, "capacity", capacity);
5939
5955
  __publicField(this, "defs", defs);
5940
5956
  __publicField(this, "owners", owners);
5957
+ __publicField(this, "sources", sources);
5941
5958
  __publicField(this, "live", 0);
5942
5959
  __publicField(this, "drawCount", 0);
5943
5960
  __publicField(this, "position");
@@ -5956,6 +5973,7 @@ var GameVfxThree = (() => {
5956
5973
  __publicField(this, "alphaMul");
5957
5974
  __publicField(this, "tag");
5958
5975
  __publicField(this, "owner");
5976
+ __publicField(this, "source");
5959
5977
  __publicField(this, "colorHex");
5960
5978
  __publicField(this, "rgbStart");
5961
5979
  __publicField(this, "rgbEnd");
@@ -5977,6 +5995,7 @@ var GameVfxThree = (() => {
5977
5995
  this.alphaMul = new Float32Array(n);
5978
5996
  this.tag = new Int32Array(n);
5979
5997
  this.owner = new Int32Array(n);
5998
+ this.source = new Int32Array(n);
5980
5999
  this.colorHex = new Int32Array(n);
5981
6000
  this.rgbStart = new Float32Array(n * 3);
5982
6001
  this.rgbEnd = new Float32Array(n * 3);
@@ -6003,6 +6022,7 @@ var GameVfxThree = (() => {
6003
6022
  this.alphaMul[i] = options?.alpha ?? 1;
6004
6023
  this.tag[i] = options?.tag ?? 0;
6005
6024
  this.owner[i] = options?.owner === void 0 ? -1 : this.ownerIndex(options.owner);
6025
+ this.source[i] = options?.source === void 0 ? -1 : this.sourceIndex(options.source);
6006
6026
  this.colorHex[i] = options?.color ?? -1;
6007
6027
  this.rgbStart.set(rgb(options?.color ?? def.c0), i * 3);
6008
6028
  this.rgbEnd.set(rgb(options?.color ?? def.c1), i * 3);
@@ -6017,6 +6037,26 @@ var GameVfxThree = (() => {
6017
6037
  if (index < 0) index = this.owners.push(name) - 1;
6018
6038
  return index;
6019
6039
  }
6040
+ sourceIndex(name) {
6041
+ let index = this.sources.ids.get(name);
6042
+ if (index === void 0) {
6043
+ index = this.sources.next++;
6044
+ this.sources.ids.set(name, index);
6045
+ }
6046
+ return index;
6047
+ }
6048
+ /** Kills the live sprites made for `source`; returns how many went. */
6049
+ clearSource(source) {
6050
+ const index = this.sources.ids.get(source);
6051
+ if (index === void 0) return 0;
6052
+ let killed = 0;
6053
+ for (let i = 0; i < this.high; i++) {
6054
+ if (!this.alive[i] || this.source[i] !== index) continue;
6055
+ this.kill(i);
6056
+ killed++;
6057
+ }
6058
+ return killed;
6059
+ }
6020
6060
  kill(i) {
6021
6061
  if (!this.alive[i]) return;
6022
6062
  this.alive[i] = 0;
@@ -6462,14 +6502,15 @@ var GameVfxThree = (() => {
6462
6502
  __publicField(this, "defs");
6463
6503
  __publicField(this, "index", /* @__PURE__ */ new Map());
6464
6504
  __publicField(this, "owners", []);
6505
+ __publicField(this, "sources", { ids: /* @__PURE__ */ new Map(), next: 0 });
6465
6506
  __publicField(this, "listeners", /* @__PURE__ */ new Map());
6466
6507
  const kinds = options.kinds ?? SPRITE_KINDS;
6467
6508
  this.ids = Object.keys(kinds);
6468
6509
  this.defs = this.ids.map((id) => kinds[id]);
6469
6510
  this.ids.forEach((id, at3) => this.index.set(id, at3));
6470
6511
  const additiveCapacity = Math.floor(options.capacity * 0.4);
6471
- this.additive = new SpriteKindPool(additiveCapacity, this.defs, this.owners);
6472
- this.normal = new SpriteKindPool(options.capacity - additiveCapacity, this.defs, this.owners);
6512
+ this.additive = new SpriteKindPool(additiveCapacity, this.defs, this.owners, this.sources);
6513
+ this.normal = new SpriteKindPool(options.capacity - additiveCapacity, this.defs, this.owners, this.sources);
6473
6514
  this.random = spriteRandom(options.seed);
6474
6515
  }
6475
6516
  get capacity() {
@@ -6543,9 +6584,16 @@ var GameVfxThree = (() => {
6543
6584
  if (this.additive.live > 0 || this.additive.drawCount > 0) this.additive.update(dt, host);
6544
6585
  if (this.normal.live > 0 || this.normal.drawCount > 0) this.normal.update(dt, host);
6545
6586
  }
6587
+ /** Kills the live sprites made for `source` (`SpriteSpawnOptions.source`); returns how many went. */
6588
+ clearSource(source) {
6589
+ const killed = this.additive.clearSource(source) + this.normal.clearSource(source);
6590
+ this.sources.ids.delete(source);
6591
+ return killed;
6592
+ }
6546
6593
  clear() {
6547
6594
  this.additive.clear();
6548
6595
  this.normal.clear();
6596
+ this.sources.ids.clear();
6549
6597
  }
6550
6598
  };
6551
6599
  var TWO_PI_ROUNDED = 6.2832;
@@ -7573,7 +7621,8 @@ var GameVfxThree = (() => {
7573
7621
  groundAt,
7574
7622
  ...options.marklessAt ? { marklessAt: options.marklessAt } : {},
7575
7623
  ...options.cratersAt ? { cratersAt: options.cratersAt } : {},
7576
- emit: (request) => options.onRequest?.(request)
7624
+ emit: (request) => options.onRequest?.(request),
7625
+ source: void 0
7577
7626
  };
7578
7627
  function definitionOf(id) {
7579
7628
  return explosions[id] ?? explosions[aliases[id] ?? ""];
@@ -7584,7 +7633,13 @@ var GameVfxThree = (() => {
7584
7633
  return streamFor(seed ?? Math.imul(handles.events, AUTO_SEED) + (options.seed ?? 0));
7585
7634
  }
7586
7635
  function detonate(def, point, call3) {
7587
- composeExplosion(core, def, { x: point[0], y: point[1], z: point[2], direction: call3.direction, random: call3.random, handle: call3.handle });
7636
+ const outer = core.source;
7637
+ core.source = call3.source;
7638
+ try {
7639
+ composeExplosion(core, def, { x: point[0], y: point[1], z: point[2], direction: call3.direction, random: call3.random, handle: call3.handle });
7640
+ } finally {
7641
+ core.source = outer;
7642
+ }
7588
7643
  }
7589
7644
  let engine;
7590
7645
  let player;
@@ -7625,8 +7680,9 @@ var GameVfxThree = (() => {
7625
7680
  const handle = ++handles.next;
7626
7681
  const direction = explosionOptions.direction && { x: explosionOptions.direction[0], y: explosionOptions.direction[1], z: explosionOptions.direction[2] };
7627
7682
  const random = streamOf(explosionOptions.seed);
7628
- if (explosionOptions.delay) core.schedule.at(core.clock.time + explosionOptions.delay, () => detonate(def, point, { direction, random, handle }));
7629
- else detonate(def, point, { direction, random, handle });
7683
+ const source = explosionOptions.source;
7684
+ if (explosionOptions.delay) core.schedule.at(core.clock.time + explosionOptions.delay, () => detonate(def, point, { direction, random, handle, source }));
7685
+ else detonate(def, point, { direction, random, handle, source });
7630
7686
  return handle;
7631
7687
  },
7632
7688
  fire(fireOptions) {
@@ -7668,6 +7724,15 @@ var GameVfxThree = (() => {
7668
7724
  const fires = core.fires;
7669
7725
  for (let index = fires.items.length - 1; index >= 0; index--) if (fires.items[index].handle === handle) fires.removeAt(index);
7670
7726
  },
7727
+ clearSource(source) {
7728
+ const keep = (record, gone) => record.source !== gone;
7729
+ const drop = (pool) => {
7730
+ const before = pool.count;
7731
+ pool.compact(keep, source);
7732
+ return before - pool.count;
7733
+ };
7734
+ return drop(core.fires) + drop(core.puffs) + drop(core.sparks) + drop(core.chunks) + drop(core.glows) + spriteSystem.clearSource(source);
7735
+ },
7671
7736
  setLayer(layer2, on) {
7672
7737
  layers[layer2] = on;
7673
7738
  },