@adatechnology/game-destruction-three 0.27.1 → 0.28.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.
@@ -10138,6 +10138,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
10138
10138
  maxContacts: 4096,
10139
10139
  maxBodies: 8192
10140
10140
  };
10141
+ var AWAKE_BOUNDS_STRIDE = 10;
10141
10142
  var DEFAULT_WAKE_COST_TARGET_MS = 4;
10142
10143
  var DEFAULT_MAX_WAKE_DELAY = 0.08;
10143
10144
  var DEFAULT_MAX_QUEUED_WAKES = 2048;
@@ -14013,6 +14014,101 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14013
14014
  return maxX < 0 ? null : { x: minX, z: minZ, sizeX: maxX - minX + 1, sizeZ: maxZ - minZ + 1 };
14014
14015
  };
14015
14016
 
14017
+ // src/engine-ground-follow.ts
14018
+ var AHEAD_S = 0.15;
14019
+ var IDLE_UPDATES = 600;
14020
+ var SWEEP_EVERY = 30;
14021
+ var MOST_PER_SWEEP = 64;
14022
+ var HALF_HEIGHT = 2e3;
14023
+ var INITIAL_ROWS = 64;
14024
+ var OCCUPANTS = ["debris", "prop", "character", "agent", "vehicle", "corpse"];
14025
+ var GroundFollow = class {
14026
+ constructor(host) {
14027
+ __publicField(this, "host", host);
14028
+ __publicField(this, "rows", new Float64Array(INITIAL_ROWS * AWAKE_BOUNDS_STRIDE));
14029
+ /** The update each tile was last asked for by an outside body: the tiles that only the pieces use are not in it, and are never taken away. */
14030
+ __publicField(this, "askedAt", /* @__PURE__ */ new Map());
14031
+ __publicField(this, "occupants", []);
14032
+ __publicField(this, "sweepFilter", { layers: OCCUPANTS });
14033
+ __publicField(this, "stamp", 0);
14034
+ __publicField(this, "box", { kind: "box", half: [0, HALF_HEIGHT, 0] });
14035
+ this.box.half[0] = this.box.half[2] = host.tile / 2;
14036
+ }
14037
+ /** The tile count the follower is keeping an eye on. */
14038
+ get watched() {
14039
+ return this.askedAt.size;
14040
+ }
14041
+ clear() {
14042
+ this.askedAt.clear();
14043
+ }
14044
+ update(dt, stamp) {
14045
+ this.stamp = stamp;
14046
+ const { world, skip } = this.host;
14047
+ let count = world.readAwakeBounds(this.rows, skip);
14048
+ if (count * AWAKE_BOUNDS_STRIDE > this.rows.length) {
14049
+ this.rows = new Float64Array(count * 2 * AWAKE_BOUNDS_STRIDE);
14050
+ count = world.readAwakeBounds(this.rows, skip);
14051
+ }
14052
+ for (let row = 0; row < count; row++) this.cover(row * AWAKE_BOUNDS_STRIDE, dt);
14053
+ if (stamp % SWEEP_EVERY === 0) this.sweep();
14054
+ }
14055
+ /** The tiles under the row's box laid now, the ring around it and the path ahead of it as the host lays them. */
14056
+ cover(o, dt) {
14057
+ const r = this.rows;
14058
+ const { margin, tile, maxStops } = this.host;
14059
+ const minX = r[o + 2], minZ = r[o + 4], maxX = r[o + 5], maxZ = r[o + 7];
14060
+ const vx2 = r[o + 8], vz2 = r[o + 9];
14061
+ this.visit(minX, maxX, minZ, maxZ, true);
14062
+ const time = dt + AHEAD_S;
14063
+ const travel = Math.hypot(vx2, vz2) * time;
14064
+ const stops = travel > margin ? Math.min(maxStops, Math.ceil(travel / tile)) : 0;
14065
+ for (let stop = 0; stop <= stops; stop++) {
14066
+ const fraction = stops === 0 ? 0 : stop / stops;
14067
+ const dx = vx2 * time * fraction;
14068
+ const dz = vz2 * time * fraction;
14069
+ this.visit(minX + dx - margin, maxX + dx + margin, minZ + dz - margin, maxZ + dz + margin, false);
14070
+ }
14071
+ }
14072
+ visit(minX, maxX, minZ, maxZ, now) {
14073
+ const host = this.host;
14074
+ const { tile: size, keyOrigin, keyStride } = host;
14075
+ for (let ix = Math.floor(minX / size); ix <= Math.floor(maxX / size); ix++) {
14076
+ for (let iz = Math.floor(minZ / size); iz <= Math.floor(maxZ / size); iz++) {
14077
+ const key = (ix + keyOrigin) * keyStride + (iz + keyOrigin);
14078
+ this.askedAt.set(key, this.stamp);
14079
+ if (!host.needs(key)) continue;
14080
+ if (now) host.layNow(key, ix, iz);
14081
+ else host.layLater(key, ix, iz);
14082
+ }
14083
+ }
14084
+ }
14085
+ /** The tiles unasked for `IDLE_UPDATES` with nothing that moves on them are taken away; one with something on it is asked again later. */
14086
+ sweep() {
14087
+ const host = this.host;
14088
+ let looked = 0;
14089
+ for (const [key, last] of this.askedAt) {
14090
+ if (!host.has(key)) {
14091
+ this.askedAt.delete(key);
14092
+ continue;
14093
+ }
14094
+ if (this.stamp - last < IDLE_UPDATES) continue;
14095
+ if (looked++ >= MOST_PER_SWEEP) return;
14096
+ if (this.isOccupied(key)) {
14097
+ this.askedAt.set(key, this.stamp);
14098
+ continue;
14099
+ }
14100
+ this.askedAt.delete(key);
14101
+ host.drop(key);
14102
+ }
14103
+ }
14104
+ isOccupied(key) {
14105
+ const { tile, keyOrigin, keyStride, world } = this.host;
14106
+ const ix = Math.floor(key / keyStride) - keyOrigin;
14107
+ const iz = key % keyStride - keyOrigin;
14108
+ return world.overlapShape(this.box, [(ix + 0.5) * tile, 0, (iz + 0.5) * tile], [0, 0, 0, 1], this.occupants, this.sweepFilter) > 0;
14109
+ }
14110
+ };
14111
+
14016
14112
  // src/engine-ground-schedule.ts
