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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
test(spine): the wasm tests load skeletons through SpineModuleController, so they follow its atlas encoding
yhh1baf1003947b
diff --git a/sdk/tests/spine-batch-storage.test.ts b/sdk/tests/spine-batch-storage.test.tsindex 4007b6f69..d5b8920da 100644--- a/sdk/tests/spine-batch-storage.test.ts+++ b/sdk/tests/spine-batch-storage.test.ts@@ -23,6 +23,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { withScratch } from '../src/wasm/wasmScratch';@@ -97,11 +98,7 @@ function storage(): Storage {function posed(asset: { skel: string; atlas: string }, texture = 1): number {const skelData = new Uint8Array(readFileSync(resolve(FIXTURES, asset.skel)));const atlasText = readFileSync(resolve(FIXTURES, asset.atlas), 'utf-8');- const skelHandle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlasText, atlasText.length, true);- });+ const skelHandle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlasText, true);for (let i = 0, pages = api.getAtlasPageCount(skelHandle); i < pages; i++) {api.setAtlasPageTexture(skelHandle, i, texture, 1024, 1024);}diff --git a/sdk/tests/spine-clip-convex-bypass.test.ts b/sdk/tests/spine-clip-convex-bypass.test.tsindex 3feca0614..a833e7c75 100644--- a/sdk/tests/spine-clip-convex-bypass.test.ts+++ b/sdk/tests/spine-clip-convex-bypass.test.ts@@ -22,6 +22,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { withScratch } from '../src/wasm/wasmScratch';import { syntheticSkeleton } from './helpers/syntheticSpine';@@ -62,11 +63,7 @@ beforeAll(async () => {function instanceOf(options: SyntheticOptions): number {const { json, atlas } = syntheticSkeleton(options);const skelData = new TextEncoder().encode(json);- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlas, atlas.length, false);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlas, false);if (handle < 0) throw new Error(api.getLastError());api.setAtlasPageTexture(handle, 0, 1, 64, 64);const instanceId = api.createInstance(handle);@@ -156,11 +153,7 @@ describe.skipIf(!HAS_WASM)('a convex region is its own only piece', () => {it('coin opens without being triangulated', () => {const skelData = new Uint8Array(readFileSync(resolve(FIXTURES, 'coin-38/coin-pro.skel')));const atlasText = readFileSync(resolve(FIXTURES, 'coin-38/coin.atlas'), 'utf-8');- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlasText, atlasText.length, true);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlasText, true);api.setAtlasPageTexture(handle, 0, 1, 1024, 1024);const instanceId = api.createInstance(handle);api.playAnimation(instanceId, 'animation', true, 0);diff --git a/sdk/tests/spine-clip-parity.test.ts b/sdk/tests/spine-clip-parity.test.tsindex 1bbaf354c..fd9bd1918 100644--- a/sdk/tests/spine-clip-parity.test.ts+++ b/sdk/tests/spine-clip-parity.test.ts@@ -20,6 +20,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { withScratch } from '../src/wasm/wasmScratch';import { syntheticSkeleton } from './helpers/syntheticSpine';@@ -72,11 +73,7 @@ function instanceOf(test: (typeof CASES)[number]): number {const atlas = real? readFileSync(resolve(FIXTURES, test.atlas!), 'utf-8'): syntheticSkeleton(test.options!).atlas;- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlas, atlas.length, real);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlas, real);if (handle < 0) throw new Error(`${test.name}: ${api.getLastError()}`);for (let i = 0, pages = api.getAtlasPageCount(handle); i < pages; i++) {api.setAtlasPageTexture(handle, i, 1, 1024, 1024);diff --git a/sdk/tests/spine-clip-stages.test.ts b/sdk/tests/spine-clip-stages.test.tsindex 256ce99f2..4ca5e8846 100644--- a/sdk/tests/spine-clip-stages.test.ts+++ b/sdk/tests/spine-clip-stages.test.ts@@ -15,6 +15,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { withScratch } from '../src/wasm/wasmScratch';import { syntheticSkeleton } from './helpers/syntheticSpine';@@ -57,11 +58,7 @@ beforeAll(async () => {function instanceOf(options: SyntheticOptions): number {const { json, atlas } = syntheticSkeleton(options);const skelData = new TextEncoder().encode(json);- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlas, atlas.length, false);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlas, false);if (handle < 0) throw new Error(api.getLastError());for (let i = 0, pages = api.getAtlasPageCount(handle); i < pages; i++) {api.setAtlasPageTexture(handle, i, 1, 64, 64);@@ -188,11 +185,7 @@ describe.skipIf(!HAS_WASM)('the clip fast paths answer without cutting', () => {// test earns its place on a shipped asset, not only an authored one.const skelData = new Uint8Array(readFileSync(resolve(FIXTURES, 'spineboy-38/spineboy-pro.skel')));const atlasText = readFileSync(resolve(FIXTURES, 'spineboy-38/spineboy.atlas'), 'utf-8');- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlasText, atlasText.length, true);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlasText, true);api.setAtlasPageTexture(handle, 0, 1, 2048, 2048);const instanceId = api.createInstance(handle);expect(api.playAnimation(instanceId, 'portal', true, 0)).toBeTruthy();diff --git a/sdk/tests/spine-clip-start.test.ts b/sdk/tests/spine-clip-start.test.tsindex 0e20357fc..a8a413a4b 100644--- a/sdk/tests/spine-clip-start.test.ts+++ b/sdk/tests/spine-clip-start.test.ts@@ -19,6 +19,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { SpineRuntime } from '../src/spine/SpineRuntime';import type { SpineEraBinding } from '../src/spine/prepareSpine';@@ -63,11 +64,7 @@ beforeAll(async () => {function instanceOf(options: SyntheticOptions): number {const { json, atlas } = syntheticSkeleton(options);const skelData = new TextEncoder().encode(json);- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlas, atlas.length, false);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlas, false);if (handle < 0) throw new Error(api.getLastError());api.setAtlasPageTexture(handle, 0, 1, 64, 64);const instanceId = api.createInstance(handle);@@ -148,11 +145,7 @@ describe.skipIf(!HAS_WASM)('the staged open is the shipped open', () => {// is one polygon at one pose, which is a point, not a slope.const skelData = new Uint8Array(readFileSync(resolve(FIXTURES, 'coin-38/coin-pro.skel')));const atlasText = readFileSync(resolve(FIXTURES, 'coin-38/coin.atlas'), 'utf-8');- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlasText, atlasText.length, true);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlasText, true);api.setAtlasPageTexture(handle, 0, 1, 1024, 1024);const instanceId = api.createInstance(handle);api.playAnimation(instanceId, 'animation', true, 0);diff --git a/sdk/tests/spine-extract-stages.test.ts b/sdk/tests/spine-extract-stages.test.tsindex b7224604c..f973651d7 100644--- a/sdk/tests/spine-extract-stages.test.ts+++ b/sdk/tests/spine-extract-stages.test.ts@@ -20,6 +20,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { SpineRuntime } from '../src/spine/SpineRuntime';import { withScratch } from '../src/wasm/wasmScratch';@@ -68,11 +69,7 @@ beforeAll(async () => {function posed(asset: { skel: string; atlas: string }): { skelHandle: number; instanceId: number } {const skelData = new Uint8Array(readFileSync(resolve(FIXTURES, asset.skel)));const atlasText = readFileSync(resolve(FIXTURES, asset.atlas), 'utf-8');- const skelHandle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlasText, atlasText.length, true);- });+ const skelHandle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlasText, true);for (let i = 0, pages = api.getAtlasPageCount(skelHandle); i < pages; i++) {api.setAtlasPageTexture(skelHandle, i, 1, 1024, 1024);}diff --git a/sdk/tests/spine-phase-split.test.ts b/sdk/tests/spine-phase-split.test.tsindex 3c2099308..3468f4ae5 100644--- a/sdk/tests/spine-phase-split.test.ts+++ b/sdk/tests/spine-phase-split.test.ts@@ -21,6 +21,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { withScratch } from '../src/wasm/wasmScratch';import { drawnGeometry } from './helpers/clipGeometry';@@ -64,11 +65,7 @@ function skeletonOf(asset: (typeof ASSETS)[number]): number {if (cached !== undefined) return cached;const skelData = new Uint8Array(readFileSync(resolve(FIXTURES, asset.skel)));const atlasText = readFileSync(resolve(FIXTURES, asset.atlas), 'utf-8');- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlasText, atlasText.length, true);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlasText, true);if (handle < 0) throw new Error(api.getLastError());for (let i = 0, pages = api.getAtlasPageCount(handle); i < pages; i++) {api.setAtlasPageTexture(handle, i, 1, 2048, 2048);diff --git a/sdk/tests/spine-pose-demand.test.ts b/sdk/tests/spine-pose-demand.test.tsindex a0f272703..14351e6de 100644--- a/sdk/tests/spine-pose-demand.test.ts+++ b/sdk/tests/spine-pose-demand.test.ts@@ -21,6 +21,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { SpineRuntime } from '../src/spine/SpineRuntime';import type { SpineEraBinding } from '../src/spine/prepareSpine';@@ -54,11 +55,7 @@ beforeAll(async () => {});function loadSkeleton(): number {- const handle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlasText, atlasText.length, true);- });+ const handle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlasText, true);if (handle < 0) throw new Error(api.getLastError());api.setAtlasPageTexture(handle, 0, 1, 2048, 2048);return handle;diff --git a/sdk/tests/spine-pose-stages.test.ts b/sdk/tests/spine-pose-stages.test.tsindex d13bde704..f440294b2 100644--- a/sdk/tests/spine-pose-stages.test.ts+++ b/sdk/tests/spine-pose-stages.test.ts@@ -19,6 +19,7 @@ import { existsSync, readFileSync } from 'node:fs';import { resolve } from 'node:path';import { WASM_DIR, hasSideModule } from './helpers/loadWasm';import { wrapSpineModule } from '../src/spine/SpineModuleLoader';+import { SpineModuleController } from '../src/spine/SpineController';import type { SpineWasmModule, SpineWrappedAPI } from '../src/spine/SpineModuleLoader';import { withScratch } from '../src/wasm/wasmScratch';@@ -60,11 +61,7 @@ beforeAll(async () => {const skelData = new Uint8Array(readFileSync(resolve(FIXTURES, SKEL)));const atlasText = readFileSync(resolve(FIXTURES, ATLAS), 'utf-8');- skelHandle = withScratch(raw, (alloc) => {- const ptr = alloc(skelData.length);- raw.HEAPU8.set(skelData, ptr);- return api.loadSkeleton(ptr, skelData.length, atlasText, atlasText.length, true);- });+ skelHandle = new SpineModuleController(raw, api).loadSkeleton(skelData, atlasText, true);for (let i = 0, pages = api.getAtlasPageCount(skelHandle); i < pages; i++) {api.setAtlasPageTexture(skelHandle, i, 1, 1024, 1024);}diff --git a/sdk/tests/ui-text-render-mode.test.ts b/sdk/tests/ui-text-render-mode.test.tsindex 00f7fa23c..d446f518f 100644--- a/sdk/tests/ui-text-render-mode.test.ts+++ b/sdk/tests/ui-text-render-mode.test.ts@@ -160,7 +160,7 @@ describe('world text under a perspective camera', () => {it('draws Auto text as SDF there, at any scale, and keeps a forced mode', async () => {const { domainViewOf, glyphKind } = await import('../src/ui/text/plugin');const view = domainViewOf(perspective(55, 16 / 9), 1920, 1);- const at = (scale: number, renderMode = TextRenderMode.Auto) =>+ const at = (scale: number, renderMode: TextRenderMode = TextRenderMode.Auto) =>glyphKind({ renderMode }, { worldScale: { x: scale, y: scale, z: scale } }, 'sans-serif', view);expect(at(1)).toBe('sdf');expect(at(1.5)).toBe('sdf');