@adatechnology/game-vfx 0.14.0 → 0.15.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.d.ts +43 -2
- package/dist/index.global.js +86 -17
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +86 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1041,6 +1041,9 @@ function patchExplosions(base, changes) {
|
|
|
1041
1041
|
}
|
|
1042
1042
|
return result;
|
|
1043
1043
|
}
|
|
1044
|
+
function explosionEffectIds(explosions = EXPLOSIONS) {
|
|
1045
|
+
return Object.keys(explosions);
|
|
1046
|
+
}
|
|
1044
1047
|
|
|
1045
1048
|
// src/color.ts
|
|
1046
1049
|
var BYTE_MAX = 255;
|
|
@@ -1166,7 +1169,8 @@ function createChunkPool(capacity, placeholder) {
|
|
|
1166
1169
|
trail: 0,
|
|
1167
1170
|
glow: null,
|
|
1168
1171
|
rng: placeholder,
|
|
1169
|
-
outColor: [0, 0, 0]
|
|
1172
|
+
outColor: [0, 0, 0],
|
|
1173
|
+
source: void 0
|
|
1170
1174
|
}),
|
|
1171
1175
|
freezeFollowingGlow
|
|
1172
1176
|
);
|
|
@@ -1272,7 +1276,8 @@ function createGlowPool(capacity) {
|
|
|
1272
1276
|
outY: 0,
|
|
1273
1277
|
outZ: 0,
|
|
1274
1278
|
outSize: 0,
|
|
1275
|
-
outIntensity: 0
|
|
1279
|
+
outIntensity: 0,
|
|
1280
|
+
source: void 0
|
|
1276
1281
|
}));
|
|
1277
1282
|
}
|
|
1278
1283
|
function spawnGlow(pool, init) {
|
|
@@ -1292,6 +1297,7 @@ function spawnGlow(pool, init) {
|
|
|
1292
1297
|
glow.fx = init.fx ?? 0;
|
|
1293
1298
|
glow.fy = init.fy ?? 0;
|
|
1294
1299
|
glow.fz = init.fz ?? 0;
|
|
1300
|
+
glow.source = init.source;
|
|
1295
1301
|
return glow;
|
|
1296
1302
|
}
|
|
1297
1303
|
function ageOrKeep(glow, dt) {
|
|
@@ -1607,7 +1613,8 @@ function createPuffPool(capacity) {
|
|
|
1607
1613
|
rng: placeholder,
|
|
1608
1614
|
age: 0,
|
|
1609
1615
|
heat: 0,
|
|
1610
|
-
size: 0
|
|
1616
|
+
size: 0,
|
|
1617
|
+
source: void 0
|
|
1611
1618
|
}));
|
|
1612
1619
|
}
|
|
1613
1620
|
function spawnPuff(pool, random, init) {
|
|
@@ -1640,6 +1647,7 @@ function spawnPuff(pool, random, init) {
|
|
|
1640
1647
|
puff3.age = 0;
|
|
1641
1648
|
puff3.heat = 0;
|
|
1642
1649
|
puff3.size = 0;
|
|
1650
|
+
puff3.source = init.source;
|
|
1643
1651
|
return puff3;
|
|
1644
1652
|
}
|
|
1645
1653
|
function ageOrKeep2(puff3, dt) {
|
|
@@ -1700,7 +1708,7 @@ function updatePuffs(pool, dt, wind, confiner) {
|
|
|
1700
1708
|
var GROUND_LIFT = 0.02;
|
|
1701
1709
|
var BOUNCE_SLIDE = 0.55;
|
|
1702
1710
|
function createSparkPool(capacity) {
|
|
1703
|
-
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 }));
|
|
1711
|
+
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 }));
|
|
1704
1712
|
}
|
|
1705
1713
|
function spawnSpark(pool, init) {
|
|
1706
1714
|
const spark = pool.acquire();
|
|
@@ -1719,6 +1727,7 @@ function spawnSpark(pool, init) {
|
|
|
1719
1727
|
spark.g = init.g ?? 9.8;
|
|
1720
1728
|
spark.bounce = init.bounce ?? 0.35;
|
|
1721
1729
|
spark.age = 0;
|
|
1730
|
+
spark.source = init.source;
|
|
1722
1731
|
return spark;
|
|
1723
1732
|
}
|
|
1724
1733
|
function ageOrKeep3(spark, dt) {
|
|
@@ -1754,22 +1763,26 @@ var HOT_GLOW_COLOR = [1, 0.45, 0.12];
|
|
|
1754
1763
|
function addPuff(core, random, init) {
|
|
1755
1764
|
core.spawned.puffs++;
|
|
1756
1765
|
const puff3 = spawnPuff(core.puffs, random, init);
|
|
1766
|
+
puff3.source = init.source ?? core.source;
|
|
1757
1767
|
core.trace?.puff?.(puff3);
|
|
1758
1768
|
return puff3;
|
|
1759
1769
|
}
|
|
1760
1770
|
function addSpark(core, init) {
|
|
1761
1771
|
core.spawned.sparks++;
|
|
1762
1772
|
const spark = spawnSpark(core.sparks, init);
|
|
1773
|
+
spark.source = init.source ?? core.source;
|
|
1763
1774
|
core.trace?.spark?.(spark);
|
|
1764
1775
|
return spark;
|
|
1765
1776
|
}
|
|
1766
1777
|
function addGlow(core, init) {
|
|
1767
1778
|
const glow = spawnGlow(core.glows, init);
|
|
1779
|
+
glow.source = init.source ?? core.source;
|
|
1768
1780
|
core.trace?.glow?.(glow);
|
|
1769
1781
|
return glow;
|
|
1770
1782
|
}
|
|
1771
1783
|
function addChunk(core, random, init) {
|
|
1772
1784
|
const chunk = spawnChunk(core.chunks, random, init);
|
|
1785
|
+
chunk.source = core.source;
|
|
1773
1786
|
core.spawned.chunks++;
|
|
1774
1787
|
if (chunk.hot && core.layers.shrapnel) {
|
|
1775
1788
|
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 });
|
|
@@ -1800,7 +1813,8 @@ function createFirePool(capacity, placeholder) {
|
|
|
1800
1813
|
fz: 0,
|
|
1801
1814
|
color: SMOKE_COLORS.black,
|
|
1802
1815
|
rng: placeholder,
|
|
1803
|
-
handle: 0
|
|
1816
|
+
handle: 0,
|
|
1817
|
+
source: void 0
|
|
1804
1818
|
}));
|
|
1805
1819
|
}
|
|
1806
1820
|
function spawnFire(pool, random, init, handle) {
|
|
@@ -1825,6 +1839,7 @@ function spawnFire(pool, random, init, handle) {
|
|
|
1825
1839
|
fire.color = init.color ?? SMOKE_COLORS.black;
|
|
1826
1840
|
fire.rng = random;
|
|
1827
1841
|
fire.handle = handle;
|
|
1842
|
+
fire.source = init.source;
|
|
1828
1843
|
return fire;
|
|
1829
1844
|
}
|
|
1830
1845
|
function addFire(core, random, init, handle) {
|
|
@@ -1859,7 +1874,8 @@ function emitFlames(core, fire, radius, dt) {
|
|
|
1859
1874
|
buoy: 3.2,
|
|
1860
1875
|
color: fire.color,
|
|
1861
1876
|
kind: 0,
|
|
1862
|
-
wind: 0.4
|
|
1877
|
+
wind: 0.4,
|
|
1878
|
+
source: fire.source
|
|
1863
1879
|
});
|
|
1864
1880
|
}
|
|
1865
1881
|
}
|
|
@@ -1882,7 +1898,8 @@ function emitSmoke(core, fire, radius, dt) {
|
|
|
1882
1898
|
drag: 0.6,
|
|
1883
1899
|
buoy: 0.55,
|
|
1884
1900
|
color: fire.color,
|
|
1885
|
-
kind: 0
|
|
1901
|
+
kind: 0,
|
|
1902
|
+
source: fire.source
|
|
1886
1903
|
});
|
|
1887
1904
|
}
|
|
1888
1905
|
}
|
|
@@ -1901,7 +1918,8 @@ function emitEmber(core, fire, radius, dt) {
|
|
|
1901
1918
|
st: 0.02,
|
|
1902
1919
|
kind: 4,
|
|
1903
1920
|
g: -0.6,
|
|
1904
|
-
drag: 1.2
|
|
1921
|
+
drag: 1.2,
|
|
1922
|
+
source: fire.source
|
|
1905
1923
|
});
|
|
1906
1924
|
}
|
|
1907
1925
|
function updateFires(core, dt) {
|
|
@@ -6006,10 +6024,11 @@ function leaveTrail(core, chunk, dt) {
|
|
|
6006
6024
|
st: 0.05,
|
|
6007
6025
|
kind: 0,
|
|
6008
6026
|
g: 0,
|
|
6009
|
-
drag: 1
|
|
6027
|
+
drag: 1,
|
|
6028
|
+
source: chunk.source
|
|
6010
6029
|
});
|
|
6011
6030
|
if (random.next() < 0.25) {
|
|
6012
|
-
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 });
|
|
6031
|
+
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 });
|
|
6013
6032
|
}
|
|
6014
6033
|
}
|
|
6015
6034
|
function updateChunks(core, dt) {
|
|
@@ -6069,10 +6088,11 @@ function spriteRandom(seed) {
|
|
|
6069
6088
|
};
|
|
6070
6089
|
}
|
|
6071
6090
|
var SpriteKindPool = class {
|
|
6072
|
-
constructor(capacity, defs, owners) {
|
|
6091
|
+
constructor(capacity, defs, owners, sources = { ids: /* @__PURE__ */ new Map(), next: 0 }) {
|
|
6073
6092
|
__publicField(this, "capacity", capacity);
|
|
6074
6093
|
__publicField(this, "defs", defs);
|
|
6075
6094
|
__publicField(this, "owners", owners);
|
|
6095
|
+
__publicField(this, "sources", sources);
|
|
6076
6096
|
__publicField(this, "live", 0);
|
|
6077
6097
|
/** Records from the start the renderer draws (the highest live index + 1). */
|
|
6078
6098
|
__publicField(this, "drawCount", 0);
|
|
@@ -6092,6 +6112,7 @@ var SpriteKindPool = class {
|
|
|
6092
6112
|
__publicField(this, "alphaMul");
|
|
6093
6113
|
__publicField(this, "tag");
|
|
6094
6114
|
__publicField(this, "owner");
|
|
6115
|
+
__publicField(this, "source");
|
|
6095
6116
|
__publicField(this, "colorHex");
|
|
6096
6117
|
__publicField(this, "rgbStart");
|
|
6097
6118
|
__publicField(this, "rgbEnd");
|
|
@@ -6113,6 +6134,7 @@ var SpriteKindPool = class {
|
|
|
6113
6134
|
this.alphaMul = new Float32Array(n);
|
|
6114
6135
|
this.tag = new Int32Array(n);
|
|
6115
6136
|
this.owner = new Int32Array(n);
|
|
6137
|
+
this.source = new Int32Array(n);
|
|
6116
6138
|
this.colorHex = new Int32Array(n);
|
|
6117
6139
|
this.rgbStart = new Float32Array(n * 3);
|
|
6118
6140
|
this.rgbEnd = new Float32Array(n * 3);
|
|
@@ -6139,6 +6161,7 @@ var SpriteKindPool = class {
|
|
|
6139
6161
|
this.alphaMul[i] = options?.alpha ?? 1;
|
|
6140
6162
|
this.tag[i] = options?.tag ?? 0;
|
|
6141
6163
|
this.owner[i] = options?.owner === void 0 ? -1 : this.ownerIndex(options.owner);
|
|
6164
|
+
this.source[i] = options?.source === void 0 ? -1 : this.sourceIndex(options.source);
|
|
6142
6165
|
this.colorHex[i] = options?.color ?? -1;
|
|
6143
6166
|
this.rgbStart.set(rgb(options?.color ?? def.c0), i * 3);
|
|
6144
6167
|
this.rgbEnd.set(rgb(options?.color ?? def.c1), i * 3);
|
|
@@ -6153,6 +6176,26 @@ var SpriteKindPool = class {
|
|
|
6153
6176
|
if (index < 0) index = this.owners.push(name) - 1;
|
|
6154
6177
|
return index;
|
|
6155
6178
|
}
|
|
6179
|
+
sourceIndex(name) {
|
|
6180
|
+
let index = this.sources.ids.get(name);
|
|
6181
|
+
if (index === void 0) {
|
|
6182
|
+
index = this.sources.next++;
|
|
6183
|
+
this.sources.ids.set(name, index);
|
|
6184
|
+
}
|
|
6185
|
+
return index;
|
|
6186
|
+
}
|
|
6187
|
+
/** Kills the live sprites made for `source`; returns how many went. */
|
|
6188
|
+
clearSource(source) {
|
|
6189
|
+
const index = this.sources.ids.get(source);
|
|
6190
|
+
if (index === void 0) return 0;
|
|
6191
|
+
let killed = 0;
|
|
6192
|
+
for (let i = 0; i < this.high; i++) {
|
|
6193
|
+
if (!this.alive[i] || this.source[i] !== index) continue;
|
|
6194
|
+
this.kill(i);
|
|
6195
|
+
killed++;
|
|
6196
|
+
}
|
|
6197
|
+
return killed;
|
|
6198
|
+
}
|
|
6156
6199
|
kill(i) {
|
|
6157
6200
|
if (!this.alive[i]) return;
|
|
6158
6201
|
this.alive[i] = 0;
|
|
@@ -6612,14 +6655,15 @@ var SpriteKindSystem = class {
|
|
|
6612
6655
|
__publicField(this, "defs");
|
|
6613
6656
|
__publicField(this, "index", /* @__PURE__ */ new Map());
|
|
6614
6657
|
__publicField(this, "owners", []);
|
|
6658
|
+
__publicField(this, "sources", { ids: /* @__PURE__ */ new Map(), next: 0 });
|
|
6615
6659
|
__publicField(this, "listeners", /* @__PURE__ */ new Map());
|
|
6616
6660
|
const kinds = options.kinds ?? SPRITE_KINDS;
|
|
6617
6661
|
this.ids = Object.keys(kinds);
|
|
6618
6662
|
this.defs = this.ids.map((id) => kinds[id]);
|
|
6619
6663
|
this.ids.forEach((id, at3) => this.index.set(id, at3));
|
|
6620
6664
|
const additiveCapacity = Math.floor(options.capacity * 0.4);
|
|
6621
|
-
this.additive = new SpriteKindPool(additiveCapacity, this.defs, this.owners);
|
|
6622
|
-
this.normal = new SpriteKindPool(options.capacity - additiveCapacity, this.defs, this.owners);
|
|
6665
|
+
this.additive = new SpriteKindPool(additiveCapacity, this.defs, this.owners, this.sources);
|
|
6666
|
+
this.normal = new SpriteKindPool(options.capacity - additiveCapacity, this.defs, this.owners, this.sources);
|
|
6623
6667
|
this.random = spriteRandom(options.seed);
|
|
6624
6668
|
}
|
|
6625
6669
|
get capacity() {
|
|
@@ -6693,9 +6737,16 @@ var SpriteKindSystem = class {
|
|
|
6693
6737
|
if (this.additive.live > 0 || this.additive.drawCount > 0) this.additive.update(dt, host);
|
|
6694
6738
|
if (this.normal.live > 0 || this.normal.drawCount > 0) this.normal.update(dt, host);
|
|
6695
6739
|
}
|
|
6740
|
+
/** Kills the live sprites made for `source` (`SpriteSpawnOptions.source`); returns how many went. */
|
|
6741
|
+
clearSource(source) {
|
|
6742
|
+
const killed = this.additive.clearSource(source) + this.normal.clearSource(source);
|
|
6743
|
+
this.sources.ids.delete(source);
|
|
6744
|
+
return killed;
|
|
6745
|
+
}
|
|
6696
6746
|
clear() {
|
|
6697
6747
|
this.additive.clear();
|
|
6698
6748
|
this.normal.clear();
|
|
6749
|
+
this.sources.ids.clear();
|
|
6699
6750
|
}
|
|
6700
6751
|
};
|
|
6701
6752
|
|
|
@@ -7748,7 +7799,8 @@ function createVfx(options = {}) {
|
|
|
7748
7799
|
groundAt,
|
|
7749
7800
|
...options.marklessAt ? { marklessAt: options.marklessAt } : {},
|
|
7750
7801
|
...options.cratersAt ? { cratersAt: options.cratersAt } : {},
|
|
7751
|
-
emit: (request) => options.onRequest?.(request)
|
|
7802
|
+
emit: (request) => options.onRequest?.(request),
|
|
7803
|
+
source: void 0
|
|
7752
7804
|
};
|
|
7753
7805
|
function definitionOf(id) {
|
|
7754
7806
|
return explosions[id] ?? explosions[aliases[id] ?? ""];
|
|
@@ -7759,7 +7811,13 @@ function createVfx(options = {}) {
|
|
|
7759
7811
|
return streamFor(seed ?? Math.imul(handles.events, AUTO_SEED) + (options.seed ?? 0));
|
|
7760
7812
|
}
|
|
7761
7813
|
function detonate(def, point, call3) {
|
|
7762
|
-
|
|
7814
|
+
const outer = core.source;
|
|
7815
|
+
core.source = call3.source;
|
|
7816
|
+
try {
|
|
7817
|
+
composeExplosion(core, def, { x: point[0], y: point[1], z: point[2], direction: call3.direction, random: call3.random, handle: call3.handle });
|
|
7818
|
+
} finally {
|
|
7819
|
+
core.source = outer;
|
|
7820
|
+
}
|
|
7763
7821
|
}
|
|
7764
7822
|
let engine;
|
|
7765
7823
|
let player;
|
|
@@ -7800,8 +7858,9 @@ function createVfx(options = {}) {
|
|
|
7800
7858
|
const handle = ++handles.next;
|
|
7801
7859
|
const direction = explosionOptions.direction && { x: explosionOptions.direction[0], y: explosionOptions.direction[1], z: explosionOptions.direction[2] };
|
|
7802
7860
|
const random = streamOf(explosionOptions.seed);
|
|
7803
|
-
|
|
7804
|
-
|
|
7861
|
+
const source = explosionOptions.source;
|
|
7862
|
+
if (explosionOptions.delay) core.schedule.at(core.clock.time + explosionOptions.delay, () => detonate(def, point, { direction, random, handle, source }));
|
|
7863
|
+
else detonate(def, point, { direction, random, handle, source });
|
|
7805
7864
|
return handle;
|
|
7806
7865
|
},
|
|
7807
7866
|
fire(fireOptions) {
|
|
@@ -7843,6 +7902,15 @@ function createVfx(options = {}) {
|
|
|
7843
7902
|
const fires = core.fires;
|
|
7844
7903
|
for (let index = fires.items.length - 1; index >= 0; index--) if (fires.items[index].handle === handle) fires.removeAt(index);
|
|
7845
7904
|
},
|
|
7905
|
+
clearSource(source) {
|
|
7906
|
+
const keep = (record, gone) => record.source !== gone;
|
|
7907
|
+
const drop = (pool) => {
|
|
7908
|
+
const before = pool.count;
|
|
7909
|
+
pool.compact(keep, source);
|
|
7910
|
+
return before - pool.count;
|
|
7911
|
+
};
|
|
7912
|
+
return drop(core.fires) + drop(core.puffs) + drop(core.sparks) + drop(core.chunks) + drop(core.glows) + spriteSystem.clearSource(source);
|
|
7913
|
+
},
|
|
7846
7914
|
setLayer(layer, on) {
|
|
7847
7915
|
layers[layer] = on;
|
|
7848
7916
|
},
|
|
@@ -9723,6 +9791,7 @@ export {
|
|
|
9723
9791
|
createWorkshopBehaviors,
|
|
9724
9792
|
effectForEvent,
|
|
9725
9793
|
estimateCost,
|
|
9794
|
+
explosionEffectIds,
|
|
9726
9795
|
hexToLinearRgb,
|
|
9727
9796
|
hexToRgb,
|
|
9728
9797
|
inPuddle,
|