@adatechnology/game-characters 0.2.6 → 0.2.8

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.
@@ -317,6 +317,7 @@ var GameCharacters = (() => {
317
317
  };
318
318
 
319
319
  // ../game-contracts/dist/index.js
320
+ var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
320
321
  var MISSING_BITS = {
321
322
  head: 1,
322
323
  armL: 2,
@@ -329,6 +330,54 @@ var GameCharacters = (() => {
329
330
  legRBroken: 256,
330
331
  jaw: 512
331
332
  };
333
+ var DEFERRED_QUEUE_ID = {
334
+ DESTRUCTION_EVENTS: "destruction.events",
335
+ BREACH_PAINT: "floorplan.breach-paint",
336
+ AUDIO_VOICES: "audio.voices",
337
+ VEHICLE_CREASE: "vehicles.crease"
338
+ };
339
+ var DEFERRED_PRIORITY = {
340
+ [DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
341
+ [DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present" },
342
+ [DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
343
+ [DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" }
344
+ };
345
+ var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
346
+ var GAIT_IDS = ["walk", "run"];
347
+ var LANDING_IDS = ["light", "heavy"];
348
+ var BODY_SOUND_IDS = [
349
+ "jump",
350
+ "cloth_rustle",
351
+ "body_fall",
352
+ "fall_damage",
353
+ "player_hurt",
354
+ "player_breath_run",
355
+ "player_death",
356
+ "bite",
357
+ "grab",
358
+ "punch_swing",
359
+ "punch_hit_body",
360
+ "punch_hit_face",
361
+ "punch_hit_object",
362
+ "kick_swing",
363
+ "kick_hit",
364
+ "kick_hit_object",
365
+ "shove_two_hands",
366
+ "knife_swing",
367
+ "knife_stab",
368
+ "knife_slash",
369
+ "knife_hit_object",
370
+ "blunt_swing",
371
+ "blunt_hit",
372
+ "blunt_hit_object",
373
+ "axe_swing",
374
+ "axe_chop",
375
+ "axe_hit_object"
376
+ ];
377
+ var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
378
+ var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
379
+ var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
380
+ var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
332
381
 
333
382
  // src/presets/team-game.json
334
383
  var team_game_default = {
@@ -941,7 +990,24 @@ var GameCharacters = (() => {
941
990
  const parts = describeBody({ rig, body: bodySpec, build: spec.build, name: spec.kind });
942
991
  const fresh = () => createBodyState({ vitality: spec.vitality, detail: spec.detail, crawling: spec.crawling ?? false, hitPointsOf: hitPointsOf ?? ((kind) => SEGMENT_NUMBERS[kind].hitPoints) });
943
992
  const body = fresh();
944
- return { spec, rig, body, position: [0, 0, 0], rotation: [0, 0, 0, 1], describe: () => parts, resetBody: () => void Object.assign(body, fresh()) };
993
+ let cachedState;
994
+ const core = {
995
+ spec,
996
+ rig,
997
+ body,
998
+ position: [0, 0, 0],
999
+ rotation: [0, 0, 0, 1],
1000
+ describe: () => parts,
1001
+ resetBody: () => {
1002
+ Object.assign(body, fresh());
1003
+ cachedState = void 0;
1004
+ },
1005
+ readState: () => cachedState ?? (cachedState = toObjectState({ id: spec.id, name: spec.kind, position: core.position, rotation: core.rotation, body, spec: parts })),
1006
+ invalidateState: () => {
1007
+ cachedState = void 0;
1008
+ }
1009
+ };
1010
+ return core;
945
1011
  };
946
1012
  var characterView = (core) => ({
947
1013
  id: core.spec.id,
@@ -959,13 +1025,15 @@ var GameCharacters = (() => {
959
1025
  if (detail === "regions") regionsFromSegments(core.body);
960
1026
  else segmentsFromRegions(core.body);
961
1027
  core.body.detail = detail;
1028
+ core.invalidateState();
962
1029
  },
963
1030
  setTransform(position, rotation) {
964
1031
  core.position = [...position];
965
1032
  if (rotation) core.rotation = [...rotation];
1033
+ core.invalidateState();
966
1034
  },
967
1035
  describe: core.describe,
968
- state: () => toObjectState({ id: core.spec.id, name: core.spec.kind, position: core.position, rotation: core.rotation, body: core.body, spec: core.describe() }),
1036
+ state: core.readState,
969
1037
  reset: core.resetBody
970
1038
  });
971
1039
 
@@ -1726,7 +1794,9 @@ var GameCharacters = (() => {
1726
1794
  hitCounter += 1;
1727
1795
  const random = core.spec.random ?? createRng((core.spec.seed ^ hitCounter) >>> 0);
1728
1796
  const ops = opsFor(random, hit.source);
1797
+ core.invalidateState();
1729
1798
  lastHit = applyBlow({ ops, hit, setup, worn, localPoint: toLocal(transform(), hit.point), jointOf, describe: core.describe });
1799
+ core.invalidateState();
1730
1800
  return ops.events;
1731
1801
  },
1732
1802
  update(dt) {
@@ -1761,6 +1831,7 @@ var GameCharacters = (() => {
1761
1831
  bleeders = structuredClone(saved.bleeders);
1762
1832
  hitCounter = saved.hitCounter;
1763
1833
  clock = saved.clock;
1834
+ core.invalidateState();
1764
1835
  }
1765
1836
  };
1766
1837
  return character;