@adatechnology/game-floorplan-structure 1.3.3 → 2.0.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.
@@ -2383,6 +2383,7 @@ var GameFloorplanStructure = (() => {
2383
2383
  }
2384
2384
 
2385
2385
  // ../game-contracts/dist/index.js
2386
+ var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
2386
2387
  var DEFAULT_IGNITION_RULES = {
2387
2388
  fillCurve: [
2388
2389
  [0, 0.6],
@@ -2426,6 +2427,54 @@ var GameFloorplanStructure = (() => {
2426
2427
  const flame = flameBase * (1 - rules.flameFillInfluence * (1 - k));
2427
2428
  return 1 - (1 - Math.min(1, Math.max(0, spark))) * (1 - Math.min(1, Math.max(0, flame)));
2428
2429
  };
2430
+ var DEFERRED_QUEUE_ID = {
2431
+ DESTRUCTION_EVENTS: "destruction.events",
2432
+ BREACH_PAINT: "floorplan.breach-paint",
2433
+ AUDIO_VOICES: "audio.voices",
2434
+ VEHICLE_CREASE: "vehicles.crease"
2435
+ };
2436
+ var DEFERRED_PRIORITY = {
2437
+ [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
2438
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
2439
+ [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
2440
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
2441
+ };
2442
+ var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
2443
+ var GAIT_IDS = ["walk", "run"];
2444
+ var LANDING_IDS = ["light", "heavy"];
2445
+ var BODY_SOUND_IDS = [
2446
+ "jump",
2447
+ "cloth_rustle",
2448
+ "body_fall",
2449
+ "fall_damage",
2450
+ "player_hurt",
2451
+ "player_breath_run",
2452
+ "player_death",
2453
+ "bite",
2454
+ "grab",
2455
+ "punch_swing",
2456
+ "punch_hit_body",
2457
+ "punch_hit_face",
2458
+ "punch_hit_object",
2459
+ "kick_swing",
2460
+ "kick_hit",
2461
+ "kick_hit_object",
2462
+ "shove_two_hands",
2463
+ "knife_swing",
2464
+ "knife_stab",
2465
+ "knife_slash",
2466
+ "knife_hit_object",
2467
+ "blunt_swing",
2468
+ "blunt_hit",
2469
+ "blunt_hit_object",
2470
+ "axe_swing",
2471
+ "axe_chop",
2472
+ "axe_hit_object"
2473
+ ];
2474
+ var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
2475
+ var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
2476
+ var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
2477
+ var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
2429
2478
 
2430
2479
  // ../game-destruction/dist/index.js
2431
2480
  var FIRE_PRIME_C = 300;
@@ -5137,6 +5186,7 @@ var GameFloorplanStructure = (() => {
5137
5186
  const ignitionRules = resolveIgnitionRules(options.ignition);
5138
5187
  const breachBlastFactor = options.breach?.blastFactor ?? BREACH_BLAST_FACTOR;
5139
5188
  const chipEnergy = options.breach?.chipEnergy ?? CHIP_ENERGY;
5189
+ const chainLinkCap = options.chainLinksPerUpdate !== void 0 && options.chainLinksPerUpdate >= 1 ? Math.floor(options.chainLinksPerUpdate) : Infinity;
5140
5190
  const rng = createRng(options.seed ?? 1);
5141
5191
  const rnd = () => rng.next();
5142
5192
  let time = 0;
@@ -6084,7 +6134,7 @@ var GameFloorplanStructure = (() => {
6084
6134
  if (disc < 0) return true;
6085
6135
  return -b - Math.sqrt(disc) > maxDist;
6086
6136
  };
6087
- const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false) => {
6137
+ const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false) => {
6088
6138
  const d = vec.normalize(dir);
6089
6139
  let best = null;
6090
6140
  for (const o of objects.values()) {
@@ -6099,13 +6149,25 @@ var GameFloorplanStructure = (() => {
6099
6149
  }
6100
6150
  }
6101
6151
  for (const im of worldOnly ? [] : impls.values()) {
6152
+ let boxHit = null;
6102
6153
  for (const ps of im.impl.describe().parts) {
6103
6154
  if (ignore?.has(`${im.impl.id}\0${ps.id}`)) continue;
6104
6155
  const ov = im.poses.get(ps.id);
6105
6156
  const r = rayPartRaw(im.position, im.rotation, ps, ov?.q ?? quatFromEuler(...ps.rotation ?? [0, 0, 0]), origin, d, ov?.pos);
6106
- if (!r || r.t0 < 0 || r.t0 > maxDist) continue;
6107
- if (!best || r.t0 < best.distance) best = { object: im.impl.id, part: ps.id, point: vec.madd(origin, d, r.t0), normal: r.n, distance: r.t0, pathLen: r.t1 - r.t0 };
6157
+ if (!r || r.t1 < 0 || r.t0 > maxDist) continue;
6158
+ if (r.t0 < 0) {
6159
+ if (precise && im.impl.surfaceRay) boxHit = boxHit ?? { object: im.impl.id, part: ps.id, point: origin, normal: r.n, distance: 0, pathLen: r.t1 };
6160
+ continue;
6161
+ }
6162
+ if (!boxHit || r.t0 < boxHit.distance) boxHit = { object: im.impl.id, part: ps.id, point: vec.madd(origin, d, r.t0), normal: r.n, distance: r.t0, pathLen: r.t1 - r.t0 };
6108
6163
  }
6164
+ if (!boxHit) continue;
6165
+ if (precise && im.impl.surfaceRay) {
6166
+ const far = best ? Math.min(maxDist, best.distance) : maxDist;
6167
+ const implId = im.impl.id;
6168
+ const s = im.impl.surfaceRay({ origin, direction: d, maxDistance: far, ...ignore ? { ignored: (part) => ignore.has(`${implId}\0${part}`) } : {} });
6169
+ if (s && (!best || s.distance < best.distance)) best = { object: implId, part: s.part, point: s.point, normal: s.normal, distance: s.distance, pathLen: s.pathLen };
6170
+ } else if (!best || boxHit.distance < best.distance) best = boxHit;
6109
6171
  }
6110
6172
  return best;
6111
6173
  };
@@ -7589,7 +7651,9 @@ var GameFloorplanStructure = (() => {
7589
7651
  };
7590
7652
  const detonatePrimed = (until) => {
7591
7653
  const end = time;
7592
- for (let next = nextPrimed(until); next; next = nextPrimed(until)) {
7654
+ let fired = 0;
7655
+ for (let next = nextPrimed(until); next && fired < chainLinkCap; next = nextPrimed(until)) {
7656
+ fired++;
7593
7657
  primed.delete(next.p);
7594
7658
  time = Math.max(0, Math.min(end, next.p.rt.chainDue));
7595
7659
  next.p.rt.chainDue = void 0;
@@ -7659,6 +7723,7 @@ var GameFloorplanStructure = (() => {
7659
7723
  updateBound(o);
7660
7724
  },
7661
7725
  remove(id) {
7726
+ impls.get(id)?.impl.dispose?.();
7662
7727
  objects.delete(id);
7663
7728
  impls.delete(id);
7664
7729
  },
@@ -7734,7 +7799,7 @@ var GameFloorplanStructure = (() => {
7734
7799
  return withCollapses(run(() => blastWorld(point, energy, radius, source, blast)));
7735
7800
  },
7736
7801
  raycast(origin, direction, maxDistance = Infinity) {
7737
- const r = raycastInternal(origin, direction, maxDistance);
7802
+ const r = raycastInternal(origin, direction, maxDistance, void 0, false, true);
7738
7803
  return r ? { object: r.object, part: r.part, point: r.point, normal: r.normal, distance: r.distance } : null;
7739
7804
  },
7740
7805
  sweepBox(box2, direction, distance2, options2 = {}) {
@@ -7759,11 +7824,11 @@ var GameFloorplanStructure = (() => {
7759
7824
  let org = origin;
7760
7825
  let E = energy;
7761
7826
  for (let i = 0; i < 4 && E > 0; i++) {
7762
- const rh = raycastInternal(org, d, Infinity, ignore);
7827
+ const rh = raycastInternal(org, d, Infinity, ignore, false, true);
7763
7828
  if (!rh) break;
7764
7829
  const im = impls.get(rh.object);
7765
7830
  if (im) {
7766
- const r = implHit(im, { type: "ballistic", point: rh.point, direction: d, energy: E, caliber, ...extras, ...source !== void 0 ? { source } : {} });
7831
+ const r = implHit(im, { type: "ballistic", point: rh.point, part: rh.part, normal: rh.normal, direction: d, energy: E, caliber, ...extras, ...source !== void 0 ? { source } : {} });
7767
7832
  r.part = rh.part;
7768
7833
  r.point = rh.point;
7769
7834
  r.exitEnergy = r.penetrated ? E * 0.5 : 0;
@@ -8085,12 +8150,27 @@ var GameFloorplanStructure = (() => {
8085
8150
  breach: { area: 0.1 }
8086
8151
  }
8087
8152
  ];
8153
+ var SHIPPED = structuredClone(assemblies_default);
8088
8154
  var ASSEMBLIES = assemblies_default;
8089
- var getAssembly = (id) => ASSEMBLIES.find((a) => a.id === id);
8155
+ var assembliesOver = (defs) => {
8156
+ const get = (id) => defs.find((a) => a.id === id);
8157
+ return {
8158
+ list: () => defs,
8159
+ get,
8160
+ register(def) {
8161
+ const at2 = defs.findIndex((a) => a.id === def.id);
8162
+ if (at2 >= 0) defs[at2] = def;
8163
+ else defs.push(def);
8164
+ },
8165
+ part: (assemblyId, options) => buildAssemblyPart(get(assemblyId), assemblyId, options)
8166
+ };
8167
+ };
8168
+ var defaultSet;
8169
+ var defaultAssemblies = () => defaultSet ?? (defaultSet = assembliesOver(ASSEMBLIES));
8170
+ var getAssembly = (id) => defaultAssemblies().get(id);
8090
8171
  var faceCount = (layer) => layer.faces === "both" ? 2 : 1;
8091
8172
  var assemblyDepth = (def) => def.depth ?? def.core.thickness + (def.layers ?? []).reduce((sum, l) => sum + l.thickness * faceCount(l), 0);
8092
- var assemblyPart = (assemblyId, options) => {
8093
- const def = getAssembly(assemblyId);
8173
+ var buildAssemblyPart = (def, assemblyId, options) => {
8094
8174
  if (!def) throw new Error(`unknown assembly "${assemblyId}"`);
8095
8175
  const densityOf2 = (id) => {
8096
8176
  const m = options.materials?.get(id) ?? MATERIALS.find((x) => x.id === id);
@@ -8117,6 +8197,7 @@ var GameFloorplanStructure = (() => {
8117
8197
  ...options.extra
8118
8198
  };
8119
8199
  };
8200
+ var assemblyPart = (assemblyId, options) => defaultAssemblies().part(assemblyId, options);
8120
8201
  var buildFrame = (o = {}) => {
8121
8202
  const spanX = o.spanX ?? 8, spanZ = o.spanZ ?? 8;
8122
8203
  const nx = Math.max(2, o.columnsX ?? 3), nz = Math.max(2, o.columnsZ ?? 3);