@threenative/core 0.3.11 → 0.3.13
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 +1 -1
- package/capabilities.json +1988 -204
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/chunk-4SRAQFTU.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DIPIJICH.js +8916 -0
- package/dist/chunk-EEABDLUC.js +2237 -0
- package/dist/chunk-EFWZWLPY.js +1895 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-GYUZJQ7U.js +280 -0
- package/dist/chunk-H4J6IAJE.js +504 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-SV4QVUTQ.js +31 -0
- package/dist/chunk-U4YHUKKL.js +615 -0
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/chunk-XDTZ4QMO.js +160 -0
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -52
- package/dist/index.d.ts +633 -1351
- package/dist/index.js +12873 -23068
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +25 -75
- package/dist/quality-BYqKGAwo.d.ts +868 -0
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +3 -2
- package/dist/render-environment.d.ts +170 -0
- package/dist/render-environment.js +352 -0
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
- package/dist/spells/index.d.ts +643 -0
- package/dist/spells/index.js +1558 -0
- package/dist/spells/ultra/index.d.ts +1600 -0
- package/dist/spells/ultra/index.js +6804 -0
- package/dist/terrain-jobs-worker.js +1 -123
- package/dist/two-sided-foliage-W523J3UM.js +1 -0
- package/dist/ui-layer.js +6 -384
- package/dist/worker.js +13 -43
- package/dist/world.d.ts +988 -268
- package/dist/world.js +17464 -18290
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +245 -52
- package/mcp/servers.mjs +10 -3
- package/mcp/terrain.mjs +8 -0
- package/package.json +19 -7
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/animation-batch.ts +193 -0
- package/src/animation-layers.ts +7 -3
- package/src/animation.ts +209 -29
- package/src/asset-cache.ts +3 -3
- package/src/asset-memo.ts +202 -0
- package/src/assets.ts +437 -125
- package/src/auto-batch.ts +190 -44
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +103 -22
- package/src/dev-global.ts +54 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +50 -23
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +86 -0
- package/src/game-frame-loop.ts +958 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1076 -0
- package/src/game-ui.ts +84 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +198 -2264
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +13 -0
- package/src/geometry-capture.ts +28 -4
- package/src/gpu-readings.ts +98 -0
- package/src/gpu-scene-bvh.ts +149 -36
- package/src/hot.ts +4 -7
- package/src/index.ts +141 -9
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +25 -0
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/local-exposure.ts +2 -7
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +14 -5
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +113 -103
- package/src/loop.ts +29 -0
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +139 -17
- package/src/particle-kinds.ts +515 -0
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/picking.ts +17 -3
- package/src/platform.ts +23 -4
- package/src/playtest.ts +27 -1
- package/src/profiling/FrameStages.ts +5 -6
- package/src/profiling/Spans.ts +3 -17
- package/src/profiling/debug-telemetry.ts +2 -6
- package/src/profiling/render-list-validate.ts +6 -15
- package/src/projection-apply.ts +4 -1
- package/src/projection-marker.ts +2 -1
- package/src/projection-plan.ts +9 -6
- package/src/quiet-markers.ts +3 -10
- package/src/render/cpu-bvh.ts +100 -0
- package/src/render/depth-pyramid.ts +6 -14
- package/src/render/environment/environmentContribution.ts +202 -0
- package/src/render/environment/environmentRadiance.ts +44 -0
- package/src/render/environment/environmentSampleCache.ts +56 -0
- package/src/render/environment/environmentSampling.ts +201 -0
- package/src/render/environment/environmentSnapshot.ts +71 -0
- package/src/render/environment/gate.ts +57 -0
- package/src/render/mesh-pool.ts +4 -20
- package/src/render/probe-trace.ts +872 -0
- package/src/render/probe-volume.ts +780 -34
- package/src/render/radiance-cache.ts +17 -0
- package/src/render/resolution-subrect.ts +2 -0
- package/src/render/rough-diffuse.ts +46 -12
- package/src/render/soft-shadow.ts +27 -12
- package/src/render/virtual-shadow-adaptive.ts +55 -0
- package/src/render/virtual-shadow-casters.ts +175 -0
- package/src/render/virtual-shadow-layers.ts +76 -0
- package/src/render/virtual-shadow-level.ts +224 -0
- package/src/render/virtual-shadow-markers.ts +193 -0
- package/src/render/virtual-shadow-options.ts +370 -0
- package/src/render/virtual-shadow-pages.ts +5 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +231 -1008
- package/src/render/world-impostor-surface.ts +402 -40
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +98 -3
- package/src/render-environment.ts +41 -0
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +144 -65
- package/src/resolution-scaler.ts +3 -2
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +2 -1
- package/src/spells/cast-pool.ts +361 -0
- package/src/spells/index.ts +177 -0
- package/src/spells/mechanisms.ts +295 -0
- package/src/spells/reaction-field.ts +415 -0
- package/src/spells/spell-lights.ts +139 -0
- package/src/spells/spell-world.ts +187 -0
- package/src/spells/spell.ts +397 -0
- package/src/spells/spells.ts +283 -0
- package/src/spells/ultra/engine/camera.ts +184 -0
- package/src/spells/ultra/engine/quality.ts +96 -0
- package/src/spells/ultra/index.ts +52 -0
- package/src/spells/ultra/main.ts +305 -0
- package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
- package/src/spells/ultra/spells/cast.ts +233 -0
- package/src/spells/ultra/spells/fire.ts +1267 -0
- package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
- package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
- package/src/spells/ultra/vfx/FxTarget.ts +61 -0
- package/src/spells/ultra/vfx/GroundField.ts +1399 -0
- package/src/spells/ultra/vfx/Particles.ts +1475 -0
- package/src/spells/ultra/vfx/Ribbons.ts +645 -0
- package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
- package/src/spells/ultra/vfx/Volumes.ts +489 -0
- package/src/spells/ultra/vfx/common.ts +1195 -0
- package/src/spells/ultra/vfx/noise.ts +441 -0
- package/src/startup-offscreen-bytes.ts +78 -0
- package/src/startup-readiness.ts +128 -34
- package/src/static-transform.ts +25 -19
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +446 -0
- package/src/world-cell-batches.ts +1178 -0
- package/src/world-cell-chunks.ts +1128 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1461 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +177 -0
- package/src/world-cell-placements.ts +798 -0
- package/src/world-cell-prewarm.ts +592 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +710 -0
- package/src/world-cell-render-main-cull.ts +540 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +259 -0
- package/src/world-cell-render.ts +1501 -0
- package/src/world-cell-residency.ts +754 -0
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +1335 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +131 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +524 -0
- package/src/world-gpu-scene.ts +256 -2286
- package/src/world-gpu-shadow.ts +203 -0
- package/src/world-gpu-types.ts +409 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +111 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-noise.ts +241 -0
- package/src/world-package.ts +42 -0
- package/src/world-region.ts +1 -1
- package/src/world-river-ribbon.ts +282 -0
- package/src/world-root-frame.ts +39 -0
- package/src/world-shore-field.ts +91 -0
- package/src/world-static-pose.ts +163 -0
- package/src/world-surface-sampler.ts +48 -0
- package/src/world-terrain-splat.ts +361 -153
- package/src/world-tile-budget.ts +249 -0
- package/src/world-tile-geometry.ts +469 -0
- package/src/world-tile-lod.ts +408 -0
- package/src/world-tile-observation.ts +566 -0
- package/src/world-tile-stitch.ts +166 -0
- package/src/world-tiles.ts +247 -1755
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +48 -741
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { vec3, materialEmissive, normalView, positionViewDirection, float, uniform } from 'three/tsl';
|
|
2
|
+
|
|
3
|
+
// src/render/two-sided-foliage.ts
|
|
4
|
+
function addFoliageBackLight(material, backIrradiance) {
|
|
5
|
+
const colour = material.subsurfaceColor;
|
|
6
|
+
if (material.twoSidedFoliage !== true || colour === void 0) return false;
|
|
7
|
+
const back = vec3(colour.r, colour.g, colour.b).mul(backIrradiance);
|
|
8
|
+
const target = material;
|
|
9
|
+
target.emissiveNode = (target.emissiveNode ?? materialEmissive).add(back);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
function foliageTransmission(lightDirection, lightColor, subsurface) {
|
|
13
|
+
const wrap = normalView.dot(lightDirection).negate().add(0.5).div(2.25).clamp();
|
|
14
|
+
const cosine = positionViewDirection.dot(lightDirection).negate().clamp();
|
|
15
|
+
const denominator = float(1).sub(cosine.mul(cosine).mul(0.64));
|
|
16
|
+
const scatter = float(0.36 / Math.PI).div(denominator.mul(denominator));
|
|
17
|
+
return lightColor.mul(wrap.mul(scatter)).mul(subsurface);
|
|
18
|
+
}
|
|
19
|
+
var PATCHED = /* @__PURE__ */ Symbol.for("threenative.foliageTransmission");
|
|
20
|
+
function installFoliageTransmission(classes) {
|
|
21
|
+
let patched = 0;
|
|
22
|
+
for (const name of ["MeshStandardNodeMaterial", "MeshPhysicalNodeMaterial"]) {
|
|
23
|
+
const prototype = classes[name]?.prototype;
|
|
24
|
+
const setup = prototype?.setupLightingModel;
|
|
25
|
+
if (prototype === void 0 || typeof setup !== "function" || Object.hasOwn(prototype, PATCHED))
|
|
26
|
+
continue;
|
|
27
|
+
prototype.setupLightingModel = function(builder) {
|
|
28
|
+
const model = setup.call(this, builder);
|
|
29
|
+
if (this.twoSidedFoliage !== true || this.subsurfaceColor === void 0) return model;
|
|
30
|
+
const direct = model.direct.bind(model);
|
|
31
|
+
const subsurface = uniform(this.subsurfaceColor);
|
|
32
|
+
model.direct = (input, inner) => {
|
|
33
|
+
direct(input, inner);
|
|
34
|
+
input.reflectedLight.directDiffuse.addAssign(
|
|
35
|
+
foliageTransmission(input.lightDirection, input.lightColor, subsurface)
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
return model;
|
|
39
|
+
};
|
|
40
|
+
prototype[PATCHED] = true;
|
|
41
|
+
patched++;
|
|
42
|
+
}
|
|
43
|
+
return patched;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { addFoliageBackLight, foliageTransmission, installFoliageTransmission };
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { devGlobal, publishDevGlobal } from './chunk-VP43GIWW.js';
|
|
2
|
+
|
|
3
|
+
// src/debug.ts
|
|
4
|
+
function envName(name) {
|
|
5
|
+
return `TN_DEBUG_${name.replace(/([a-z0-9])([A-Z])/gu, "$1_$2").toUpperCase()}`;
|
|
6
|
+
}
|
|
7
|
+
function readLaunchSeams(spec, search) {
|
|
8
|
+
const values = [];
|
|
9
|
+
if (spec.environment.length > 0) {
|
|
10
|
+
const env = envValue(spec.environment);
|
|
11
|
+
if (env !== void 0 && env !== "") values.push(env);
|
|
12
|
+
}
|
|
13
|
+
const query = search ?? globalThis.location?.search;
|
|
14
|
+
if (typeof query === "string") {
|
|
15
|
+
const fromQuery = new URLSearchParams(query).get(spec.query);
|
|
16
|
+
if (fromQuery !== null) values.push(fromQuery);
|
|
17
|
+
}
|
|
18
|
+
if (spec.global !== void 0) {
|
|
19
|
+
const fromGlobal = globalThis[spec.global];
|
|
20
|
+
if (typeof fromGlobal === "string") values.push(fromGlobal);
|
|
21
|
+
else if (typeof fromGlobal === "number") values.push(String(fromGlobal));
|
|
22
|
+
else if (typeof fromGlobal === "boolean") values.push(fromGlobal ? "true" : "false");
|
|
23
|
+
}
|
|
24
|
+
return values;
|
|
25
|
+
}
|
|
26
|
+
function isOff(value) {
|
|
27
|
+
return value === "0" || value === "false";
|
|
28
|
+
}
|
|
29
|
+
function readLaunchFlag(spec, askedFor = "on", search) {
|
|
30
|
+
const values = readLaunchSeams(spec, search);
|
|
31
|
+
return askedFor === "off" ? values.some((value) => isOff(value)) : values.some((value) => !isOff(value));
|
|
32
|
+
}
|
|
33
|
+
function readLaunchValue(spec) {
|
|
34
|
+
return readLaunchSeams(spec)[0];
|
|
35
|
+
}
|
|
36
|
+
function readLaunchValues(spec) {
|
|
37
|
+
return readLaunchSeams(spec);
|
|
38
|
+
}
|
|
39
|
+
function envValue(name) {
|
|
40
|
+
const scope = globalThis;
|
|
41
|
+
if (typeof scope !== "object" || scope === null || !("process" in scope)) return void 0;
|
|
42
|
+
const hostProcess = scope.process;
|
|
43
|
+
if (typeof hostProcess !== "object" || hostProcess === null || !("env" in hostProcess))
|
|
44
|
+
return void 0;
|
|
45
|
+
const env = hostProcess.env;
|
|
46
|
+
if (typeof env !== "object" || env === null) return void 0;
|
|
47
|
+
const value = env[name];
|
|
48
|
+
return typeof value === "string" ? value : void 0;
|
|
49
|
+
}
|
|
50
|
+
function debugFlag(name) {
|
|
51
|
+
return readLaunchFlag({ environment: envName(name), query: name });
|
|
52
|
+
}
|
|
53
|
+
function exposeDebug(name, value) {
|
|
54
|
+
const isDev = import.meta.env?.DEV === true;
|
|
55
|
+
if (!isDev) return;
|
|
56
|
+
const tools = devGlobal(globalThis) ?? {};
|
|
57
|
+
const debug = tools.debug ?? {};
|
|
58
|
+
debug[name] = value;
|
|
59
|
+
publishDevGlobal("debug", debug, globalThis);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/profiling/debug-telemetry.ts
|
|
63
|
+
var CONTENT_SCALED_LIMIT = 10;
|
|
64
|
+
function isContentScaled(name) {
|
|
65
|
+
return name.startsWith("bridge:") || /^(?:assetDispatch|assetLoad|textureDecode)\./u.test(name);
|
|
66
|
+
}
|
|
67
|
+
var DEBUG_GLOBAL = "__THREENATIVE_DEBUG__";
|
|
68
|
+
function debugRequested() {
|
|
69
|
+
return readLaunchFlag({ environment: "TN_DEBUG", global: DEBUG_GLOBAL, query: "tnDebug" });
|
|
70
|
+
}
|
|
71
|
+
function countDebug(name, value, area, caller, unit = "count") {
|
|
72
|
+
if (!Number.isFinite(value) || value < 0)
|
|
73
|
+
throw new Error(`TN_DEBUG: invalid ${name} observation.`);
|
|
74
|
+
const host = globalThis;
|
|
75
|
+
host.__tnEngineCost ??= {};
|
|
76
|
+
host.__tnDebugSources ??= {};
|
|
77
|
+
host.__tnEngineCost[name] = (host.__tnEngineCost[name] ?? 0) + value;
|
|
78
|
+
host.__tnDebugSources[name] ??= { area, caller, unit };
|
|
79
|
+
}
|
|
80
|
+
function measureDebug(name, area, caller, run) {
|
|
81
|
+
const start = performance.now();
|
|
82
|
+
try {
|
|
83
|
+
return run();
|
|
84
|
+
} finally {
|
|
85
|
+
countDebug(`${name}Ms`, performance.now() - start, area, caller, "ms");
|
|
86
|
+
countDebug(`${name}Calls`, 1, area, caller);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function observeDebugGc() {
|
|
90
|
+
if (!globalThis.PerformanceObserver?.supportedEntryTypes?.includes("gc")) return void 0;
|
|
91
|
+
const observer = new PerformanceObserver((list) => {
|
|
92
|
+
for (const entry of list.getEntries()) {
|
|
93
|
+
countDebug("gcPauses", 1, "memory", "PerformanceObserver.gc");
|
|
94
|
+
countDebug("gcPauseMs", entry.duration, "memory", "PerformanceObserver.gc", "ms");
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
observer.observe({ type: "gc" });
|
|
98
|
+
return () => observer.disconnect();
|
|
99
|
+
}
|
|
100
|
+
function sourceOf(name) {
|
|
101
|
+
const source = globalThis.__tnDebugSources?.[name];
|
|
102
|
+
if (source !== void 0)
|
|
103
|
+
return { ...source, unit: source.unit ?? (name.endsWith("Ms") ? "ms" : "count") };
|
|
104
|
+
const areas = [
|
|
105
|
+
[/bridge|children|wrapper|share|scratch|widen|overflow/iu, "bridge"],
|
|
106
|
+
[/velocity|temporal|history|rejected|clamped/iu, "temporal"],
|
|
107
|
+
[
|
|
108
|
+
/heap|memory|live|released|allocated|gc|CreatedBytes|FreedBytes|handleCreates|handleReleases/iu,
|
|
109
|
+
"memory"
|
|
110
|
+
],
|
|
111
|
+
[/gpu|map|timestamp|gate|submit|completion/iu, "gpu"],
|
|
112
|
+
[/matrix|travers|transform|hierarchy|walk/iu, "scene"]
|
|
113
|
+
];
|
|
114
|
+
const area = areas.find(([pattern]) => pattern.test(name))?.[1] ?? "renderer";
|
|
115
|
+
const nativeCallers = [
|
|
116
|
+
[/^gate/u, "renderer/frame_gate.h:FrameGate::decline"],
|
|
117
|
+
[/^(pipeline|bindGroups)/u, "renderer/pipeline_cache.cpp"],
|
|
118
|
+
[/^(buffer|texture|queue|readback)/u, "renderer/gpu_resources.cpp"],
|
|
119
|
+
[/^handle/u, "foundation/handles.cpp"],
|
|
120
|
+
[
|
|
121
|
+
/^(velocity|temporal|timestamp|gpuTimestamp|render|shadow|aux|uniform|attribute)/u,
|
|
122
|
+
"renderer/renderer.cpp"
|
|
123
|
+
],
|
|
124
|
+
[/^cull/u, "scene/projected_cull.cpp"],
|
|
125
|
+
[/scene|matrix|hierarchy/iu, "scene/object3d.cpp"]
|
|
126
|
+
];
|
|
127
|
+
const site = nativeCallers.find(([pattern]) => pattern.test(name))?.[1];
|
|
128
|
+
const async = /queueCallback|queueDelivery/iu.test(name);
|
|
129
|
+
return {
|
|
130
|
+
area,
|
|
131
|
+
caller: /^gc/u.test(name) ? `packages/runtime-native/src/adapters/v8/adapter.cpp (${name})` : site === void 0 ? `engine counter: ${name}` : `packages/runtime-native/src/engine/${site} (${name})`,
|
|
132
|
+
unit: async ? "async-ms" : name.endsWith("Ms") ? "ms" : "count"
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function leverOf(area) {
|
|
136
|
+
const anchor = {
|
|
137
|
+
bridge: "2026-10-27--web-engine-bridge-keep-what-game-code-reads-again-three-native-back-end--keep",
|
|
138
|
+
renderer: "2026-10-27--wasted-work-on-the-shooter-counted-by-class--diagnostic-2-of-6-classes-have-a-fix-in-another-lane",
|
|
139
|
+
scene: "2026-10-27--a-scratch-objects-death-leaves-the-hierarchy-counter-alone-native-engine--keep",
|
|
140
|
+
ui: "2026-10-14--publishuistate-serializes-a-changed-hud-frame-once-instead-of-three-times--keep",
|
|
141
|
+
update: "2026-10-27--rapier-step-grew-from-21-to-34-66-ms-a-frame-in-profiler-round-2--not-a-cause-host-load",
|
|
142
|
+
host: "method-lessons"
|
|
143
|
+
};
|
|
144
|
+
return anchor[area] === void 0 ? void 0 : `PERFORMANCE-LEARNINGS.md#${anchor[area]}`;
|
|
145
|
+
}
|
|
146
|
+
function formatDebugReport(window) {
|
|
147
|
+
const interval = window.presented.samples > 0 && window.presented.mean > 0 ? window.presented.mean : void 0;
|
|
148
|
+
const engine = window.counters?.engine ?? {};
|
|
149
|
+
const durationMs = window.durationMs;
|
|
150
|
+
const observations = Object.fromEntries(
|
|
151
|
+
Object.entries(engine).map(([name, series]) => {
|
|
152
|
+
if (!Number.isFinite(series.mean) || series.mean < 0)
|
|
153
|
+
throw new Error(`TN_DEBUG: invalid ${name} series.`);
|
|
154
|
+
const source = sourceOf(name);
|
|
155
|
+
const rate = source.unit === "count" || source.unit?.endsWith("bytes");
|
|
156
|
+
return [
|
|
157
|
+
name,
|
|
158
|
+
{
|
|
159
|
+
...series,
|
|
160
|
+
...source,
|
|
161
|
+
...rate ? {
|
|
162
|
+
perSecond: durationMs !== void 0 && durationMs > 0 && series.samples === window.frames ? series.mean * series.samples * 1e3 / durationMs : null
|
|
163
|
+
} : {}
|
|
164
|
+
}
|
|
165
|
+
];
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
const offenders = [];
|
|
169
|
+
const add = (name, ms, source, basis) => {
|
|
170
|
+
if (ms <= 0) return;
|
|
171
|
+
const lever = source.lever ?? leverOf(source.area);
|
|
172
|
+
offenders.push({
|
|
173
|
+
name,
|
|
174
|
+
ms,
|
|
175
|
+
area: source.area,
|
|
176
|
+
caller: source.caller,
|
|
177
|
+
share: interval === void 0 ? null : ms / interval,
|
|
178
|
+
basis,
|
|
179
|
+
...lever === void 0 ? {} : { lever }
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
for (const [name, series] of Object.entries(engine)) {
|
|
183
|
+
const source = sourceOf(name);
|
|
184
|
+
if (source.unit === "ms" || source.unit === "estimated-ms")
|
|
185
|
+
add(
|
|
186
|
+
name,
|
|
187
|
+
series.mean,
|
|
188
|
+
source,
|
|
189
|
+
source.unit === "estimated-ms" ? "estimated-getter-equivalent" : "measured"
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
for (const [name, series] of Object.entries(window.phases))
|
|
193
|
+
add(
|
|
194
|
+
`phase.${name}`,
|
|
195
|
+
series.mean,
|
|
196
|
+
{ area: name === "hostGap" ? "host" : name, caller: "FixedStepLoop"},
|
|
197
|
+
"measured-parent"
|
|
198
|
+
);
|
|
199
|
+
for (const [name, ms] of [
|
|
200
|
+
["main", window.gpuMain],
|
|
201
|
+
["shadow", window.gpuShadow],
|
|
202
|
+
["other", window.gpuOther],
|
|
203
|
+
["compute", window.gpuCompute]
|
|
204
|
+
])
|
|
205
|
+
if (ms !== void 0)
|
|
206
|
+
add(
|
|
207
|
+
`gpu.${name}`,
|
|
208
|
+
ms,
|
|
209
|
+
{ area: "gpu", caller: "GPU timestamp query"},
|
|
210
|
+
"gpu-execution"
|
|
211
|
+
);
|
|
212
|
+
offenders.sort((a, b) => (b.share ?? -1) - (a.share ?? -1) || a.name.localeCompare(b.name));
|
|
213
|
+
const findings = [];
|
|
214
|
+
const total = (name) => {
|
|
215
|
+
const series = engine[name];
|
|
216
|
+
return series === void 0 ? void 0 : series.mean * series.samples;
|
|
217
|
+
};
|
|
218
|
+
const ratio = (code, numerator, denominator, limit) => {
|
|
219
|
+
const n = total(numerator);
|
|
220
|
+
const d = total(denominator);
|
|
221
|
+
if (n === void 0 || d === void 0 || d <= 0 || n / d <= limit) return;
|
|
222
|
+
const source = sourceOf(numerator);
|
|
223
|
+
const timing = engine[`${numerator}Ms`];
|
|
224
|
+
const lever = source.lever ?? leverOf(source.area);
|
|
225
|
+
findings.push({
|
|
226
|
+
code,
|
|
227
|
+
ratio: n / d,
|
|
228
|
+
share: timing === void 0 || interval === void 0 ? null : timing.mean / interval,
|
|
229
|
+
caller: source.caller,
|
|
230
|
+
...lever === void 0 ? {} : { lever }
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
ratio("temporal-missing-velocity", "velocitySkipped", "velocityCandidates", 0);
|
|
234
|
+
ratio("temporal-history-unavailable", "temporalInvalidFrames", "temporalActiveFrames", 0);
|
|
235
|
+
const activity = (code, counter) => {
|
|
236
|
+
const value = engine[counter]?.mean;
|
|
237
|
+
if (value === void 0 || value <= 0) return;
|
|
238
|
+
const source = sourceOf(counter);
|
|
239
|
+
const lever = source.lever ?? leverOf(source.area);
|
|
240
|
+
findings.push({
|
|
241
|
+
code,
|
|
242
|
+
perFrame: value,
|
|
243
|
+
share: null,
|
|
244
|
+
caller: source.caller,
|
|
245
|
+
...lever === void 0 ? {} : { lever }
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
activity("timestamp-oversampling", "gpuTimestampUnrequestedSamples");
|
|
249
|
+
activity("bridge-arena-overflow", "bridgeOverflowAllocations");
|
|
250
|
+
activity("gate-capacity-decline", "gateDeclinedCapacity");
|
|
251
|
+
activity("gate-completion-age-decline", "gateDeclinedAge");
|
|
252
|
+
ratio("bridge-typed-array-widening", "bridgeTypedEncodedBytes", "bridgeTypedSourceBytes", 1);
|
|
253
|
+
const host = globalThis;
|
|
254
|
+
const contentScaled = Object.entries({ ...host.__tnEngineCounters?.(), ...host.__tnEngineCost }).filter(([name, total2]) => {
|
|
255
|
+
if (!isContentScaled(name)) return false;
|
|
256
|
+
if (!Number.isFinite(total2) || total2 < 0)
|
|
257
|
+
throw new Error(`TN_DEBUG: invalid ${name} counter.`);
|
|
258
|
+
return total2 > 0;
|
|
259
|
+
}).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, CONTENT_SCALED_LIMIT).map(([name, total2]) => ({ name, total: total2, ...sourceOf(name) }));
|
|
260
|
+
return `TN_DEBUG_REPORT:${JSON.stringify({ window: window.window, frames: window.frames, durationMs: durationMs ?? null, intervalMs: interval ?? null, offenders, findings, observations, contentScaled: { basis: "run-total", top: contentScaled }, longTasks: window.longTasks, gpu: window.gpu, passes: window.passes })}`;
|
|
261
|
+
}
|
|
262
|
+
function debugHotCalls(window) {
|
|
263
|
+
const interval = window.presented.mean;
|
|
264
|
+
if (!(interval > 0)) return void 0;
|
|
265
|
+
const calls = Object.entries(window.counters?.engine ?? {}).flatMap(([name, series]) => {
|
|
266
|
+
const source = sourceOf(name);
|
|
267
|
+
return source.area === "update" && source.unit === "ms" && series.p95 > interval ? [
|
|
268
|
+
{
|
|
269
|
+
name,
|
|
270
|
+
caller: source.caller,
|
|
271
|
+
ms: series.p95,
|
|
272
|
+
share: series.p95 / interval,
|
|
273
|
+
lever: source.lever ?? leverOf(source.area)
|
|
274
|
+
}
|
|
275
|
+
] : [];
|
|
276
|
+
}).sort((a, b) => b.share - a.share);
|
|
277
|
+
return calls.length === 0 ? void 0 : `TN_HOT_CALL:${JSON.stringify({ window: window.window, intervalMs: interval, calls })}`;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export { countDebug, debugFlag, debugHotCalls, debugRequested, exposeDebug, formatDebugReport, isContentScaled, measureDebug, observeDebugGc, readLaunchFlag, readLaunchValue, readLaunchValues };
|