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(render): the built-in ripple map is drawn again after a device loss, and no copy of it is kept - every game held 256 KB for a map only water reads; and the checks that went red since: a cost scene with no criterion, TilemapLayer.lit in its defaults, NativeChannel frozen before it earned it, a wav encoder that refused read-only channels, a worker test with five seconds for twenty realms
yhhe414f692013e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 665233b97..b08a8612f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -55,6 +55,7 @@ published separately; it ships inside the editor.### Fixed+- **A game no longer keeps a copy of the built-in ripple map.** The map of wind ripples water reads (256 pixels square) was made when the engine started and the device kept its bytes to put back after a loss: 262,144 bytes in every game, water or none, which is what took the device-roundtrip criteria for text and for DragonBones over their 64 KiB ceiling (315,852 read). The map is content the engine can build again from code, so it is now owed after a loss and built again; what the device keeps is back to 53,708 bytes. A new criterion, `device-roundtrip-ripples`, loses the device twice under a shader that reads `default(ripples)` and compares the frame, on both backends. With it, what had been red on master since 12 November: `NativeChannel` is no longer tagged `@public` (nothing in a golden project calls it yet), `encodeWav` takes read-only channels, and four checks say what the engine now does.- **A picture made in the editor ships as a recipe.** The editor's image tools type an `.esimage` as a picture's source, and an export sent an asset of that type out as a plain file: a scene that named one got a texture nothing could load, and a map's own picture was left out of the package. A picture's source is now that one type everywhere (a file with no `.meta` is adopted as it too), ships as a texture, has a texture's import settings, and the cook follows what it names. In the editor a texture field takes a picture's source, the viewport draws it as a game does, the image tools write a picture's normal and surface maps as recipes beside it (`wall_normal.esimage`, set as data) and answer their refs, and text is set by the same drawer a game uses. Checked in the hidden editor (written, placed on sprites, drawn) and in an export of metas of that type opened twice.- **A splatmap is read between its pixels.** A `Terrain` asked its splatmap for the nearest pixel. Near the eye a page samples the ground finer than the paint is (a splatmap of 3 m a pixel under pages of under a metre), so every pixel of the splatmap was drawn as a flat square, and a wide fade from grass into sand was a staircase of squares that smeared into streaks at a low angle. The splatmaps are now read between their four nearest pixels, on the workers as here; a ground painted in whole pixels (a brush's own) reads as it did at the pixels themselves.- **Grass on a hill is not thinned under your feet.** Plants thin with distance, and the distance was measured from their cell, which stood at the `Foliage` entity's own height while the plants stood on the ground. On a meadow 16 m up, with the eye 3 m over it, the grass underfoot was thinned as grass 19 m away: a third of the blades, each grown several times as wide, bare ground between them; on a mountain every blade was at its thinnest at any distance. A cell now stands on the ground under its centre and its plants about that height, so the distance is the one to where they are.diff --git a/desktop b/desktopindex 8e9710277..82da21bf7 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 8e9710277775e668caa8ee056985fb43a3be3fbd+Subproject commit 82da21bf7413988f086f36ce9d6880ced31d392cdiff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.jsonindex 13ba3acca..72c8d99a5 100644--- a/docs/astro/src/data/apiStability.generated.json+++ b/docs/astro/src/data/apiStability.generated.json@@ -1,12 +1,12 @@{"note": "Generated by tools/api-stability.mjs from sdk/etc/*.api.md — do not edit.","counts": {- "public": 117,+ "public": 115,"beta": 178,- "experimental": 3075,+ "experimental": 3092,"deprecated": 3},- "total": 3370,+ "total": 3385,"subsystems": [{"id": "mobile-controls",@@ -1204,30 +1204,6 @@"minigame"]},- {- "name": "NativeChannel",- "kind": "const",- "deprecated": false,- "entries": [- "index",- "index.node",- "index.native",- "wechat",- "minigame"- ]- },- {- "name": "NativeChannelApi",- "kind": "interface",- "deprecated": false,- "entries": [- "index",- "index.node",- "index.native",- "wechat",- "minigame"- ]- },{"name": "Parent","kind": "const",diff --git a/fixtures/scenes/mat-ripples/ripples.esmaterial b/fixtures/scenes/mat-ripples/ripples.esmaterialnew file mode 100644index 000000000..acc0bc438--- /dev/null+++ b/fixtures/scenes/mat-ripples/ripples.esmaterial@@ -0,0 +1,8 @@+{+ "version": "1.0",+ "type": "material",+ "shader": "ripples.esshader",+ "blendMode": 0,+ "depthTest": false,+ "properties": {}+}diff --git a/fixtures/scenes/mat-ripples/ripples.esshader b/fixtures/scenes/mat-ripples/ripples.esshadernew file mode 100644index 000000000..1477c0ba3--- /dev/null+++ b/fixtures/scenes/mat-ripples/ripples.esshader@@ -0,0 +1,33 @@+#pragma shader "RippleMap"+#pragma version 300 es+#pragma domain Unlit+#pragma param u_map texture default(ripples)++#pragma vertex+layout(location = 0) in vec3 a_position;+layout(location = 1) in vec4 a_color;+layout(location = 2) in vec2 a_texCoord;+layout(location = 3) in float a_texIndex;++out vec4 v_color;+out vec2 v_texCoord;++void main() {+ gl_Position = u_projection * vec4(a_position, 1.0);+ v_color = a_color;+ v_texCoord = a_texCoord;+}+#pragma end++#pragma fragment+precision mediump float;++in vec4 v_color;+in vec2 v_texCoord;++out vec4 fragColor;++void main() {+ fragColor = vec4(texture(u_map, v_texCoord).rgb, 1.0);+}+#pragma enddiff --git a/fixtures/scenes/ripple-map.esscene b/fixtures/scenes/ripple-map.esscenenew file mode 100644index 000000000..616368aa9--- /dev/null+++ b/fixtures/scenes/ripple-map.esscene@@ -0,0 +1,20 @@+{+ "version": 4,+ "name": "The built-in ripple map, as a shader that asks for it reads it",+ "entities": [+ {+ "id": 0, "name": "Camera", "parent": null, "children": [], "visible": true,+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 3 } } },+ { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 1, "fov": 45, "nearPlane": 0.1, "farPlane": 100, "isActive": true, "clearFlags": 3 } }+ ]+ },+ {+ "id": 1, "name": "Ripple Map", "parent": null, "children": [], "visible": true,+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 2, "y": 2 }, "material": "/scenes/mat-ripples/ripples.esmaterial" } }+ ]+ }+ ]+}diff --git a/pipeline/src/sound/soundRender.ts b/pipeline/src/sound/soundRender.tsindex faad9f1b8..40947ca52 100644--- a/pipeline/src/sound/soundRender.ts+++ b/pipeline/src/sound/soundRender.ts@@ -548,7 +548,7 @@ export function renderSound(source: SoundSource, variant = 0, at: { pitch?: numb}/** The samples as a 16-bit PCM `.wav`, which every platform the engine runs on plays. */-export function encodeWav(sound: Pick<RenderedSound, 'rate' | 'channels'>): Uint8Array {+export function encodeWav(sound: { rate: number; channels: readonly Float32Array[] }): Uint8Array {const [channels, frames] = [sound.channels.length, sound.channels[0]!.length];const bytes = new Uint8Array(44 + frames * channels * 2);const view = new DataView(bytes.buffer);diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex cbf3abf57..a2aac8f3e 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -1,7 +1,7 @@# API surface — esengine/index<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 117 public · 166 beta · 2179 experimental · 3 deprecated+Symbols: 115 public · 166 beta · 2181 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -6665,12 +6665,12 @@ ComponentDef<NameData>value: string```-## NativeChannel — const @public+## NativeChannel — const @experimental```NativeChannelApi```-## NativeChannelApi — interface @public+## NativeChannelApi — interface @experimental```available: booleancall: <T = unknown>(method: string, args?: unknown) => Promise<T>diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 2aaf94cec..f3ea56060 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.native<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 117 public · 171 beta · 2199 experimental · 3 deprecated+Symbols: 115 public · 171 beta · 2201 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -6713,12 +6713,12 @@ textEditor: NativeTextEditorBridge | undefinedwriteCacheFile: ((key: string, bytes: ArrayBuffer) => Promise<void>) | undefined```-## NativeChannel — const @public+## NativeChannel — const @experimental```NativeChannelApi```-## NativeChannelApi — interface @public+## NativeChannelApi — interface @experimental```available: booleancall: <T = unknown>(method: string, args?: unknown) => Promise<T>diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 0608dadd9..7f9ef5e89 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.node<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 117 public · 168 beta · 2178 experimental · 3 deprecated+Symbols: 115 public · 168 beta · 2180 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -6660,12 +6660,12 @@ ComponentDef<NameData>value: string```-## NativeChannel — const @public+## NativeChannel — const @experimental```NativeChannelApi```-## NativeChannelApi — interface @public+## NativeChannelApi — interface @experimental```available: booleancall: <T = unknown>(method: string, args?: unknown) => Promise<T>diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 879121b83..f20e8db20 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -1,7 +1,7 @@# API surface — esengine/minigame<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 117 public · 166 beta · 2200 experimental · 3 deprecated+Symbols: 115 public · 166 beta · 2202 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -6957,12 +6957,12 @@ ComponentDef<NameData>value: string```-## NativeChannel — const @public+## NativeChannel — const @experimental```NativeChannelApi```-## NativeChannelApi — interface @public+## NativeChannelApi — interface @experimental```available: booleancall: <T = unknown>(method: string, args?: unknown) => Promise<T>diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex b4aaeb44a..30aa6f9b0 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -1,7 +1,7 @@# API surface — esengine/wechat<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 117 public · 166 beta · 2191 experimental · 3 deprecated+Symbols: 115 public · 166 beta · 2193 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -6667,12 +6667,12 @@ ComponentDef<NameData>value: string```-## NativeChannel — const @public+## NativeChannel — const @experimental```NativeChannelApi```-## NativeChannelApi — interface @public+## NativeChannelApi — interface @experimental```available: booleancall: <T = unknown>(method: string, args?: unknown) => Promise<T>diff --git a/sdk/src/services/nativeChannel.ts b/sdk/src/services/nativeChannel.tsindex 9cdb9a996..a7aebb601 100644--- a/sdk/src/services/nativeChannel.ts+++ b/sdk/src/services/nativeChannel.ts@@ -26,7 +26,7 @@*/import { platformNativeChannel } from '../platform';-/** @public */+/** What a script can ask of the app's native code. */export interface NativeChannelApi {/** Whether this platform has native code to reach at all. */readonly available: boolean;@@ -42,7 +42,7 @@ export interface NativeChannelApi {on<T = unknown>(event: string, handler: (data: T) => void): () => void;}-/** @public */+/** The app's native code, by name: see the file's own note for what each platform answers. */export const NativeChannel: NativeChannelApi = {get available(): boolean {return platformNativeChannel() !== null;diff --git a/sdk/tests/basis-workers.test.ts b/sdk/tests/basis-workers.test.tsindex 91de17fb9..fef146eea 100644--- a/sdk/tests/basis-workers.test.ts+++ b/sdk/tests/basis-workers.test.ts@@ -148,7 +148,9 @@ describe.skipIf(!hasSideModule('basis'))('KTX2 transcoding on workers', () => {host.dispose!();}expect(StandInWorker.live).toBe(before);- });+ // Twenty realms, each loading the transcoder: two seconds here and past the default five on a loaded runner, where the+ // timeout left four workers alive for the next test to count.+ }, 30_000);it('goes back to the main thread, once and for good, when the workers fail', async () => {const warn = vi.spyOn(log, 'warn');diff --git a/sdk/tests/tilemap.test.ts b/sdk/tests/tilemap.test.tsindex 14a57f255..150dcd5d1 100644--- a/sdk/tests/tilemap.test.ts+++ b/sdk/tests/tilemap.test.ts@@ -83,6 +83,7 @@ describe('Tilemap Components', () => {opacity: 1,parallaxFactor: { x: 1, y: 1 },visible: true,+ lit: false,});});});diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex b1113a94d..78a3b07a3 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -339,7 +339,10 @@ bool provideReplacementDevice() {*/bool recoverDevice() {GfxDevice* device = activeGfxDevice();- return device && device->recoverDevice();+ if (!device || !device->recoverDevice()) return false;+ // What the render context built from code it builds again; everything else owed has a provider on the other side.+ if (auto* context = g_renderContext) context->restoreBuiltinContent();+ return true;}/**diff --git a/src/esengine/renderer/frame/RenderContext.cpp b/src/esengine/renderer/frame/RenderContext.cppindex 6b75f19da..48b553cd3 100644--- a/src/esengine/renderer/frame/RenderContext.cpp+++ b/src/esengine/renderer/frame/RenderContext.cpp@@ -105,6 +105,12 @@ TextureHandle RenderContext::make1x1Texture(u32 rgba) {return device_.createTexture(desc, GfxContent::retained(), &rgba);}+namespace {+/// Content this context builds from nothing but code, and builds again after a loss: the device keeps no copy of it.+constexpr u32 BUILTIN_CONTENT_PROVIDER = 0x4255494C;+constexpr u32 BUILTIN_RIPPLES = 1;+} // namespace+TextureHandle RenderContext::makeRipplesTexture() {TextureDesc desc;desc.width = RIPPLE_NORMALS_SIZE;@@ -113,11 +119,25 @@ TextureHandle RenderContext::makeRipplesTexture() {desc.wrapT = TextureWrap::Repeat;desc.mipmaps = true;const std::vector<u8> pixels = buildRippleNormals();- const TextureHandle texture = device_.createTexture(desc, GfxContent::retained(), pixels.data());+ const TextureHandle texture =+ device_.createTexture(desc, GfxContent::sourced(BUILTIN_CONTENT_PROVIDER, BUILTIN_RIPPLES), pixels.data());if (texture != TextureHandle::Invalid) device_.generateMipmaps(texture);return texture;}+void RenderContext::restoreBuiltinContent() {+ for (const GfxOwedContent& owed : device_.owedContent()) {+ if (owed.kind != GfxOwedContent::Kind::Texture || owed.provider != BUILTIN_CONTENT_PROVIDER) continue;+ if (owed.key != BUILTIN_RIPPLES || ripplesTexture_ == TextureHandle::Invalid) {+ device_.forgoContent(owed);+ continue;+ }+ const std::vector<u8> pixels = buildRippleNormals();+ device_.updateTexture(ripplesTexture_, 0, 0, RIPPLE_NORMALS_SIZE, RIPPLE_NORMALS_SIZE, pixels.data(), false);+ device_.restoreContent(owed);+ }+}+void RenderContext::initDefaultTextures() {// Byte order in memory is R,G,B,A; these u32s are little-endian (so 0xAABBGGRR).whiteTexture_ = make1x1Texture(0xFFFFFFFF); // RGBA(255,255,255,255)diff --git a/src/esengine/renderer/frame/RenderContext.hpp b/src/esengine/renderer/frame/RenderContext.hppindex cd2b07b8d..72634cdd2 100644--- a/src/esengine/renderer/frame/RenderContext.hpp+++ b/src/esengine/renderer/frame/RenderContext.hpp@@ -84,6 +84,11 @@ public:*/void shutdown();+ /**+ * @brief Builds again what this context made from code alone and the device lost: call once the device is back.+ */+ void restoreBuiltinContent();+/*** @brief Checks if the context is initialized* @return True if init() has been called successfullydiff --git a/tools/check-fixture-scenes.mjs b/tools/check-fixture-scenes.mjsindex 56254281f..772721322 100644--- a/tools/check-fixture-scenes.mjs+++ b/tools/check-fixture-scenes.mjs@@ -33,6 +33,9 @@ const UNDRIVEN = {// Pixel-perfect snapping moves a solid-colour sprite by less than a fifth of// a pixel here: the fixture has no texture whose sampling would show it.'pixel-perfect.esscene': 'a camera at a fractional position snapped to whole pixels',+ // A scene to measure and not to judge: it is handed to the render host by name when the cost of lit sprites is read+ // (docs/GPU_PERFORMANCE_OPTIONS.md), and a cost is a number for a machine, which no criterion here can hold.+ 'sprite-lit-cost.esscene': 'what 32 layers of lit sprites cost a frame on each backend',};const drivers = [];diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 6cf7e27dc..9a11b3f6a 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -4696,6 +4696,8 @@ export const NOTED = {{"note": "A recipe is read wherever an image is, with its text, its figures and its surface maps."},"feat(assets): a picture's source is one kind of asset that ships as a texture - an .esimage made in the editor is a recipe an export carries and a game draws, where its type sent it out as a file nothing loads; the editor takes it in a texture field and writes a picture's maps as recipes beside it":{"note": "A picture made in the editor ships as a recipe."},+ "fix(render): the built-in ripple map is drawn again after a device loss, and no copy of it is kept - every game held 256 KB for a map only water reads; and the checks that went red since: a cost scene with no criterion, TilemapLayer.lit in its defaults, NativeChannel frozen before it earned it, a wav encoder that refused read-only channels, a worker test with five seconds for twenty realms":+ {"note": "A game no longer keeps a copy of the built-in ripple map."},"fix(terrain): a detail the pages cannot hold no longer cracks the ground - a tree that wanted more nodes than the atlas has pages was drawn in part by coarser pages standing in, which do not meet their finer neighbours' edges, and the pages were fought over every frame; the ground is now drawn at the share of its detail's range that fits, and says so once":{"note": "A detail the pages cannot hold no longer cracks the ground."},"fix(foliage): a far plant grows across the ground, not taller - a mesh plant kept in a far version was grown the same every way to cover the ground of those left out, so a flower that stood for ten stood ten times as high and a far meadow was a field of poles; it now grows across the ground only, and Foliage.farGrowUp gives its height a share of the growth back":diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex 470698ebc..e0a60b7a8 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -1114,6 +1114,9 @@ export const SCENES = [{ id: "device-roundtrip-morph-material", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/mesh-morph-mat.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },{ id: "device-roundtrip-shadow-material", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/mesh-shadow-material.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },{ id: "device-roundtrip-sky", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/mesh-sky.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },+ // The built-in ripple map is drawn from code and the device keeps no copy of it: after a loss it is drawn again, and a+ // shader that asks for default(ripples) reads the same waves and not the placeholder.+ { id: "device-roundtrip-ripples", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/ripple-map.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3", ESTELLA_VERIFY_COUNTERS_MAX: "{\"render.retained.bytes\":65536}" } },// A restored WebGL context has no extension enabled: unless the engine enables them again, the float targets of an HDR chain come back incomplete and the frame is black.{ id: "device-roundtrip-hdr-bloom", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/hdr-bloom.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/hdr-bloom.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10" } },{ id: "device-roundtrip-env", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/mat-env.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },