@adatechnology/game-player 0.6.4 → 0.8.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.
@@ -21,8 +21,11 @@ var GamePlayer = (() => {
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
+ DOOR_ARM_REACH: () => DOOR_ARM_REACH,
25
+ DOOR_SHOULDER_HEIGHT: () => DOOR_SHOULDER_HEIGHT,
24
26
  DOOR_USE_DEFAULTS: () => DOOR_USE_DEFAULTS,
25
27
  FURNITURE_PUSH_DEFAULTS: () => FURNITURE_PUSH_DEFAULTS,
28
+ HANDS_DEFAULTS: () => HANDS_DEFAULTS,
26
29
  PLAYER_DEFAULTS: () => PLAYER_DEFAULTS,
27
30
  PLAYER_TEXT: () => PLAYER_TEXT,
28
31
  canPush: () => canPush,
@@ -33,9 +36,12 @@ var GamePlayer = (() => {
33
36
  createRng: () => createRng,
34
37
  deriveVitals: () => deriveVitals,
35
38
  dragMarkFor: () => dragMarkFor,
39
+ drawBackOf: () => drawBackOf,
36
40
  drawWound: () => drawWound,
37
41
  frictionFor: () => frictionFor,
38
42
  gripSecondsFor: () => gripSecondsFor,
43
+ interactionHandsFor: () => interactionHandsFor,
44
+ planHands: () => planHands,
39
45
  playerTextOf: () => playerTextOf,
40
46
  pushAccelerationFor: () => pushAccelerationFor,
41
47
  pushSpeedFor: () => pushSpeedFor,
@@ -49,15 +55,37 @@ var GamePlayer = (() => {
49
55
  var DEFERRED_QUEUE_ID = {
50
56
  DESTRUCTION_EVENTS: "destruction.events",
51
57
  BREACH_PAINT: "floorplan.breach-paint",
58
+ BREACH_CUT: "floorplan.breach-cut",
52
59
  AUDIO_VOICES: "audio.voices",
53
- VEHICLE_CREASE: "vehicles.crease"
60
+ VEHICLE_CREASE: "vehicles.crease",
61
+ AUDIO_OCCLUSION: "audio.occlusion",
62
+ FLUID_FILM: "fluids.film",
63
+ VEHICLE_LOD_BATCH: "vehicles.lod-batch",
64
+ SETTLED_BATCH: "destruction.settled-batch",
65
+ STATIC_BATCH: "render.static-batch",
66
+ ANIMALS_STATIC_BATCH: "animals.static-batch",
67
+ CHARACTERS_STATIC_BATCH: "characters.static-batch",
68
+ HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
69
+ DESTRUCTION_PREFIT: "destruction.prefit"
54
70
  };
55
71
  var DEFERRED_PRIORITY = {
56
72
  [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
57
- [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
73
+ // every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
74
+ [DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
75
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
58
76
  [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
59
- [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
77
+ [DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
78
+ [DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
79
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
80
+ [DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
81
+ [DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
82
+ [DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
83
+ [DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
84
+ [DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
85
+ [DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
86
+ [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
60
87
  };
88
+ var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
61
89
  var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
62
90
  var DEFAULT_SURFACE = "concrete";
63
91
  var GAIT_IDS = ["walk", "run"];
@@ -136,6 +164,7 @@ var GamePlayer = (() => {
136
164
  soil: "dirt",
137
165
  mud: "dirt",
138
166
  clay: "dirt",
167
+ laterite: "gravel",
139
168
  wax: "dirt",
140
169
  flesh_fruit: "dirt",
141
170
  turf: "grass",
@@ -164,6 +193,22 @@ var GamePlayer = (() => {
164
193
  if (isSurfaceId(material)) return material;
165
194
  return table[material] ?? fallback;
166
195
  }
196
+ var WORKER_KIND_ID = {
197
+ GROUND_TILES: "destruction.ground-tiles",
198
+ CROWD_PHYSICS: "crowd.physics",
199
+ PIECE_BOXES: "destruction.piece-boxes",
200
+ STATIC_COLLIDERS: "destruction.static-colliders",
201
+ SHAPES_GENERATE: "shapes.generate",
202
+ WORLD_REGION: "world.region"
203
+ };
204
+ var WORKER_KIND_DEFAULTS = {
205
+ [WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
206
+ [WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
207
+ [WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
208
+ [WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
209
+ [WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
210
+ [WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
211
+ };
167
212
 
168
213
  // src/data/defaults.json
169
214
  var defaults_default = {
@@ -250,6 +295,8 @@ var GamePlayer = (() => {
250
295
  regenMoving: 4,
251
296
  regenStill: 8,
252
297
  acceleration: 10,
298
+ heightMetres: 1.8,
299
+ crouchHeightRatio: 0.65,
253
300
  radius: 0.3,
254
301
  blockHeight: 0.4,
255
302
  pushApartRadius: 0.55,
@@ -379,6 +426,11 @@ var GamePlayer = (() => {
379
426
  const formulas = { ...PLAYER_DEFAULTS.derived, ...options.derived };
380
427
  const derived = deriveVitals(attributes, formulas);
381
428
  const numbers = { ...PLAYER_DEFAULTS.numbers, ...options.numbers };
429
+ const heightMetres = options.heightMetres ?? numbers.heightMetres;
430
+ if (!Number.isFinite(heightMetres) || heightMetres < 0.8 || heightMetres > 3) {
431
+ throw new RangeError(`Player height ${String(heightMetres)} m is outside supported range [0.8, 3.0] m.`);
432
+ }
433
+ const heightScale = heightMetres / numbers.heightMetres;
382
434
  const wounds = options.wounds ?? PLAYER_DEFAULTS.wounds;
383
435
  const infection = options.infection === void 0 || options.infection === false ? null : options.infection === true ? PLAYER_DEFAULTS.infection : { ...PLAYER_DEFAULTS.infection, ...options.infection };
384
436
  const fist = options.fist ?? PLAYER_DEFAULTS.fist;
@@ -671,7 +723,7 @@ var GamePlayer = (() => {
671
723
  const tvz = want ? mz / ml * sp : 0;
672
724
  P.vx = lerp(P.vx, tvx, Math.min(1, dt * numbers.acceleration));
673
725
  P.vz = lerp(P.vz, tvz, Math.min(1, dt * numbers.acceleration));
674
- const r = numbers.radius;
726
+ const r = numbers.radius * heightScale;
675
727
  const nx = P.x + P.vx * dt;
676
728
  const nz = P.z + P.vz * dt;
677
729
  if (!blocked(nx + Math.sign(P.vx) * r, P.z)) P.x = nx;
@@ -743,6 +795,11 @@ var GamePlayer = (() => {
743
795
  get state() {
744
796
  return P;
745
797
  },
798
+ heightMetres,
799
+ collider: () => ({
800
+ heightMetres: P.crouch ? heightMetres * numbers.crouchHeightRatio : heightMetres,
801
+ radiusMetres: numbers.radius * heightScale
802
+ }),
746
803
  attributes,
747
804
  derived,
748
805
  numbers,
@@ -1380,12 +1437,15 @@ var GamePlayer = (() => {
1380
1437
  var DOOR_USE_DEFAULTS = {
1381
1438
  reachSeconds: 0.3,
1382
1439
  swingSeconds: { base: 0.45, perKg: 0.02, min: 0.45, max: 1.6 },
1440
+ pushSeconds: 0.18,
1383
1441
  releaseSeconds: 0.22,
1384
1442
  // the length of the recorded handle shaken (game-audio door_locked_rattle, 0.6 to 0.83 s): the hand lets go as the sound ends
1385
1443
  rattleSeconds: 0.75,
1386
1444
  stepFraction: 0.04,
1387
1445
  endTolerance: 0.02
1388
1446
  };
1447
+ var DOOR_SHOULDER_HEIGHT = 1.42;
1448
+ var DOOR_ARM_REACH = 0.55;
1389
1449
  var swingSecondsFor = (massKg, rules = DOOR_USE_DEFAULTS) => Math.min(rules.swingSeconds.max, Math.max(rules.swingSeconds.min, rules.swingSeconds.base + rules.swingSeconds.perKg * Math.max(0, massKg)));
1390
1450
  function createDoorUse(rules = {}) {
1391
1451
  const r = { ...DOOR_USE_DEFAULTS, ...rules, swingSeconds: { ...DOOR_USE_DEFAULTS.swingSeconds, ...rules.swingSeconds } };
@@ -1395,7 +1455,26 @@ var GamePlayer = (() => {
1395
1455
  let time = 0;
1396
1456
  let swing = 1;
1397
1457
  let start = 0;
1458
+ let coasting = false;
1398
1459
  const out = (progress, arrived = false, b = null) => ({ phase, opening, progress: Math.max(0, Math.min(1, progress)), block: b, arrived });
1460
+ const advance = (dt, isFree) => {
1461
+ const want = goal - opening;
1462
+ const reach = Math.min(Math.abs(want), dt / swing);
1463
+ let moved = 0;
1464
+ while (moved < reach - 1e-9) {
1465
+ const inc = Math.min(r.stepFraction, reach - moved);
1466
+ const next = opening + Math.sign(want) * inc;
1467
+ if (!isFree(opening, next)) return "stopped";
1468
+ opening = next;
1469
+ moved += inc;
1470
+ }
1471
+ return Math.abs(goal - opening) < 1e-6 ? "arrived" : "moving";
1472
+ };
1473
+ const releaseOut = (arrived, b = null) => {
1474
+ const p = time / r.releaseSeconds;
1475
+ if (p >= 1 && !coasting) phase = "idle";
1476
+ return out(p, arrived, b);
1477
+ };
1399
1478
  return {
1400
1479
  get phase() {
1401
1480
  return phase;
@@ -1409,6 +1488,7 @@ var GamePlayer = (() => {
1409
1488
  begin(target) {
1410
1489
  opening = Math.max(0, Math.min(1, target.opening));
1411
1490
  time = 0;
1491
+ coasting = false;
1412
1492
  if (target.locked) {
1413
1493
  phase = "rattle";
1414
1494
  return null;
@@ -1421,58 +1501,59 @@ var GamePlayer = (() => {
1421
1501
  phase = phase === "swing" ? "swing" : "reach";
1422
1502
  return goal;
1423
1503
  },
1424
- step(dt, isFree) {
1504
+ step(dt, isFree, hand) {
1425
1505
  if (phase === "idle") return out(0);
1426
1506
  time += dt;
1427
1507
  if (phase === "rattle") {
1428
- const p2 = time / r.rattleSeconds;
1429
- if (p2 >= 1) {
1508
+ const p = time / r.rattleSeconds;
1509
+ if (p >= 1) {
1430
1510
  phase = "idle";
1431
1511
  return out(1, false, "locked");
1432
1512
  }
1433
- return out(p2, false, time === dt ? "locked" : null);
1513
+ return out(p, false, time === dt ? "locked" : null);
1434
1514
  }
1435
1515
  if (phase === "reach") {
1436
- const p2 = time / r.reachSeconds;
1437
- if (p2 < 1) return out(p2);
1516
+ const p = time / r.reachSeconds;
1517
+ if (p < 1) return out(p);
1438
1518
  phase = "swing";
1439
1519
  time = 0;
1440
1520
  start = opening;
1441
1521
  }
1442
- if (phase === "swing") {
1443
- const want = goal - opening;
1444
- const reach = Math.min(Math.abs(want), dt / swing);
1445
- let moved = 0;
1446
- let stopped = false;
1447
- while (moved < reach - 1e-9) {
1448
- const inc = Math.min(r.stepFraction, reach - moved);
1449
- const next = opening + Math.sign(want) * inc;
1450
- if (!isFree(opening, next)) {
1451
- stopped = true;
1452
- break;
1522
+ if (phase === "swing" || phase === "push" || coasting) {
1523
+ const result = advance(dt, isFree);
1524
+ const travel = Math.abs(goal - start) || 1;
1525
+ const progress = 1 - Math.abs(goal - opening) / travel;
1526
+ const inHand = phase !== "release";
1527
+ if (result === "stopped" || result === "arrived") {
1528
+ if (result === "arrived") opening = goal;
1529
+ coasting = false;
1530
+ if (inHand) {
1531
+ phase = "release";
1532
+ time = 0;
1453
1533
  }
1454
- opening = next;
1455
- moved += inc;
1534
+ if (result === "arrived") return inHand ? out(1, true) : releaseOut(true);
1535
+ return inHand ? out(progress, false, "obstacle") : releaseOut(false, "obstacle");
1456
1536
  }
1457
- const travel = Math.abs(goal - start) || 1;
1458
- if (stopped) {
1459
- phase = "release";
1537
+ if (inHand && hand && !hand.reaches()) {
1460
1538
  time = 0;
1461
- return out(1 - Math.abs(goal - opening) / travel, false, "obstacle");
1539
+ if (hand.pull) {
1540
+ phase = "release";
1541
+ coasting = true;
1542
+ } else phase = "push";
1543
+ return out(0);
1462
1544
  }
1463
- if (Math.abs(goal - opening) < 1e-6) {
1464
- opening = goal;
1465
- phase = "release";
1466
- time = 0;
1467
- return out(1, true);
1545
+ if (phase === "push") {
1546
+ if (time >= r.pushSeconds) {
1547
+ phase = "release";
1548
+ time = 0;
1549
+ coasting = true;
1550
+ return out(0);
1551
+ }
1552
+ return out(time / r.pushSeconds);
1468
1553
  }
1469
- return out(1 - Math.abs(goal - opening) / travel);
1470
- }
1471
- const p = time / r.releaseSeconds;
1472
- if (p >= 1) {
1473
- phase = "idle";
1554
+ if (phase === "swing") return out(progress);
1474
1555
  }
1475
- return out(p, false, null);
1556
+ return releaseOut(false);
1476
1557
  },
1477
1558
  cancel() {
1478
1559
  phase = "idle";
@@ -1480,6 +1561,34 @@ var GamePlayer = (() => {
1480
1561
  }
1481
1562
  };
1482
1563
  }
1564
+
1565
+ // src/hands.ts
1566
+ var HANDS_DEFAULTS = { oneHand: { maxKg: 4, maxLength: 0.7 } };
1567
+ function interactionHandsFor(thing, rules = HANDS_DEFAULTS) {
1568
+ const longest = Math.max(0, ...thing.size ?? []);
1569
+ return thing.massKg > rules.oneHand.maxKg || longest > rules.oneHand.maxLength ? 2 : 1;
1570
+ }
1571
+ var holds = (weapon) => !!weapon && weapon.hands > 0;
1572
+ function planHands(params) {
1573
+ const { R, L } = params.weapons;
1574
+ const free = [...params.slots];
1575
+ const stow = (hand, weapon) => {
1576
+ const at = weapon.slot === null ? -1 : free.indexOf(weapon.slot);
1577
+ if (at < 0) return { hand, weapon: weapon.id, move: "drop" };
1578
+ free.splice(at, 1);
1579
+ return { hand, weapon: weapon.id, move: "holster", slot: weapon.slot };
1580
+ };
1581
+ if (params.hands === 2) {
1582
+ const moves = [...holds(R) ? [stow("R", R)] : [], ...holds(L) ? [stow("L", L)] : []];
1583
+ return { hand: "both", moves };
1584
+ }
1585
+ if (holds(L)) return { hand: "L", moves: [stow("L", L)] };
1586
+ if (!holds(R)) return { hand: "R", moves: [] };
1587
+ return { hand: "L", moves: R.hands === 2 ? [stow("R", R)] : [] };
1588
+ }
1589
+ function drawBackOf(plan) {
1590
+ return plan.moves.filter((move) => move.move === "holster").map((move) => ({ hand: move.hand, weapon: move.weapon }));
1591
+ }
1483
1592
  return __toCommonJS(index_exports);
1484
1593
  })();
1485
1594
  //# sourceMappingURL=index.global.js.map