14017
14113
  var MAX_FREE_PATCHES = 64;
14018
14114
  var EMPTY = new Float64Array(0);
@@ -14313,6 +14409,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14313
14409
  /** The pieces by object id: what the sweep meets that the engine already has (`sweepOn`). */
14314
14410
  __publicField(this, "byObject", /* @__PURE__ */ new Map());
14315
14411
  __publicField(this, "byBody", /* @__PURE__ */ new Map());
14412
+ /** The same bodies as a set: what the engine leaves out when it lists the bodies that are not the pieces' (`GroundFollow`). */
14413
+ __publicField(this, "bodyIds", /* @__PURE__ */ new Set());
14414
+ /** Ground under the bodies and characters of the world that are not the pieces. */
14415
+ /** Ground under the bodies and characters of the world that are not the pieces. */
14416
+ __publicField(this, "follow");
14316
14417
  /** The engine's awake bodies as `finish` last read them (one crossing), and the pieces they are. */
14317
14418
  __publicField(this, "activeIds", []);
14318
14419
  __publicField(this, "active", /* @__PURE__ */ new Set());
@@ -14385,6 +14486,33 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14385
14486
  this.statics = new EngineStatics(world, GROUND);
14386
14487
  this.schedule = o.groundWorker ? new GroundSchedule(o.groundWorker, Math.max(1, Math.round(o.groundWorkerFrames ?? GROUND_WORKER_FRAMES))) : null;
14387
14488
  if (this.schedule) this.warmGround(this.schedule);
14489
+ this.follow = new GroundFollow({
14490
+ world,
14491
+ skip: this.bodyIds,
14492
+ tile: TILE,
14493
+ margin: TILE_MARGIN,
14494
+ maxStops: MAX_PATH_STOPS,
14495
+ keyOrigin: TILE_KEY_ORIGIN,
14496
+ keyStride: TILE_KEY,
14497
+ needs: (key) => {
14498
+ const tile = this.tiles.get(key);
14499
+ return !tile || tile.dirty !== null;
14500
+ },
14501
+ has: (key) => this.tiles.has(key),
14502
+ layNow: this.layAt,
14503
+ layLater: this.schedule ? this.askAt : this.layAt,
14504
+ drop: (key) => this.dropTile(key)
14505
+ });
14506
+ }
14507
+ /** A tile nobody needs any more: its bodies leave the world, and a piece or body that comes back asks for it again. */
14508
+ dropTile(key) {
14509
+ const tile = this.tiles.get(key);
14510
+ if (!tile) return;
14511
+ this.world.removeBody(tile.ground);
14512
+ if (tile.steps !== null) this.world.removeBody(tile.steps);
14513
+ if (tile.solid !== null) this.world.removeBody(tile.solid);
14514
+ if (tile.patch) this.schedule?.givePatch(tile.patch.heights);
14515
+ this.tiles.delete(key);
14388
14516
  }
14389
14517
  /** The fixed bodies as a broad phase for the destruction world's rays (`engine-rays.ts`). */
14390
14518
  rayBroadPhase() {
@@ -14409,6 +14537,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14409
14537
  if (wakeNeighbours && (b.sleeping || link.sleeping)) this.wakeAround(b, link.pos);
14410
14538
  this.byUser.delete(link.user);
14411
14539
  this.byBody.delete(link.id);
14540
+ this.bodyIds.delete(link.id);
14412
14541
  this.active.delete(b);
14413
14542
  if (this.byObject.get(b.objectId) === b) this.byObject.delete(b.objectId);
14414
14543
  this.links.delete(b);
@@ -14429,6 +14558,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14429
14558
  if (t.solid !== null) this.world.removeBody(t.solid);
14430
14559
  }
14431
14560
  this.tiles.clear();
14561
+ this.follow.clear();
14432
14562
  this.schedule?.clear();
14433
14563
  this.blastAgain.clear();
14434
14564
  this.blasts.length = 0;
@@ -14544,6 +14674,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14544
14674
  this.layStatics();
14545
14675
  this.applyDueGround();
14546
14676
  this.layBlastGround();
14677
+ this.follow.update(dt, n);
14547
14678
  this.makeBodies(each);
14548
14679
  each((b) => this.hang(b));
14549
14680
  each((b) => this.sync(b, dt, h));
@@ -14817,6 +14948,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
14817
14948
  this.links.set(b, link);
14818
14949
  this.byUser.set(user, b);
14819
14950
  this.byBody.set(id, b);
14951
+ this.bodyIds.add(id);
14820
14952
  this.byObject.set(b.objectId, b);
14821
14953
  this.outOfStatics(b, link);
14822
14954
  });