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(tilemap): compare cell dimensions independently
yhh58771b417485
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 04c86f15b..87db26141 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,8 @@ published separately; it ships inside the editor.### Fixed+- **Fractional tile cell edits refresh the drawn and hit grids.** Tilemap layers compare width and height independently rather than combining them into a numeric cache key. Valid fractional dimensions no longer alias another size and leave stale geometry or coordinate conversion; unchanged frames still avoid native layer reinitialization.+- **Unloaded scene contexts reject late mutations.** A context belongs to one scene instance: after unload, reload or reset, it cannot spawn or adopt entities, destroy another scene's objects, change persistence, or register callbacks and post-processing bindings. A late asset scope is released before cancellation is reported, so asynchronous setup cannot strand its acquisitions.- **Scene adoption transfers existing entity ownership.** Adopting an entity into another scene removes its outgoing scene records, retains its bound asset generation, and restores any outgoing sleep state before applying the destination's state. An outgoing parent is detached while preserving world placement. Unloading the source no longer destroys the adopted entity; the destination's final unload still releases it normally, and repeated adoption preserves the saved awake state.diff --git a/sdk/src/tilemap/tilemapPlugin.ts b/sdk/src/tilemap/tilemapPlugin.tsindex 818d5e758..d9c85b9e6 100644--- a/sdk/src/tilemap/tilemapPlugin.ts+++ b/sdk/src/tilemap/tilemapPlugin.ts@@ -59,11 +59,8 @@ export class TilemapRuntime {private collisionInputs_ = new Map<number, CollisionInputs>();private applyTilesetRefs_: ((entity: number, refs: readonly string[]) => void) | null = null;private initializedLayers_ = new Set<number>();- /** TilemapLayer entity → the tile size last pushed to its C++ layer (`w*K+h`).- * The renderer + worldToTile read the C++ `tile_width`; the component `cellSize`- * is the authority, so an edit must re-push — otherwise the paint grid (cellSize)- * and the drawn/hit grid (stale tile_width) diverge and tiles land off-cursor. */- private appliedCellSize_ = new Map<number, number>();+ /** Last applied dimensions, compared separately so fractional sizes cannot alias. */+ private appliedCellSize_ = new Map<number, { x: number; y: number }>();/** TilemapLayer entity → the grid params last pushed (orientation|side|axis|index).* Grid type + stagger/hex params live in the C++ LayerData; the component is the* authority, so an orientation edit (or a cellSize re-init, which resets LayerData)@@ -294,7 +291,8 @@ export class TilemapRuntime {// init; initInfiniteLayer is idempotent (keeps chunks), so re-push// whenever the applied size drifts. Stale dims misplace every tile// relative to the paint grid (renderer + worldToTile read tile_width).- const csKey = layerData.cellSize.x * 65536 + layerData.cellSize.y;+ const cellSize = layerData.cellSize;+ const appliedSize = appliedCellSize.get(entity);let reinit = false;if (!initializedLayers.has(entity)) {TilemapAPI.initInfiniteLayer(@@ -302,13 +300,13 @@ export class TilemapRuntime {);TilemapAPI.setOriginEntity(entity, entity);initializedLayers.add(entity);- appliedCellSize.set(entity, csKey);+ appliedCellSize.set(entity, { x: cellSize.x, y: cellSize.y });reinit = true;- } else if (appliedCellSize.get(entity) !== csKey) {+ } else if (appliedSize?.x !== cellSize.x || appliedSize.y !== cellSize.y) {TilemapAPI.initInfiniteLayer(entity, layerData.cellSize.x, layerData.cellSize.y,);- appliedCellSize.set(entity, csKey);+ appliedCellSize.set(entity, { x: cellSize.x, y: cellSize.y });reinit = true;}diff --git a/sdk/tests/tilemap-multi-app-wasm.test.ts b/sdk/tests/tilemap-multi-app-wasm.test.tsindex 67f831764..0efae28c2 100644--- a/sdk/tests/tilemap-multi-app-wasm.test.ts+++ b/sdk/tests/tilemap-multi-app-wasm.test.ts@@ -2,7 +2,7 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamimport { readFileSync } from 'node:fs';import { resolve } from 'node:path';-import { afterEach, beforeAll, describe, expect, it } from 'vitest';+import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';import { HAS_WASM, WASM_DIR, WASM_FILE, loadWasmModule } from './helpers/loadWasm';import type { ESEngineModule } from '../src/wasm';import { App } from '../src/app/app';@@ -38,6 +38,23 @@ describe.skipIf(!HAS_WASM)('tilemap runtimes in independent apps', () => {await app.tick(1 / 60);return { app, entity, tiles, runtime };}+ it('applies fractional cell dimensions without a combined-key collision', async () => {+ const { app, entity, tiles } = await scene(mainCore, 1);+ const before = tiles.tileToWorld(entity, 1, 1, 0, 0);+ const reinitialize = vi.spyOn(tiles, 'initInfiniteLayer');+ app.world.update(entity, TilemapLayer, value => { value.cellSize = { x: 16 + 8 / 65536, y: 8 }; });+ await app.tick(1 / 60);+ expect(reinitialize).toHaveBeenCalledTimes(1);+ for (let i = 0; i < 20; i++) await app.tick(1 / 60);+ expect(reinitialize).toHaveBeenCalledTimes(1);+ const edited = tiles.tileToWorld(entity, 1, 1, 0, 0);+ tiles.initInfiniteLayer(entity, 16 + 8 / 65536, 8);+ const rebuilt = tiles.tileToWorld(entity, 1, 1, 0, 0);+ expect(rebuilt).not.toEqual(before);+ expect(edited).toEqual(rebuilt);+ expect(tiles.getTile(entity, 0, 0)).toBe(1);+ });+it('quitting the older app leaves the newer map and runtime alive', async () => {const main = await scene(mainCore, 1), preview = await scene(previewCore, 2);expect(main.entity).toBe(preview.entity);diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 10c7de612..9db4f8b79 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(tilemap): compare cell dimensions independently':+ { note: 'Fractional tile cell edits refresh the drawn and hit grids.' },'fix(scene): reject mutations from unloaded contexts':{ note: 'Unloaded scene contexts reject late mutations.' },'fix(scene): transfer ownership when adopting live entities':