Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

test(spine): asking what clipping costs may not move what it is measuring

esenginec68c871e6215
diff --git a/desktop b/desktop
index e5075c1df..30ee2a80b 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit e5075c1dfc4c3572ef7d96fa21cbbebacaffe322
+Subproject commit 30ee2a80bebd5be9601008b8a0facb2cd6c52d75
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index 81eab631e..3b87a3cdb 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -3,10 +3,10 @@
"counts": {
"public": 113,
"beta": 91,
- "experimental": 1669,
+ "experimental": 1670,
"deprecated": 3
},
- "total": 1873,
+ "total": 1874,
"subsystems": [
{
"id": "ecs",
diff --git a/sdk/etc/spine.api.md b/sdk/etc/spine.api.md
index c9624872c..f3612eec5 100644
--- a/sdk/etc/spine.api.md
+++ b/sdk/etc/spine.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/spine
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 0 public · 1 beta · 46 experimental · 0 deprecated
+Symbols: 0 public · 1 beta · 47 experimental · 0 deprecated
## ConstraintList — interface @experimental
```
@@ -78,6 +78,23 @@ update: (instanceId: number, dt: number) => void
envelopeFor: (skeleton: string, atlas: string) => SpineCullingEnvelope
```
+## SpineClipBudget — interface @experimental
+```
+bypassedTriangles: number
+candidateTriangles: number
+chargedTriangles: number
+edgeWork: number
+effectiveEdges: number
+inputVertices: number
+outputTriangles: number
+outputVertices: number
+pieces: number
+rawVertices: number
+rejectedTriangles: number
+triangleAmplification: number
+vertexAmplification: number
+```
+
## SpineCullingEnvelope — type @experimental
```
| { kind: 'certified'; bounds: SpineAABB; source: 'explicit' }
diff --git a/sdk/src/spine/index.ts b/sdk/src/spine/index.ts
index d7482f677..af6416bd8 100644
--- a/sdk/src/spine/index.ts
+++ b/sdk/src/spine/index.ts
@@ -10,6 +10,7 @@ export type { ConstraintList, TransformMixData, PathMixData } from './SpineContr
export type { SpineModuleFactory } from './SpineModuleLoader';
export { wrapSpineModule } from './SpineModuleLoader';
export type { SpinePair } from './prepareSpine';
+export type { SpineClipBudget } from './spineMetrics';
export type {
SpineAABB, SpineCullingEnvelope, SpineScanCoverage, SpineBoundsSource,
} from './spineBounds';
diff --git a/sdk/tests/spine-clip-budget.test.ts b/sdk/tests/spine-clip-budget.test.ts
index 860e7926d..03f10b64b 100644
--- a/sdk/tests/spine-clip-budget.test.ts
+++ b/sdk/tests/spine-clip-budget.test.ts
@@ -88,6 +88,32 @@ describe.skipIf(!HAS_WASM)('the clip budget charges what is still being paid', (
expect(budget.edgeWork, 'work was charged for triangles nothing ran on').toBe(0);
});
+ it('asking costs the instance nothing — it is a diagnosis, not a step', () => {
+ // The inspector reads this off the LIVE entity somebody is looking at.
+ // A counted walk that advanced the clock, or left the clipper's state
+ // behind, would make the panel change the thing it is describing.
+ const handle = controller.loadSkeleton(
+ new Uint8Array(readFileSync(resolve(FIXTURES, 'coin-38/coin-pro.skel'))),
+ readFileSync(resolve(FIXTURES, 'coin-38/coin.atlas'), 'utf-8'), true);
+ for (let i = 0, pages = controller.getAtlasPageCount(handle); i < pages; i++) {
+ controller.setAtlasPageTexture(handle, i, 1, 2048, 2048);
+ }
+ const instanceId = controller.createInstance(handle);
+ controller.play(instanceId, 'animation', true);
+ controller.update(instanceId, 0.35);
+
+ const before = controller.getBounds(instanceId);
+ const first = controller.clipBudget(instanceId)!;
+ const second = controller.clipBudget(instanceId)!;
+ const after = controller.getBounds(instanceId);
+
+ expect(second, 'a second scan of an unmoved pose disagreed with the first')
+ .toEqual(first);
+ expect(after, 'the scan moved the pose it was measuring').toEqual(before);
+ controller.destroyInstance(instanceId);
+ controller.unloadSkeleton(handle);
+ });
+
it('a skeleton that really crosses is charged for all of it', () => {
const budget = budgetOfAsset('coin-38/coin-pro.skel', 'coin-38/coin.atlas', 'animation', 0.35);
expect(budget.rejectedTriangles + budget.bypassedTriangles + budget.chargedTriangles)
diff --git a/sdk/tests/spine-pose-eligibility.test.ts b/sdk/tests/spine-pose-eligibility.test.ts
index 5699ae965..90bb1a943 100644
--- a/sdk/tests/spine-pose-eligibility.test.ts
+++ b/sdk/tests/spine-pose-eligibility.test.ts
@@ -16,42 +16,36 @@
import { describe, it, expect } from 'vitest';
import { SpineRuntime } from '../src/spine/SpineRuntime';
import { fakeSpineModule, fakeSpineEra } from './helpers/fakeSpineModule';
-import { SpineCertificates, NO_CERTIFICATES } from '../src/spine/spineCertificates';
+import { spineCertificatesFrom, NO_CERTIFICATES } from '../src/spine/spineCertificates';
import { certifyBounds, scanObservedBounds, mayDeferWorldPose } from '../src/spine/spineBounds';
import type { SpineAABB, SpineCullingEnvelope } from '../src/spine/spineBounds';
-import { spinePairKey } from '../src/spine/prepareSpine';
import type { Entity } from '../src/types';
const PROMISE: SpineAABB = { minX: -200, minY: -100, maxX: 200, maxY: 400 };
+/** The same promise as a manifest stores one. */
+const RECT = { x: -200, y: -100, width: 400, height: 500 };
function certified(): SpineCullingEnvelope {
return certifyBounds(PROMISE);
}
describe('a promise about a pair, carried to the residency that needs it', () => {
- it('is recorded against the pair, and another atlas is another asset', () => {
- const certificates = new SpineCertificates();
- const withA = spinePairKey('hero.skel', 'hero.atlas');
- const withB = spinePairKey('hero.skel', 'winter.atlas');
- certificates.certify(withA, PROMISE);
-
- expect(certificates.envelopeFor(withA).kind).toBe('certified');
- expect(certificates.envelopeFor(withB).kind,
+ it('is read for the pair asked about, and another atlas is another asset', () => {
+ // The source answers about BOTH refs; there is no way to ask about a
+ // skeleton alone, which is what kept a second atlas from inheriting one.
+ const certificates = spineCertificatesFrom({
+ spineCulling: (skeleton, atlas) =>
+ (skeleton === 'hero.skel' && atlas === 'hero.atlas' ? RECT : undefined),
+ });
+ expect(certificates.envelopeFor('hero.skel', 'hero.atlas').kind).toBe('certified');
+ expect(certificates.envelopeFor('hero.skel', 'winter.atlas').kind,
'a promise about one atlas was read for another').toBe('unknown');
});
- it('a realm with nothing recorded promises nothing', () => {
- expect(NO_CERTIFICATES.envelopeFor(spinePairKey('hero.skel', 'hero.atlas')).kind)
+ it('a realm whose source answers nothing promises nothing', () => {
+ expect(NO_CERTIFICATES.envelopeFor('hero.skel', 'hero.atlas').kind).toBe('unknown');
+ expect(spineCertificatesFrom({}).envelopeFor('hero.skel', 'hero.atlas').kind)
.toBe('unknown');
- expect(new SpineCertificates().envelopeFor('anything').kind).toBe('unknown');
- });
-
- it('a withdrawn promise is not a promise', () => {
- const certificates = new SpineCertificates();
- const key = spinePairKey('hero.skel', 'hero.atlas');
- certificates.certify(key, PROMISE);
- certificates.revoke(key);
- expect(certificates.envelopeFor(key).kind).toBe('unknown');
});
it('the residency settles both facts, and asks the runtime exactly once', () => {
@@ -132,13 +126,11 @@ describe('a promise about a pair, carried to the residency that needs it', () =>
it('the promise survives the generation the asset was read at', () => {
// What the certificate is ABOUT is the asset, so reloading its bytes
- // does not withdraw it — the pair key is the same one.
- const certificates = new SpineCertificates();
- const key = spinePairKey('hero.skel', 'hero.atlas');
- certificates.certify(key, PROMISE);
+ // does not withdraw it — the pair is the same pair.
+ const certificates = spineCertificatesFrom({ spineCulling: () => RECT });
for (const generation of [17, 18, 19]) {
- const envelope = certificates.envelopeFor(key);
- expect(envelope.kind, `generation ${generation} lost the promise`).toBe('certified');
+ expect(certificates.envelopeFor('hero.skel', 'hero.atlas').kind,
+ `generation ${generation} lost the promise`).toBe('certified');
}
});
diff --git a/tools/check-spine-panel.mjs b/tools/check-spine-panel.mjs
index d4215beb3..70586a3f7 100644
--- a/tools/check-spine-panel.mjs
+++ b/tools/check-spine-panel.mjs
@@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
/**
- * @file check-spine-panel.mjs — the profiler's spine section renders a report
- * and never becomes a second one.
+ * @file check-spine-panel.mjs — the spine diagnostic surfaces render facts and
+ * never manufacture them.
*
* The whole value of the spine diagnostics is that ONE side computes them: the
* realm that ran the frame. An editor panel that starts a clock, keeps a
@@ -25,7 +25,9 @@ const VIEW = 'desktop/src/panels/spineDiagnosticsView.ts';
const SECTION = 'desktop/src/panels/SpineDiagnosticsSection.tsx';
const HOLDER = 'desktop/src/engine/spineDiagnosticsStore.ts';
const REALM = 'desktop/src/playHost.ts';
-const FILES = [VIEW, SECTION, HOLDER, REALM];
+const CLIP = 'desktop/src/spine/clipComplexity.ts';
+const DETAILS = 'desktop/src/panels/Details.tsx';
+const FILES = [VIEW, SECTION, HOLDER, REALM, CLIP, DETAILS];
// The panel IS the subject, so an absent editor is refused rather than passed:
// an empty scan finds nothing wrong with nothing. run-gates skips it by
@@ -48,6 +50,16 @@ const strip = (text) => text
.replace(/\/\*[\s\S]*?\*\//g, '')
.replace(/\/\/[^\n]*/g, '');
+/** One function's body, to the next top-level `function` — enough to judge it. */
+function component(file, signature) {
+ const text = strip(read(file));
+ const at = text.indexOf(signature);
+ if (at < 0) return null;
+ const rest = text.slice(at + signature.length);
+ const end = rest.indexOf('\nfunction ');
+ return end < 0 ? rest : rest.slice(0, end);
+}
+
/** What the realm's answer to `query { kind: 'spine' }` is made of. */
function realmAnswer() {
const text = strip(read(REALM));
@@ -127,6 +139,54 @@ const RULES = [
? 'the section authors a culling contract' : null;
},
},
+ {
+ rule: 'The clipping scan runs when somebody asks and at no other time. The counted walk IS a clip pass, so a panel that ran it to fill itself in would be paying the exact cost it exists to explain.',
+ holds: () => {
+ const body = component(DETAILS, 'function SpineClipComplexity');
+ if (!body) return 'Details has no SpineClipComplexity section';
+ if (/useEffect|useMemo|useLayoutEffect/.test(body)) {
+ return 'the clipping section scans from a hook rather than from a click';
+ }
+ const calls = body.match(/spineClipComplexity\s*\(/g) ?? [];
+ return calls.length === 1 ? null
+ : `the clipping section scans ${calls.length} time(s) — it may ask once, when asked`;
+ },
+ },
+ {
+ rule: 'A clipping scan diagnoses; it does not author. It stores nothing, writes no `.meta`, and proposes no import edit — unlike the culling contract beside it, which is a promise somebody makes.',
+ holds: () => {
+ const body = component(DETAILS, 'function SpineClipComplexity');
+ if (!body) return 'Details has no SpineClipComplexity section';
+ const authoring = /\bwrite\s*\(|useAsFixedBounds|removeFixedBounds|setImportSettings/;
+ return authoring.test(body) ? 'the clipping section authors an asset' : null;
+ },
+ },
+ {
+ rule: 'Clipping notes fire on STRUCTURE, never on size. Nothing here has been calibrated across real projects, so a number crossing a line somebody picked would be an opinion wearing a measurement\'s clothes.',
+ holds: () => {
+ const text = strip(read(CLIP));
+ if (/\b(score|grade|poor|excellent|rating)\b/i.test(text)) {
+ return 'the clipping diagnosis grades the asset';
+ }
+ // A threshold is always a literal. 0 and 1 are structural boundaries
+ // — "is there a region", "did it decompose" — and nothing else is.
+ const thresholds = [...text.matchAll(/[<>]=?\s*(\d+)/g)]
+ .map((m) => Number(m[1])).filter((n) => n > 1);
+ return thresholds.length === 0 ? null
+ : `the clipping diagnosis compares against ${thresholds.join(', ')} — a threshold, not a structure`;
+ },
+ },
+ {
+ rule: 'The scene report never computes a clip budget. Pricing clipping means posing and extracting, so a profiler that did it to explain extraction would be manufacturing the extraction it is explaining.',
+ holds: () => {
+ for (const file of [VIEW, SECTION, HOLDER]) {
+ if (/clipBudget|spineClipComplexity/.test(strip(read(file)))) {
+ return `${file} prices clipping from the scene report`;
+ }
+ }
+ return null;
+ },
+ },
];
const findings = [];