@adatechnology/game-crowd 0.5.3 → 0.6.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.
- package/README.md +8 -7
- package/dist/index.d.ts +172 -7
- package/dist/index.global.js +404 -122
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +305 -115
- package/dist/index.js.map +1 -1
- package/dist/physics-worker.js +2 -2
- package/dist/physics-worker.js.map +1 -1
- package/package.json +4 -3
package/dist/index.global.js
CHANGED
|
@@ -31,6 +31,8 @@ var GameCrowd = (() => {
|
|
|
31
31
|
FALL_CAUSE: () => FALL_CAUSE,
|
|
32
32
|
HERD_DEFAULTS: () => HERD_DEFAULTS,
|
|
33
33
|
HERD_ROLES: () => HERD_ROLES,
|
|
34
|
+
HORDE_COMMAND: () => HORDE_COMMAND,
|
|
35
|
+
HORDE_SIM_ID: () => HORDE_SIM_ID,
|
|
34
36
|
MISSING: () => MISSING,
|
|
35
37
|
STATE: () => STATE,
|
|
36
38
|
attachPhysicsWorker: () => attachPhysicsWorker,
|
|
@@ -39,22 +41,46 @@ var GameCrowd = (() => {
|
|
|
39
41
|
contactStep: () => contactStep,
|
|
40
42
|
createCivilians: () => createCivilians,
|
|
41
43
|
createContactView: () => createContactView,
|
|
44
|
+
createCoordinatorRunner: () => createCoordinatorRunner,
|
|
42
45
|
createCrowd: () => createCrowd,
|
|
43
46
|
createDoors: () => createDoors,
|
|
44
47
|
createFlock: () => createFlock,
|
|
45
48
|
createHerd: () => createHerd,
|
|
49
|
+
createHordeCrowd: () => createHordeCrowd,
|
|
46
50
|
createMovableContacts: () => createMovableContacts,
|
|
47
51
|
createNavGrid: () => createNavGrid,
|
|
48
52
|
createRng: () => createRng,
|
|
49
53
|
createStore: () => createStore,
|
|
54
|
+
crowdPhysicsKind: () => crowdPhysicsKind,
|
|
55
|
+
hordeSimModule: () => hordeSimModule,
|
|
56
|
+
hordeSnapshotBytes: () => hordeSnapshotBytes,
|
|
57
|
+
hordeSnapshotLayout: () => hordeSnapshotLayout,
|
|
50
58
|
identityOf: () => identityOf,
|
|
51
59
|
mix32: () => mix32,
|
|
60
|
+
readHordeSnapshot: () => readHordeSnapshot,
|
|
52
61
|
resolvePhysics: () => resolvePhysics,
|
|
53
62
|
unit: () => unit,
|
|
54
|
-
walksInto: () => walksInto
|
|
63
|
+
walksInto: () => walksInto,
|
|
64
|
+
writeHordeSnapshot: () => writeHordeSnapshot
|
|
55
65
|
});
|
|
56
66
|
|
|
57
67
|
// ../game-contracts/dist/index.js
|
|
68
|
+
var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
|
|
69
|
+
var NEAREST = 0.3;
|
|
70
|
+
function sideOnImpulse(tnt, distance, nearest = NEAREST) {
|
|
71
|
+
if (!(tnt > 0)) return 0;
|
|
72
|
+
const w3 = Math.cbrt(tnt);
|
|
73
|
+
const z = Math.max(distance, nearest) / w3;
|
|
74
|
+
const near = z / 0.23 * (z / 0.23);
|
|
75
|
+
const far = z / 1.55;
|
|
76
|
+
const scaled = 0.067 * Math.sqrt(1 + near * near) / (z * z * Math.cbrt(1 + far * far * far));
|
|
77
|
+
return scaled * w3 * 100;
|
|
78
|
+
}
|
|
79
|
+
function bodyImpulse(tnt, distance) {
|
|
80
|
+
if (!(tnt > 0)) return 0;
|
|
81
|
+
const z = Math.max(distance, NEAREST) / Math.cbrt(tnt);
|
|
82
|
+
return sideOnImpulse(tnt, distance) * (2 + 4 / (1 + z * z));
|
|
83
|
+
}
|
|
58
84
|
var DEFAULT_BLAST_SHOVE = { coupling: 0.02, maxSpeed: 20, lift: 0.3, minSpeed: 0.3, falloffPower: 2 };
|
|
59
85
|
var clampShare = (share) => Math.min(1, Math.max(0, share));
|
|
60
86
|
function blastShove(blast, target, options = {}) {
|
|
@@ -67,13 +93,12 @@ var GameCrowd = (() => {
|
|
|
67
93
|
const falloff = (1 - distance / blast.radius) ** o.falloffPower;
|
|
68
94
|
const mass = Math.max(target.mass, 0.05);
|
|
69
95
|
const reach = clampShare(blast.reach ?? 1);
|
|
70
|
-
const speed = Math.sqrt(reach) * Math.min(o.maxSpeed, Math.sqrt(2 * blast.energy * o.coupling / mass)) * falloff;
|
|
96
|
+
const speed = target.area !== void 0 ? Math.min(o.maxSpeed, bodyImpulse(blast.tnt ?? blast.energy * DEFAULT_BLAST_IMPULSE.tntPerJoule, distance) * target.area * reach / mass) : Math.sqrt(reach) * Math.min(o.maxSpeed, Math.sqrt(2 * blast.energy * o.coupling / mass)) * falloff;
|
|
71
97
|
if (!(speed >= o.minSpeed)) return void 0;
|
|
72
98
|
const direction = distance > 1e-4 ? [dx / distance, dy / distance + o.lift, dz / distance] : [0, 1, 0];
|
|
73
99
|
const length = Math.hypot(direction[0], direction[1], direction[2]);
|
|
74
100
|
return { speed, direction: [direction[0] / length, direction[1] / length, direction[2] / length], distance, falloff };
|
|
75
101
|
}
|
|
76
|
-
var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
|
|
77
102
|
var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
|
|
78
103
|
var MISSING_BITS = {
|
|
79
104
|
head: 1,
|
|
@@ -90,15 +115,37 @@ var GameCrowd = (() => {
|
|
|
90
115
|
var DEFERRED_QUEUE_ID = {
|
|
91
116
|
DESTRUCTION_EVENTS: "destruction.events",
|
|
92
117
|
BREACH_PAINT: "floorplan.breach-paint",
|
|
118
|
+
BREACH_CUT: "floorplan.breach-cut",
|
|
93
119
|
AUDIO_VOICES: "audio.voices",
|
|
94
|
-
VEHICLE_CREASE: "vehicles.crease"
|
|
120
|
+
VEHICLE_CREASE: "vehicles.crease",
|
|
121
|
+
AUDIO_OCCLUSION: "audio.occlusion",
|
|
122
|
+
FLUID_FILM: "fluids.film",
|
|
123
|
+
VEHICLE_LOD_BATCH: "vehicles.lod-batch",
|
|
124
|
+
SETTLED_BATCH: "destruction.settled-batch",
|
|
125
|
+
STATIC_BATCH: "render.static-batch",
|
|
126
|
+
ANIMALS_STATIC_BATCH: "animals.static-batch",
|
|
127
|
+
CHARACTERS_STATIC_BATCH: "characters.static-batch",
|
|
128
|
+
HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
|
|
129
|
+
DESTRUCTION_PREFIT: "destruction.prefit"
|
|
95
130
|
};
|
|
96
131
|
var DEFERRED_PRIORITY = {
|
|
97
132
|
[DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
|
|
98
|
-
|
|
133
|
+
// every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
|
|
134
|
+
[DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
|
|
135
|
+
[DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
|
|
99
136
|
[DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
|
|
100
|
-
[DEFERRED_QUEUE_ID.
|
|
137
|
+
[DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
|
|
138
|
+
[DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
|
|
139
|
+
[DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
|
|
140
|
+
[DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
|
|
141
|
+
[DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
|
|
142
|
+
[DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
143
|
+
[DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
144
|
+
[DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
145
|
+
[DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
|
|
146
|
+
[DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
|
|
101
147
|
};
|
|
148
|
+
var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
|
|
102
149
|
var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
|
|
103
150
|
var GAIT_IDS = ["walk", "run"];
|
|
104
151
|
var LANDING_IDS = ["light", "heavy"];
|
|
@@ -135,6 +182,22 @@ var GameCrowd = (() => {
|
|
|
135
182
|
var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
|
|
136
183
|
var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
|
|
137
184
|
var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
|
|
185
|
+
var WORKER_KIND_ID = {
|
|
186
|
+
GROUND_TILES: "destruction.ground-tiles",
|
|
187
|
+
CROWD_PHYSICS: "crowd.physics",
|
|
188
|
+
PIECE_BOXES: "destruction.piece-boxes",
|
|
189
|
+
STATIC_COLLIDERS: "destruction.static-colliders",
|
|
190
|
+
SHAPES_GENERATE: "shapes.generate",
|
|
191
|
+
WORLD_REGION: "world.region"
|
|
192
|
+
};
|
|
193
|
+
var WORKER_KIND_DEFAULTS = {
|
|
194
|
+
[WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
|
|
195
|
+
[WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
|
|
196
|
+
[WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
|
|
197
|
+
[WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
|
|
198
|
+
[WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
|
|
199
|
+
[WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
|
|
200
|
+
};
|
|
138
201
|
|
|
139
202
|
// ../game-characters/dist/index.js
|
|
140
203
|
var __defProp2 = Object.defineProperty;
|
|
@@ -214,6 +277,35 @@ var GameCrowd = (() => {
|
|
|
214
277
|
lod0: 2500,
|
|
215
278
|
lod1: 800,
|
|
216
279
|
lod2: 250
|
|
280
|
+
},
|
|
281
|
+
heightRangeMetres: {
|
|
282
|
+
min: 0.8,
|
|
283
|
+
max: 3,
|
|
284
|
+
source: "Spec 012 (R1/R2): covers children (~0.94 m), adults (1.40-2.10 m) and Brutamonte (2.56 m)"
|
|
285
|
+
},
|
|
286
|
+
heightsByTypeMetres: {
|
|
287
|
+
human: 1.8,
|
|
288
|
+
Lento: 1.8,
|
|
289
|
+
Corredor: 1.75,
|
|
290
|
+
Brutamonte: 2.56,
|
|
291
|
+
Rastejante: 1.8,
|
|
292
|
+
Gritador: 1.8,
|
|
293
|
+
Inchado: 1.85,
|
|
294
|
+
Espreitador: 1.8,
|
|
295
|
+
Farejador: 1.8,
|
|
296
|
+
Saltador: 1.8,
|
|
297
|
+
Cego: 1.8,
|
|
298
|
+
Afogado: 1.8,
|
|
299
|
+
Carbonizado: 1.8,
|
|
300
|
+
Devorador: 1.8
|
|
301
|
+
},
|
|
302
|
+
anthropometry: {
|
|
303
|
+
source: "ISO 7250-1 / NASA-STD-3000 (Vol. I \xA73.3) / ANSUR II (adult p50): sitting height 0.520, sitting eye 0.455, bideltoid shoulder width 0.260, buttock-knee thigh 0.340, knee-sole shin 0.285",
|
|
304
|
+
seatedHeightRatio: 0.52,
|
|
305
|
+
seatedEyeHeightRatio: 0.455,
|
|
306
|
+
shoulderWidthRatio: 0.26,
|
|
307
|
+
thighLengthRatio: 0.34,
|
|
308
|
+
shinLengthRatio: 0.285
|
|
217
309
|
}
|
|
218
310
|
};
|
|
219
311
|
var SEGMENT_RADIUS = {
|
|
@@ -800,6 +892,20 @@ var GameCrowd = (() => {
|
|
|
800
892
|
legR: { severed: MISSING_BITS.legR, broken: MISSING_BITS.legRBroken }
|
|
801
893
|
};
|
|
802
894
|
var HEAD_RESISTANCE = segmentResistance({ kind: "head", bodyCount: 1, protection: 0 });
|
|
895
|
+
var REFERENCE_HEIGHT_METRES = body_default.guide.heightMetres;
|
|
896
|
+
var HEIGHT_RANGE_METRES = {
|
|
897
|
+
min: body_default.heightRangeMetres.min,
|
|
898
|
+
max: body_default.heightRangeMetres.max
|
|
899
|
+
};
|
|
900
|
+
var HEIGHTS_BY_TYPE_METRES = body_default.heightsByTypeMetres;
|
|
901
|
+
var ANTHROPOMETRY_SOURCE = body_default.anthropometry.source;
|
|
902
|
+
var ANTHROPOMETRY_RATIOS = {
|
|
903
|
+
seatedHeightRatio: body_default.anthropometry.seatedHeightRatio,
|
|
904
|
+
seatedEyeHeightRatio: body_default.anthropometry.seatedEyeHeightRatio,
|
|
905
|
+
shoulderWidthRatio: body_default.anthropometry.shoulderWidthRatio,
|
|
906
|
+
thighLengthRatio: body_default.anthropometry.thighLengthRatio,
|
|
907
|
+
shinLengthRatio: body_default.anthropometry.shinLengthRatio
|
|
908
|
+
};
|
|
803
909
|
var gait_default = {
|
|
804
910
|
cascade: {
|
|
805
911
|
hip: 16,
|
|
@@ -1629,17 +1735,22 @@ var GameCrowd = (() => {
|
|
|
1629
1735
|
const c = cellOf(x, z);
|
|
1630
1736
|
return c < 0 || occ[c] !== 0 && occ[c] !== 3 && occH[c] > y;
|
|
1631
1737
|
};
|
|
1738
|
+
let version = 0;
|
|
1632
1739
|
const fillRect = (x0, z0, x1, z1, kind, h) => {
|
|
1633
1740
|
const a = Math.floor((x0 + half) / cell);
|
|
1634
1741
|
const b = Math.ceil((x1 + half) / cell);
|
|
1635
1742
|
const c = Math.floor((z0 + half) / cell);
|
|
1636
1743
|
const d = Math.ceil((z1 + half) / cell);
|
|
1744
|
+
let changed = false;
|
|
1637
1745
|
for (let gz = Math.max(0, c); gz < Math.min(n, d); gz++)
|
|
1638
1746
|
for (let gx = Math.max(0, a); gx < Math.min(n, b); gx++) {
|
|
1639
1747
|
const i = gz * n + gx;
|
|
1748
|
+
if (occ[i] === kind && occH[i] === Math.fround(h)) continue;
|
|
1640
1749
|
occ[i] = kind;
|
|
1641
1750
|
occH[i] = h;
|
|
1751
|
+
changed = true;
|
|
1642
1752
|
}
|
|
1753
|
+
if (changed) version++;
|
|
1643
1754
|
};
|
|
1644
1755
|
if (options.border ?? true) {
|
|
1645
1756
|
fillRect(-half, -half, half, -half + BORDER_WIDTH, 1, BORDER_HEIGHT);
|
|
@@ -1653,6 +1764,9 @@ var GameCrowd = (() => {
|
|
|
1653
1764
|
cell,
|
|
1654
1765
|
n,
|
|
1655
1766
|
occ,
|
|
1767
|
+
get version() {
|
|
1768
|
+
return version;
|
|
1769
|
+
},
|
|
1656
1770
|
occH,
|
|
1657
1771
|
cellOf,
|
|
1658
1772
|
solidAt,
|
|
@@ -2477,26 +2591,6 @@ var GameCrowd = (() => {
|
|
|
2477
2591
|
return { height, step, weightOn };
|
|
2478
2592
|
}
|
|
2479
2593
|
|
|
2480
|
-
// src/physics/offload/default-worker.ts
|
|
2481
|
-
var import_meta = {};
|
|
2482
|
-
function createDefaultWorkerFactory() {
|
|
2483
|
-
if (typeof Worker === "undefined") return null;
|
|
2484
|
-
let url;
|
|
2485
|
-
try {
|
|
2486
|
-
url = new URL("./physics-worker.js", import_meta.url);
|
|
2487
|
-
} catch {
|
|
2488
|
-
return null;
|
|
2489
|
-
}
|
|
2490
|
-
return () => {
|
|
2491
|
-
const worker = new Worker(url, { type: "module" });
|
|
2492
|
-
return {
|
|
2493
|
-
postMessage: (message, transfer) => worker.postMessage(message, transfer ?? []),
|
|
2494
|
-
onMessage: (listener) => worker.addEventListener("message", (event) => listener(event.data)),
|
|
2495
|
-
terminate: () => worker.terminate()
|
|
2496
|
-
};
|
|
2497
|
-
};
|
|
2498
|
-
}
|
|
2499
|
-
|
|
2500
2594
|
// src/physics/offload/frame.ts
|
|
2501
2595
|
var F32_INPUTS = ["x", "z", "y", "vx", "vz", "pushX", "pushZ", "mass", "build", "aimX", "aimZ", "driveFactor", "fieldPrev"];
|
|
2502
2596
|
var U8_INPUTS = ["band", "balance", "state", "type"];
|
|
@@ -2504,7 +2598,7 @@ var GameCrowd = (() => {
|
|
|
2504
2598
|
var HEADER = { n: 0, h: 1, playerOn: 2, playerX: 3, playerZ: 4, contacts: 5, maxOverlap: 6, overlapSum: 7, playerLoad: 8, drivers: 9, fieldMax: 10, size: 16 };
|
|
2505
2599
|
var align8 = (bytes) => Math.ceil(bytes / 8) * 8;
|
|
2506
2600
|
var frameBytes = ({ capacity, cells }) => HEADER.size * 8 + (F32_INPUTS.length + F32_OUTPUTS.length + 2) * align8(capacity * 4) + U8_INPUTS.length * align8(capacity) + align8(cells);
|
|
2507
|
-
function createFrame(buffer, shape) {
|
|
2601
|
+
function createFrame(buffer, shape, occupancy) {
|
|
2508
2602
|
const { capacity, cells } = shape;
|
|
2509
2603
|
let offset = 0;
|
|
2510
2604
|
const take = (make, bytesPerElement, length) => {
|
|
@@ -2522,97 +2616,11 @@ var GameCrowd = (() => {
|
|
|
2522
2616
|
const doorCell = take((b, o, l) => new Int32Array(b, o, l), 4, capacity);
|
|
2523
2617
|
const bytes = {};
|
|
2524
2618
|
for (const key of U8_INPUTS) bytes[key] = take(u8, 1, capacity);
|
|
2525
|
-
const occ = take(u8, 1, cells);
|
|
2619
|
+
const occ = occupancy ?? take(u8, 1, cells);
|
|
2526
2620
|
return { header, f32: floats, u8: bytes, identity, doorCell, occ };
|
|
2527
2621
|
}
|
|
2528
2622
|
var INPUT_KEYS = { f32: F32_INPUTS, u8: U8_INPUTS };
|
|
2529
2623
|
|
|
2530
|
-
// src/physics/offload/offload.ts
|
|
2531
|
-
var isOpen2 = (grid, x, z) => {
|
|
2532
|
-
const cell = grid.cellOf(x, z);
|
|
2533
|
-
return cell >= 0 && (grid.occ[cell] === 0 || grid.occ[cell] === 3);
|
|
2534
|
-
};
|
|
2535
|
-
function writeSnapshot(frame, source, h, player) {
|
|
2536
|
-
const { store, grid } = source;
|
|
2537
|
-
const n = store.n;
|
|
2538
|
-
for (const key of INPUT_KEYS.f32) frame.f32[key].set(store[key].subarray(0, n));
|
|
2539
|
-
for (const key of INPUT_KEYS.u8) frame.u8[key].set(store[key].subarray(0, n));
|
|
2540
|
-
frame.identity.set(store.identity.subarray(0, n));
|
|
2541
|
-
frame.occ.set(grid.occ);
|
|
2542
|
-
frame.header[HEADER.n] = n;
|
|
2543
|
-
frame.header[HEADER.h] = h;
|
|
2544
|
-
frame.header[HEADER.playerOn] = player ? 1 : 0;
|
|
2545
|
-
frame.header[HEADER.playerX] = player?.x ?? 0;
|
|
2546
|
-
frame.header[HEADER.playerZ] = player?.z ?? 0;
|
|
2547
|
-
}
|
|
2548
|
-
function createOffload(runner, host, latency = 1) {
|
|
2549
|
-
const { store, grid, stats, contact } = host;
|
|
2550
|
-
const queue = [];
|
|
2551
|
-
const spare = Array.from({ length: latency }, () => ({ count: 0, origin: null, originBuffer: new Int32Array(store.capacity) }));
|
|
2552
|
-
const result = { playerLoad: 0 };
|
|
2553
|
-
const apply = (frame, pending) => {
|
|
2554
|
-
const { f32, header } = frame;
|
|
2555
|
-
const { origin, count } = pending;
|
|
2556
|
-
for (let agent = 0; agent < store.n; agent++) {
|
|
2557
|
-
const from = origin ? origin[agent] : agent < count ? agent : -1;
|
|
2558
|
-
if (from < 0) {
|
|
2559
|
-
contact.workspace.shove[agent] = 0;
|
|
2560
|
-
continue;
|
|
2561
|
-
}
|
|
2562
|
-
const dx = f32.deltaX[from];
|
|
2563
|
-
const dz = f32.deltaZ[from];
|
|
2564
|
-
if (dx !== 0 && isOpen2(grid, store.x[agent] + dx, store.z[agent])) store.x[agent] += dx;
|
|
2565
|
-
if (dz !== 0 && isOpen2(grid, store.x[agent], store.z[agent] + dz)) store.z[agent] += dz;
|
|
2566
|
-
store.pushX[agent] += f32.deltaPushX[from];
|
|
2567
|
-
store.pushZ[agent] += f32.deltaPushZ[from];
|
|
2568
|
-
store.vx[agent] += f32.deltaVx[from];
|
|
2569
|
-
store.vz[agent] += f32.deltaVz[from];
|
|
2570
|
-
store.field[agent] = f32.field[from];
|
|
2571
|
-
store.fieldPrev[agent] = f32.field[from];
|
|
2572
|
-
contact.workspace.shove[agent] = f32.shove[from];
|
|
2573
|
-
const cell = frame.doorCell[from];
|
|
2574
|
-
if (cell >= 0) host.addDoorLoad(cell, f32.doorLoad[from]);
|
|
2575
|
-
}
|
|
2576
|
-
stats.contacts = header[HEADER.contacts];
|
|
2577
|
-
stats.maxOverlap = header[HEADER.maxOverlap];
|
|
2578
|
-
stats.meanOverlap = header[HEADER.contacts] ? header[HEADER.overlapSum] / header[HEADER.contacts] : 0;
|
|
2579
|
-
stats.fieldMax = header[HEADER.fieldMax];
|
|
2580
|
-
result.playerLoad = header[HEADER.playerLoad];
|
|
2581
|
-
};
|
|
2582
|
-
const step = (h, player) => {
|
|
2583
|
-
result.playerLoad = 0;
|
|
2584
|
-
if (queue.length >= latency) {
|
|
2585
|
-
const frame2 = runner.settle();
|
|
2586
|
-
if (frame2) {
|
|
2587
|
-
const pending = queue.shift();
|
|
2588
|
-
apply(frame2, pending);
|
|
2589
|
-
pending.origin = null;
|
|
2590
|
-
spare.push(pending);
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
const frame = runner.frame();
|
|
2594
|
-
if (frame && spare.length) {
|
|
2595
|
-
writeSnapshot(frame, { store, grid }, h, player);
|
|
2596
|
-
runner.submit();
|
|
2597
|
-
const pending = spare.shift();
|
|
2598
|
-
pending.count = store.n;
|
|
2599
|
-
queue.push(pending);
|
|
2600
|
-
}
|
|
2601
|
-
return result;
|
|
2602
|
-
};
|
|
2603
|
-
const remap = (removed, moved) => {
|
|
2604
|
-
queue.forEach((pending) => {
|
|
2605
|
-
if (!pending.origin) {
|
|
2606
|
-
pending.origin = pending.originBuffer.fill(-1);
|
|
2607
|
-
for (let agent = 0; agent < pending.count; agent++) pending.origin[agent] = agent;
|
|
2608
|
-
}
|
|
2609
|
-
pending.origin[removed] = removed === moved ? -1 : pending.origin[moved];
|
|
2610
|
-
if (removed !== moved) pending.origin[moved] = -1;
|
|
2611
|
-
});
|
|
2612
|
-
};
|
|
2613
|
-
return { step, remap, dispose: () => runner.dispose() };
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
2624
|
// src/physics/pressure.ts
|
|
2617
2625
|
var TOUCH_SLACK = 0.08;
|
|
2618
2626
|
var WALL_PROBE = 0.12;
|
|
@@ -2836,6 +2844,176 @@ var GameCrowd = (() => {
|
|
|
2836
2844
|
return { run };
|
|
2837
2845
|
}
|
|
2838
2846
|
|
|
2847
|
+
// src/physics/offload/kind.ts
|
|
2848
|
+
var crowdPhysicsKind = Object.freeze({
|
|
2849
|
+
id: WORKER_KIND_ID.CROWD_PHYSICS,
|
|
2850
|
+
kind: "resident",
|
|
2851
|
+
...WORKER_KIND_DEFAULTS[WORKER_KIND_ID.CROWD_PHYSICS],
|
|
2852
|
+
create(init) {
|
|
2853
|
+
const kernel = createKernel(init.setup);
|
|
2854
|
+
return {
|
|
2855
|
+
step(buffer) {
|
|
2856
|
+
kernel.run(createFrame(buffer, init.shape, init.occupancy));
|
|
2857
|
+
return buffer;
|
|
2858
|
+
}
|
|
2859
|
+
};
|
|
2860
|
+
},
|
|
2861
|
+
transferOutput: (buffer) => [buffer]
|
|
2862
|
+
});
|
|
2863
|
+
function createCoordinatorRunner(setup, shape, coordinator, slots = 1, grid) {
|
|
2864
|
+
const frameShape = grid ? { capacity: shape.capacity, cells: 0 } : shape;
|
|
2865
|
+
const open = () => {
|
|
2866
|
+
const occupancy = grid?.occ.slice();
|
|
2867
|
+
return { resident: coordinator.resident(crowdPhysicsKind, { setup, shape: frameShape, ...occupancy ? { occupancy } : {} }), pending: 0, retired: false };
|
|
2868
|
+
};
|
|
2869
|
+
let current = open();
|
|
2870
|
+
let version = grid?.version ?? 0;
|
|
2871
|
+
const buffers = Array.from({ length: slots }, () => new ArrayBuffer(frameBytes(frameShape)));
|
|
2872
|
+
const frames = buffers.map((buffer) => createFrame(buffer, frameShape));
|
|
2873
|
+
const handles = [];
|
|
2874
|
+
const views = /* @__PURE__ */ new WeakMap();
|
|
2875
|
+
let submitted = 0;
|
|
2876
|
+
let settled = 0;
|
|
2877
|
+
const release = (owner) => {
|
|
2878
|
+
if (owner.retired && owner.pending === 0) owner.resident.dispose();
|
|
2879
|
+
};
|
|
2880
|
+
return {
|
|
2881
|
+
transport: "transfer",
|
|
2882
|
+
get inFlight() {
|
|
2883
|
+
return submitted - settled;
|
|
2884
|
+
},
|
|
2885
|
+
frame: () => submitted - settled < slots ? frames[submitted % slots] : null,
|
|
2886
|
+
submit: () => {
|
|
2887
|
+
if (grid && grid.version !== version) {
|
|
2888
|
+
version = grid.version;
|
|
2889
|
+
current.retired = true;
|
|
2890
|
+
release(current);
|
|
2891
|
+
current = open();
|
|
2892
|
+
}
|
|
2893
|
+
const owner = current;
|
|
2894
|
+
owner.pending++;
|
|
2895
|
+
handles.push({ handle: owner.resident.step(buffers[submitted % slots], { frame: submitted, latencyFrames: slots }), owner });
|
|
2896
|
+
submitted++;
|
|
2897
|
+
},
|
|
2898
|
+
settle: () => {
|
|
2899
|
+
const next = handles.shift();
|
|
2900
|
+
if (!next) return null;
|
|
2901
|
+
settled++;
|
|
2902
|
+
let out;
|
|
2903
|
+
try {
|
|
2904
|
+
out = next.handle.collect(next.handle.dueFrame);
|
|
2905
|
+
} finally {
|
|
2906
|
+
next.owner.pending--;
|
|
2907
|
+
release(next.owner);
|
|
2908
|
+
}
|
|
2909
|
+
let view = views.get(out);
|
|
2910
|
+
if (!view) views.set(out, view = createFrame(out, frameShape));
|
|
2911
|
+
return view;
|
|
2912
|
+
},
|
|
2913
|
+
dispose: () => {
|
|
2914
|
+
current.resident.dispose();
|
|
2915
|
+
for (const { owner } of handles) owner.resident.dispose();
|
|
2916
|
+
}
|
|
2917
|
+
};
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
// src/physics/offload/offload.ts
|
|
2921
|
+
var isOpen2 = (grid, x, z) => {
|
|
2922
|
+
const cell = grid.cellOf(x, z);
|
|
2923
|
+
return cell >= 0 && (grid.occ[cell] === 0 || grid.occ[cell] === 3);
|
|
2924
|
+
};
|
|
2925
|
+
var clearStats = (stats) => {
|
|
2926
|
+
stats.contacts = 0;
|
|
2927
|
+
stats.maxOverlap = 0;
|
|
2928
|
+
stats.meanOverlap = 0;
|
|
2929
|
+
stats.fieldMax = 0;
|
|
2930
|
+
};
|
|
2931
|
+
function writeSnapshot(frame, source, h, player) {
|
|
2932
|
+
const { store, grid } = source;
|
|
2933
|
+
const n = store.n;
|
|
2934
|
+
for (const key of INPUT_KEYS.f32) frame.f32[key].set(store[key].subarray(0, n));
|
|
2935
|
+
for (const key of INPUT_KEYS.u8) frame.u8[key].set(store[key].subarray(0, n));
|
|
2936
|
+
frame.identity.set(store.identity.subarray(0, n));
|
|
2937
|
+
if (frame.occ.length > 0) frame.occ.set(grid.occ);
|
|
2938
|
+
frame.header[HEADER.n] = n;
|
|
2939
|
+
frame.header[HEADER.h] = h;
|
|
2940
|
+
frame.header[HEADER.playerOn] = player ? 1 : 0;
|
|
2941
|
+
frame.header[HEADER.playerX] = player?.x ?? 0;
|
|
2942
|
+
frame.header[HEADER.playerZ] = player?.z ?? 0;
|
|
2943
|
+
}
|
|
2944
|
+
function createOffload(runner, host, latency = 1) {
|
|
2945
|
+
const { store, grid, stats, contact } = host;
|
|
2946
|
+
const queue = [];
|
|
2947
|
+
const spare = Array.from({ length: latency }, () => ({ count: 0, origin: null, originBuffer: new Int32Array(store.capacity) }));
|
|
2948
|
+
const result = { playerLoad: 0 };
|
|
2949
|
+
const apply = (frame, pending) => {
|
|
2950
|
+
const { f32, header } = frame;
|
|
2951
|
+
const { origin, count } = pending;
|
|
2952
|
+
for (let agent = 0; agent < store.n; agent++) {
|
|
2953
|
+
const from = origin ? origin[agent] : agent < count ? agent : -1;
|
|
2954
|
+
if (from < 0) {
|
|
2955
|
+
contact.workspace.shove[agent] = 0;
|
|
2956
|
+
continue;
|
|
2957
|
+
}
|
|
2958
|
+
const dx = f32.deltaX[from];
|
|
2959
|
+
const dz = f32.deltaZ[from];
|
|
2960
|
+
if (dx !== 0 && isOpen2(grid, store.x[agent] + dx, store.z[agent])) store.x[agent] += dx;
|
|
2961
|
+
if (dz !== 0 && isOpen2(grid, store.x[agent], store.z[agent] + dz)) store.z[agent] += dz;
|
|
2962
|
+
store.pushX[agent] += f32.deltaPushX[from];
|
|
2963
|
+
store.pushZ[agent] += f32.deltaPushZ[from];
|
|
2964
|
+
store.vx[agent] += f32.deltaVx[from];
|
|
2965
|
+
store.vz[agent] += f32.deltaVz[from];
|
|
2966
|
+
store.field[agent] = f32.field[from];
|
|
2967
|
+
store.fieldPrev[agent] = f32.field[from];
|
|
2968
|
+
contact.workspace.shove[agent] = f32.shove[from];
|
|
2969
|
+
const cell = frame.doorCell[from];
|
|
2970
|
+
if (cell >= 0) host.addDoorLoad(cell, f32.doorLoad[from]);
|
|
2971
|
+
}
|
|
2972
|
+
stats.contacts = header[HEADER.contacts];
|
|
2973
|
+
stats.maxOverlap = header[HEADER.maxOverlap];
|
|
2974
|
+
stats.meanOverlap = header[HEADER.contacts] ? header[HEADER.overlapSum] / header[HEADER.contacts] : 0;
|
|
2975
|
+
stats.fieldMax = header[HEADER.fieldMax];
|
|
2976
|
+
result.playerLoad = header[HEADER.playerLoad];
|
|
2977
|
+
};
|
|
2978
|
+
const step = (h, player) => {
|
|
2979
|
+
result.playerLoad = 0;
|
|
2980
|
+
if (queue.length >= latency || store.n === 0 && queue.length > 0) {
|
|
2981
|
+
const frame2 = runner.settle();
|
|
2982
|
+
if (frame2) {
|
|
2983
|
+
const pending = queue.shift();
|
|
2984
|
+
apply(frame2, pending);
|
|
2985
|
+
pending.origin = null;
|
|
2986
|
+
spare.push(pending);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
if (store.n === 0) {
|
|
2990
|
+
contact.workspace.shove.fill(0);
|
|
2991
|
+
if (queue.length === 0) clearStats(stats);
|
|
2992
|
+
return result;
|
|
2993
|
+
}
|
|
2994
|
+
const frame = runner.frame();
|
|
2995
|
+
if (frame && spare.length) {
|
|
2996
|
+
writeSnapshot(frame, { store, grid }, h, player);
|
|
2997
|
+
runner.submit();
|
|
2998
|
+
const pending = spare.shift();
|
|
2999
|
+
pending.count = store.n;
|
|
3000
|
+
queue.push(pending);
|
|
3001
|
+
}
|
|
3002
|
+
return result;
|
|
3003
|
+
};
|
|
3004
|
+
const remap = (removed, moved) => {
|
|
3005
|
+
queue.forEach((pending) => {
|
|
3006
|
+
if (!pending.origin) {
|
|
3007
|
+
pending.origin = pending.originBuffer.fill(-1);
|
|
3008
|
+
for (let agent = 0; agent < pending.count; agent++) pending.origin[agent] = agent;
|
|
3009
|
+
}
|
|
3010
|
+
pending.origin[removed] = removed === moved ? -1 : pending.origin[moved];
|
|
3011
|
+
if (removed !== moved) pending.origin[moved] = -1;
|
|
3012
|
+
});
|
|
3013
|
+
};
|
|
3014
|
+
return { step, remap, dispose: () => runner.dispose() };
|
|
3015
|
+
}
|
|
3016
|
+
|
|
2839
3017
|
// src/physics/offload/worker-host.ts
|
|
2840
3018
|
var CONTROL = { IDLE: 0, SUBMITTED: 1, DONE: 2, STOP: 3 };
|
|
2841
3019
|
function attachPhysicsWorker(port) {
|
|
@@ -3255,12 +3433,13 @@ var GameCrowd = (() => {
|
|
|
3255
3433
|
const gridCells = grid.occ.length;
|
|
3256
3434
|
const shape = { capacity: store.capacity, cells: gridCells };
|
|
3257
3435
|
const setup = { capacity: store.capacity, gridSize: grid.size, gridCell: grid.cell, contact: options.contact, pressure: options.pressure, driveForceOfType: Array.from(driveForceOfType) };
|
|
3258
|
-
const transport = options.workerTransport ?? (isSharedAvailable() ? "shared" : "transfer");
|
|
3259
3436
|
const slots = options.workerLatency;
|
|
3437
|
+
if (options.workers) return createCoordinatorRunner(setup, shape, options.workers, slots, grid);
|
|
3438
|
+
const transport = options.workerTransport ?? (isSharedAvailable() ? "shared" : "transfer");
|
|
3260
3439
|
if (transport === "inline") return createInlineRunner(setup, shape, slots);
|
|
3261
|
-
const factory = options.workerFactory
|
|
3440
|
+
const factory = options.workerFactory;
|
|
3262
3441
|
if (!factory) {
|
|
3263
|
-
if (options.worker === "on") throw new Error('crowd physics: worker "on" but no Worker
|
|
3442
|
+
if (options.worker === "on") throw new Error('crowd physics: worker "on" but no Worker was provided (give physics.workers or physics.workerFactory)');
|
|
3264
3443
|
return null;
|
|
3265
3444
|
}
|
|
3266
3445
|
return transport === "shared" ? createSharedRunner(setup, shape, factory, slots) : createTransferRunner(setup, shape, factory, slots);
|
|
@@ -3529,10 +3708,11 @@ var GameCrowd = (() => {
|
|
|
3529
3708
|
doorPressureDamage: physics.door?.pressureDamage ?? DOOR_PRESSURE_DAMAGE,
|
|
3530
3709
|
playerPressure,
|
|
3531
3710
|
deterministic: physics.deterministic ?? false,
|
|
3532
|
-
worker: physics.worker ?? "off",
|
|
3711
|
+
worker: physics.worker ?? (physics.workers ? "auto" : "off"),
|
|
3533
3712
|
workerFactory: physics.workerFactory,
|
|
3534
3713
|
workerTransport: physics.workerTransport,
|
|
3535
|
-
workerLatency: physics.workerLatency ?? 1
|
|
3714
|
+
workerLatency: physics.workerLatency ?? 1,
|
|
3715
|
+
workers: physics.workers
|
|
3536
3716
|
};
|
|
3537
3717
|
}
|
|
3538
3718
|
|
|
@@ -3843,7 +4023,7 @@ var GameCrowd = (() => {
|
|
|
3843
4023
|
const GC = grid.cell;
|
|
3844
4024
|
const FW = grid.n;
|
|
3845
4025
|
const physics = resolvePhysics(options.physics);
|
|
3846
|
-
const flowCells = options.flow?.cellsPerStep ?? (physics.deterministic ? DETERMINISTIC_FLOW_CELLS : void 0);
|
|
4026
|
+
const flowCells = options.flow?.cellsPerStep ?? (physics.deterministic || !options.flow?.clock ? DETERMINISTIC_FLOW_CELLS : void 0);
|
|
3847
4027
|
const seed32 = (options.seed ?? 1) >>> 0;
|
|
3848
4028
|
let serial = 0;
|
|
3849
4029
|
const moundHeight = new Uint16Array(physics.mound ? FW * FW : 0);
|
|
@@ -4058,7 +4238,7 @@ var GameCrowd = (() => {
|
|
|
4058
4238
|
};
|
|
4059
4239
|
const flowStep = (budget, cellsPerStep) => {
|
|
4060
4240
|
if (!flow.phase) return;
|
|
4061
|
-
const t0 = clock();
|
|
4241
|
+
const t0 = cellsPerStep === void 0 ? clock() : 0;
|
|
4062
4242
|
let cellsLeft = cellsPerStep ?? Infinity;
|
|
4063
4243
|
const D = flow.dist;
|
|
4064
4244
|
const Q = flow.q;
|
|
@@ -4107,7 +4287,7 @@ var GameCrowd = (() => {
|
|
|
4107
4287
|
flow.win = W;
|
|
4108
4288
|
flow.winB = tw;
|
|
4109
4289
|
flow.phase = 0;
|
|
4110
|
-
flow.ms = flow.t + clock() - t0;
|
|
4290
|
+
flow.ms = cellsPerStep === void 0 ? flow.t + clock() - t0 : 0;
|
|
4111
4291
|
return;
|
|
4112
4292
|
}
|
|
4113
4293
|
const cx = W[0] + j % ww;
|
|
@@ -5867,6 +6047,108 @@ var GameCrowd = (() => {
|
|
|
5867
6047
|
}
|
|
5868
6048
|
};
|
|
5869
6049
|
}
|
|
6050
|
+
|
|
6051
|
+
// src/sim/horde.ts
|
|
6052
|
+
var HORDE_COMMAND = {
|
|
6053
|
+
/** `[TARGET, x, z, yaw, alive]` */
|
|
6054
|
+
TARGET: 1,
|
|
6055
|
+
/** `[BLAST, x, y, z, radius, energy J]` */
|
|
6056
|
+
BLAST: 2
|
|
6057
|
+
};
|
|
6058
|
+
var HORDE_SIM_ID = "crowd.horde";
|
|
6059
|
+
var HEADER2 = 16;
|
|
6060
|
+
var align82 = (n) => Math.ceil(n / 8) * 8;
|
|
6061
|
+
function hordeSnapshotLayout(store) {
|
|
6062
|
+
let offset = HEADER2;
|
|
6063
|
+
const fields = [];
|
|
6064
|
+
for (const key of [...AGENT_FIELDS, "armHp", "legHp"]) {
|
|
6065
|
+
const array = store[key];
|
|
6066
|
+
const per = array.length / store.capacity;
|
|
6067
|
+
fields.push({ key, per, bytes: array.BYTES_PER_ELEMENT, offset });
|
|
6068
|
+
offset = align82(offset + array.byteLength);
|
|
6069
|
+
}
|
|
6070
|
+
return { bytes: offset, fields };
|
|
6071
|
+
}
|
|
6072
|
+
var bytesOf = (array, count) => new Uint8Array(array.buffer, array.byteOffset, count * array.BYTES_PER_ELEMENT);
|
|
6073
|
+
function writeHordeSnapshot(store, out, header, layout = hordeSnapshotLayout(store)) {
|
|
6074
|
+
const words = new Int32Array(out.buffer, out.byteOffset, HEADER2 / 4);
|
|
6075
|
+
words[0] = store.n;
|
|
6076
|
+
words[1] = header.frame;
|
|
6077
|
+
words[2] = header.kills;
|
|
6078
|
+
words[3] = Math.round(header.hurt * 1e3);
|
|
6079
|
+
for (const field of layout.fields) out.set(bytesOf(store[field.key], store.n * field.per), field.offset);
|
|
6080
|
+
}
|
|
6081
|
+
function readHordeSnapshot(store, bytes, layout = hordeSnapshotLayout(store)) {
|
|
6082
|
+
const words = new Int32Array(bytes.buffer, bytes.byteOffset, HEADER2 / 4);
|
|
6083
|
+
const n = words[0];
|
|
6084
|
+
store.n = n;
|
|
6085
|
+
for (const field of layout.fields) {
|
|
6086
|
+
const target = store[field.key];
|
|
6087
|
+
bytesOf(target, n * field.per).set(bytes.subarray(field.offset, field.offset + n * field.per * field.bytes));
|
|
6088
|
+
}
|
|
6089
|
+
return { n, frame: words[1], kills: words[2], hurt: words[3] / 1e3 };
|
|
6090
|
+
}
|
|
6091
|
+
var mirrorTarget = (x, z) => {
|
|
6092
|
+
const state = { x, z, y: 0, floor: 0, alive: true, turned: false, crouch: false, bleeding: 0, scentTimer: 0, screamBoost: 0, grabbedBy: -1, blind: 0, burnTimer: 0, yaw: 0 };
|
|
6093
|
+
const damage = { total: 0 };
|
|
6094
|
+
return {
|
|
6095
|
+
state,
|
|
6096
|
+
damage,
|
|
6097
|
+
grab: (by) => void (state.grabbedBy = by),
|
|
6098
|
+
hurt: (amount) => void (damage.total += amount),
|
|
6099
|
+
knock: () => {
|
|
6100
|
+
},
|
|
6101
|
+
release: () => void (state.grabbedBy = -1)
|
|
6102
|
+
};
|
|
6103
|
+
};
|
|
6104
|
+
function createHordeCrowd(init, target) {
|
|
6105
|
+
const crowd = createCrowd({
|
|
6106
|
+
pack: init.pack,
|
|
6107
|
+
seed: init.seed,
|
|
6108
|
+
capacity: init.capacity,
|
|
6109
|
+
target,
|
|
6110
|
+
flow: { cellsPerStep: init.flowCellsPerStep ?? 2e4 },
|
|
6111
|
+
...init.physics ? { physics: { ...init.physics, worker: "off" } } : {}
|
|
6112
|
+
});
|
|
6113
|
+
if (init.initial) {
|
|
6114
|
+
readHordeSnapshot(crowd.store, init.initial);
|
|
6115
|
+
return crowd;
|
|
6116
|
+
}
|
|
6117
|
+
for (let k = 0; k < init.count; k++) {
|
|
6118
|
+
const angle = k / Math.max(1, init.count) * Math.PI * 2 * 7.31;
|
|
6119
|
+
const ring = init.spawn.radius * (0.35 + 0.65 * (k * 0.618034 % 1));
|
|
6120
|
+
crowd.spawn(init.spawn.x + Math.cos(angle) * ring, init.spawn.z + Math.sin(angle) * ring);
|
|
6121
|
+
}
|
|
6122
|
+
return crowd;
|
|
6123
|
+
}
|
|
6124
|
+
var hordeSimModule = Object.freeze({
|
|
6125
|
+
id: HORDE_SIM_ID,
|
|
6126
|
+
create(init) {
|
|
6127
|
+
const target = mirrorTarget(init.target.x, init.target.z);
|
|
6128
|
+
const crowd = createHordeCrowd(init, target);
|
|
6129
|
+
const layout = hordeSnapshotLayout(crowd.store);
|
|
6130
|
+
return {
|
|
6131
|
+
step(_frame, dt, commands) {
|
|
6132
|
+
for (const c of commands) {
|
|
6133
|
+
if (c[0] === HORDE_COMMAND.TARGET) {
|
|
6134
|
+
target.state.x = c[1];
|
|
6135
|
+
target.state.z = c[2];
|
|
6136
|
+
target.state.yaw = c[3];
|
|
6137
|
+
target.state.alive = c[4] !== 0;
|
|
6138
|
+
} else if (c[0] === HORDE_COMMAND.BLAST) crowd.blast({ point: [c[1], c[2], c[3]], radius: c[4], energy: c[5] });
|
|
6139
|
+
}
|
|
6140
|
+
crowd.update(dt);
|
|
6141
|
+
},
|
|
6142
|
+
write(out, frame) {
|
|
6143
|
+
writeHordeSnapshot(crowd.store, out, { frame, kills: crowd.stats.kills, hurt: target.damage.total }, layout);
|
|
6144
|
+
},
|
|
6145
|
+
dispose: () => crowd.dispose()
|
|
6146
|
+
};
|
|
6147
|
+
}
|
|
6148
|
+
});
|
|
6149
|
+
function hordeSnapshotBytes(capacity) {
|
|
6150
|
+
return hordeSnapshotLayout(createStore(capacity)).bytes;
|
|
6151
|
+
}
|
|
5870
6152
|
return __toCommonJS(index_exports);
|
|
5871
6153
|
})();
|
|
5872
6154
|
//# sourceMappingURL=index.global.js.map
|