@threenative/playtest 0.3.6 → 0.3.9

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.
@@ -218,6 +218,7 @@ interface IPlaytestPathAssertion {
218
218
  atSteps?: Array<{
219
219
  equals?: unknown;
220
220
  label: string;
221
+ lte?: number;
221
222
  textIncludes?: string;
222
223
  }>;
223
224
  changed?: boolean;
@@ -316,6 +317,75 @@ interface IPlaytestSceneAssertion {
316
317
  /** Floor on how many lights the renderer will actually see. */
317
318
  minVisibleLights?: number;
318
319
  }
320
+ /**
321
+ * Bounds how far a planted foot slides, measured from the feet's world positions every tick of one
322
+ * step. A clip reports its own stride; a procedural rig reports nothing, so this measures what the
323
+ * screen shows instead of what the game says. Browser target only; elsewhere it fails unobserved.
324
+ */
325
+ interface IPlaytestFootSlipAssertion {
326
+ atStep: string;
327
+ entity?: string;
328
+ feet: string[];
329
+ /** Ceiling on planted-foot travel over body travel. At least one of this and `maxSlideSpeed` is required. */
330
+ maxSlip?: number;
331
+ /** Ceiling on a planted foot's world speed in m/s, whatever the body's speed is. */
332
+ maxSlideSpeed?: number;
333
+ /** Seconds per fixed tick, for `maxSlideSpeed`; the engine's own default step is 1/60. */
334
+ stepSeconds?: number;
335
+ }
336
+ /**
337
+ * Bounds the share of the run in which geometry stood between the camera and the subject.
338
+ *
339
+ * The camera is the thing a player looks through, so a cast that clips a pillar or a wall that
340
+ * eats the framing is a frame-destroying failure that leaves every count healthy. Browser target
341
+ * only; elsewhere it fails unobserved.
342
+ */
343
+ interface IPlaytestSightLineAssertion {
344
+ /** The entity whose world bounds centre the camera should see; defaults to the subject. */
345
+ entity?: string;
346
+ /** Ceiling on the share of samples, 0..1, with any solid between the lens and the subject. */
347
+ maxBlockedRatio: number;
348
+ }
349
+ /**
350
+ * Audits the text the page draws: developer left-overs and unreadable colours reach the player.
351
+ *
352
+ * A placeholder or a `NaN` in the HUD is a shipped defect no screenshot gate catches, and text
353
+ * the same colour as its backing plate is unreadable while every node count stays healthy.
354
+ * Browser target only; elsewhere it fails unobserved.
355
+ */
356
+ /**
357
+ * Bounds on the engine's own work counters (PRD-748): per-frame means and single-frame maxima over each
358
+ * `TN_FRAME_BUDGET` window (`counters.engine`, plus `counters.bridgeCrossings`), read off the console.
359
+ * Fails closed when no window arrives or a bounded counter is missing from one.
360
+ */
361
+ interface IPlaytestEngineCostAssertion {
362
+ /** Counter name to its bound on the window's per-frame mean. */
363
+ maxPerFrame?: Readonly<Record<string, number>>;
364
+ /** Counter name to its bound on any single frame in the window. */
365
+ maxInFrame?: Readonly<Record<string, number>>;
366
+ /** Windows the run must report (default 1). */
367
+ minWindows?: number;
368
+ /** Windows left unbounded before every other bound applies: the boot (loading, first builds). Default 0. */
369
+ skipWindows?: number;
370
+ /** Bounds on the first `windows` windows only, which the scenario keeps still (no input). */
371
+ still?: {
372
+ readonly windows: number;
373
+ readonly maxPerFrame: Readonly<Record<string, number>>;
374
+ };
375
+ /** Bounds on the windows after the still ones, which the scenario fills with play. Needs `still`. */
376
+ moving?: {
377
+ readonly maxPerFrame?: Readonly<Record<string, number>>;
378
+ readonly maxInFrame?: Readonly<Record<string, number>>;
379
+ };
380
+ /** Where the bounds came from: the measured after-values and their headroom. */
381
+ source: string;
382
+ }
383
+ interface IPlaytestHudAuditAssertion {
384
+ /** WCAG 2.x contrast ratio, 1..21, every judged text item must reach. */
385
+ minContrast?: number;
386
+ /** Require that no text reads like developer copy. Only `true` is accepted. */
387
+ noDebugText?: true;
388
+ }
319
389
  /**
320
390
  * Bounds on named nodes of the scene graph — the questions a screenshot gets taken for.
321
391
  *
@@ -406,6 +476,8 @@ interface IPlaytestEffectSpec {
406
476
  interface IPlaytestAnimationAssertion {
407
477
  advancedFrames?: number;
408
478
  allowTrivial?: string;
479
+ /** Judge the animation report sampled after this labeled step, not the last one: one scenario then checks several clips. */
480
+ atStep?: string;
409
481
  clip?: string;
410
482
  entered?: boolean;
411
483
  entity?: string;
@@ -450,6 +522,8 @@ interface IPlaytestDiagnosticsAssertion {
450
522
  interface IPlaytestPerformanceAssertion {
451
523
  maxDrawCalls?: number;
452
524
  maxFrameMsP95?: number;
525
+ /** Required when `maxFrameMsP95` is above 16.7 ms: why this scenario cannot hold 60 fps. The report prints it. */
526
+ maxFrameMsReason?: string;
453
527
  maxTriangles?: number;
454
528
  /** Frame-budget floor: the median presented frame must sustain at least this many frames a second. */
455
529
  minFps?: number;
@@ -509,6 +583,16 @@ interface IPlaytestStartupAssertion {
509
583
  maxCompileSettledMs?: number;
510
584
  /** `whenReady()` resolved: the world is safe to show. */
511
585
  maxReadyMs?: number;
586
+ /**
587
+ * Ceiling on the bytes the reveal waited for that the spawn camera does not show, from the
588
+ * runtime's own measurement. `0` asserts that everything awaited is in view.
589
+ */
590
+ maxOffscreenBytes?: number;
591
+ /**
592
+ * Every frame the page presented between navigation and readiness looks like the last one
593
+ * before readiness (the loading cover): no black, blank or page-background frame in between.
594
+ */
595
+ steadyCover?: true;
512
596
  }
513
597
  /** Ceilings on work observed after the runtime's explicit shader warm-up settled. */
514
598
  interface IPlaytestPipelineCensusAssertion {
@@ -547,6 +631,8 @@ interface IPlaytestVisualRegionThresholds {
547
631
  minNonblankPixelRatio?: number;
548
632
  }
549
633
  interface IPlaytestVisualStaticRegion extends IPlaytestVisualRegionBounds, IPlaytestVisualRegionThresholds {
634
+ /** Floor on `regionSharpness` (Laplacian variance at full over half resolution); a smeared frame drops it. */
635
+ minSharpness?: number;
550
636
  }
551
637
  interface IPlaytestVisualElementRegion extends IPlaytestVisualRegionThresholds {
552
638
  element: IPlaytestVisualRegionTarget;
@@ -681,6 +767,10 @@ interface IPlaytestScenarioAssertions {
681
767
  scene?: IPlaytestSceneAssertion;
682
768
  causedBy?: IPlaytestCausedByAssertion[];
683
769
  sceneNodes?: IPlaytestSceneNodesAssertion[];
770
+ footSlip?: IPlaytestFootSlipAssertion[];
771
+ sightLine?: IPlaytestSightLineAssertion;
772
+ hudAudit?: IPlaytestHudAuditAssertion;
773
+ engineCost?: IPlaytestEngineCostAssertion;
684
774
  startup?: IPlaytestStartupAssertion;
685
775
  states?: IPlaytestStateAssertion[];
686
776
  tags?: IPlaytestTagCountAssertion[];
@@ -797,6 +887,14 @@ interface IPlaytestScenarioSetup {
797
887
  resources?: IPlaytestSetupResource[];
798
888
  spawn?: IPlaytestSpawnRequest;
799
889
  }
890
+ /**
891
+ * A browser-only network profile applied before the page loads, so a scenario can prove what a
892
+ * real link costs. Throughput is in kilobits per second, one direction, as a user reads a plan.
893
+ */
894
+ interface IPlaytestNetworkProfile {
895
+ readonly downloadKbps: number;
896
+ readonly latencyMs: number;
897
+ }
800
898
  interface IPlaytestScenario {
801
899
  acceptanceId?: string;
802
900
  artifacts?: IPlaytestArtifactRequest;
@@ -812,7 +910,15 @@ interface IPlaytestScenario {
812
910
  awaitStartup?: boolean;
813
911
  inputDelivery?: PlaytestInputDelivery;
814
912
  name: string;
913
+ /** Browser-only: throttle the page before navigation. See {@link IPlaytestNetworkProfile}. */
914
+ network?: IPlaytestNetworkProfile;
815
915
  parity?: IPlaytestParityConfig;
916
+ /**
917
+ * Browser-only: run this scenario on the wall clock, as `--live-clock` does for a whole run. A
918
+ * performance scenario needs it, because counted ticks advance faster than frames draw and a window
919
+ * then holds a few GPU samples. Tick counts keep their meaning; the other scenarios of one glob run stay counted.
920
+ */
921
+ clock?: "wall-clock";
816
922
  /**
817
923
  * Browser-only: open the page with `prefers-reduced-motion: reduce` emulated, so a game that
818
924
  * honours the preference can prove it. Applied before navigation, so the first read sees it.
@@ -1,70 +1,7 @@
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';
1
+ import { e as IPlaytestScenario, j as IPlaytestPerformanceAssertion } from './schema-base-B26KSBoa.js';
2
+ import { IPlaytestObservationSnapshot } from './protocol.js';
3
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>;
4
+ import { I as IPlaytestReport, p as IPlaytestProtocolDiagnostic, l as IPlaytestDiagnosticsPolicy, a as IPlaytestAssertionResult } from './diagnostics-BKg7C6Lf.js';
68
5
 
69
6
  /** Capture the largest rendered canvas bounds without waiting for locator screenshot stability. */
70
7
  declare function captureVisualSurface(page: Page, artifactPath?: string): Promise<Buffer | undefined>;
@@ -73,7 +10,11 @@ declare function captureVisualSurface(page: Page, artifactPath?: string): Promis
73
10
  * handshake can finish one browser frame before the fixed-step loop starts. Retry only that
74
11
  * exact startup race; a stopped loop that does not recover remains a runner failure.
75
12
  */
76
- declare function advanceFixedStep(page: Page, bridge: Pick<IPlaytestBridgeClient, "advance">, ticks: number, render?: boolean): Promise<void>;
13
+ declare function advanceFixedStep(page: Page, bridge: {
14
+ advance(ticks: number, options?: {
15
+ render?: boolean;
16
+ }): Promise<number | undefined | void>;
17
+ }, ticks: number, render?: boolean): Promise<void>;
77
18
  declare function playtestStepDrivesMovement(step: IPlaytestScenario["steps"][number], hasHeldInput: boolean): boolean;
78
19
  interface ICompletionWindow {
79
20
  label: string;
@@ -204,7 +145,8 @@ interface IStandalonePlaytestConfig {
204
145
  * Injects `__THREENATIVE_PLAYTEST_CLOCK__ = "wall-clock"` ahead of every page script, so the
205
146
  * host's frame pump moves the simulation and `advance` names the span its ticks cover — the
206
147
  * 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
148
+ * also selected automatically for browser frame-time/FPS assertions unless explicitly false.
149
+ * It never changes the authored tick unit: a deterministic scenario is still
208
150
  * a count of ticks, and a run that takes this flag reports the clock it measured on.
209
151
  */
210
152
  liveClock?: boolean;
@@ -412,6 +354,12 @@ declare const PLAYTEST_FLAGS: {
412
354
  declare class PlaytestCliUsageError extends Error {
413
355
  constructor(message: string);
414
356
  }
357
+ /** A scenario that asks for `clock: "wall-clock"` runs as `--live-clock` does, whatever the other scenarios of the glob do. */
358
+ declare function withScenarioClock<T extends {
359
+ liveClock?: boolean;
360
+ }>(config: T, scenario: {
361
+ clock?: "wall-clock";
362
+ }): T;
415
363
  declare function formatUsage(): string;
416
364
  declare function parseStandalonePlaytestArgs(argv: readonly string[], cwd?: string): IStandalonePlaytestConfig;
417
365
 
@@ -449,6 +397,11 @@ interface IStandalonePlaytestReport extends IPlaytestReport {
449
397
  * which one this was — the same field the native production profile carries.
450
398
  */
451
399
  clock: "fixed-step" | "wall-clock";
400
+ /**
401
+ * `worker` when the page drew its game from a worker and the run relaunched with that thread's
402
+ * measurement flags (`measurementBrowserArgs`); absent for a page-thread game.
403
+ */
404
+ gameThread?: "worker";
452
405
  /**
453
406
  * What the run waited for before it observed anything, and what it settled on.
454
407
  *
@@ -486,4 +439,4 @@ declare class ManagedServerError extends Error {
486
439
  }
487
440
  declare function failedDiagnosticsAssertion(policy: IPlaytestDiagnosticsPolicy): IPlaytestAssertionResult;
488
441
 
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 };
442
+ 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 IPlaytestFlagHelp as e, type IPlaytestServerConfig as f, type IRunStepSamples as g, PlaytestCliUsageError as h, advanceFixedStep as i, captureVisualSurface as j, failedDiagnosticsAssertion as k, formatUsage as l, playtestStepDrivesMovement as m, parseStandalonePlaytestArgs as p, withScenarioClock as w };
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { Box3, Vector3, Vector2, Matrix4, Frustum } from 'three';
2
+ import { Box3, Vector3, Vector2, DoubleSide, Raycaster, Matrix4, Frustum } from 'three';
3
3
 
4
4
  // src/three/renderWorkloadAdvisor.ts
5
5
  var DEFAULT_TOP_N = 10;
@@ -821,10 +821,105 @@ function observeSceneResources(scene, camera) {
821
821
  }
822
822
  };
823
823
  }
824
+ var MAX_BLOCKERS = 5;
825
+ var EPSILON_M = 0.05;
826
+ var SLIVER_M = 0.15;
827
+ var SLIVER_SECTION_M = 0.3;
828
+ var SAME_SURFACE_M = 1e-4;
829
+ function visibleThroughAncestors(object) {
830
+ for (let current = object; current !== null; current = current.parent) {
831
+ if (!current.visible) return false;
832
+ }
833
+ return true;
834
+ }
835
+ function within(object, root) {
836
+ for (let current = object; current !== null; current = current.parent) {
837
+ if (current === root) return true;
838
+ }
839
+ return false;
840
+ }
841
+ function fadesAway(material) {
842
+ const materials = Array.isArray(material) ? material : [material];
843
+ return materials.some(
844
+ (entry) => entry.alphaTest > 0 || entry.transparent && (entry.opacity < 0.5 || !entry.depthWrite)
845
+ );
846
+ }
847
+ function thinInTwoAxes(object) {
848
+ const geometry = object.geometry;
849
+ if (geometry === void 0) return false;
850
+ if (geometry.boundingBox === null) geometry.computeBoundingBox();
851
+ const bounds = geometry.boundingBox;
852
+ if (bounds === null) return false;
853
+ const size = bounds.getSize(new Vector3()).multiply(object.getWorldScale(new Vector3()));
854
+ const [, middle = 0] = [Math.abs(size.x), Math.abs(size.y), Math.abs(size.z)].sort((a, b) => a - b);
855
+ return middle < SLIVER_SECTION_M;
856
+ }
857
+ function standingInTheWay(hits, distance) {
858
+ const surfaces = [];
859
+ for (const hit of hits) {
860
+ const last = surfaces[surfaces.length - 1];
861
+ if (last !== void 0 && last.object === hit.object && hit.distance - last.distance < SAME_SURFACE_M) continue;
862
+ surfaces.push(hit);
863
+ }
864
+ const walls = [];
865
+ for (let index = 0; index < surfaces.length; index += 1) {
866
+ const entry = surfaces[index];
867
+ if (entry === void 0 || !(entry.distance < distance - EPSILON_M)) break;
868
+ const exit = surfaces[index + 1];
869
+ if (exit !== void 0 && exit.object === entry.object && exit.distance - entry.distance < SLIVER_M && thinInTwoAxes(entry.object)) {
870
+ index += 1;
871
+ continue;
872
+ }
873
+ walls.push(entry);
874
+ }
875
+ return walls;
876
+ }
877
+ function observeSightLine(scene, camera, subject) {
878
+ const target = new Box3().setFromObject(subject).getCenter(new Vector3());
879
+ const origin = camera.getWorldPosition(new Vector3());
880
+ const direction = target.clone().sub(origin);
881
+ const distance = direction.length();
882
+ const candidates = [];
883
+ scene.traverse((object) => {
884
+ const mesh = object;
885
+ if (mesh.isMesh !== true || !visibleThroughAncestors(mesh) || within(mesh, subject) || within(mesh, camera)) return;
886
+ if (fadesAway(mesh.material)) return;
887
+ candidates.push(mesh);
888
+ });
889
+ if (!(distance > 0) || candidates.length === 0) return { blocked: false, blockers: [], distance };
890
+ const sides = /* @__PURE__ */ new Map();
891
+ for (const mesh of candidates) {
892
+ for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) {
893
+ if (sides.has(material)) continue;
894
+ sides.set(material, material.side);
895
+ material.side = DoubleSide;
896
+ }
897
+ }
898
+ let hits;
899
+ try {
900
+ const raycaster = new Raycaster();
901
+ raycaster.layers.enableAll();
902
+ raycaster.far = distance;
903
+ raycaster.set(origin, direction.normalize());
904
+ hits = raycaster.intersectObjects(candidates, false);
905
+ } finally {
906
+ sides.forEach((side, material) => {
907
+ material.side = side;
908
+ });
909
+ }
910
+ const blockers = [];
911
+ for (const hit of standingInTheWay(hits, distance)) {
912
+ const name = hit.object.name || hit.object.type;
913
+ if (blockers.includes(name)) continue;
914
+ blockers.push(name);
915
+ if (blockers.length === MAX_BLOCKERS) break;
916
+ }
917
+ return { blocked: blockers.length > 0, blockers, distance };
918
+ }
824
919
 
825
920
  // src/three/observations.ts
826
921
  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;
922
+ 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 && request.sightLine === void 0;
828
923
  }
829
924
  function sampleClock(input) {
830
925
  return {
@@ -860,7 +955,8 @@ function sampleThreeObservations(input, request) {
860
955
  // Only walked when a scenario asks. The node walk reads geometry, materials and world
861
956
  // bounds per object, which is real work on a large scene, and no run should pay for it
862
957
  // when nothing is going to read it.
863
- ...request.sceneNodes === void 0 || request.sceneNodes.length === 0 ? {} : { sceneNodes: observeSceneNodes(input.scene, input.camera, request.sceneNodes) }
958
+ ...request.sceneNodes === void 0 || request.sceneNodes.length === 0 ? {} : { sceneNodes: observeSceneNodes(input.scene, input.camera, request.sceneNodes) },
959
+ ...input.sightLineSubject === void 0 ? {} : { sightLine: observeSightLine(input.scene, input.camera, input.sightLineSubject) }
864
960
  };
865
961
  }
866
962
  function rendererPerformance(renderer) {
@@ -1353,29 +1449,36 @@ function installThreePlaytestBridge(options) {
1353
1449
  assertJsonSafe(startup);
1354
1450
  return { ready: true, startup };
1355
1451
  },
1356
- sample: (request) => {
1357
- const resourceOnly = isResourceOnlySample(request);
1358
- if (!resourceOnly) syncEntities(registry, options.entities);
1359
- const snapshot = sampleThreeObservations({
1360
- camera: options.camera,
1361
- clockMode: clockMode(),
1362
- diagnostics: options.diagnostics,
1363
- gameplay: options.gameplay,
1364
- runtimeDiagnosticsSeries: options.runtimeDiagnosticsSeries,
1365
- renderChain: options.renderChain,
1366
- registry,
1367
- renderer: options.renderer,
1368
- resources: options.resources === void 0 ? void 0 : () => options.resources.read(),
1369
- scene: options.scene,
1370
- tick: options.tick?.()
1371
- }, request);
1372
- const components = resourceOnly ? void 0 : options.components?.();
1373
- const withComponents = components === void 0 || Object.keys(components).length === 0 ? snapshot : { ...snapshot, components };
1374
- const result = recorder === void 0 || request.include?.includes("physicsDebugSeries") !== true ? withComponents : { ...withComponents, physicsDebugSeries: recorder.sample(request, options.tick()) };
1375
- assertJsonSafe(result);
1376
- return result;
1377
- }
1452
+ // The observer's scene walk is not the game's: three-native's bridge census
1453
+ // (TN_BRIDGE_WARNING) leaves reads made under this mark out.
1454
+ sample: (request) => observing(() => sampleNow(request))
1378
1455
  };
1456
+ function sampleNow(request) {
1457
+ const resourceOnly = isResourceOnlySample(request);
1458
+ if (!resourceOnly) syncEntities(registry, options.entities);
1459
+ const sightLineSubject = resourceOnly || request.sightLine === void 0 ? void 0 : registry.get(request.sightLine.entity)?.object;
1460
+ if (request.sightLine !== void 0 && !resourceOnly && sightLineSubject === void 0)
1461
+ throw new Error(`Sight-line entity '${request.sightLine.entity}' is not registered.`);
1462
+ const snapshot = sampleThreeObservations({
1463
+ camera: options.camera,
1464
+ clockMode: clockMode(),
1465
+ diagnostics: options.diagnostics,
1466
+ gameplay: options.gameplay,
1467
+ runtimeDiagnosticsSeries: options.runtimeDiagnosticsSeries,
1468
+ renderChain: options.renderChain,
1469
+ registry,
1470
+ renderer: options.renderer,
1471
+ resources: options.resources === void 0 ? void 0 : () => options.resources.read(),
1472
+ scene: options.scene,
1473
+ ...sightLineSubject === void 0 ? {} : { sightLineSubject },
1474
+ tick: options.tick?.()
1475
+ }, request);
1476
+ const components = resourceOnly ? void 0 : options.components?.();
1477
+ const withComponents = components === void 0 || Object.keys(components).length === 0 ? snapshot : { ...snapshot, components };
1478
+ const result = recorder === void 0 || request.include?.includes("physicsDebugSeries") !== true ? withComponents : { ...withComponents, physicsDebugSeries: recorder.sample(request, options.tick()) };
1479
+ assertJsonSafe(result);
1480
+ return result;
1481
+ }
1379
1482
  host[PLAYTEST_BRIDGE_GLOBAL] = bridge;
1380
1483
  const endpoint = readPlaytestEndpoint();
1381
1484
  let device;
@@ -1417,5 +1520,15 @@ function applySetup(registry, resources, request) {
1417
1520
  });
1418
1521
  return { entities, resources: resourceIds };
1419
1522
  }
1523
+ var OBSERVING_GLOBAL = "__tnPlaytestObserving";
1524
+ function observing(work) {
1525
+ const host = globalThis;
1526
+ host[OBSERVING_GLOBAL] = (host[OBSERVING_GLOBAL] ?? 0) + 1;
1527
+ try {
1528
+ return work();
1529
+ } finally {
1530
+ host[OBSERVING_GLOBAL] = host[OBSERVING_GLOBAL] - 1;
1531
+ }
1532
+ }
1420
1533
 
1421
1534
  export { PLAYTEST_PHYSICS_BODY_LIMIT, PLAYTEST_PHYSICS_SAMPLE_LIMIT, SCENE_LIGHT_CAP, SCENE_WALK_OBJECT_CAP, ThreePlaytestPhysicsRecorder, adviseThreeRenderWorkload, connectDevicePlaytestBridge, installThreePlaytestBridge, observeSceneResources, readPlaytestEndpoint };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threenative/playtest",
3
- "version": "0.3.6",
3
+ "version": "0.3.9",
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": [