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.

feat(spine): a world pose is owed, paid once, and owed again when something moves

esengine682c26546be4
diff --git a/sdk/etc/spine.api.md b/sdk/etc/spine.api.md
index e291d7574..756d8593b 100644
--- a/sdk/etc/spine.api.md
+++ b/sdk/etc/spine.api.md
@@ -105,6 +105,7 @@ static prototype: SpineManager
## SpineModuleController — class @experimental
```
addAnimation: (instanceId: number, animation: string, loop?: boolean, delay?: number, track?: number) => boolean
+advanceAndApply: (instanceId: number, dt: number) => void
animationDuration: (skeletonHandle: number, animation: string) => number
clipBudget: (instanceId: number) => SpineClipBudget | null
collectEvents: (instanceId: number) => RawSpineEvent[]
@@ -124,6 +125,7 @@ getSkins: (instanceId: number) => string[]
getTransformConstraintMix: (instanceId: number, name: string) => TransformMixData | null
listConstraints: (instanceId: number) => ConstraintList
loadSkeleton: (skelData: Uint8Array | string, atlasText: string, isBinary: boolean) => number
+materializeWorldPose: (instanceId: number, dt: number) => void
play: (instanceId: number, animation: string, loop?: boolean, track?: number) => boolean
raw: SpineWasmModule
requiresContinuousWorldPose: (skeletonHandle: number) => boolean
@@ -168,6 +170,7 @@ clipBudget: (entity: Entity) => SpineClipBudget | null
collectAllEvents: () => { entity: Entity; raw: RawSpineEvent; }[]
dispose: () => void
enableEvents: (entity: Entity) => void
+ensurePose: (entity: Entity) => boolean
entityCount: number
extractAndSubmitMeshes: (core: NonNullable<EngineApi>, registry: CppRegistry, materialOf?: SkeletalMaterialOf) => void
getAnimations: (entity: Entity) => string[]
diff --git a/sdk/src/spine/SpineController.ts b/sdk/src/spine/SpineController.ts
index b168ba218..fafbaa2fd 100644
--- a/sdk/src/spine/SpineController.ts
+++ b/sdk/src/spine/SpineController.ts
@@ -227,6 +227,17 @@ export class SpineModuleController {
});
}
+ /** The animation clock onto the bones' LOCAL transforms — see spineBounds
+ * and the runtime's ensurePose for why this is not the whole pose. */
+ advanceAndApply(instanceId: number, dt: number): void {
+ this.api_.advanceAndApply(instanceId, dt);
+ }
+
+ /** The world transforms the local pose implies. */
+ materializeWorldPose(instanceId: number, dt: number): void {
+ this.api_.materializeWorldPose(instanceId, dt);
+ }
+
/** Seconds; negative where this skeleton has no such animation. */
animationDuration(skeletonHandle: number, animation: string): number {
return this.api_.getAnimationDuration(skeletonHandle, animation);
diff --git a/sdk/src/spine/SpineRuntime.ts b/sdk/src/spine/SpineRuntime.ts
index 1b915daf4..577d8f14e 100644
--- a/sdk/src/spine/SpineRuntime.ts
+++ b/sdk/src/spine/SpineRuntime.ts
@@ -39,6 +39,17 @@ interface EntityInfo {
playing: boolean;
/** Which era of which asset. Entities sharing it share one loaded skeleton. */
era: string;
+
+ /**
+ * Bumped by anything that changes what a world pose would come out as: an
+ * advance, and any constraint or attachment change that only takes effect
+ * when the world transforms are next resolved.
+ */
+ logicalRevision: number;
+ /** The revision the world transforms currently reflect. */
+ worldRevision: number;
+ /** Advanced but not yet resolved, for the runtimes whose world step reads it. */
+ pendingDt: number;
}
/** One parsed skeleton, and the era it was parsed from. The claim is the
@@ -92,6 +103,9 @@ export class SpineRuntime {
this.entities_.set(entity, {
skelHandle: claimed, instanceId, era: era.id,
skeletonScale: 1, flipX: false, flipY: false, layer: 0, timeScale: 1, playing: true,
+ // Equal because creating the instance resolved its setup pose: an
+ // entity that never plays owes nothing and is never re-resolved.
+ logicalRevision: 0, worldRevision: 0, pendingDt: 0,
});
return true;
}
@@ -156,7 +170,9 @@ export class SpineRuntime {
setSkin(entity: Entity, skin: string): void {
const info = this.entities_.get(entity);
- if (info) this.controller_.setSkin(info.instanceId, skin);
+ if (!info) return;
+ this.controller_.setSkin(info.instanceId, skin);
+ this.poseChanged_(info);
}
getBounds(entity: Entity): { x: number; y: number; width: number; height: number } | null {
@@ -205,12 +221,14 @@ export class SpineRuntime {
setAttachment(entity: Entity, slotName: string, attachmentName: string): boolean {
const info = this.entities_.get(entity);
if (!info) return false;
+ this.poseChanged_(info);
return this.controller_.setAttachment(info.instanceId, slotName, attachmentName);
}
setIKTarget(entity: Entity, constraintName: string, targetX: number, targetY: number, mix: number): boolean {
const info = this.entities_.get(entity);
if (!info) return false;
+ this.poseChanged_(info);
return this.controller_.setIKTarget(info.instanceId, constraintName, targetX, targetY, mix);
}
@@ -235,6 +253,7 @@ export class SpineRuntime {
setTransformConstraintMix(entity: Entity, name: string, mix: TransformMixData): boolean {
const info = this.entities_.get(entity);
if (!info) return false;
+ this.poseChanged_(info);
return this.controller_.setTransformConstraintMix(info.instanceId, name, mix);
}
@@ -247,6 +266,7 @@ export class SpineRuntime {
setPathConstraintMix(entity: Entity, name: string, mix: PathMixData): boolean {
const info = this.entities_.get(entity);
if (!info) return false;
+ this.poseChanged_(info);
return this.controller_.setPathConstraintMix(info.instanceId, name, mix);
}
@@ -274,6 +294,35 @@ export class SpineRuntime {
return result;
}
+ /**
+ * Resolve this entity's world transforms if they do not already reflect its
+ * local pose; returns whether it had to. The REVISION is the authority, not
+ * the frame — a frame that resolves and then moves an IK target owes another
+ * one, and a frame key would hand the next asker the pose from before it.
+ */
+ ensurePose(entity: Entity): boolean {
+ const info = this.entities_.get(entity);
+ if (!info || this.disabledEntities_.has(entity)) return false;
+ if (info.worldRevision === info.logicalRevision) {
+ if (this.metrics_) this.metrics_.pose.worldDeferred++;
+ return false;
+ }
+ this.controller_.materializeWorldPose(info.instanceId, info.pendingDt);
+ info.worldRevision = info.logicalRevision;
+ info.pendingDt = 0;
+ if (this.metrics_) {
+ this.metrics_.pose.worldMaterializations++;
+ this.metrics_.abi.world++;
+ }
+ return true;
+ }
+
+ /** What only the world transforms will show — a constraint retargeted, an
+ * attachment swapped. The local pose is already whatever it was. */
+ private poseChanged_(info: EntityInfo): void {
+ info.logicalRevision++;
+ }
+
updateAll(dt: number): void {
const m = this.metrics_;
if (m) beginSpineFrame(m);
@@ -284,8 +333,17 @@ export class SpineRuntime {
if (this.disabledEntities_.has(entity)) continue;
// playing=false freezes the pose (skip advance, still submitted);
// timeScale scales the advance (update() takes an arbitrary dt).
- if (info.playing) this.controller_.update(info.instanceId, dt * info.timeScale);
- if (m) m.abi.pose++;
+ if (info.playing) {
+ const step = dt * info.timeScale;
+ this.controller_.advanceAndApply(info.instanceId, step);
+ info.logicalRevision++;
+ info.pendingDt += step;
+ if (m) { m.abi.pose++; m.pose.logicalUpdates++; }
+ }
+ // Every entity's world pose is demanded here for now. Which of them
+ // could be left owed is the next cut's question; this one is only
+ // about the debt existing.
+ this.ensurePose(entity);
}
if (!m) return;
m.time.pose = performance.now() - started;
@@ -303,6 +361,10 @@ export class SpineRuntime {
const started = m ? performance.now() : 0;
for (const [entity, info] of this.entities_) {
if (this.disabledEntities_.has(entity)) continue;
+ // The renderer is a consumer of the world pose like any other, and
+ // asks for it the same way. Today it is already resolved.
+ this.ensurePose(entity);
+ if (m) m.pose.meshExtractions++;
// Shared with every skeletal runtime (skeletal/submitMeshes): the core's
// entry point takes geometry and a transform, and knows nothing about
// what posed them. A false means the core cannot take geometry at all,
diff --git a/sdk/src/spine/spineMetrics.ts b/sdk/src/spine/spineMetrics.ts
index 12f52ec0e..75a03d2da 100644
--- a/sdk/src/spine/spineMetrics.ts
+++ b/sdk/src/spine/spineMetrics.ts
@@ -57,6 +57,8 @@ export interface SpineClipBudget {
/** Every crossing a frame made into the module, by what it asked for. */
export interface SpineAbiCounts {
pose: number;
+ /** Crossings that resolved world transforms — the other half of a pose. */
+ world: number;
batchCount: number;
vertexCount: number;
indexCount: number;
@@ -78,6 +80,19 @@ export interface SpineByteCounts {
/** One runtime's frame. Mutated in place — a frame that allocates to say what a
* frame cost is measuring itself. */
+/**
+ * A frame's posing, as what was asked for rather than what was called.
+ *
+ * `worldDeferred` is a demand that found the world already current — which is
+ * how "at most one materialization per revision" reads from the outside.
+ */
+export interface SpinePoseCounts {
+ logicalUpdates: number;
+ worldMaterializations: number;
+ worldDeferred: number;
+ meshExtractions: number;
+}
+
export interface SpineFrameMetrics {
frame: number;
entities: number;
@@ -86,6 +101,8 @@ export interface SpineFrameMetrics {
vertices: number;
indices: number;
abi: SpineAbiCounts;
+ /** What the frame's poses were made of, in demand rather than in calls. */
+ pose: SpinePoseCounts;
bytes: SpineByteCounts;
/** Milliseconds. `readback` is the whole extract+submit pass; see the file
* note for why it is not four numbers. */
@@ -95,7 +112,8 @@ export interface SpineFrameMetrics {
export function newSpineFrameMetrics(): SpineFrameMetrics {
return {
frame: 0, entities: 0, residencies: 0, meshBatches: 0, vertices: 0, indices: 0,
- abi: { pose: 0, batchCount: 0, vertexCount: 0, indexCount: 0, batchData: 0, malloc: 0, free: 0, submit: 0 },
+ abi: { pose: 0, world: 0, batchCount: 0, vertexCount: 0, indexCount: 0, batchData: 0, malloc: 0, free: 0, submit: 0 },
+ pose: { logicalUpdates: 0, worldMaterializations: 0, worldDeferred: 0, meshExtractions: 0 },
bytes: { wasmRead: 0, coreWrite: 0, scratchAllocated: 0 },
time: { pose: 0, readback: 0, total: 0 },
};
@@ -105,9 +123,11 @@ export function newSpineFrameMetrics(): SpineFrameMetrics {
export function beginSpineFrame(m: SpineFrameMetrics): void {
m.frame++;
m.entities = 0; m.residencies = 0; m.meshBatches = 0; m.vertices = 0; m.indices = 0;
- m.abi.pose = 0; m.abi.batchCount = 0; m.abi.vertexCount = 0; m.abi.indexCount = 0;
+ m.abi.pose = 0; m.abi.world = 0; m.abi.batchCount = 0; m.abi.vertexCount = 0; m.abi.indexCount = 0;
m.abi.batchData = 0; m.abi.malloc = 0; m.abi.free = 0; m.abi.submit = 0;
m.bytes.wasmRead = 0; m.bytes.coreWrite = 0; m.bytes.scratchAllocated = 0;
+ m.pose.logicalUpdates = 0; m.pose.worldMaterializations = 0;
+ m.pose.worldDeferred = 0; m.pose.meshExtractions = 0;
m.time.pose = 0; m.time.readback = 0; m.time.total = 0;
}
diff --git a/sdk/tests/spine-abi-cost.test.ts b/sdk/tests/spine-abi-cost.test.ts
index c7eaa9a9c..7b5de93e4 100644
--- a/sdk/tests/spine-abi-cost.test.ts
+++ b/sdk/tests/spine-abi-cost.test.ts
@@ -180,7 +180,10 @@ describe.skipIf(!HAS_ASSETS)('what a spine entity costs per frame', () => {
expect(rows).toHaveLength(10);
});
- it('posing is one crossing per entity, whatever the entity count', () => {
+ it('posing is two crossings per entity, whatever the entity count', () => {
+ // Two since a pose became two things it can be asked for separately:
+ // advancing the animation, and resolving the world it implies. The
+ // second one is what a frame can one day decline to ask for.
const { module, crossings } = counting(module38);
const runtime = new SpineRuntime('3.8', module);
populate(runtime, 10, 1);
@@ -194,12 +197,14 @@ describe.skipIf(!HAS_ASSETS)('what a spine entity costs per frame', () => {
frame(runtime, null);
const hundred = crossings.total();
- expect(ten).toBe(10);
- expect(hundred, 'posing stopped being one call per entity').toBe(100);
+ expect(ten).toBe(20);
+ expect(hundred, 'posing stopped being two calls per entity').toBe(200);
runtime.dispose();
});
it('reading a pose back is 2 + 3 per batch, per entity, per frame', () => {
+ // The pose itself is two more, which this counts but does not attribute
+ // to the readback: they are the frame's other half.
// The number a batch ABI would change: today the walk asks how many
// batches, then three questions per batch, and allocates twice per batch
// — all of it per entity.
@@ -214,16 +219,19 @@ describe.skipIf(!HAS_ASSETS)('what a spine entity costs per frame', () => {
const c = crossings.counts;
expect(batches).toBeGreaterThan(0);
- expect(c.get('spine_update')).toBe(1);
+ expect(c.get('spine_advanceAndApply')).toBe(1);
+ expect(c.get('spine_materializeWorldPose'), 'the world was resolved more than once')
+ .toBe(1);
expect(c.get('spine_getMeshBatchCount')).toBe(1);
expect(c.get('spine_getMeshBatchVertexCount')).toBe(batches);
expect(c.get('spine_getMeshBatchIndexCount')).toBe(batches);
expect(c.get('spine_getMeshBatchData')).toBe(batches);
// Two allocations per batch (vertices + indices) plus the meta pair.
expect(c.get('_malloc')).toBe(1 + batches * 2);
- // The formula, for the wall: 4 fixed + 7 per batch, per entity, per
- // frame. A batch ABI is a change to THIS.
- expect(crossings.total()).toBe(4 + 7 * batches);
+ // The formula, for the wall: 5 fixed + 7 per batch, per entity, per
+ // frame. It was 4 while a pose was one call. A batch ABI is a change to
+ // THIS; so was splitting the pose, deliberately.
+ expect(crossings.total()).toBe(5 + 7 * batches);
runtime.dispose();
});
diff --git a/sdk/tests/spine-observability.test.ts b/sdk/tests/spine-observability.test.ts
index cdfb33ad6..198794462 100644
--- a/sdk/tests/spine-observability.test.ts
+++ b/sdk/tests/spine-observability.test.ts
@@ -159,8 +159,13 @@ describe.skipIf(!HAS_ASSETS)('a frame can say what it cost', () => {
expect(m.residencies, 'ten eras, ten native skeletons').toBe(10);
expect(Object.keys(m)).toEqual([
'frame', 'entities', 'residencies', 'meshBatches', 'vertices', 'indices',
- 'abi', 'bytes', 'time',
+ 'abi', 'pose', 'bytes', 'time',
]);
+ // `pose` is the frame in DEMAND rather than in calls: what was advanced,
+ // what had to be resolved, and what asked and found it already was.
+ expect(m.pose.logicalUpdates).toBe(100);
+ expect(m.pose.worldMaterializations, 'a world pose was resolved twice').toBe(100);
+ expect(m.pose.worldDeferred, 'the extraction re-resolved what it asked for').toBe(100);
runtime.dispose();
});
});
diff --git a/sdk/tests/spine-pose-demand.test.ts b/sdk/tests/spine-pose-demand.test.ts
index 6520b3c52..7d6c37c84 100644
--- a/sdk/tests/spine-pose-demand.test.ts
+++ b/sdk/tests/spine-pose-demand.test.ts
@@ -89,13 +89,14 @@ function posedBounds(instanceId: number): Rect {
/** A runtime whose per-entity work can be counted from the outside. */
function countingRuntime(): { runtime: SpineRuntime; calls: Record<string, number> } {
- const calls: Record<string, number> = { update: 0, batchCount: 0, submit: 0 };
+ const calls: Record<string, number> = { update: 0, world: 0, batchCount: 0, submit: 0 };
const cwrap = raw.cwrap.bind(raw);
const watched = Object.create(raw) as SpineWasmModule;
watched.cwrap = ((name: string, ret: unknown, args: unknown) => {
const fn = cwrap(name, ret as never, args as never);
return (...called: unknown[]) => {
- if (name === 'spine_update') calls.update++;
+ if (name === 'spine_advanceAndApply') calls.update++;
+ if (name === 'spine_materializeWorldPose') calls.world++;
if (name === 'spine_getMeshBatchCount') calls.batchCount++;
return (fn as (...a: unknown[]) => unknown)(...called);
};
@@ -129,7 +130,8 @@ describe.skipIf(!HAS_WASM)('what a spine frame poses, and who asked', () => {
runtime.updateAll(1 / 60);
runtime.extractAndSubmitMeshes(core, {} as never);
- expect(calls.update, 'a pose was skipped for some entity').toBe(entities);
+ expect(calls.update, 'an advance was skipped for some entity').toBe(entities);
+ expect(calls.world, 'a world pose was skipped, or resolved twice').toBe(entities);
expect(calls.batchCount, 'an extraction was skipped for some entity').toBe(entities);
runtime.dispose();
});
@@ -150,7 +152,10 @@ describe.skipIf(!HAS_WASM)('what a spine frame poses, and who asked', () => {
runtime.updateAll(1 / 60);
runtime.extractAndSubmitMeshes(core, {} as never);
- expect(calls.update, 'frozen and disabled entities did not both decline a pose').toBe(3);
+ expect(calls.update, 'frozen and disabled entities did not both decline an advance').toBe(3);
+ // A frozen entity's world already reflects its local pose, so demanding
+ // one costs nothing — the revision says the debt was already paid.
+ expect(calls.world, 'a frozen entity was re-resolved').toBe(3);
expect(calls.batchCount, 'a frozen entity stopped being drawn').toBe(5);
runtime.dispose();
});
diff --git a/sdk/tests/spine-pose-materialization.test.ts b/sdk/tests/spine-pose-materialization.test.ts
new file mode 100644
index 000000000..d57c04f0f
--- /dev/null
+++ b/sdk/tests/spine-pose-materialization.test.ts
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file spine-pose-materialization.test.ts
+ * @brief A world pose is owed, paid once, and owed again when something moves.
+ *
+ * @details The frame is not the authority; the revision is. Deduplicating by
+ * frame would be right almost always and wrong exactly when it matters:
+ * a frame that resolves the world and THEN retargets an IK constraint
+ * owes another one, and a frame-keyed cache hands the next asker a pose
+ * taken before the change.
+ *
+ * Nothing is skipped yet. Every entity's world pose is still demanded
+ * every frame — what this cut establishes is that it is DEMANDED, by
+ * consumers, rather than computed because a loop reached it.
+ */
+import { describe, it, expect, beforeAll } from 'vitest';
+import { existsSync, readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+import { WASM_DIR } from './helpers/loadWasm';
+import type { SpineWasmModule } from '../src/spine/SpineModuleLoader';
+import { SpineRuntime } from '../src/spine/SpineRuntime';
+import type { SpineEraBinding } from '../src/spine/prepareSpine';
+import type { Entity } from '../src/types';
+
+const SPINE38_JS = resolve(WASM_DIR, 'spine38.js');
+const SPINE38_WASM = resolve(WASM_DIR, 'spine38.wasm');
+const FIXTURES = resolve(__dirname, '../benchmarks/fixtures/spine');
+const HAS_WASM = existsSync(SPINE38_WASM)
+ && existsSync(resolve(FIXTURES, 'spineboy-38/spineboy-pro.skel'));
+
+let raw: SpineWasmModule;
+let skelData: Uint8Array;
+let atlasText: string;
+
+beforeAll(async () => {
+ if (!HAS_WASM) return;
+ const factory = (await import(SPINE38_JS)).default as (opts: unknown) => Promise<SpineWasmModule>;
+ const bytes = readFileSync(SPINE38_WASM);
+ raw = await factory({
+ instantiateWasm(imports: WebAssembly.Imports, cb: (i: WebAssembly.Instance, m: WebAssembly.Module) => void) {
+ void WebAssembly.instantiate(bytes, imports).then((r) => cb(r.instance, r.module));
+ return {};
+ },
+ });
+ skelData = new Uint8Array(readFileSync(resolve(FIXTURES, 'spineboy-38/spineboy-pro.skel')));
+ atlasText = readFileSync(resolve(FIXTURES, 'spineboy-38/spineboy.atlas'), 'utf-8');
+});
+
+function era(id: string): SpineEraBinding {
+ return {
+ id,
+ value: { skelData, atlasText, isBinary: true, textures: new Map() },
+ retain: () => ({ release: () => {} }),
+ };
+}
+
+/** A runtime whose world resolutions can be counted from outside it. */
+function counting(): { runtime: SpineRuntime; worlds: () => number; reset: () => void } {
+ let worlds = 0;
+ const cwrap = raw.cwrap.bind(raw);
+ const watched = Object.create(raw) as SpineWasmModule;
+ watched.cwrap = ((name: string, ret: unknown, args: unknown) => {
+ const fn = cwrap(name, ret as never, args as never);
+ return (...called: unknown[]) => {
+ if (name === 'spine_materializeWorldPose') worlds++;
+ return (fn as (...a: unknown[]) => unknown)(...called);
+ };
+ }) as never;
+ return { runtime: new SpineRuntime('3.8', watched), worlds: () => worlds, reset: () => { worlds = 0; } };
+}
+
+const core = {
+ renderer_submitSkeletalBatchByEntity: () => {},
+ _malloc: () => 0, _free: () => {}, HEAPU8: new Uint8Array(1 << 20),
+} as never;
+
+describe.skipIf(!HAS_WASM)('a world pose is owed, and paid once', () => {
+ it('a frame asks three times and pays once', () => {
+ const { runtime, worlds, reset } = counting();
+ runtime.loadEntity(1 as Entity, era('mat#1'));
+ runtime.setAnimation(1 as Entity, 'walk', true);
+ runtime.updateAll(1 / 60);
+ reset();
+
+ // The update already resolved it; every later consumer this frame finds
+ // the debt paid.
+ expect(runtime.ensurePose(1 as Entity), 'the world was resolved twice').toBe(false);
+ expect(runtime.ensurePose(1 as Entity)).toBe(false);
+ runtime.extractAndSubmitMeshes(core, {} as never);
+ expect(worlds()).toBe(0);
+ runtime.dispose();
+ });
+
+ it('retargeting a constraint owes another one, in the same frame', () => {
+ // What a frame-keyed cache gets wrong. Nothing advanced; the animation
+ // is at the same time; and the world it implies is a different one.
+ const { runtime, worlds, reset } = counting();
+ runtime.loadEntity(1 as Entity, era('mat#2'));
+ runtime.setAnimation(1 as Entity, 'walk', true);
+ runtime.updateAll(1 / 60);
+ reset();
+
+ expect(runtime.setIKTarget(1 as Entity, 'aim-ik', 100, 200, 1)
+ || runtime.setAttachment(1 as Entity, 'head', 'head')).toBe(true);
+ expect(runtime.ensurePose(1 as Entity), 'a consumer was handed the pose from before the change')
+ .toBe(true);
+ expect(worlds()).toBe(1);
+ expect(runtime.ensurePose(1 as Entity), 'and then paid for it twice').toBe(false);
+ runtime.dispose();
+ });
+
+ it('a frozen entity keeps the world it has, however many frames pass', () => {
+ // playing=false has always meant a frozen pose that is still drawn.
+ // Under revisions that is free rather than re-resolved every frame.
+ const { runtime, worlds, reset } = counting();
+ runtime.loadEntity(1 as Entity, era('mat#3'));
+ runtime.setAnimation(1 as Entity, 'walk', true);
+ runtime.updateAll(1 / 60);
+ runtime.setEntityProps(1 as Entity, { playing: false });
+ reset();
+
+ for (let frame = 0; frame < 30; frame++) {
+ runtime.updateAll(1 / 60);
+ runtime.extractAndSubmitMeshes(core, {} as never);
+ }
+ expect(worlds(), 'a frozen pose was resolved again').toBe(0);
+ runtime.dispose();
+ });
+
+ it('an advance owes a new one every frame', () => {
+ const { runtime, worlds, reset } = counting();
+ runtime.loadEntity(1 as Entity, era('mat#4'));
+ runtime.setAnimation(1 as Entity, 'walk', true);
+ reset();
+
+ for (let frame = 0; frame < 10; frame++) runtime.updateAll(1 / 60);
+ expect(worlds(), 'an advancing entity stopped being resolved').toBe(10);
+ runtime.dispose();
+ });
+
+ it('a disabled entity is not resolved at all', () => {
+ const { runtime, worlds, reset } = counting();
+ runtime.loadEntity(1 as Entity, era('mat#5'));
+ runtime.setAnimation(1 as Entity, 'walk', true);
+ runtime.setEnabled(1 as Entity, false);
+ reset();
+
+ runtime.updateAll(1 / 60);
+ expect(runtime.ensurePose(1 as Entity)).toBe(false);
+ expect(worlds()).toBe(0);
+ runtime.dispose();
+ });
+
+ it('what a frame did is reported in demand, not in calls', () => {
+ const { runtime } = counting();
+ for (let i = 0; i < 5; i++) {
+ runtime.loadEntity(i as Entity, era('mat#6'));
+ runtime.setAnimation(i as Entity, 'walk', true);
+ }
+ runtime.observe(true);
+ runtime.updateAll(1 / 60);
+ runtime.extractAndSubmitMeshes(core, {} as never);
+
+ const m = runtime.metrics()!;
+ expect(m.pose.logicalUpdates).toBe(5);
+ expect(m.pose.worldMaterializations).toBe(5);
+ expect(m.pose.worldDeferred, 'the extraction found five debts already paid').toBe(5);
+ expect(m.pose.meshExtractions).toBe(5);
+ runtime.dispose();
+ });
+});