@adatechnology/game-vfx 0.4.4 → 0.6.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
@@ -1320,12 +1320,262 @@ function updateGlows(pool, dt) {
1320
1320
  }
1321
1321
  }
1322
1322
 
1323
+ // src/random.ts
1324
+ var LEHMER_MULTIPLIER = 16807;
1325
+ var LEHMER_MODULUS = 2147483647;
1326
+ var LCG_MULTIPLIER = 1664525;
1327
+ var LCG_INCREMENT = 1013904223;
1328
+ var LCG_RANGE = 4294967296;
1329
+ var HASH_MIX = 2654435761;
1330
+ function normalizeLehmerSeed(seed) {
1331
+ const whole = Math.floor(Math.abs(seed)) % (LEHMER_MODULUS - 1);
1332
+ return whole === 0 ? 1 : whole;
1333
+ }
1334
+ function lehmer(seed) {
1335
+ let state = normalizeLehmerSeed(seed);
1336
+ const next = () => {
1337
+ state = state * LEHMER_MULTIPLIER % LEHMER_MODULUS;
1338
+ return (state - 1) / (LEHMER_MODULUS - 1);
1339
+ };
1340
+ return {
1341
+ next,
1342
+ between: (min2, max2) => min2 + (max2 - min2) * next(),
1343
+ direction(out) {
1344
+ const up = next() * 2 - 1;
1345
+ const angle = next() * Math.PI * 2;
1346
+ const ring2 = Math.sqrt(1 - up * up);
1347
+ out.x = ring2 * Math.cos(angle);
1348
+ out.y = up;
1349
+ out.z = ring2 * Math.sin(angle);
1350
+ return out;
1351
+ },
1352
+ get state() {
1353
+ return state;
1354
+ }
1355
+ };
1356
+ }
1357
+ function lcg(seed) {
1358
+ let state = seed >>> 0;
1359
+ const next = () => {
1360
+ state = Math.imul(state, LCG_MULTIPLIER) + LCG_INCREMENT >>> 0;
1361
+ return state / LCG_RANGE;
1362
+ };
1363
+ return {
1364
+ next,
1365
+ between: (min2, max2) => min2 + (max2 - min2) * next(),
1366
+ direction(out) {
1367
+ const up = next() * 2 - 1;
1368
+ const angle = next() * Math.PI * 2;
1369
+ const ring2 = Math.sqrt(1 - up * up);
1370
+ out.x = ring2 * Math.cos(angle);
1371
+ out.y = up;
1372
+ out.z = ring2 * Math.sin(angle);
1373
+ return out;
1374
+ },
1375
+ get state() {
1376
+ return state;
1377
+ }
1378
+ };
1379
+ }
1380
+ function mixEventSeed(eventSeed) {
1381
+ let mixed = Math.imul((eventSeed | 0) ^ HASH_MIX, 2246822507);
1382
+ mixed ^= mixed >>> 13;
1383
+ mixed = Math.imul(mixed, 3266489909);
1384
+ mixed ^= mixed >>> 16;
1385
+ return (mixed >>> 0) % (LEHMER_MODULUS - 1) + 1;
1386
+ }
1387
+ function streamFor(eventSeed) {
1388
+ return lehmer(mixEventSeed(eventSeed));
1389
+ }
1390
+
1391
+ // src/enclosures.ts
1392
+ var SKIN = 5e-3;
1393
+ var MAX_PAD = 0.45;
1394
+ function rotation(q) {
1395
+ const [x, y, z, w] = q ?? [0, 0, 0, 1];
1396
+ const n = Math.hypot(x, y, z, w) || 1;
1397
+ const qx = x / n;
1398
+ const qy = y / n;
1399
+ const qz = z / n;
1400
+ const qw = w / n;
1401
+ return new Float64Array([
1402
+ 1 - 2 * (qy * qy + qz * qz),
1403
+ 2 * (qx * qy - qz * qw),
1404
+ 2 * (qx * qz + qy * qw),
1405
+ 2 * (qx * qy + qz * qw),
1406
+ 1 - 2 * (qx * qx + qz * qz),
1407
+ 2 * (qy * qz - qx * qw),
1408
+ 2 * (qx * qz - qy * qw),
1409
+ 2 * (qy * qz + qx * qw),
1410
+ 1 - 2 * (qx * qx + qy * qy)
1411
+ ]);
1412
+ }
1413
+ var Enclosures = class {
1414
+ constructor(seed = 20973) {
1415
+ __publicField(this, "spaces", /* @__PURE__ */ new Map());
1416
+ __publicField(this, "list", []);
1417
+ __publicField(this, "random");
1418
+ __publicField(this, "out", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
1419
+ __publicField(this, "l0", new Float64Array(3));
1420
+ __publicField(this, "l1", new Float64Array(3));
1421
+ __publicField(this, "q", new Float64Array(3));
1422
+ this.random = lehmer(seed);
1423
+ }
1424
+ get empty() {
1425
+ return this.list.length === 0;
1426
+ }
1427
+ get size() {
1428
+ return this.list.length;
1429
+ }
1430
+ /** Declares, moves or (with `null`) ends the space `id`. */
1431
+ set(id, enclosure) {
1432
+ if (!enclosure) {
1433
+ if (this.spaces.delete(id)) this.list = [...this.spaces.values()];
1434
+ return;
1435
+ }
1436
+ const [hx, hy, hz] = enclosure.halfSize;
1437
+ const space = {
1438
+ cx: enclosure.center[0],
1439
+ cy: enclosure.center[1],
1440
+ cz: enclosure.center[2],
1441
+ hx: Math.abs(hx),
1442
+ hy: Math.abs(hy),
1443
+ hz: Math.abs(hz),
1444
+ r: rotation(enclosure.orientation),
1445
+ radius: Math.hypot(hx, hy, hz),
1446
+ openings: enclosure.openings ?? [],
1447
+ leak: Math.max(0, enclosure.leak ?? 0)
1448
+ };
1449
+ const old = this.spaces.get(id);
1450
+ this.spaces.set(id, space);
1451
+ const at3 = old ? this.list.indexOf(old) : -1;
1452
+ if (at3 >= 0) this.list[at3] = space;
1453
+ else this.list.push(space);
1454
+ }
1455
+ get(id) {
1456
+ const s = this.spaces.get(id);
1457
+ if (!s) return void 0;
1458
+ return { center: [s.cx, s.cy, s.cz], halfSize: [s.hx, s.hy, s.hz], openings: s.openings, leak: s.leak };
1459
+ }
1460
+ ids() {
1461
+ return [...this.spaces.keys()];
1462
+ }
1463
+ clear() {
1464
+ this.spaces.clear();
1465
+ this.list = [];
1466
+ }
1467
+ /** Whether a point is inside any space (on the inside of its walls). */
1468
+ inside(x, y, z) {
1469
+ for (const s of this.list) {
1470
+ this.toLocal(s, x, y, z, this.l0);
1471
+ if (Math.abs(this.l0[0]) <= s.hx && Math.abs(this.l0[1]) <= s.hy && Math.abs(this.l0[2]) <= s.hz) return true;
1472
+ }
1473
+ return false;
1474
+ }
1475
+ toLocal(s, x, y, z, out) {
1476
+ const dx = x - s.cx;
1477
+ const dy = y - s.cy;
1478
+ const dz = z - s.cz;
1479
+ const r = s.r;
1480
+ out[0] = r[0] * dx + r[3] * dy + r[6] * dz;
1481
+ out[1] = r[1] * dx + r[4] * dy + r[7] * dz;
1482
+ out[2] = r[2] * dx + r[5] * dy + r[8] * dz;
1483
+ }
1484
+ /** Passes at `rate` per second. */
1485
+ chance(rate, dt) {
1486
+ return rate > 0 && this.random.next() < 1 - Math.exp(-rate * dt);
1487
+ }
1488
+ /** The opening the wall point `q` (local) is in lets it through now. */
1489
+ through(s, q, dt) {
1490
+ for (const o of s.openings) {
1491
+ 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;
1492
+ if (o.rate === void 0 || this.chance(o.rate, dt)) return true;
1493
+ }
1494
+ return this.chance(s.leak, dt);
1495
+ }
1496
+ confine(x0, y0, z0, x1, y1, z1, pad, dt) {
1497
+ const list = this.list;
1498
+ if (list.length === 0) return false;
1499
+ const p = Math.min(Math.max(0, pad), MAX_PAD);
1500
+ const l0 = this.l0;
1501
+ const l1 = this.l1;
1502
+ const q = this.q;
1503
+ for (const s of list) {
1504
+ const reach = s.radius + p + 0.05;
1505
+ const dx = x1 - s.cx;
1506
+ const dy = y1 - s.cy;
1507
+ const dz = z1 - s.cz;
1508
+ if (dx * dx + dy * dy + dz * dz > reach * reach) {
1509
+ const ex = x0 - s.cx;
1510
+ const ey = y0 - s.cy;
1511
+ const ez = z0 - s.cz;
1512
+ if (ex * ex + ey * ey + ez * ez > reach * reach) continue;
1513
+ }
1514
+ this.toLocal(s, x0, y0, z0, l0);
1515
+ this.toLocal(s, x1, y1, z1, l1);
1516
+ const h = [s.hx, s.hy, s.hz];
1517
+ const in0 = Math.abs(l0[0]) <= s.hx && Math.abs(l0[1]) <= s.hy && Math.abs(l0[2]) <= s.hz;
1518
+ let axis2 = 0;
1519
+ let sign = 1;
1520
+ if (in0) {
1521
+ if (Math.abs(l1[0]) <= s.hx && Math.abs(l1[1]) <= s.hy && Math.abs(l1[2]) <= s.hz) continue;
1522
+ for (let a = 0; a < 3; a++) q[a] = Math.min(h[a], Math.max(-h[a], l1[a]));
1523
+ if (this.through(s, q, dt)) continue;
1524
+ let worst = -Infinity;
1525
+ for (let a = 0; a < 3; a++) {
1526
+ const over = Math.abs(l1[a]) - h[a];
1527
+ if (over > worst) {
1528
+ worst = over;
1529
+ axis2 = a;
1530
+ }
1531
+ }
1532
+ sign = l1[axis2] < 0 ? -1 : 1;
1533
+ for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN, Math.max(-(h[a] - SKIN), l1[a]));
1534
+ sign = -sign;
1535
+ } else {
1536
+ const padded0 = Math.abs(l0[0]) <= s.hx + p && Math.abs(l0[1]) <= s.hy + p && Math.abs(l0[2]) <= s.hz + p;
1537
+ const bound = padded0 ? 0 : p;
1538
+ if (!(Math.abs(l1[0]) <= s.hx + bound && Math.abs(l1[1]) <= s.hy + bound && Math.abs(l1[2]) <= s.hz + bound)) continue;
1539
+ for (let a = 0; a < 3; a++) q[a] = Math.min(h[a], Math.max(-h[a], l1[a]));
1540
+ if (this.through(s, q, dt)) continue;
1541
+ let worst = -Infinity;
1542
+ for (let a = 0; a < 3; a++) {
1543
+ const over = Math.abs(l0[a]) - (h[a] + bound);
1544
+ if (over > worst) {
1545
+ worst = over;
1546
+ axis2 = a;
1547
+ }
1548
+ }
1549
+ sign = l0[axis2] < 0 ? -1 : 1;
1550
+ l1[axis2] = sign * (h[axis2] + bound + SKIN);
1551
+ }
1552
+ const r = s.r;
1553
+ const out = this.out;
1554
+ out.x = s.cx + r[0] * l1[0] + r[1] * l1[1] + r[2] * l1[2];
1555
+ out.y = s.cy + r[3] * l1[0] + r[4] * l1[1] + r[5] * l1[2];
1556
+ out.z = s.cz + r[6] * l1[0] + r[7] * l1[1] + r[8] * l1[2];
1557
+ out.nx = r[axis2] * sign;
1558
+ out.ny = r[3 + axis2] * sign;
1559
+ out.nz = r[6 + axis2] * sign;
1560
+ return true;
1561
+ }
1562
+ return false;
1563
+ }
1564
+ };
1565
+ function slideAlong(out, vx2, vy2, vz2) {
1566
+ const into = vx2 * out.nx + vy2 * out.ny + vz2 * out.nz;
1567
+ if (into >= 0) return [vx2, vy2, vz2];
1568
+ return [vx2 - into * out.nx, vy2 - into * out.ny, vz2 - into * out.nz];
1569
+ }
1570
+
1323
1571
  // src/pools/puffs.ts
