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
fix(native): text reaches the engine, which wanted one more argument
yhh43cb5581082f
diff --git a/sdk/src/ecs/bridge/nativeRuntime.ts b/sdk/src/ecs/bridge/nativeRuntime.tsindex 0b585520f..348671af2 100644--- a/sdk/src/ecs/bridge/nativeRuntime.ts+++ b/sdk/src/ecs/bridge/nativeRuntime.ts@@ -230,7 +230,15 @@ function installNativeRenderer(app: App, scope: Record<string, unknown>): void {* text, exactly as a host without an audio device stays silent.*/function installNativeUI(app: App, scope: Record<string, unknown>): void {- if (!hasTextBindings(scope)) return;+ if (!hasTextBindings(scope)) {+ // Named, because what this drops is the whole UI plugin — layout, masks,+ // interaction, focus — and a host missing one binding looks from the frame+ // like a scene that simply has no UI in it.+ const missing = Object.values(TEXT_BINDINGS).filter((n) => typeof scope[n] !== 'function');+ log.warn('native', `no UI: this host binds no ${missing.join(', ')}, and the UI plugin `+ + 'owns layout and interaction as well as text');+ return;+ }// The engine's own renderer_submitTextBatch, generated for QuickJS: same// argument list as the wasm call in ui/text/submit.ts, because it IS that@@ -239,11 +247,11 @@ function installNativeUI(app: App, scope: Record<string, unknown>): void {const submit = scope[TEXT_BINDINGS.submitTextBatch] as (vertices: Float32Array, vertexCount: number, indices: Uint16Array, indexCount: number,textureId: number, transform: Float32Array, entity: number, layer: number,- depth: number, sdf: number,+ depth: number, sdf: number, cullBit: number,) => void;- setNativeTextSubmit((vertices, vertexCount, indices, textureId, transform, entity, layer, depth, sdf) => {+ setNativeTextSubmit((vertices, vertexCount, indices, textureId, transform, entity, layer, depth, sdf, cullBit) => {submit(vertices, vertexCount, indices, indices.length, textureId, transform,- entity, layer, depth, sdf ? 1 : 0);+ entity, layer, depth, sdf ? 1 : 0, cullBit);});app.addPlugin(uiPlugin);}diff --git a/sdk/src/ui/text/glyph-atlas.ts b/sdk/src/ui/text/glyph-atlas.tsindex 29164725f..becb4729a 100644--- a/sdk/src/ui/text/glyph-atlas.ts+++ b/sdk/src/ui/text/glyph-atlas.ts@@ -17,6 +17,7 @@* therefore carries no display size — only (font, codepoint, style).*/import { ShelfPacker, type Packer } from '../../util/shelfPack';+import { log } from '../../util/logger';/** A glyph rendered to an upload-ready bitmap plus its layout metrics (in render-size px). */export interface RasterGlyph {@@ -150,6 +151,9 @@ export class GlyphAtlas {: Math.max(1, Math.round(displaySize * this.dpr * this.contentScale_));}+ /** Families already reported as producing no glyph — one line each, not one per character. */+ private readonly mute_ = new Set<string>();+private key(codepoint: number, fontFamily: string, style: number, pixelSize: number): string {return `${fontFamily}|${codepoint}|${style % STYLE_COUNT_HINT}|${pixelSize}`;}@@ -166,6 +170,14 @@ export class GlyphAtlas {const raster = this.rasterizer.rasterize(codepoint, fontFamily, style, pixelSize);if (!raster) {+ // Once per family, because the alternative is what this cost to find:+ // a rasterizer answering null for every codepoint draws no text and+ // says nothing, on a screen full of everything else that worked.+ if (!this.mute_.has(fontFamily)) {+ this.mute_.add(fontFamily);+ log.warn('text', `no glyph for U+${codepoint.toString(16).toUpperCase()} in `+ + `"${fontFamily}" — this family produced none, so its text draws nothing`);+ }this.cache.set(k, null);return null;}diff --git a/sdk/src/ui/text/submit.ts b/sdk/src/ui/text/submit.tsindex 8319ac4e4..1c4db26b9 100644--- a/sdk/src/ui/text/submit.ts+++ b/sdk/src/ui/text/submit.ts@@ -28,6 +28,7 @@ export type NativeTextBatchSubmit = (layer: number,depth: number,sdf: boolean,+ cullBit: number,) => void;let nativeSubmit_: NativeTextBatchSubmit | null = null;@@ -60,7 +61,7 @@ export function submitTextBatch(if (vertexCount <= 0 || indices.length <= 0 || transform.length < 16) return;// No wasm heap (the native core): the host reads the arrays as they are.if (!module?.renderer_submitTextBatch) {- nativeSubmit_?.(vertices, vertexCount, indices, textureId, transform, entity, layer, depth, sdf);+ nativeSubmit_?.(vertices, vertexCount, indices, textureId, transform, entity, layer, depth, sdf, cullBit);return;}diff --git a/sdk/tests/nativeTextSubmit.test.ts b/sdk/tests/nativeTextSubmit.test.tsnew file mode 100644index 000000000..e943c8d8b--- /dev/null+++ b/sdk/tests/nativeTextSubmit.test.ts@@ -0,0 +1,49 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team++// The native submit seam carries every argument the engine entry point takes.+// The far side is generated from the C++ signature and opens `if (argc < 11)+// return`, so a seam one argument short draws nothing and says nothing.+import { describe, it, expect } from 'vitest';+import { submitTextBatch, setNativeTextSubmit, TEXT_VERTEX_FLOATS } from '../src/ui/text/submit';++function capture() {+ const calls: unknown[][] = [];+ setNativeTextSubmit((...args: unknown[]) => { calls.push(args); });+ return calls;+}++const vertices = new Float32Array(TEXT_VERTEX_FLOATS * 4);+const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);+const transform = new Float32Array(16);++describe('the native text submit seam', () => {+ it('passes cullBit on, so the host binding sees a full argument list', () => {+ const calls = capture();+ submitTextBatch(null, vertices, indices, 7, transform, 42, 3, 0.5, true, 0b1010);+ setNativeTextSubmit(null);++ expect(calls).toHaveLength(1);+ // vertices, vertexCount, indices, textureId, transform, entity, layer, depth, sdf, cullBit+ expect(calls[0]).toHaveLength(10);+ expect(calls[0][9]).toBe(0b1010);+ });++ it('defaults cullBit rather than dropping the argument', () => {+ const calls = capture();+ submitTextBatch(null, vertices, indices, 7, transform, 42, 3, 0.5, false);+ setNativeTextSubmit(null);++ expect(calls[0]).toHaveLength(10);+ expect(calls[0][9]).toBe(0);+ });++ it('says nothing for a batch with no geometry', () => {+ const calls = capture();+ submitTextBatch(null, new Float32Array(0), indices, 7, transform, 42, 3, 0.5, true);+ submitTextBatch(null, vertices, new Uint16Array(0), 7, transform, 42, 3, 0.5, true);+ setNativeTextSubmit(null);++ expect(calls).toHaveLength(0);+ });+});