@adatechnology/game-destruction-three 0.26.2 → 0.26.4

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.
@@ -3449,6 +3449,7 @@ var GameDestructionThree = (() => {
3449
3449
  __publicField2(this, "centerZ", 0);
3450
3450
  __publicField2(this, "puddles", WORKSHOP_PUDDLES);
3451
3451
  __publicField2(this, "puddleAt");
3452
+ __publicField2(this, "coverTopAt");
3452
3453
  }
3453
3454
  /** `initRain` (W321): `count` streaks (thinned by the quality), each drawn at a random place in the box. */
3454
3455
  init(count, wind) {
@@ -3494,6 +3495,13 @@ var GameDestructionThree = (() => {
3494
3495
  positions[o + 3] += slant;
3495
3496
  positions[o + 1] -= fall;
3496
3497
  positions[o + 4] -= fall;
3498
+ if (this.coverTopAt) {
3499
+ const top = this.coverTopAt(positions[o], positions[o + 2]);
3500
+ if (top !== void 0 && positions[o + 4] < top) {
3501
+ this.restart(o);
3502
+ continue;
3503
+ }
3504
+ }
3497
3505
  const ground = context.groundAt(positions[o], positions[o + 2]);
3498
3506
  if (positions[o + 4] < ground) {
3499
3507
  const x = positions[o];
@@ -3509,10 +3517,7 @@ var GameDestructionThree = (() => {
3509
3517
  }
3510
3518
  }
3511
3519
  }
3512
- const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
3513
- const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
3514
- const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
3515
- this.set(o, nx, ny, nz);
3520
+ this.restart(o);
3516
3521
  }
3517
3522
  }
3518
3523
  }
@@ -3520,6 +3525,13 @@ var GameDestructionThree = (() => {
3520
3525
  clear() {
3521
3526
  this.on = false;
3522
3527
  }
3528
+ restart(offset) {
3529
+ const { random } = this.engine;
3530
+ const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
3531
+ const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
3532
+ const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
3533
+ this.set(offset, nx, ny, nz);
3534
+ }
3523
3535
  set(offset, x, y, z) {
3524
3536
  const positions = this.positions;
3525
3537
  positions[offset] = x;
@@ -4312,8 +4324,11 @@ var GameDestructionThree = (() => {
4312
4324
  aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
4313
4325
  /** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
4314
4326
  aliasOf(ENGINE_SMOKE, "vehicle_exhaust", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 0 }, loop: 0.5 }),
4315
- /** A hole in the tank: the page's petrol leak without the fire and the blast (the pool and the drips). A normal bullet does only this. */
4316
- aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", {}),
4327
+ /**
4328
+ * A hole in a tank: the page's drips, falling from the point it is played at (the hole). No pool of its own: the pool is the liquid that came out, laid by the
4329
+ * host's fluid world as it leaks (it grows with the volume and spreads by the liquid's own kind), not a drawing of a size the page chose.
4330
+ */
4331
+ aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", { anchor: TANK, timeline: [] }),
4317
4332
  /** The leak caught fire (an incendiary or tracer round, a spark, a fire near): the page's whole sequence, the fire running along the pool to the tank and the blast. */
4318
4333
  aliasOf(FUEL_LEAK, "vehicle_leak_ignited", {})
4319
4334
  ];
@@ -15394,6 +15409,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15394
15409
  var SUPPORT_MARGIN = 0.05;
15395
15410
  var TOPPLE2 = 3;
15396
15411
  var TIP_ACCELERATION = 30;
15412
+ var TIP_RISING = 0.02;
15413
+ var TIP_RISE_AFTER = 0.5;
15397
15414
  var TIP_LYING = 0.25;
15398
15415
  var TIP_SECONDS = 3;
15399
15416
  var STEP = 0.03;
@@ -15412,6 +15429,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15412
15429
  };
15413
15430
  var SUPPORT_CHECKS2 = 16;
15414
15431
  var SUPPORT_GAP2 = 0.02;
15432
+ var STEEP_MARGIN = 1.1;
15433
+ var SLOPE_MIN_NORMAL = 0.5;
15434
+ var LIES_FLAT = 0.985;
15415
15435
  var KEEP_EVERY = 0.5;
15416
15436
  var WAKE_ABOVE_SPEED = 0.05;
15417
15437
  var WAKE_ABOVE_SPIN = 0.1;
@@ -15542,6 +15562,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15542
15562
  /** The surface normal and the friction of what the last `supportAt` found under the point (the ground and fixed tops are level: up, and no piece). */
15543
15563
  __publicField(this, "supportNormal", UP16);
15544
15564
  __publicField(this, "supportFriction", null);
15565
+ __publicField(this, "supportBody", null);
15545
15566
  /** The terrain's surfaces by rolling resistance and damping (`terrainSurface`), one object each. */
15546
15567
  __publicField(this, "terrainSurfaces", /* @__PURE__ */ new Map());
15547
15568
  /** The terrain's surface by ground tile (`groundTileKey`) this update, null for the default: read once per tile, not per contact per substep. */
@@ -15730,6 +15751,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
15730
15751
  get(objectId) {
15731
15752
  return this.list.find((b) => b.objectId === objectId) ?? null;
15732
15753
  }
15754
+ /** Whether `upper` lies flat on a top of `lower` that is steeper than its friction holds: what it slides on, not a wall in its way. */
15755
+ slidesOn(upper, lower) {
15756
+ return this.restsOn(upper, lower, false) && this.onSteepSupport(upper);
15757
+ }
15733
15758
  /** Sets a piece falling over, about the world axes x and z (a unit axis): its feet are thinner than the box that stands for it, so the box alone would hold it up. */
15734
15759
  tip(body, x, z) {
15735
15760
  body.tipping = { x, z, seconds: TIP_SECONDS };
@@ -16199,9 +16224,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16199
16224
  for (let k = 0; k < Math.min(SUPPORT_CHECKS2, n); k++) {
16200
16225
  this.supportTurn = (this.supportTurn + 1) % n;
16201
16226
  const b = this.list[this.supportTurn];
16202
- if (!b.sleeping || b.held || onlyBudget && !b.restPoints?.length) continue;
16227
+ if (!b.sleeping || b.held) continue;
16203
16228
  const rest = b.restPoints;
16204
- if (rest && rest.length > 0 ? rest.every((point) => this.supportsPoint(b, point)) : this.supported(b, false) || this.supported(b, true)) continue;
16229
+ const budgeted = !!rest && rest.length > 0;
16230
+ const held = onlyBudget && !budgeted ? true : budgeted ? rest.every((point) => this.supportsPoint(b, point)) : this.supported(b, false) || this.supported(b, true);
16231
+ if (held && !this.onSteepSupport(b)) continue;
16205
16232
  b.sleeping = false;
16206
16233
  b.still = 0;
16207
16234
  b.calmAt = null;
@@ -16324,6 +16351,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16324
16351
  if (fixed >= top) on = null;
16325
16352
  this.supportNormal = on ? faceNormal(on, face) : UP16;
16326
16353
  this.supportFriction = on?.body.friction ?? null;
16354
+ this.supportBody = on?.body ?? null;
16327
16355
  return Math.max(top, fixed);
16328
16356
  }
16329
16357
  /** Stops a piece that ran into something on its way from `start` to `pos` (`sweep`): moves it back to where it met it and takes the speed into it. */
@@ -16658,7 +16686,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16658
16686
  b.tipping.seconds -= h;
16659
16687
  const [hx, hy, hz2] = b.halfExtents;
16660
16688
  const upHalf = Math.abs(e[1]) * hx + Math.abs(e[5]) * hy + Math.abs(e[9]) * hz2;
16661
- if (upHalf < TIP_LYING || b.tipping.seconds <= 0) b.tipping = null;
16689
+ const rising = TIP_SECONDS - b.tipping.seconds > TIP_RISE_AFTER && v[1] > TIP_RISING;
16690
+ if (upHalf < TIP_LYING || b.tipping.seconds <= 0 || rising) b.tipping = null;
16662
16691
  else {
16663
16692
  w[0] += b.tipping.x * TIP_ACCELERATION * h;
16664
16693
  w[2] += b.tipping.z * TIP_ACCELERATION * h;
@@ -16708,7 +16737,31 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
16708
16737
  b.balancing = unstable;
16709
16738
  this.keepsTilt(b, q, dt);
16710
16739
  const held = (touched || propped !== void 0) && !b.tipping;
16711
- if (!b.hinge && (b.still >= SLEEP_AFTER || this.staysInPlace(b, held, pos, q, dt))) this.sleep(b);
16740
+ if (!b.hinge && (b.still >= SLEEP_AFTER || this.staysInPlace(b, held, pos, q, dt)) && !this.onSteepSupport(b)) this.sleep(b);
16741
+ }
16742
+ /**
16743
+ * Whether `b` lies flat on a settled top (asleep) tilted past what the friction of the two holds (a laptop on a table top gone over at 42 degrees, held by 0.49 up to 26),
16744
+ * with every corner that touches on it: it slides, it does not sleep there, and one asleep there wakes. Held by anything else (the floor, a flat top, a side it leans on, a
16745
+ * pile still moving) it is not this case: the contacts hold or move it.
16746
+ */
16747
+ onSteepSupport(b) {
16748
+ const c = this.centerOf(b, this.p);
16749
+ const e = this.m.makeRotationFromQuaternion(b.root.quaternion).elements;
16750
+ let touching = false;
16751
+ for (const [sx, sy, sz] of this.samples(b, false)) {
16752
+ const y = c.y + e[1] * sx + e[5] * sy + e[9] * sz;
16753
+ if (this.supportAt(b, c.x + e[0] * sx + e[4] * sy + e[8] * sz, y, c.z + e[2] * sx + e[6] * sy + e[10] * sz, STEP) < y - SUPPORT_GAP2) continue;
16754
+ if (this.supportBody && !this.supportBody.sleeping) return false;
16755
+ const n = this.supportNormal;
16756
+ const ny = n[1];
16757
+ const holds = pairFriction(b.friction, this.supportFriction).static;
16758
+ if (ny >= 1 - 1e-6 || ny < SLOPE_MIN_NORMAL || Math.sqrt(Math.max(0, 1 - ny * ny)) / ny <= holds * STEEP_MARGIN) return false;
16759
+ let flat = 0;
16760
+ for (let axis2 = 0; axis2 < 12; axis2 += 4) flat = Math.max(flat, Math.abs(e[axis2] * n[0] + e[axis2 + 1] * n[1] + e[axis2 + 2] * n[2]));
16761
+ if (flat < LIES_FLAT) return false;
16762
+ touching = true;
16763
+ }
16764
+ return touching;
16712
16765
  }
16713
16766
  /** The piece sleeps where it lies: its speeds are dropped, nothing moves it. */
16714
16767
  sleep(b) {
@@ -17149,6 +17202,12 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
17149
17202
  if (resting) return;
17150
17203
  const [upper, c, up] = n[1] > 0 ? [a, ca, n] : [b, cb, [-n[0], -n[1], -n[2]]];
17151
17204
  if (upper.held || upper.sleeping) return;
17205
+ const otherCentre = upper === a ? cb : ca;
17206
+ if (c[1] < otherCentre[1] - SLOP) {
17207
+ const level = boxesApartAlongGround(sa, sb);
17208
+ if (level) this.slideApart(a, b, ima, imb, level);
17209
+ return;
17210
+ }
17152
17211
  upper.propped = up;
17153
17212
  const e = this.m.makeRotationFromQuaternion(upper.root.quaternion).elements;
17154
17213
  const r = [hit.point[0] - c[0], hit.point[1] - c[1], hit.point[2] - c[2]];
@@ -24532,6 +24591,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
24532
24591
  if (mat.ductility >= 0.5 && p.thickness <= THIN_SHEET_DISHING) addDent(o, p, entry, n, Math.max(caliber * 3 / 1e3, 0.012), clamp23(E * 2e-5, 1e-3, 0.03), src);
24533
24592
  if (brittle && mat.fracture === "shatter") addCrack(o, p, entry, n, crackLen, src);
24534
24593
  if (p.spec.contains && (p.st.liters ?? 0) > 1e-4) {
24594
+ o.active = true;
24535
24595
  emit2({
24536
24596
  ...base(o, src),
24537
24597
  type: "leak",
@@ -28527,6 +28587,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
28527
28587
  this.batcher?.update();
28528
28588
  this.sinceMade += dt;
28529
28589
  if (!this.options.enabled || this.sinceMade < this.options.intervalSeconds) return;
28590
+ if (this.queue.pending() > 0) return;
28530
28591
  const meshes = atRest().filter((mesh2) => isBatchableDebris(mesh2, this.options.maxVertices) || this.batched(mesh2));
28531
28592
  const outside = meshes.length - (this.batcher?.stats().batched ?? 0);
28532
28593
  if (outside < this.options.minMeshes) return;
@@ -29476,6 +29537,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
29476
29537
  if (!hit) return null;
29477
29538
  const other = this.pieceSys.get(hit.object);
29478
29539
  if (other && (p.round || other.round)) return null;
29540
+ if (other && this.pieceSys.slidesOn(p, other)) return null;
29479
29541
  const material = this.world.part(hit.object, hit.part)?.material;
29480
29542
  const restitution = material === void 0 ? void 0 : surfaceOf(material, this.world.materials.get(material))?.restitution;
29481
29543
  return { object: hit.object, part: hit.part, distance: hit.distance, point: hit.point, normal: hit.normal, ...restitution === void 0 ? {} : { restitution } };