1324
1572
  var FLOOR_FRACTION = 0.4;
1325
1573
  var FLOOR_BOUNCE = -0.2;
1326
1574
  var ARRIVAL_FRAME = 30;
1327
1575
  var ARRIVAL_BASE = 0.3;
1328
1576
  var GROWTH_CAP_SECONDS = 3.5;
1577
+ var CARRIED_KINDS = [true, true, false, true, false];
1578
+ var PAD_OF_SIZE = 0.35;
1329
1579
  function createPuffPool(capacity) {
1330
1580
  const placeholder = { next: () => 0, between: (min2) => min2, direction: (out) => out, state: 0 };
1331
1581
  return new OrderedPool(capacity, () => ({
@@ -1420,13 +1670,24 @@ function moveFree(puff3, dt, age, heat, wind) {
1420
1670
  if (puff3.vy < 0) puff3.vy *= FLOOR_BOUNCE;
1421
1671
  }
1422
1672
  }
1423
- function updatePuffs(pool, dt, wind) {
1673
+ function updatePuffs(pool, dt, wind, confiner) {
1424
1674
  pool.compact(ageOrKeep2, dt);
1675
+ const confining = confiner !== void 0 && !confiner.empty;
1425
1676
  for (const puff3 of pool.items) {
1426
1677
  const age = puff3.t / puff3.life;
1427
1678
  const heat = puff3.h0 > 0 ? puff3.h0 * Math.pow(Math.max(0, 1 - puff3.t / puff3.hl), 1.25) : 0;
1679
+ const x0 = puff3.x;
1680
+ const y0 = puff3.y;
1681
+ const z0 = puff3.z;
1428
1682
  if (puff3.ring) moveOnRing(puff3, puff3.ring, wind);
1429
1683
  else moveFree(puff3, dt, age, heat, wind);
1684
+ if (confining && CARRIED_KINDS[puff3.kind] && confiner.confine(x0, y0, z0, puff3.x, puff3.y, puff3.z, puff3.size * PAD_OF_SIZE, dt)) {
1685
+ const out = confiner.out;
1686
+ puff3.x = out.x;
1687
+ puff3.y = out.y;
1688
+ puff3.z = out.z;
1689
+ [puff3.vx, puff3.vy, puff3.vz] = slideAlong(out, puff3.vx, puff3.vy, puff3.vz);
1690
+ }
1430
1691
  const size = puff3.s0 + (puff3.s1 - puff3.s0) * (1 - Math.exp(-puff3.t * puff3.gk)) + puff3.sg * Math.min(puff3.t, GROWTH_CAP_SECONDS);
1431
1692
  puff3.size = size * Math.min(1, puff3.t * ARRIVAL_FRAME + ARRIVAL_BASE);
1432
1693
  puff3.age = age;
@@ -1980,10 +2241,10 @@ var SCREAMER_SHRIEK = {
1980
2241
  };
1981
2242
 
1982
2243
  // src/effects/props.ts
1983
- function localToWorld(translation, rotation, local2) {
2244
+ function localToWorld(translation, rotation2, local2) {
1984
2245
  const [x, y, z] = local2;
1985
- const [a, c, e] = [Math.cos(rotation[0]), Math.cos(rotation[1]), Math.cos(rotation[2])];
1986
- const [b, d, f] = [Math.sin(rotation[0]), Math.sin(rotation[1]), Math.sin(rotation[2])];
2246
+ const [a, c, e] = [Math.cos(rotation2[0]), Math.cos(rotation2[1]), Math.cos(rotation2[2])];
2247
+ const [b, d, f] = [Math.sin(rotation2[0]), Math.sin(rotation2[1]), Math.sin(rotation2[2])];
1987
2248
  const [ae, af, be, bf] = [a * e, a * f, b * e, b * f];
1988
2249
  return [
1989
2250
  c * e * x + -c * f * y + d * z + translation[0],
@@ -3740,74 +4001,6 @@ function patchEffects(base, changes) {
3740
4001
  return result;
3741
4002
  }
3742
4003
 
3743
- // src/random.ts
3744
- var LEHMER_MULTIPLIER = 16807;
3745
- var LEHMER_MODULUS = 2147483647;
3746
- var LCG_MULTIPLIER = 1664525;
3747
- var LCG_INCREMENT = 1013904223;
3748
- var LCG_RANGE = 4294967296;
3749
- var HASH_MIX = 2654435761;
3750
- function normalizeLehmerSeed(seed) {
3751
- const whole = Math.floor(Math.abs(seed)) % (LEHMER_MODULUS - 1);
3752
- return whole === 0 ? 1 : whole;
3753
- }
3754
- function lehmer(seed) {
3755
- let state = normalizeLehmerSeed(seed);
3756
- const next = () => {
3757
- state = state * LEHMER_MULTIPLIER % LEHMER_MODULUS;
3758
- return (state - 1) / (LEHMER_MODULUS - 1);
3759
- };
3760
- return {
3761
- next,
3762
- between: (min2, max2) => min2 + (max2 - min2) * next(),
3763
- direction(out) {
3764
- const up = next() * 2 - 1;
3765
- const angle = next() * Math.PI * 2;
3766
- const ring2 = Math.sqrt(1 - up * up);
3767
- out.x = ring2 * Math.cos(angle);
3768
- out.y = up;
3769
- out.z = ring2 * Math.sin(angle);
3770
- return out;
3771
- },
3772
- get state() {
3773
- return state;
3774
- }
3775
- };
3776
- }
3777
- function lcg(seed) {
3778
- let state = seed >>> 0;
3779
- const next = () => {
3780
- state = Math.imul(state, LCG_MULTIPLIER) + LCG_INCREMENT >>> 0;
3781
- return state / LCG_RANGE;
3782
- };
3783
- return {
3784
- next,
3785
- between: (min2, max2) => min2 + (max2 - min2) * next(),
3786
- direction(out) {
3787
- const up = next() * 2 - 1;
3788
- const angle = next() * Math.PI * 2;
3789
- const ring2 = Math.sqrt(1 - up * up);
3790
- out.x = ring2 * Math.cos(angle);
3791
- out.y = up;
3792
- out.z = ring2 * Math.sin(angle);
3793
- return out;
3794
- },
3795
- get state() {
3796
- return state;
3797
- }
3798
- };
3799
- }
3800
- function mixEventSeed(eventSeed) {
3801
- let mixed = Math.imul((eventSeed | 0) ^ HASH_MIX, 2246822507);
3802
- mixed ^= mixed >>> 13;
3803
- mixed = Math.imul(mixed, 3266489909);
3804
- mixed ^= mixed >>> 16;
3805
- return (mixed >>> 0) % (LEHMER_MODULUS - 1) + 1;
3806
- }
3807
- function streamFor(eventSeed) {
3808
- return lehmer(mixEventSeed(eventSeed));
3809
- }
3810
-
3811
4004
  // src/effects/builders/impact-table.ts
3812
4005
  var TABLE = {
3813
4006
  concrete: { dust: 9078138, chip: 7236195, spark: 2 },
@@ -5158,8 +5351,8 @@ function nextLift(store) {
5158
5351
  function addScorch(store, random, x, z, radius) {
5159
5352
  const variant = Math.floor(random.next() * SCORCH_VARIANTS);
5160
5353
  const lift = 0.03 + nextLift(store) * 1e-3;
5161
- const rotation = random.next() * 6;
5162
- store.add({ kind: "scorch", x, z, radius, variant, lift, rotation });
5354
+ const rotation2 = random.next() * 6;
5355
+ store.add({ kind: "scorch", x, z, radius, variant, lift, rotation: rotation2 });
5163
5356
  }
5164
5357
  function addRimRocks(store, ground, random, x, z, radius) {
5165
5358
  const count = Math.round(6 + radius * 7);
@@ -5188,8 +5381,8 @@ function addRimRocks(store, ground, random, x, z, radius) {
5188
5381
  function addCrater(store, ground, random, spec) {
5189
5382
  ground?.dent(random, spec.x, spec.z, spec.radius, spec.depth);
5190
5383
  if (!spec.marks) return;
5191
- const rotation = random.next() * 6;
5192
- store.add({ kind: "dirt", x: spec.x, z: spec.z, radius: spec.radius * 1.02, lift: 0.045, rotation });
5384
+ const rotation2 = random.next() * 6;
5385
+ store.add({ kind: "dirt", x: spec.x, z: spec.z, radius: spec.radius * 1.02, lift: 0.045, rotation: rotation2 });
5193
5386
  addRimRocks(store, ground, random, spec.x, spec.z, spec.radius);
5194
5387
  }
5195
5388
  function addBloodSplat(store, ground, random, spec) {
@@ -5757,6 +5950,7 @@ function updateScreen(state, dt) {
5757
5950
  }
5758
5951
 
5759
5952
  // src/sprites/kind-pool.ts
5953
+ var PAD_OF_SIZE2 = 0.35;
5760
5954
  var clamp4 = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
5761
5955
  var lerp4 = (a, b, t) => a + (b - a) * t;
5762
5956
  function rgb(hex) {
@@ -5917,9 +6111,20 @@ var SpriteKindPool = class {
5917
6111
  vy2 *= k;
5918
6112
  vz2 *= k;
5919
6113
  }
5920
- const x = this.position[i3] + vx2 * dt;
6114
+ let x = this.position[i3] + vx2 * dt;
5921
6115
  let y = this.position[i3 + 1] + vy2 * dt;
5922
- const z = this.position[i3 + 2] + vz2 * dt;
6116
+ let z = this.position[i3 + 2] + vz2 * dt;
6117
+ const confiner = host.confiner;
6118
+ if (def.carried && confiner && !confiner.empty) {
6119
+ const pad = this.size0[i] * lerp4(1, def.grow, t) * PAD_OF_SIZE2;
6120
+ if (confiner.confine(this.position[i3], this.position[i3 + 1], this.position[i3 + 2], x, y, z, pad, dt)) {
6121
+ const out = confiner.out;
6122
+ x = out.x;
6123
+ y = out.y;
6124
+ z = out.z;
6125
+ [vx2, vy2, vz2] = slideAlong(out, vx2, vy2, vz2);
6126
+ }
6127
+ }
5923
6128
  if (def.ground !== "none") {
5924
6129
  const own = this.floor[i];
5925
6130
  const gy = Number.isNaN(own) ? host.groundAt(x, z) + 5e-3 : own;
@@ -6007,7 +6212,8 @@ var sprite_kinds_default = {
6007
6212
  alpha: 0.35,
6008
6213
  fadeIn: 0.15,
6009
6214
  cone: 0.6,
6010
- ground: "none"
6215
+ ground: "none",
6216
+ carried: true
6011
6217
  },
6012
6218
  sparks: {
6013
6219
  id: "sparks",
@@ -6051,7 +6257,8 @@ var sprite_kinds_default = {
6051
6257
  alpha: 0.4,
6052
6258
  fadeIn: 0.1,
6053
6259
  cone: 0.4,
6054
- ground: "none"
6260
+ ground: "none",
6261
+ carried: true
6055
6262
  },
6056
6263
  shards: {
6057
6264
  id: "shards",
@@ -6209,7 +6416,8 @@ var sprite_kinds_default = {
6209
6416
  fadeIn: 0.1,
6210
6417
  cone: 0.5,
6211
6418
  ground: "stop",
6212
- flutter: 0.6
6419
+ flutter: 0.6,
6420
+ carried: true
6213
6421
  },
6214
6422
  steam: {
6215
6423
  id: "steam",
@@ -6231,7 +6439,8 @@ var sprite_kinds_default = {
6231
6439
  alpha: 0.35,
6232
6440
  fadeIn: 0.15,
6233
6441
  cone: 0.6,
6234
- ground: "none"
6442
+ ground: "none",
6443
+ carried: true
6235
6444
  },
6236
6445
  flash: {
6237
6446
  id: "flash",
@@ -6376,7 +6585,8 @@ var SpriteKindSystem = class {
6376
6585
  const host = {
6377
6586
  groundAt: this.options.groundAt,
6378
6587
  gravity: this.options.gravity,
6379
- land: (owner, x, y, z, color, tag) => this.listeners.get(owner)?.(x, y, z, color, tag)
6588
+ land: (owner, x, y, z, color, tag) => this.listeners.get(owner)?.(x, y, z, color, tag),
6589
+ ...this.options.confiner ? { confiner: this.options.confiner } : {}
6380
6590
  };
6381
6591
  if (this.additive.live > 0 || this.additive.drawCount > 0) this.additive.update(dt, host);
6382
6592
  if (this.normal.live > 0 || this.normal.drawCount > 0) this.normal.update(dt, host);
@@ -6584,6 +6794,24 @@ var DecalPool = class {
6584
6794
  for (const decal2 of this.decals) decal2.on = false;
6585
6795
  this.count = 0;
6586
6796
  }
6797
+ /**
6798
+ * Takes away the marks inside a box: world `center`, `half` extents along the axes of the world `rotation` (a quaternion, x y z w; none means the
6799
+ * world axes). The surface they were on is gone (a brick came out of a wall with its bullet holes). Returns how many went.
6800
+ */
6801
+ clearInside(center, half, rotation2 = [0, 0, 0, 1]) {
6802
+ const qx = -rotation2[0], qy = -rotation2[1], qz = -rotation2[2], qw = rotation2[3];
6803
+ let gone = 0;
6804
+ for (const decal2 of this.decals) {
6805
+ if (!decal2.on) continue;
6806
+ const vx2 = decal2.x - center[0], vy2 = decal2.y - center[1], vz2 = decal2.z - center[2];
6807
+ const tx = 2 * (qy * vz2 - qz * vy2), ty = 2 * (qz * vx2 - qx * vz2), tz = 2 * (qx * vy2 - qy * vx2);
6808
+ const lx = vx2 + qw * tx + (qy * tz - qz * ty), ly = vy2 + qw * ty + (qz * tx - qx * tz), lz = vz2 + qw * tz + (qx * ty - qy * tx);
6809
+ if (Math.abs(lx) > half[0] || Math.abs(ly) > half[1] || Math.abs(lz) > half[2]) continue;
6810
+ decal2.on = false;
6811
+ gone++;
6812
+ }
6813
+ return gone;
6814
+ }
6587
6815
  update(dt) {
6588
6816
  this.count = 0;
6589
6817
  for (const decal2 of this.decals) {
@@ -6696,10 +6924,14 @@ var MeshPool = class {
6696
6924
  var DEFAULT_FADE_IN = 0.1;
6697
6925
  var FLOATS_PER_VECTOR = 3;
6698
6926
  var BYTE_MAX2 = 255;
6927
+ var CARRIED_GRAVITY = 3;
6928
+ var PAD_OF_SIZE3 = 0.35;
6699
6929
  var SpritePool = class {
6700
- constructor(capacity, context) {
6930
+ /** `carried`: the normal-blend pool (smoke, dust, steam), whose light sprites go round the closed spaces; the additive one (flames, sparks) does not. */
6931
+ constructor(capacity, context, carried = false) {
6701
6932
  __publicField(this, "capacity", capacity);
6702
6933
  __publicField(this, "context", context);
6934
+ __publicField(this, "carried", carried);
6703
6935
  __publicField(this, "count", 0);
6704
6936
  __publicField(this, "position");
6705
6937
  __publicField(this, "velocity");
@@ -6800,6 +7032,7 @@ var SpritePool = class {
6800
7032
  }
6801
7033
  update(dt, leaveDecal) {
6802
7034
  const { position, velocity } = this;
7035
+ const confiner = this.context.confiner;
6803
7036
  for (let index = this.count - 1; index >= 0; index--) {
6804
7037
  this.life[index] -= dt;
6805
7038
  if (this.life[index] <= 0) {
@@ -6813,9 +7046,25 @@ var SpritePool = class {
6813
7046
  velocity[offset] *= factor;
6814
7047
  velocity[offset + 1] *= factor;
6815
7048
  velocity[offset + 2] *= factor;
7049
+ const x0 = position[offset];
7050
+ const y0 = position[offset + 1];
7051
+ const z0 = position[offset + 2];
6816
7052
  position[offset] += velocity[offset] * dt;
6817
7053
  position[offset + 1] += velocity[offset + 1] * dt;
6818
7054
  position[offset + 2] += velocity[offset + 2] * dt;
7055
+ if (this.carried && confiner && !confiner.empty && Math.abs(this.gravity[index]) < CARRIED_GRAVITY) {
7056
+ const size = this.startSize[index] * (1 + (this.growth[index] - 1) * age);
7057
+ if (confiner.confine(x0, y0, z0, position[offset], position[offset + 1], position[offset + 2], size * PAD_OF_SIZE3, dt)) {
7058
+ const out = confiner.out;
7059
+ position[offset] = out.x;
7060
+ position[offset + 1] = out.y;
7061
+ position[offset + 2] = out.z;
7062
+ const [vx2, vy2, vz2] = slideAlong(out, velocity[offset], velocity[offset + 1], velocity[offset + 2]);
7063
+ velocity[offset] = vx2;
7064
+ velocity[offset + 1] = vy2;
7065
+ velocity[offset + 2] = vz2;
7066
+ }
7067
+ }
6819
7068
  const mode = this.groundMode[index];
6820
7069
  if (mode) {
6821
7070
  const groundHeight = this.context.groundAt(position[offset], position[offset + 2]);
@@ -7100,9 +7349,9 @@ var WorkshopEngine = class {
7100
7349
  __publicField(this, "placement");
7101
7350
  __publicField(this, "accumulators", /* @__PURE__ */ new Map());
7102
7351
  const profile = options.profile ?? PROFILES.high;
7103
- this.context = { random: options.random, groundAt: options.groundAt ?? workshopGround, quality: { level: 0, mult: 1 }, trace: options.trace };
7352
+ this.context = { random: options.random, groundAt: options.groundAt ?? workshopGround, quality: { level: 0, mult: 1 }, trace: options.trace, ...options.confiner ? { confiner: options.confiner } : {} };
7104
7353
  this.add = new SpritePool(profile.sprites.add, this.context);
7105
- this.normal = new SpritePool(profile.sprites.normal, this.context);
7354
+ this.normal = new SpritePool(profile.sprites.normal, this.context, true);
7106
7355
  this.streaks = new StreakPool(profile.streaks, this.context);
7107
7356
  this.debris = new DebrisPool(this.context);
7108
7357
  this.decals = new DecalPool(this.context);
@@ -7294,12 +7543,14 @@ function createVfx(options = {}) {
7294
7543
  const groundAt = options.groundAt ?? (ground ? (x, z) => ground.heightAt(x, z) : () => 0);
7295
7544
  const handles = { next: 0, events: 0 };
7296
7545
  const low = options.profile === "low";
7546
+ const enclosures = new Enclosures(20973 + (options.seed ?? 0));
7297
7547
  const spriteSystem = new SpriteKindSystem({
7298
7548
  capacity: options.sprites?.capacity ?? (low ? 1250 : 2500),
7299
7549
  density: options.sprites?.density ?? (low ? 0.6 : 1),
7300
7550
  seed: 2654435761 + (options.seed ?? 0),
7301
7551
  groundAt,
7302
7552
  gravity: options.gravity ?? DEFAULT_GRAVITY,
7553
+ confiner: enclosures,
7303
7554
  ...options.sprites?.kinds ? { kinds: options.sprites.kinds } : {}
7304
7555
  });
7305
7556
  const core = {
@@ -7349,7 +7600,7 @@ function createVfx(options = {}) {
7349
7600
  return [camera2.x, camera2.y, camera2.z];
7350
7601
  }, forward: (local2) => [local2[0] ?? 0, local2[1] ?? 0, local2[2] ?? 0] };
7351
7602
  function workshop() {
7352
- return engine ?? (engine = new WorkshopEngine({ random: sharedRandom, profile, groundAt }));
7603
+ return engine ?? (engine = new WorkshopEngine({ random: sharedRandom, profile, groundAt, confiner: enclosures }));
7353
7604
  }
7354
7605
  function effectPlayer() {
7355
7606
  return player ?? (player = createEffectPlayer({ engine: workshop(), effects, view }));
@@ -7408,6 +7659,10 @@ function createVfx(options = {}) {
7408
7659
  puff3.vz += dz * strength;
7409
7660
  }
7410
7661
  },
7662
+ enclose(id, enclosure) {
7663
+ enclosures.set(id, enclosure);
7664
+ },
7665
+ enclosures: () => enclosures,
7411
7666
  stop(handle) {
7412
7667
  player?.stop(handle);
7413
7668
  const fires = core.fires;
@@ -7435,7 +7690,7 @@ function createVfx(options = {}) {
7435
7690
  core.clock.time += dt;
7436
7691
  core.schedule.update(core.clock.time);
7437
7692
  updateRings(core.rings, dt);
7438
- updatePuffs(core.puffs, dt, wind);
7693
+ updatePuffs(core.puffs, dt, wind, enclosures);
7439
7694
  updateSparks(core.sparks, { dt, groundAt });
7440
7695
  updateGlows(core.glows, dt);
7441
7696
  updateShocks(core.shocks, core.puffs.items, dt);
@@ -8578,6 +8833,7 @@ export {
8578
8833
  EffectCamera,
8579
8834
  EffectInstance,
8580
8835
  EffectRunner,
8836
+ Enclosures,
8581
8837
  GAME_EFFECTS,
8582
8838
  LOD_GAME,
8583
8839
  LOD_LAB,
@@ -8618,6 +8874,7 @@ export {
8618
8874
  patchExplosions,
8619
8875
  patchSpriteKinds,
8620
8876
  resolveStrings,
8877
+ slideAlong,
8621
8878
  streamFor,
8622
8879
  updateScreen,
8623
8880
  workshopGround