@threenative/core 0.3.4 → 0.3.6
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/capabilities.json +1505 -79
- package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
- package/dist/{canvas-layer-DDmC_VVF.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
- package/dist/{game-CljaDv4D.d.ts → game-Jz4Fdoeb.d.ts} +114 -11
- package/dist/hot.d.ts +4 -4
- package/dist/index.d.ts +712 -118
- package/dist/index.js +12437 -4955
- package/dist/{gpu-readback-CqJEfWNQ.d.ts → model-lod-BDAUYgsS.d.ts} +80 -5
- package/dist/playtest.d.ts +6 -10
- package/dist/playtest.js +57 -24
- package/dist/react-css.d.ts +62 -0
- package/dist/react-css.js +591 -0
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-CfsS2hxi.d.ts → renderer-9yEo9hPa.d.ts} +489 -22
- package/dist/terrain-jobs-worker.d.ts +2 -0
- package/dist/terrain-jobs-worker.js +130 -0
- package/dist/ui-layer.js +59 -8
- package/dist/world.d.ts +766 -73
- package/dist/world.js +9307 -3543
- package/gpl/recipes/export_world.py +18 -1
- package/mcp/blender-server.mjs +7 -4
- package/mcp/blender.mjs +3 -4
- package/mcp/engine-server.mjs +2 -2
- package/mcp/servers.mjs +4 -4
- package/package.json +15 -9
- package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
- package/patches/three@0.185.1.patch +6594 -700
- package/scripts/apply-three-patch.mjs +62 -4
- package/src/animation-blend.ts +264 -0
- package/src/animation-composition.ts +362 -0
- package/src/animation-layers.ts +260 -0
- package/src/animation-root-motion.ts +283 -0
- package/src/animation.ts +896 -0
- package/src/assets.ts +1303 -0
- package/src/atmosphere/index.ts +335 -0
- package/src/atmosphere/luts.ts +298 -0
- package/src/atmosphere/params.ts +323 -0
- package/src/audio.ts +912 -0
- package/src/billboard.ts +124 -0
- package/src/bone-lengths.ts +157 -0
- package/src/camera-shake.ts +116 -0
- package/src/canvas-layer.ts +47 -0
- package/src/clip-audit.ts +401 -0
- package/src/clustered-batch.ts +492 -0
- package/src/clustered-mesh.ts +638 -0
- package/src/compute-driven.ts +176 -0
- package/src/compute-timing.ts +318 -0
- package/src/config.ts +593 -0
- package/src/debug.ts +82 -0
- package/src/engine-render-hook.ts +25 -0
- package/src/entities.ts +79 -0
- package/src/entity-snapshot.ts +53 -0
- package/src/flight.ts +683 -0
- package/src/fluid-field.ts +748 -0
- package/src/fluid-particles.ts +1253 -0
- package/src/frame-budget.ts +1368 -0
- package/src/game.ts +2408 -0
- package/src/geometry-capture.ts +1098 -0
- package/src/gpu-class.ts +160 -0
- package/src/gpu-frame-observation.ts +424 -0
- package/src/gpu-readback.ts +143 -0
- package/src/gpu-scene-bvh.ts +464 -0
- package/src/grounding.ts +100 -0
- package/src/hot.ts +161 -0
- package/src/import-meta.d.ts +13 -0
- package/src/index.ts +1536 -0
- package/src/input.ts +690 -0
- package/src/instanced-batch-lod.ts +283 -0
- package/src/instanced-batch.ts +274 -0
- package/src/interpolation.ts +129 -0
- package/src/launch-diagnostics.ts +161 -0
- package/src/loop.ts +574 -0
- package/src/matrix-world.ts +245 -0
- package/src/merge-parts.ts +812 -0
- package/src/model-lod.ts +1315 -0
- package/src/net-protocol.ts +333 -0
- package/src/net-session.ts +477 -0
- package/src/net.ts +80 -0
- package/src/ocean/fft.ts +72 -0
- package/src/ocean/spectral.ts +728 -0
- package/src/particle-significance.ts +102 -0
- package/src/particles.ts +648 -0
- package/src/path-follow.ts +175 -0
- package/src/picking.ts +250 -0
- package/src/pipeline-census.ts +1566 -0
- package/src/platform.ts +210 -0
- package/src/playtest.ts +850 -0
- package/src/pointer-events.ts +411 -0
- package/src/pose-measure.ts +435 -0
- package/src/profiling/FrameCounters.ts +231 -0
- package/src/profiling/Spans.ts +548 -0
- package/src/profiling/opacity-convention.ts +21 -0
- package/src/profiling/render-list-validate.ts +175 -0
- package/src/profiling/render-trap-audit.ts +84 -0
- package/src/profiling/scene-warning.ts +190 -0
- package/src/profiling/span-probes.ts +191 -0
- package/src/profiling/unlit-foliage-warning.ts +149 -0
- package/src/projection-apply.ts +1529 -0
- package/src/projection-marker.ts +142 -0
- package/src/projection-plan.ts +1258 -0
- package/src/projection-skinned.ts +419 -0
- package/src/projection-stability.ts +409 -0
- package/src/projection-uniform.ts +328 -0
- package/src/random.ts +41 -0
- package/src/react-css.ts +604 -0
- package/src/react-glyphs.ts +114 -0
- package/src/react-host.ts +576 -0
- package/src/react-layout.ts +265 -0
- package/src/react.ts +60 -0
- package/src/render/alpha-antialiasing.ts +159 -0
- package/src/render/batched-velocity.ts +126 -0
- package/src/render/chain.ts +1021 -0
- package/src/render/daylight.ts +189 -0
- package/src/render/depth-pyramid.ts +596 -0
- package/src/render/foliage-alpha.ts +166 -0
- package/src/render/material-key.ts +60 -0
- package/src/render/mesh-pool.ts +144 -0
- package/src/render/probe-volume.ts +1668 -0
- package/src/render/resolution-subrect.ts +253 -0
- package/src/render/velocity.ts +442 -0
- package/src/render/virtual-shadow-pages.ts +827 -0
- package/src/render/virtual-shadow-partial.ts +174 -0
- package/src/render/virtual-shadow.ts +3330 -0
- package/src/render/world-impostor-surface.ts +722 -0
- package/src/render/world-impostor.ts +558 -0
- package/src/render-camera-cull.ts +441 -0
- package/src/render-pass-budget.ts +501 -0
- package/src/renderProjection.ts +758 -0
- package/src/renderer-config.ts +127 -0
- package/src/renderer.ts +1847 -0
- package/src/replay-protocol.ts +85 -0
- package/src/replay.ts +205 -0
- package/src/resolution-scaler.ts +819 -0
- package/src/rig-preparation.ts +271 -0
- package/src/ripple-field.ts +432 -0
- package/src/scale.ts +109 -0
- package/src/scene.ts +239 -0
- package/src/schedule.ts +155 -0
- package/src/skeletal-mesh.ts +61 -0
- package/src/skeleton.ts +100 -0
- package/src/snow-field.ts +744 -0
- package/src/softbody-topology.ts +269 -0
- package/src/softbody.ts +516 -0
- package/src/sprite-animator.ts +222 -0
- package/src/startup-readiness.ts +386 -0
- package/src/state.ts +66 -0
- package/src/static-transform.ts +274 -0
- package/src/storage-buffer.ts +253 -0
- package/src/streaming.ts +308 -0
- package/src/target-fps.ts +92 -0
- package/src/terrain-jobs-worker.ts +17 -0
- package/src/terrain-jobs.ts +353 -0
- package/src/textures.ts +39 -0
- package/src/tracers.ts +237 -0
- package/src/ui-bridge.ts +368 -0
- package/src/ui-hit-regions.ts +380 -0
- package/src/ui-layer.ts +83 -0
- package/src/ui-state.ts +220 -0
- package/src/version.ts +2 -0
- package/src/viewport.ts +253 -0
- package/src/warmup.ts +1357 -0
- package/src/water-surface.ts +384 -0
- package/src/wave-field.ts +524 -0
- package/src/world-capabilities.ts +131 -0
- package/src/world-cell-proxy.ts +392 -0
- package/src/world-cells.ts +10564 -0
- package/src/world-gpu-scene.ts +3354 -0
- package/src/world-heightmap.ts +82 -0
- package/src/world-package.ts +469 -0
- package/src/world-passes.ts +582 -0
- package/src/world-region.ts +17 -0
- package/src/world-terrain-splat.ts +564 -0
- package/src/world-tiles.ts +3826 -0
- package/src/world-topology.ts +370 -0
- package/src/world-validate.ts +48 -0
- package/src/world.ts +805 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// The neutral replay wire protocol, owned by core. Moved verbatim out of the playtest
|
|
2
|
+
// harness (PRD-181): harnesses depend on engines, never the reverse, and a parser duplicated
|
|
3
|
+
// on both sides could skew between them. Error codes are pinned by specs in both packages -
|
|
4
|
+
// do not reword.
|
|
5
|
+
export type ReplayPointer = readonly [number, number, number, number, number];
|
|
6
|
+
|
|
7
|
+
export interface IReplayRecordingSample {
|
|
8
|
+
readonly keys: readonly string[];
|
|
9
|
+
readonly pointer?: ReplayPointer;
|
|
10
|
+
readonly tick: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IReplayRecording {
|
|
14
|
+
readonly input: readonly IReplayRecordingSample[];
|
|
15
|
+
readonly randomState: number;
|
|
16
|
+
readonly runtime: {
|
|
17
|
+
agent: string;
|
|
18
|
+
core: string;
|
|
19
|
+
portable?: boolean;
|
|
20
|
+
rapier: string | null;
|
|
21
|
+
step: number;
|
|
22
|
+
};
|
|
23
|
+
readonly seed: number;
|
|
24
|
+
readonly ticks: number;
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function fail(message: string, code = "TN_REPLAY_INVALID"): never {
|
|
29
|
+
throw new Error(`${code}: ${message}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function checked(value: unknown, allowed: readonly string[]): Record<string, unknown> {
|
|
33
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) fail("bad object");
|
|
34
|
+
const result = value as Record<string, unknown>;
|
|
35
|
+
const unknown = Object.keys(result).find((key) => !allowed.includes(key));
|
|
36
|
+
if (unknown !== undefined) fail(`unknown key '${unknown}'`);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function validatePointer(value: unknown): void {
|
|
41
|
+
const pointer = Array.isArray(value) ? value : [];
|
|
42
|
+
if (
|
|
43
|
+
pointer.length !== 5 ||
|
|
44
|
+
!pointer.every(Number.isFinite) ||
|
|
45
|
+
!Number.isInteger(pointer[2]) ||
|
|
46
|
+
pointer[2] < 0 ||
|
|
47
|
+
Math.min(pointer[3], pointer[4]) <= 0
|
|
48
|
+
)
|
|
49
|
+
fail("pointer tuple is invalid");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function parseReplayRecording(value: unknown): IReplayRecording {
|
|
53
|
+
const root = checked(value, ["input", "randomState", "runtime", "seed", "ticks", "version"]);
|
|
54
|
+
if (root.version !== 1 || !Number.isFinite(root.seed) || !Number.isInteger(root.randomState))
|
|
55
|
+
fail("bad header");
|
|
56
|
+
const ticks = root.ticks as number;
|
|
57
|
+
if (!Number.isInteger(ticks) || ticks < 1) fail("ticks must be positive");
|
|
58
|
+
const input = root.input;
|
|
59
|
+
if (!Array.isArray(input) || input.length === 0) fail("empty input", "TN_REPLAY_EMPTY");
|
|
60
|
+
const runtime = checked(root.runtime, ["agent", "core", "portable", "rapier", "step"]);
|
|
61
|
+
const step = runtime.step as number;
|
|
62
|
+
if (
|
|
63
|
+
typeof runtime.agent !== "string" ||
|
|
64
|
+
!runtime.agent ||
|
|
65
|
+
typeof runtime.core !== "string" ||
|
|
66
|
+
!runtime.core ||
|
|
67
|
+
(runtime.portable !== undefined && typeof runtime.portable !== "boolean") ||
|
|
68
|
+
(runtime.rapier !== null && typeof runtime.rapier !== "string") ||
|
|
69
|
+
!Number.isFinite(step) ||
|
|
70
|
+
step <= 0
|
|
71
|
+
)
|
|
72
|
+
fail("runtime fingerprint is invalid");
|
|
73
|
+
let previousTick = -1;
|
|
74
|
+
for (const rawSample of input) {
|
|
75
|
+
const sample = checked(rawSample, ["keys", "pointer", "tick"]);
|
|
76
|
+
const tick = sample.tick as number;
|
|
77
|
+
if (!Number.isInteger(tick) || tick <= previousTick || tick >= ticks) fail("bad tick");
|
|
78
|
+
const keys = sample.keys;
|
|
79
|
+
if (!Array.isArray(keys) || keys.some((key) => typeof key !== "string")) fail("bad keys");
|
|
80
|
+
if (new Set(keys).size !== keys.length) fail("duplicate keys");
|
|
81
|
+
if (sample.pointer !== undefined) validatePointer(sample.pointer);
|
|
82
|
+
previousTick = tick;
|
|
83
|
+
}
|
|
84
|
+
return root as unknown as IReplayRecording;
|
|
85
|
+
}
|
package/src/replay.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { IGamePluginHooks, IGamePluginRuntime } from "./game.js";
|
|
2
|
+
import { type IReplayRecording, parseReplayRecording } from "./replay-protocol.js";
|
|
3
|
+
import { CORE_VERSION } from "./version.js";
|
|
4
|
+
const currentAgent = typeof navigator === "undefined" ? "node" : navigator.userAgent;
|
|
5
|
+
type Pointer = readonly [number, number, number, number, number];
|
|
6
|
+
type Point = readonly [number, number, number];
|
|
7
|
+
type ReplayContext = { renderer?: { domElement: HTMLCanvasElement } };
|
|
8
|
+
type Random = NonNullable<IGamePluginRuntime["random"]>;
|
|
9
|
+
let replayDepth = 0;
|
|
10
|
+
export type Recording = IReplayRecording;
|
|
11
|
+
export interface IReplayOptions {
|
|
12
|
+
/** Allow a recording to be replayed by a different host with the same simulation contract. */
|
|
13
|
+
readonly portable?: boolean;
|
|
14
|
+
}
|
|
15
|
+
function fail(message: string, code = "TN_REPLAY_INVALID"): never {
|
|
16
|
+
throw new Error(`${code}: ${message}`);
|
|
17
|
+
}
|
|
18
|
+
const event = (type: string, init: object): Event => Object.assign(new Event(type), init);
|
|
19
|
+
const pointerEvent = (type: string, [clientX, clientY, buttons]: Point) =>
|
|
20
|
+
event(type, { buttons, clientX, clientY, pointerId: 0 });
|
|
21
|
+
function pointerViewport(ctx: ReplayContext, point: Point = [0, 0, 0]): Pointer {
|
|
22
|
+
// Read every tick on purpose: a canvas can move or resize with no observable signal, and a
|
|
23
|
+
// stale offset would silently corrupt recorded pointer coordinates. Only the comparisons
|
|
24
|
+
// below are optimised — tuple fields, not joined strings.
|
|
25
|
+
const canvas = ctx.renderer?.domElement;
|
|
26
|
+
const rect = canvas?.getBoundingClientRect?.();
|
|
27
|
+
return [
|
|
28
|
+
point[0] - (rect?.left ?? 0),
|
|
29
|
+
point[1] - (rect?.top ?? 0),
|
|
30
|
+
point[2],
|
|
31
|
+
canvas?.clientWidth || globalThis.innerWidth || 1,
|
|
32
|
+
canvas?.clientHeight || globalThis.innerHeight || 1,
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function samePointer(previous: Pointer, next: Pointer): boolean {
|
|
37
|
+
return (
|
|
38
|
+
previous[0] === next[0] &&
|
|
39
|
+
previous[1] === next[1] &&
|
|
40
|
+
previous[2] === next[2] &&
|
|
41
|
+
previous[3] === next[3] &&
|
|
42
|
+
previous[4] === next[4]
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function sameKeys(previous: string[], next: string[]): boolean {
|
|
47
|
+
if (previous.length !== next.length) return false;
|
|
48
|
+
for (let index = 0; index < previous.length; index += 1)
|
|
49
|
+
if (previous[index] !== next[index]) return false;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const pointerType = (previous: number, next: number) =>
|
|
53
|
+
previous && !next ? "pointerup" : !previous && next ? "pointerdown" : "pointermove";
|
|
54
|
+
function targetPointerPosition(pointer: Pointer, target: EventTarget): Point {
|
|
55
|
+
const viewport = target as unknown as HTMLCanvasElement & Window;
|
|
56
|
+
const rect = viewport.getBoundingClientRect?.();
|
|
57
|
+
const width = viewport.clientWidth || viewport.innerWidth || rect?.width || pointer[3];
|
|
58
|
+
const height = viewport.clientHeight || viewport.innerHeight || rect?.height || pointer[4];
|
|
59
|
+
return [
|
|
60
|
+
(pointer[0] * width) / pointer[3] + (rect?.left ?? 0),
|
|
61
|
+
(pointer[1] * height) / pointer[4] + (rect?.top ?? 0),
|
|
62
|
+
pointer[2],
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
function dispatchKeys(target: EventTarget, current: Set<string>, keys: readonly string[]): void {
|
|
66
|
+
for (const key of current)
|
|
67
|
+
if (!keys.includes(key)) target.dispatchEvent(event("keyup", { code: key }));
|
|
68
|
+
for (const key of keys)
|
|
69
|
+
if (!current.has(key)) target.dispatchEvent(event("keydown", { code: key }));
|
|
70
|
+
current.clear();
|
|
71
|
+
for (const key of keys) current.add(key);
|
|
72
|
+
}
|
|
73
|
+
function releasePointer(pointer: Pointer, target: EventTarget): void {
|
|
74
|
+
if (pointer[2] === 0) return;
|
|
75
|
+
const released = [pointer[0], pointer[1], 0, pointer[3], pointer[4]] as Pointer;
|
|
76
|
+
target.dispatchEvent(pointerEvent("pointerup", targetPointerPosition(released, target)));
|
|
77
|
+
}
|
|
78
|
+
function dispatchPointer(previous: Pointer, next: Pointer, target: EventTarget): Pointer {
|
|
79
|
+
if (previous.join() === next.join()) return previous;
|
|
80
|
+
target.dispatchEvent(
|
|
81
|
+
pointerEvent(pointerType(previous[2], next[2]), targetPointerPosition(next, target)),
|
|
82
|
+
);
|
|
83
|
+
return next;
|
|
84
|
+
}
|
|
85
|
+
type ReplayPublic = { readonly recording: Recording | undefined; readonly runId: symbol };
|
|
86
|
+
export function replay<
|
|
87
|
+
TState extends Record<string, unknown> = Record<string, unknown>,
|
|
88
|
+
TPhysics = undefined,
|
|
89
|
+
>(options: IReplayOptions = {}): IGamePluginHooks<TState, TPhysics> & ReplayPublic {
|
|
90
|
+
const runId = Symbol("replay");
|
|
91
|
+
const portable = options.portable === true;
|
|
92
|
+
const samples: Array<Recording["input"][number]> = [];
|
|
93
|
+
let header: Omit<Recording, "input" | "ticks"> | undefined;
|
|
94
|
+
let ticks = 0;
|
|
95
|
+
let previousKeys: string[] = [];
|
|
96
|
+
let previousPointer: Pointer = [0, 0, 0, 1, 1];
|
|
97
|
+
return {
|
|
98
|
+
get recording() {
|
|
99
|
+
if (header === undefined) return undefined;
|
|
100
|
+
return {
|
|
101
|
+
...header,
|
|
102
|
+
input: [...samples],
|
|
103
|
+
ticks,
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
runId,
|
|
107
|
+
setup: (ctx, runtime) => {
|
|
108
|
+
if (runtime?.seed === null || runtime?.seed === undefined)
|
|
109
|
+
fail("replay requires a seed", "TN_REPLAY_UNSEEDED");
|
|
110
|
+
const { rapier, seed, step } = runtime;
|
|
111
|
+
header = {
|
|
112
|
+
randomState: ctx.random.state,
|
|
113
|
+
runtime: {
|
|
114
|
+
agent: currentAgent,
|
|
115
|
+
core: CORE_VERSION,
|
|
116
|
+
...(portable ? { portable: true } : {}),
|
|
117
|
+
rapier: rapier ?? null,
|
|
118
|
+
step,
|
|
119
|
+
},
|
|
120
|
+
seed,
|
|
121
|
+
version: 1,
|
|
122
|
+
};
|
|
123
|
+
samples.length = ticks = 0;
|
|
124
|
+
[previousKeys, previousPointer] = [[], pointerViewport(ctx)];
|
|
125
|
+
return undefined;
|
|
126
|
+
},
|
|
127
|
+
beforeUpdate: (ctx) => {
|
|
128
|
+
if (replayDepth > 0) return;
|
|
129
|
+
const keys = [...ctx.input.raw.keys].sort();
|
|
130
|
+
const { position, buttons } = ctx.input.raw.pointer;
|
|
131
|
+
const pointer = pointerViewport(ctx, [position.x, position.y, buttons]);
|
|
132
|
+
const pointerChanged = !samePointer(previousPointer, pointer);
|
|
133
|
+
if (pointerChanged || !sameKeys(previousKeys, keys)) {
|
|
134
|
+
samples.push({ keys, ...(pointerChanged ? { pointer } : {}), tick: ticks });
|
|
135
|
+
[previousKeys, previousPointer] = [keys, pointer];
|
|
136
|
+
}
|
|
137
|
+
ticks += 1;
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function validateRuntime(runtime: IGamePluginRuntime, recording: Recording): Random {
|
|
142
|
+
const random = runtime.random;
|
|
143
|
+
if (
|
|
144
|
+
runtime.seed !== recording.seed ||
|
|
145
|
+
runtime.step !== recording.runtime.step ||
|
|
146
|
+
(runtime.rapier ?? null) !== (recording.runtime.rapier ?? null) ||
|
|
147
|
+
recording.runtime.core !== CORE_VERSION ||
|
|
148
|
+
(recording.runtime.portable !== true && recording.runtime.agent !== currentAgent) ||
|
|
149
|
+
random === undefined
|
|
150
|
+
)
|
|
151
|
+
fail("recording runtime does not match the current build", "TN_REPLAY_RUNTIME_MISMATCH");
|
|
152
|
+
return random;
|
|
153
|
+
}
|
|
154
|
+
function restoreRandomState(random: Random, state: number): Random {
|
|
155
|
+
try {
|
|
156
|
+
random.state = state;
|
|
157
|
+
if (random.state !== state) throw new Error();
|
|
158
|
+
} catch {
|
|
159
|
+
fail("runtime random state cannot be restored", "TN_REPLAY_RUNTIME_MISMATCH");
|
|
160
|
+
}
|
|
161
|
+
return random;
|
|
162
|
+
}
|
|
163
|
+
export function createReplayDriver(
|
|
164
|
+
recording: Recording,
|
|
165
|
+
target: EventTarget,
|
|
166
|
+
pointerTarget = target,
|
|
167
|
+
) {
|
|
168
|
+
const value = parseReplayRecording(recording);
|
|
169
|
+
const samples = new Map(value.input.map((sample) => [sample.tick, sample]));
|
|
170
|
+
let preparedRandom: Pick<Random, "state"> | undefined;
|
|
171
|
+
const driver = Object.assign(
|
|
172
|
+
(runtime: IGamePluginRuntime) => {
|
|
173
|
+
const random = validateRuntime(runtime, value);
|
|
174
|
+
if (preparedRandom !== random) restoreRandomState(random, value.randomState);
|
|
175
|
+
preparedRandom = undefined;
|
|
176
|
+
target.dispatchEvent(new Event("blur"));
|
|
177
|
+
const keys = new Set<string>();
|
|
178
|
+
let pointer: Pointer = [0, 0, 0, 1, 1];
|
|
179
|
+
replayDepth += 1;
|
|
180
|
+
try {
|
|
181
|
+
for (let tick = 0; tick < value.ticks; tick += 1) {
|
|
182
|
+
const sample = samples.get(tick);
|
|
183
|
+
if (sample !== undefined) {
|
|
184
|
+
dispatchKeys(target, keys, sample.keys);
|
|
185
|
+
if (sample.pointer !== undefined)
|
|
186
|
+
pointer = dispatchPointer(pointer, sample.pointer, pointerTarget);
|
|
187
|
+
}
|
|
188
|
+
runtime.fixedStep(1);
|
|
189
|
+
}
|
|
190
|
+
dispatchKeys(target, keys, []);
|
|
191
|
+
releasePointer(pointer, pointerTarget);
|
|
192
|
+
return value.ticks;
|
|
193
|
+
} finally {
|
|
194
|
+
replayDepth -= 1;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
prepare: (runtime: IGamePluginRuntime) => {
|
|
199
|
+
preparedRandom = restoreRandomState(validateRuntime(runtime, value), value.randomState);
|
|
200
|
+
},
|
|
201
|
+
runId: Symbol("replay-driver"),
|
|
202
|
+
},
|
|
203
|
+
);
|
|
204
|
+
return driver;
|
|
205
|
+
}
|