@threenative/playtest 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/README.md +40 -2
- package/dist/capture.d.ts +23 -1
- package/dist/capture.js +92 -2
- package/dist/{diagnostics-BXhYI2sc.d.ts → diagnostics-BhS6v2n1.d.ts} +17 -748
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1693 -108
- package/dist/protocol.d.ts +43 -2
- package/dist/protocol.js +10 -1
- package/dist/runner/cli.d.ts +4 -2
- package/dist/runner/cli.js +11002 -8514
- package/dist/runner/index.d.ts +101 -83
- package/dist/runner/index.js +11928 -9916
- package/dist/schema-base-B5mr_Yr9.d.ts +844 -0
- package/dist/{shared-CHIDDJpp.d.ts → shared-DK12BZyS.d.ts} +171 -3
- package/dist/three/index.d.ts +9 -1
- package/dist/three/index.js +94 -27
- package/package.json +3 -2
|
@@ -1,5 +1,146 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IPlaytestObservationSnapshot } from './protocol.js';
|
|
1
|
+
import { e as IPlaytestScenario, j as IPlaytestPerformanceAssertion } from './schema-base-B5mr_Yr9.js';
|
|
2
|
+
import { IPlaytestSetupRequest, JsonValue, IPlaytestBridgeDescription, IPlaytestBridgeReady, IPlaytestSampleRequest, IPlaytestObservationSnapshot } from './protocol.js';
|
|
3
|
+
import { Page } from 'playwright';
|
|
4
|
+
import { p as IPlaytestSetupApplication, o as IPlaytestProtocolDiagnostic, I as IPlaytestReport, l as IPlaytestDiagnosticsPolicy, a as IPlaytestAssertionResult } from './diagnostics-BhS6v2n1.js';
|
|
5
|
+
|
|
6
|
+
/** The only seam between assertion orchestration and an application bridge. */
|
|
7
|
+
interface IBridgeTransport {
|
|
8
|
+
readonly capabilities: readonly string[];
|
|
9
|
+
call<T>(method: string, argument?: unknown, timeoutMs?: number, options?: unknown): Promise<T>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
waitForBridge(timeoutMs: number): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The budget for one `advance` call: the round-trip allowance plus time for the ticks themselves.
|
|
15
|
+
*
|
|
16
|
+
* Every other bridge method is a request and a reply, so `operationTimeoutMs` fits. `advance` runs
|
|
17
|
+
* the game loop N times before replying, so its honest bound grows with N. Fixed at 5 s it failed
|
|
18
|
+
* `starter-game-over` — 600 ticks in one call — on a two-core runner, and reported it as
|
|
19
|
+
* `TN_PLAYTEST_OPERATION_TIMEOUT`, which reads as a hung page rather than a slow one.
|
|
20
|
+
*/
|
|
21
|
+
declare function advanceTimeoutMs(ticks: number, perTickMs?: number): number;
|
|
22
|
+
declare class PlaytestBridgeError extends Error {
|
|
23
|
+
readonly diagnostic: IPlaytestProtocolDiagnostic;
|
|
24
|
+
constructor(diagnostic: IPlaytestProtocolDiagnostic);
|
|
25
|
+
}
|
|
26
|
+
interface IPlaytestBridgeClient {
|
|
27
|
+
/** `render: true` draws a world frame per tick; the default advances without drawing. Browser bridges only. */
|
|
28
|
+
advance(ticks: number, options?: {
|
|
29
|
+
render?: boolean;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
applySetup(request: IPlaytestSetupRequest): Promise<void>;
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
drainEvents(limit?: number): Promise<JsonValue[]>;
|
|
34
|
+
description: IPlaytestBridgeDescription;
|
|
35
|
+
/** Setup applied before the handshake released a held game, when the scenario declared setup. */
|
|
36
|
+
setupApplication?: IPlaytestSetupApplication;
|
|
37
|
+
/** Re-reads the bridge's readiness, including startup progress when it reports any. */
|
|
38
|
+
readiness(): Promise<IPlaytestBridgeReady>;
|
|
39
|
+
/** Draws the current world once without advancing it. Requires `runtime.renderOnly`. */
|
|
40
|
+
renderOnly(): Promise<void>;
|
|
41
|
+
sample(request: IPlaytestSampleRequest): Promise<IPlaytestObservationSnapshot>;
|
|
42
|
+
}
|
|
43
|
+
declare class PlaywrightTransport implements IBridgeTransport {
|
|
44
|
+
private readonly page;
|
|
45
|
+
private readonly operationTimeoutMs;
|
|
46
|
+
readonly capabilities: readonly ["browser.canvas", "browser.console", "browser.dom", "browser.input", "browser.network", "browser.screenshot", "browser.trace", "runtime.diagnostics", "runtime.ui"];
|
|
47
|
+
constructor(page: Page, operationTimeoutMs?: number);
|
|
48
|
+
call<T>(method: string, argument?: unknown, timeoutMs?: number, options?: unknown): Promise<T>;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
waitForBridge(timeoutMs: number): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
declare function connectPlaytestBridge(page: Page, scenario: IPlaytestScenario, timeoutMs?: number): Promise<IPlaytestBridgeClient | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* How long to wait for the page to install its playtest bridge — and for the handshake to answer.
|
|
55
|
+
*
|
|
56
|
+
* The bridge appears during application startup, not during a request/response round trip, so
|
|
57
|
+
* `operationTimeoutMs` is the wrong budget for it by construction — the same mistake, in the same
|
|
58
|
+
* direction, as timing a bulk `advance` with it. On a software-rendered two-core runner the
|
|
59
|
+
* scaffolded starter spends seconds in first-use compilation before the bridge exists, and the run
|
|
60
|
+
* was reported as `TN_PLAYTEST_BRIDGE_MISSING` with `frames: 0`: not a page without a bridge, a
|
|
61
|
+
* page that had not finished booting yet.
|
|
62
|
+
*
|
|
63
|
+
* One operation plus the startup budget, matching `advanceTimeoutMs`. A page that genuinely
|
|
64
|
+
* installs no bridge still fails with the same diagnostic, just later.
|
|
65
|
+
*/
|
|
66
|
+
declare function bridgeWaitTimeoutMs(operationMs?: number): number;
|
|
67
|
+
declare function connectPlaytestBridgeTransport(transport: IBridgeTransport, scenario: IPlaytestScenario, timeoutMs?: number, target?: string): Promise<IPlaytestBridgeClient | undefined>;
|
|
68
|
+
|
|
69
|
+
/** Capture the largest rendered canvas bounds without waiting for locator screenshot stability. */
|
|
70
|
+
declare function captureVisualSurface(page: Page, artifactPath?: string): Promise<Buffer | undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* The core bridge is installed before an async scene load completes, so its describe/ready
|
|
73
|
+
* handshake can finish one browser frame before the fixed-step loop starts. Retry only that
|
|
74
|
+
* exact startup race; a stopped loop that does not recover remains a runner failure.
|
|
75
|
+
*/
|
|
76
|
+
declare function advanceFixedStep(page: Page, bridge: Pick<IPlaytestBridgeClient, "advance">, ticks: number, render?: boolean): Promise<void>;
|
|
77
|
+
declare function playtestStepDrivesMovement(step: IPlaytestScenario["steps"][number], hasHeldInput: boolean): boolean;
|
|
78
|
+
interface ICompletionWindow {
|
|
79
|
+
label: string;
|
|
80
|
+
setupSnapshot?: IPlaytestObservationSnapshot;
|
|
81
|
+
provenance?: {
|
|
82
|
+
requestedDisplay: string;
|
|
83
|
+
qualified: false;
|
|
84
|
+
browserArgs?: readonly string[];
|
|
85
|
+
nativeVsync?: string;
|
|
86
|
+
};
|
|
87
|
+
metric: "application-completion-interval";
|
|
88
|
+
clock: "wall-clock";
|
|
89
|
+
source: string;
|
|
90
|
+
timebase: string;
|
|
91
|
+
epoch: number;
|
|
92
|
+
startTick: number;
|
|
93
|
+
startMs: number;
|
|
94
|
+
endMs: number;
|
|
95
|
+
durationMs: number;
|
|
96
|
+
intervalCount: number;
|
|
97
|
+
dropped: {
|
|
98
|
+
min: number;
|
|
99
|
+
max: number;
|
|
100
|
+
};
|
|
101
|
+
completionIntervalP50Ms: number;
|
|
102
|
+
samples: {
|
|
103
|
+
sequence: number;
|
|
104
|
+
completedAtMs: number;
|
|
105
|
+
}[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface ICpuWindow {
|
|
109
|
+
label: string;
|
|
110
|
+
frames: number;
|
|
111
|
+
/** Stack sampling perturbs these counters: diagnostic runs never qualify as benchmarks. */
|
|
112
|
+
profile?: {
|
|
113
|
+
kind: "perf-record";
|
|
114
|
+
path: string;
|
|
115
|
+
recorderScope: "native-process" | "main-thread";
|
|
116
|
+
};
|
|
117
|
+
startTick: number;
|
|
118
|
+
endTick: number;
|
|
119
|
+
startUs: number;
|
|
120
|
+
endUs: number;
|
|
121
|
+
updates: number;
|
|
122
|
+
renders: number;
|
|
123
|
+
mainThread: {
|
|
124
|
+
pid: number;
|
|
125
|
+
tid: number;
|
|
126
|
+
starttime: string;
|
|
127
|
+
cpuNs: number;
|
|
128
|
+
cpuMs: number;
|
|
129
|
+
cpuMsPerFrame: number;
|
|
130
|
+
instructions: number;
|
|
131
|
+
instructionsPerFrame: number;
|
|
132
|
+
cycles: number;
|
|
133
|
+
cyclesPerFrame: number;
|
|
134
|
+
};
|
|
135
|
+
processTree: {
|
|
136
|
+
cpuMs: number;
|
|
137
|
+
pids: number[];
|
|
138
|
+
};
|
|
139
|
+
host: {
|
|
140
|
+
load: number[];
|
|
141
|
+
governors: Record<string, string>;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
3
144
|
|
|
4
145
|
interface IPlaytestServerConfig {
|
|
5
146
|
command: string;
|
|
@@ -57,6 +198,16 @@ interface IStandalonePlaytestConfig {
|
|
|
57
198
|
transport: "device" | "simulator";
|
|
58
199
|
};
|
|
59
200
|
judgeMarkerUrl?: string;
|
|
201
|
+
/**
|
|
202
|
+
* Measure the game as it plays, instead of counting the scenario's own ticks.
|
|
203
|
+
*
|
|
204
|
+
* Injects `__THREENATIVE_PLAYTEST_CLOCK__ = "wall-clock"` ahead of every page script, so the
|
|
205
|
+
* host's frame pump moves the simulation and `advance` names the span its ticks cover — the
|
|
206
|
+
* browser half of what the native production profile's `--live-clock` already does there. It is
|
|
207
|
+
* a measurement opt-in and never a scenario semantics change: a deterministic scenario is still
|
|
208
|
+
* a count of ticks, and a run that takes this flag reports the clock it measured on.
|
|
209
|
+
*/
|
|
210
|
+
liveClock?: boolean;
|
|
60
211
|
mailboxRoot?: string;
|
|
61
212
|
/**
|
|
62
213
|
* The performance ceilings the build report declared, already proved against the artifact under
|
|
@@ -179,6 +330,11 @@ declare const PLAYTEST_FLAGS: {
|
|
|
179
330
|
readonly summary: "judge-owned loopback marker URL whose POST failures are not network errors";
|
|
180
331
|
readonly takesValue: true;
|
|
181
332
|
};
|
|
333
|
+
readonly "--live-clock": {
|
|
334
|
+
readonly default: "false";
|
|
335
|
+
readonly summary: "measure the game on its own frame clock (browser and desktop targets); a standing scene is unmeasurable on counted ticks";
|
|
336
|
+
readonly takesValue: false;
|
|
337
|
+
};
|
|
182
338
|
readonly "--host-arg": {
|
|
183
339
|
readonly allowDashValue: true;
|
|
184
340
|
readonly default: "none";
|
|
@@ -281,6 +437,18 @@ interface IRunStepSamples {
|
|
|
281
437
|
}
|
|
282
438
|
interface IStandalonePlaytestReport extends IPlaytestReport {
|
|
283
439
|
artifactDirectory: string;
|
|
440
|
+
acquisition?: {
|
|
441
|
+
requestUrls: readonly string[];
|
|
442
|
+
cpuWindows?: readonly ICpuWindow[];
|
|
443
|
+
completionWindow?: ICompletionWindow;
|
|
444
|
+
};
|
|
445
|
+
/**
|
|
446
|
+
* The clock this run measured on, as the protocol names it: `fixed-step` for the default
|
|
447
|
+
* tick-counted scenario, `wall-clock` when `--live-clock` put the host's own frame pump in
|
|
448
|
+
* charge. A frame rate is only the rate of the clock that produced it, so every report says
|
|
449
|
+
* which one this was — the same field the native production profile carries.
|
|
450
|
+
*/
|
|
451
|
+
clock: "fixed-step" | "wall-clock";
|
|
284
452
|
/**
|
|
285
453
|
* What the run waited for before it observed anything, and what it settled on.
|
|
286
454
|
*
|
|
@@ -318,4 +486,4 @@ declare class ManagedServerError extends Error {
|
|
|
318
486
|
}
|
|
319
487
|
declare function failedDiagnosticsAssertion(policy: IPlaytestDiagnosticsPolicy): IPlaytestAssertionResult;
|
|
320
488
|
|
|
321
|
-
export { type IStandalonePlaytestConfig as I, ManagedServerError as M, PLAYTEST_FLAGS as P, type IStandalonePlaytestReport as a, type IRunnerConsoleEntry as b, type ILabeledPlaytestSample as c, type IMovementSampleInterval as d, type
|
|
489
|
+
export { type IStandalonePlaytestConfig as I, ManagedServerError as M, PLAYTEST_FLAGS as P, type IStandalonePlaytestReport as a, type IRunnerConsoleEntry as b, type ILabeledPlaytestSample as c, type IMovementSampleInterval as d, type IPlaytestBridgeClient as e, type IBridgeTransport as f, type IPlaytestFlagHelp as g, type IPlaytestServerConfig as h, type IRunStepSamples as i, PlaytestBridgeError as j, PlaytestCliUsageError as k, PlaywrightTransport as l, advanceFixedStep as m, advanceTimeoutMs as n, bridgeWaitTimeoutMs as o, captureVisualSurface as p, connectPlaytestBridge as q, connectPlaytestBridgeTransport as r, failedDiagnosticsAssertion as s, formatUsage as t, parseStandalonePlaytestArgs as u, playtestStepDrivesMovement as v };
|
package/dist/three/index.d.ts
CHANGED
|
@@ -170,7 +170,15 @@ interface IThreePlaytestBridgeOptions {
|
|
|
170
170
|
*/
|
|
171
171
|
diagnostics?: () => JsonValue[];
|
|
172
172
|
entities?: readonly IThreePlaytestEntity[] | (() => readonly IThreePlaytestEntity[]);
|
|
173
|
-
fixedStep?: (ticks: number
|
|
173
|
+
fixedStep?: (ticks: number, options?: {
|
|
174
|
+
render?: boolean;
|
|
175
|
+
}) => Promise<number | void> | number | void;
|
|
176
|
+
/**
|
|
177
|
+
* Draw the current world once without advancing it, for a capture taken while the loop is driven
|
|
178
|
+
* and presents nothing between ticks. Optional: a bridge without it advertises no
|
|
179
|
+
* `runtime.renderOnly`, and a capture that needs a render-only frame is never sent one.
|
|
180
|
+
*/
|
|
181
|
+
renderCurrent?: () => Promise<number | void> | number | void;
|
|
174
182
|
gameplay?: () => IPlaytestGameplayObservation;
|
|
175
183
|
gameplayChannels?: () => readonly ("runtime.contacts" | "runtime.tags" | "runtime.transitions" | "runtime.world")[];
|
|
176
184
|
runtimeDiagnosticsSeries?: () => readonly IPlaytestRuntimeDiagnosticsSample[];
|
package/dist/three/index.js
CHANGED
|
@@ -416,6 +416,15 @@ var PLAYTEST_PROTOCOL_LIMITS = {
|
|
|
416
416
|
maxPayloadBytes: 1e6,
|
|
417
417
|
operationTimeoutMs: 5e3
|
|
418
418
|
};
|
|
419
|
+
var PLAYTEST_CLOCK_GLOBAL = "__THREENATIVE_PLAYTEST_CLOCK__";
|
|
420
|
+
function requestedPlaytestClockMode() {
|
|
421
|
+
const requested = globalThis[PLAYTEST_CLOCK_GLOBAL];
|
|
422
|
+
if (requested === void 0) return void 0;
|
|
423
|
+
if (requested === "wall-clock") return "wall-clock";
|
|
424
|
+
throw new Error(
|
|
425
|
+
`TN_PLAYTEST_CLOCK_UNSUPPORTED: '${PLAYTEST_CLOCK_GLOBAL}' is ${JSON.stringify(requested)}; this protocol knows 'wall-clock' and nothing else.`
|
|
426
|
+
);
|
|
427
|
+
}
|
|
419
428
|
function jsonByteLength(value) {
|
|
420
429
|
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
421
430
|
}
|
|
@@ -814,7 +823,21 @@ function observeSceneResources(scene, camera) {
|
|
|
814
823
|
}
|
|
815
824
|
|
|
816
825
|
// src/three/observations.ts
|
|
826
|
+
function isResourceOnlySample(request) {
|
|
827
|
+
return request.entities?.length === 0 && request.include?.length === 1 && request.include[0] === "resources" && request.resources !== void 0 && request.geometry === void 0 && request.sceneNodes === void 0;
|
|
828
|
+
}
|
|
829
|
+
function sampleClock(input) {
|
|
830
|
+
return {
|
|
831
|
+
mode: input.clockMode,
|
|
832
|
+
...input.tick === void 0 ? { timeMs: performance.now() } : { tick: input.tick },
|
|
833
|
+
// Live observations carry wall time even when the producer also supplies its tick.
|
|
834
|
+
...input.clockMode === "wall-clock" ? { timeMs: performance.now() } : {}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
817
837
|
function sampleThreeObservations(input, request) {
|
|
838
|
+
if (isResourceOnlySample(request)) {
|
|
839
|
+
return { clock: sampleClock(input), ...input.resources === void 0 ? {} : { resources: input.resources() } };
|
|
840
|
+
}
|
|
818
841
|
input.scene.updateMatrixWorld(true);
|
|
819
842
|
input.camera.updateMatrixWorld(true);
|
|
820
843
|
const rendererSize = input.renderer.getDrawingBufferSize(new Vector2());
|
|
@@ -822,14 +845,7 @@ function sampleThreeObservations(input, request) {
|
|
|
822
845
|
const renderPerformance = rendererPerformance(input.renderer);
|
|
823
846
|
const renderChain = input.renderChain?.();
|
|
824
847
|
return {
|
|
825
|
-
clock:
|
|
826
|
-
mode: input.clockMode,
|
|
827
|
-
...input.tick === void 0 ? { timeMs: performance.now() } : { tick: input.tick },
|
|
828
|
-
// A live run is measured in seconds: the runner reads `timeMs` for any mode that is not
|
|
829
|
-
// fixed-step, so a wall-clock producer that reported only a tick would leave every
|
|
830
|
-
// seconds-based rate unmeasured rather than measured.
|
|
831
|
-
...input.clockMode === "wall-clock" ? { timeMs: performance.now() } : {}
|
|
832
|
-
},
|
|
848
|
+
clock: sampleClock(input),
|
|
833
849
|
...input.diagnostics === void 0 ? {} : { diagnostics: input.diagnostics() },
|
|
834
850
|
entities,
|
|
835
851
|
...input.gameplay === void 0 ? {} : { gameplay: input.gameplay() },
|
|
@@ -879,18 +895,27 @@ function projectedBounds(object, camera, viewportWidth, viewportHeight) {
|
|
|
879
895
|
if (worldBounds.isEmpty()) return void 0;
|
|
880
896
|
const projection = new Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
881
897
|
if (!new Frustum().setFromProjectionMatrix(projection).intersectsBox(worldBounds)) return void 0;
|
|
882
|
-
const
|
|
883
|
-
const
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
898
|
+
const { near } = camera;
|
|
899
|
+
const inFront = (point) => point.z <= -near;
|
|
900
|
+
const viewCorner = (bits) => new Vector3(
|
|
901
|
+
bits & 4 ? worldBounds.max.x : worldBounds.min.x,
|
|
902
|
+
bits & 2 ? worldBounds.max.y : worldBounds.min.y,
|
|
903
|
+
bits & 1 ? worldBounds.max.z : worldBounds.min.z
|
|
904
|
+
).applyMatrix4(camera.matrixWorldInverse);
|
|
905
|
+
const clipped = [];
|
|
906
|
+
for (let bits = 0; bits < 8; bits += 1) {
|
|
907
|
+
const corner = viewCorner(bits);
|
|
908
|
+
if (inFront(corner)) clipped.push(corner);
|
|
909
|
+
for (const bit of [1, 2, 4]) {
|
|
910
|
+
if (bits & bit) continue;
|
|
911
|
+
const other = viewCorner(bits | bit);
|
|
912
|
+
if (inFront(corner) !== inFront(other)) {
|
|
913
|
+
clipped.push(corner.clone().lerp(other, (-near - corner.z) / (other.z - corner.z)));
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (clipped.length === 0) return void 0;
|
|
918
|
+
const points = clipped.map((point) => point.applyMatrix4(camera.projectionMatrix));
|
|
894
919
|
const minX = Math.min(...points.map(({ x }) => x));
|
|
895
920
|
const maxX = Math.max(...points.map(({ x }) => x));
|
|
896
921
|
const minY = Math.min(...points.map(({ y }) => y));
|
|
@@ -973,6 +998,7 @@ var BRIDGE_METHODS = /* @__PURE__ */ new Set([
|
|
|
973
998
|
"drainEvents",
|
|
974
999
|
"focus",
|
|
975
1000
|
"ready",
|
|
1001
|
+
"renderOnly",
|
|
976
1002
|
"sample"
|
|
977
1003
|
]);
|
|
978
1004
|
function connectDevicePlaytestBridge(bridge, endpoint) {
|
|
@@ -1024,6 +1050,15 @@ function connectNativeMailbox(bridge) {
|
|
|
1024
1050
|
const mailbox = globals.TN_PLAYTEST_MAILBOX;
|
|
1025
1051
|
const host = globals.__THREENATIVE_NATIVE__?.playtest;
|
|
1026
1052
|
if (typeof mailbox?.request !== "string" || typeof mailbox.response !== "string" || typeof host?.receive !== "function" || typeof host.respond !== "function") return void 0;
|
|
1053
|
+
if (typeof host.network === "function") {
|
|
1054
|
+
const describe = bridge.describe.bind(bridge);
|
|
1055
|
+
bridge.describe = async () => {
|
|
1056
|
+
const description = await describe();
|
|
1057
|
+
return { ...description, capabilities: [...description.capabilities, "runtime.network"] };
|
|
1058
|
+
};
|
|
1059
|
+
const sample = bridge.sample.bind(bridge);
|
|
1060
|
+
bridge.sample = async (request) => ({ ...await sample(request), network: host.network() });
|
|
1061
|
+
}
|
|
1027
1062
|
let closed = false;
|
|
1028
1063
|
let frame;
|
|
1029
1064
|
const nativePointers = /* @__PURE__ */ new Map();
|
|
@@ -1096,6 +1131,7 @@ async function dispatch(bridge, request, nativePointers) {
|
|
|
1096
1131
|
const operation = bridge[request.method];
|
|
1097
1132
|
if (typeof operation !== "function") throw new Error(`Bridge operation '${request.method}' is unavailable.`);
|
|
1098
1133
|
const result = await operation.call(bridge, request.argument);
|
|
1134
|
+
if (request.method === "advance") advanceHostClock(result);
|
|
1099
1135
|
if (result !== void 0) assertBounded(result);
|
|
1100
1136
|
return { id: request.id, ...result === void 0 ? {} : { result } };
|
|
1101
1137
|
} catch (error) {
|
|
@@ -1110,8 +1146,8 @@ function dispatchInput(method, argument, nativePointers) {
|
|
|
1110
1146
|
const code = argument.key;
|
|
1111
1147
|
const key = /^Key[A-Z]$/u.test(code) ? code.slice(3).toLowerCase() : code;
|
|
1112
1148
|
if (typeof host?.keyboard !== "function") throw new Error("Native playtest keyboard input is unavailable.");
|
|
1113
|
-
host.keyboard(method === "input.keyDown" ? "keydown" : "keyup", key, code);
|
|
1114
|
-
return null;
|
|
1149
|
+
const consumed = host.keyboard(method === "input.keyDown" ? "keydown" : "keyup", key, code);
|
|
1150
|
+
return consumed === true ? { consumedByUi: true } : null;
|
|
1115
1151
|
}
|
|
1116
1152
|
if (method === "input.pointer") {
|
|
1117
1153
|
if (typeof argument.x !== "number" || typeof argument.y !== "number" || typeof argument.buttons !== "number") {
|
|
@@ -1122,6 +1158,25 @@ function dispatchInput(method, argument, nativePointers) {
|
|
|
1122
1158
|
host.pointer(type, argument.x, argument.y, argument.buttons);
|
|
1123
1159
|
return null;
|
|
1124
1160
|
}
|
|
1161
|
+
if (method === "input.wheel") {
|
|
1162
|
+
const { x, y, deltaX, deltaY } = argument;
|
|
1163
|
+
if (![x, y, deltaX, deltaY].every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
1164
|
+
throw new Error("Device input.wheel requires finite x, y, deltaX and deltaY.");
|
|
1165
|
+
}
|
|
1166
|
+
if (typeof host?.wheel !== "function") throw new Error("Native playtest wheel input is unavailable.");
|
|
1167
|
+
host.wheel(x, y, deltaX, deltaY);
|
|
1168
|
+
return null;
|
|
1169
|
+
}
|
|
1170
|
+
if (method === "input.media") {
|
|
1171
|
+
const { dark, reducedMotion } = argument;
|
|
1172
|
+
if (![dark, reducedMotion].every((value) => value === -1 || value === 0 || value === 1)) {
|
|
1173
|
+
throw new Error("Device input.media requires dark and reducedMotion as -1, 0 or 1.");
|
|
1174
|
+
}
|
|
1175
|
+
if (typeof host?.media !== "function" || !host.media(dark, reducedMotion)) {
|
|
1176
|
+
throw new Error("Native playtest media emulation is unavailable: the host has no native-css UI attached to take it.");
|
|
1177
|
+
}
|
|
1178
|
+
return null;
|
|
1179
|
+
}
|
|
1125
1180
|
if (method === "input.pointers") {
|
|
1126
1181
|
if (typeof host?.pointer !== "function") {
|
|
1127
1182
|
throw new Error("Native playtest multi-pointer input is unavailable.");
|
|
@@ -1172,6 +1227,11 @@ function dispatchInput(method, argument, nativePointers) {
|
|
|
1172
1227
|
}
|
|
1173
1228
|
throw new Error(`Device input operation '${method}' is unavailable.`);
|
|
1174
1229
|
}
|
|
1230
|
+
function advanceHostClock(result) {
|
|
1231
|
+
const ticks = isRecord(result) ? result.ticks : void 0;
|
|
1232
|
+
if (typeof ticks !== "number" || !Number.isInteger(ticks) || ticks <= 0) return;
|
|
1233
|
+
globalThis.__THREENATIVE_NATIVE__?.playtestInput?.advanceClock?.(ticks);
|
|
1234
|
+
}
|
|
1175
1235
|
function parseNativePointers(value) {
|
|
1176
1236
|
if (!Array.isArray(value)) throw new Error("Device input.pointers requires a pointer array.");
|
|
1177
1237
|
const pointers = value.map((pointer, index) => {
|
|
@@ -1223,7 +1283,7 @@ function installThreePlaytestBridge(options) {
|
|
|
1223
1283
|
if (options.physics !== void 0 && options.tick === void 0)
|
|
1224
1284
|
throw new Error("A physics provider requires the authoritative tick provider, and therefore fixedStep.");
|
|
1225
1285
|
const recorder = options.physics === void 0 ? void 0 : new ThreePlaytestPhysicsRecorder(options.physics);
|
|
1226
|
-
const clockMode = () => options.clockMode ?? (options.fixedStep === void 0 ? "render-frame" : "fixed-step");
|
|
1286
|
+
const clockMode = () => options.clockMode ?? requestedPlaytestClockMode() ?? (options.fixedStep === void 0 ? "render-frame" : "fixed-step");
|
|
1227
1287
|
const host = globalThis;
|
|
1228
1288
|
const previous = host[PLAYTEST_BRIDGE_GLOBAL];
|
|
1229
1289
|
const registry = new ThreePlaytestEntityRegistry();
|
|
@@ -1244,6 +1304,7 @@ function installThreePlaytestBridge(options) {
|
|
|
1244
1304
|
...options.physics === void 0 ? [] : ["runtime.physics"],
|
|
1245
1305
|
...options.runtimeDiagnosticsSeries === void 0 ? [] : ["runtime.performance"],
|
|
1246
1306
|
...options.renderChain === void 0 ? [] : ["runtime.renderChain"],
|
|
1307
|
+
...options.renderCurrent === void 0 ? [] : ["runtime.renderOnly"],
|
|
1247
1308
|
...options.startup === void 0 ? [] : ["runtime.startup"],
|
|
1248
1309
|
...options.gameplayChannels?.().includes("runtime.contacts") === true ? ["runtime.contacts"] : [],
|
|
1249
1310
|
...options.gameplayChannels?.().includes("runtime.tags") === true ? ["runtime.tags"] : [],
|
|
@@ -1252,10 +1313,10 @@ function installThreePlaytestBridge(options) {
|
|
|
1252
1313
|
];
|
|
1253
1314
|
const bridge = {
|
|
1254
1315
|
...options.fixedStep === void 0 ? {} : {
|
|
1255
|
-
advance: async (ticks) => {
|
|
1316
|
+
advance: async (ticks, advanceOptions) => {
|
|
1256
1317
|
if (!Number.isInteger(ticks) || ticks <= 0) throw new Error("advance ticks must be a positive integer.");
|
|
1257
1318
|
const startTick = options.tick();
|
|
1258
|
-
await options.fixedStep(ticks);
|
|
1319
|
+
await options.fixedStep(ticks, advanceOptions);
|
|
1259
1320
|
const tick = options.tick();
|
|
1260
1321
|
const advanced = tick - startTick;
|
|
1261
1322
|
if (clockMode() === "wall-clock" ? advanced < 1 : advanced !== ticks)
|
|
@@ -1275,6 +1336,11 @@ function installThreePlaytestBridge(options) {
|
|
|
1275
1336
|
return events.slice(0, Math.min(limit, PLAYTEST_PROTOCOL_LIMITS.maxEventsPerDrain));
|
|
1276
1337
|
}
|
|
1277
1338
|
},
|
|
1339
|
+
...options.renderCurrent === void 0 ? {} : {
|
|
1340
|
+
renderOnly: async () => {
|
|
1341
|
+
await options.renderCurrent();
|
|
1342
|
+
}
|
|
1343
|
+
},
|
|
1278
1344
|
describe: () => ({
|
|
1279
1345
|
capabilities: capabilities(),
|
|
1280
1346
|
limits: PLAYTEST_PROTOCOL_LIMITS,
|
|
@@ -1288,7 +1354,8 @@ function installThreePlaytestBridge(options) {
|
|
|
1288
1354
|
return { ready: true, startup };
|
|
1289
1355
|
},
|
|
1290
1356
|
sample: (request) => {
|
|
1291
|
-
|
|
1357
|
+
const resourceOnly = isResourceOnlySample(request);
|
|
1358
|
+
if (!resourceOnly) syncEntities(registry, options.entities);
|
|
1292
1359
|
const snapshot = sampleThreeObservations({
|
|
1293
1360
|
camera: options.camera,
|
|
1294
1361
|
clockMode: clockMode(),
|
|
@@ -1302,7 +1369,7 @@ function installThreePlaytestBridge(options) {
|
|
|
1302
1369
|
scene: options.scene,
|
|
1303
1370
|
tick: options.tick?.()
|
|
1304
1371
|
}, request);
|
|
1305
|
-
const components = options.components?.();
|
|
1372
|
+
const components = resourceOnly ? void 0 : options.components?.();
|
|
1306
1373
|
const withComponents = components === void 0 || Object.keys(components).length === 0 ? snapshot : { ...snapshot, components };
|
|
1307
1374
|
const result = recorder === void 0 || request.include?.includes("physicsDebugSeries") !== true ? withComponents : { ...withComponents, physicsDebugSeries: recorder.sample(request, options.tick()) };
|
|
1308
1375
|
assertJsonSafe(result);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threenative/playtest",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Scenario-driven playtest harness for Three.js games. Runs on plain Three.js with zero ThreeNative dependencies.",
|
|
6
6
|
"keywords": [
|
|
@@ -81,7 +81,8 @@
|
|
|
81
81
|
"publint": "0.3.22",
|
|
82
82
|
"three": "0.185.1",
|
|
83
83
|
"tsup": "8.5.1",
|
|
84
|
-
"typescript": "
|
|
84
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
85
|
+
"@typescript/native": "npm:typescript@7.0.2"
|
|
85
86
|
},
|
|
86
87
|
"scripts": {
|
|
87
88
|
"build": "pnpm --workspace-root exec tsx scripts/generate-assertion-validators.ts --check && tsup --config tsup.config.ts && publint",
|