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(terrain): a ground with more pages wanted than it holds no longer throws every frame - the pages it had chosen to draw were marked in use only after new pages were made, so a new page took the slot of one about to be drawn and its node was placed on nothing
yhh43d62e0fe323
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fb7c40549..fece70519 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -57,6 +57,7 @@ published separately; it ships inside the editor.### Fixed+- **A large ground no longer throws every frame once its pages run out.** With every page slot in use (a `detail` that wants more than the 900 there are, or a long flight), `TerrainSystem` threw `Cannot read properties of undefined (reading 'slot')` each frame: the ground stopped following the eye, and the log filled. The ground chose what to draw, made new pages, then placed its nodes, and a page was marked as in use only when placed; a page made in between took the slot of the least recently drawn one, which was a page just chosen. What is drawn is now marked before anything is made, and when every slot is drawn that frame the new page waits.- **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.diff --git a/sdk/src/terrain/terrainPlugin.ts b/sdk/src/terrain/terrainPlugin.tsindex 8ee35f4f0..b7e830fbc 100644--- a/sdk/src/terrain/terrainPlugin.ts+++ b/sdk/src/terrain/terrainPlugin.ts@@ -1025,6 +1025,9 @@ export class TerrainPlugin implements Plugin {if (covered.has(nodeKey(up.level, up.ix, up.iz))) { drawn.delete(key); break; }}}+ // What is drawn this frame is in use before any page is made: a page made now takes the slot of the least recently drawn,+ // and a page chosen above and not yet marked was that one, gone by the time its node was placed.+ for (const key of drawn.keys()) table.touch(key);this.makePages(app, built, source, eyeAt, t.worldPosition);const set = (name: string, value: Parameters<typeof Material.setUniform>[2]): void => { Material.setUniform(built.instance, name, value); };diff --git a/sdk/tests/terrain-page-budget.test.ts b/sdk/tests/terrain-page-budget.test.tsindex 093a800d5..58530bf76 100644--- a/sdk/tests/terrain-page-budget.test.ts+++ b/sdk/tests/terrain-page-budget.test.ts@@ -1,6 +1,6 @@// SPDX-License-Identifier: Apache-2.0import { describe, expect, it } from 'vitest';-import { makePage, makePageJob, PAGE_SIDE, type PageImage } from '../src/terrain/pages';+import { makePage, makePageJob, PageTable, PAGE_SIDE, type PageImage } from '../src/terrain/pages';import { noiseProvider, ProviderSource } from '../src/terrain/provider';import type { TerrainSource } from '../src/terrain/source';@@ -50,3 +50,19 @@ describe('incremental terrain pages', () => {expect(calls).toBe(before);});});++describe('a full page table', () => {+ // The ground chooses what it draws, then makes pages, then places its nodes. A page chosen and not yet marked is the least+ // recently drawn there is, so the page made next took its slot and the node placed after had no page (a throw every frame).+ it('gives up the least recently drawn page, and never one marked as drawn this frame', () => {+ const table = new PageTable(PAGE_SIDE * 2);+ for (const key of ['a', 'b', 'c', 'd']) expect(table.claim(key, 0, 1)).not.toBeNull();+ table.tick();+ for (const key of ['a', 'b', 'c']) table.touch(key);+ expect(table.claim('e', 0, 1)).not.toBeNull();+ expect(['a', 'b', 'c', 'd'].map((key) => table.get(key) !== undefined)).toEqual([true, true, true, false]);+ // With every page drawn this frame there is no slot to give, and the page waits a frame.+ table.touch('e');+ expect(table.claim('f', 0, 1)).toBeNull();+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 0203ef51b..b2222f4d1 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -4698,6 +4698,8 @@ export const NOTED = {{"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 ground with more pages wanted than it holds no longer throws every frame - the pages it had chosen to draw were marked in use only after new pages were made, so a new page took the slot of one about to be drawn and its node was placed on nothing":+ {"note": "A large ground no longer throws every frame once its pages run out."},"chore(gates): what the checks asked of this week's work - a disposition for esengine/image in a native script and its namespace there, Waterfall's width and its place in the corpus, the recipe worker's bundle as not a contract, shadeLight2D's inout against its return, and a test that named App as a type":{"internal": "tables the gates read, brought level; a natively packaged script can now import esengine/image, which no native game has run yet"},"feat(image): a picture's source goes where a texture goes, and its maps are recipes too - a texture field takes an .esimage, the image tools write a picture's normal and surface maps as recipes beside it and answer their refs, text is set by the drawer a game sets it with, and the viewport draws a recipe as a game does":