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
feat(2d): a cooked streamed world can be cut on x and y, so a 2D scene is a grid and not one row
yhhc347a137f352
diff --git a/desktop b/desktopindex 10abc04d4..d2e2b614c 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 10abc04d4d1206b8f92035b1bee9f9ff3f6d1b8f+Subproject commit d2e2b614c23b95bf232c4f5e0cc9cb7b5528c213diff --git a/docs/astro/src/content/docs/world/streaming.mdx b/docs/astro/src/content/docs/world/streaming.mdxindex c49c57806..17a3d812e 100644--- a/docs/astro/src/content/docs/world/streaming.mdx+++ b/docs/astro/src/content/docs/world/streaming.mdx@@ -109,8 +109,10 @@ The entry scene the package boots is what is left after the cells are taken outof it — the things residency never removes. Cells are **not** switchable scenes:they are content residency brings in, and a game never names one.-Cells are cut on the XZ plane only. A cell is a vertical column, so a tower's-floors are one place.+Cells are cut on one plane. By default that is the ground (world x and z): a cell is a vertical column, so a tower's floors are one place. A 2D world+lies in the screen plane, where every entity has the same z, so set `plane` to **Screen (x, y)** (`StreamPlane.Screen`) and the cells are cut along+world x and y instead; the streaming sources are then read by their x and y too. Without it a 2D world falls into one row of cells along x. The same+field, `plane: 'xy'`, is in the cooked manifest (`WorldManifest.plane`), and a cell's `z` is then world y.## The rules a streamed world has to obeydiff --git a/docs/astro/src/content/docs/zh-cn/world/streaming.mdx b/docs/astro/src/content/docs/zh-cn/world/streaming.mdxindex 380d7f50c..e0e8b2ec0 100644--- a/docs/astro/src/content/docs/zh-cn/world/streaming.mdx+++ b/docs/astro/src/content/docs/zh-cn/world/streaming.mdx@@ -95,7 +95,7 @@ main.esscene ──cook──▶ main.esscene 持久世界包体启动的入口场景,是把格子取走之后剩下的东西——residency 永远不会移除的那部分。格子**不是**可切换的场景:它们是 residency 带进来的内容,游戏永远不会点名其中任何一个。-格子只在 XZ 平面上切。一个格子是一根垂直柱体,所以一座塔的各层是同一个地方。+格子只在一个平面上切。默认是地面(世界 x 与 z):一个格子是一根垂直柱体,所以一座塔的各层是同一个地方。2D 世界躺在屏幕平面里,所有实体的 z 都一样,这时把 `plane` 设为 **Screen (x, y)**(`StreamPlane.Screen`),格子就沿世界 x 与 y 切,流送源也按 x、y 读取。不设的话,2D 世界会落进沿 x 的一行格子里。烘焙后的清单里也有同一个字段(`WorldManifest.plane`,值为 `'xy'`),此时格子的 `z` 就是世界 y。## 一个流送世界必须遵守的规则diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.jsonindex 2449d0609..f2cf0726d 100644--- a/docs/astro/src/data/apiStability.generated.json+++ b/docs/astro/src/data/apiStability.generated.json@@ -3,10 +3,10 @@"counts": {"public": 115,"beta": 171,- "experimental": 2669,+ "experimental": 2672,"deprecated": 3},- "total": 2955,+ "total": 2958,"subsystems": [{"id": "mobile-controls",diff --git a/docs/astro/src/data/components.generated.json b/docs/astro/src/data/components.generated.jsonindex d8586f0e7..18760dc02 100644--- a/docs/astro/src/data/components.generated.json+++ b/docs/astro/src/data/components.generated.json@@ -5593,12 +5593,23 @@"key": "cellSize","type": "number","default": "1000",- "doc": "Edge of one cell on the XZ plane.",+ "doc": "Edge of one cell on the plane.","range": "≥ 1"+ },+ {+ "key": "plane",+ "type": "enum",+ "default": "Ground (x, z)",+ "doc": "Which two world axes the cells are cut along: a 3D world is cut on the ground, a 2D world on the screen plane.",+ "values": [+ "Ground (x, z)",+ "Screen (x, y)"+ ]}],"animatable": [- "cellSize"+ "cellSize",+ "plane"]},{diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex c74d0c798..904d6ea3a 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: 115 public · 159 beta · 1925 experimental · 3 deprecated+Symbols: 115 public · 159 beta · 1928 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -10088,6 +10088,12 @@ toActivate: string[]toDeactivate: string[]```+## StreamPlane — enum @experimental+```+Ground = 0+Screen = 1+```+## StreamPolicy — type @experimental```'unload' | 'sleep'@@ -10101,6 +10107,7 @@ ComponentDef<StreamedWorldData>## StreamedWorldData — interface @experimental```cellSize: number+plane: StreamPlane```## StudioPreviewReport — interface @experimental@@ -12649,6 +12656,7 @@ static prototype: WorldGenscellSize: numbercells: WorldCell[]persistentRefs: number[]+plane: "xz" | "xy" | undefinedscene: stringversion: number```@@ -12660,6 +12668,7 @@ cells: PartitionedCell[]errors: string[]persistent: SceneDatapersistentRefs: number[]+plane: "xz" | "xy"warnings: string[]```@@ -12722,6 +12731,7 @@ loadCount: numberloadingCells: string[]persistentEntities: numberpersistentHandles: number[]+plane: "xz" | "xy"prefetchCells: string[]prefetchHits: numberprefetchMisses: number@@ -14854,6 +14864,11 @@ Logger(world: World, entity: Entity, init?: WidgetInteractionInit): void```+## manifestPlane — function @experimental+```+(manifest: { plane?: "xz" | "xy"; } | null): "xz" | "xy"+```+## markThemed — function @experimental```(world: World, entity: Entity, style: ThemeStyleData): void@@ -15214,6 +15229,11 @@ ParticlePlugin(app: App, entity: Entity, view?: Entity): PlanarReflectionStatus```+## planeSecond — function @experimental+```+(position: { y: number; z?: number; }, plane: "xz" | "xy"): number+```+## planetPlugin — const @experimental```PlanetPlugindiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 55d1bd370..d535e8858 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: 115 public · 164 beta · 1944 experimental · 3 deprecated+Symbols: 115 public · 164 beta · 1947 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -10301,6 +10301,12 @@ toActivate: string[]toDeactivate: string[]```+## StreamPlane — enum @experimental+```+Ground = 0+Screen = 1+```+## StreamPolicy — type @experimental```'unload' | 'sleep'@@ -10314,6 +10320,7 @@ ComponentDef<StreamedWorldData>## StreamedWorldData — interface @experimental```cellSize: number+plane: StreamPlane```## StudioPreviewReport — interface @experimental@@ -12862,6 +12869,7 @@ static prototype: WorldGenscellSize: numbercells: WorldCell[]persistentRefs: number[]+plane: "xz" | "xy" | undefinedscene: stringversion: number```@@ -12873,6 +12881,7 @@ cells: PartitionedCell[]errors: string[]persistent: SceneDatapersistentRefs: number[]+plane: "xz" | "xy"warnings: string[]```@@ -12935,6 +12944,7 @@ loadCount: numberloadingCells: string[]persistentEntities: numberpersistentHandles: number[]+plane: "xz" | "xy"prefetchCells: string[]prefetchHits: numberprefetchMisses: number@@ -15117,6 +15127,11 @@ Logger(world: World, entity: Entity, init?: WidgetInteractionInit): void```+## manifestPlane — function @experimental+```+(manifest: { plane?: "xz" | "xy"; } | null): "xz" | "xy"+```+## markThemed — function @experimental```(world: World, entity: Entity, style: ThemeStyleData): void@@ -15477,6 +15492,11 @@ ParticlePlugin(app: App, entity: Entity, view?: Entity): PlanarReflectionStatus```+## planeSecond — function @experimental+```+(position: { y: number; z?: number; }, plane: "xz" | "xy"): number+```+## planetPlugin — const @experimental```PlanetPlugindiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex d144e0f6c..8d7b2926a 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: 115 public · 161 beta · 1924 experimental · 3 deprecated+Symbols: 115 public · 161 beta · 1927 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -10083,6 +10083,12 @@ toActivate: string[]toDeactivate: string[]```+## StreamPlane — enum @experimental+```+Ground = 0+Screen = 1+```+## StreamPolicy — type @experimental```'unload' | 'sleep'@@ -10096,6 +10102,7 @@ ComponentDef<StreamedWorldData>## StreamedWorldData — interface @experimental```cellSize: number+plane: StreamPlane```## StudioPreviewReport — interface @experimental@@ -12644,6 +12651,7 @@ static prototype: WorldGenscellSize: numbercells: WorldCell[]persistentRefs: number[]+plane: "xz" | "xy" | undefinedscene: stringversion: number```@@ -12655,6 +12663,7 @@ cells: PartitionedCell[]errors: string[]persistent: SceneDatapersistentRefs: number[]+plane: "xz" | "xy"warnings: string[]```@@ -12717,6 +12726,7 @@ loadCount: numberloadingCells: string[]persistentEntities: numberpersistentHandles: number[]+plane: "xz" | "xy"prefetchCells: string[]prefetchHits: numberprefetchMisses: number@@ -14854,6 +14864,11 @@ Logger(world: World, entity: Entity, init?: WidgetInteractionInit): void```+## manifestPlane — function @experimental+```+(manifest: { plane?: "xz" | "xy"; } | null): "xz" | "xy"+```+## markThemed — function @experimental```(world: World, entity: Entity, style: ThemeStyleData): void@@ -15219,6 +15234,11 @@ ParticlePlugin(app: App, entity: Entity, view?: Entity): PlanarReflectionStatus```+## planeSecond — function @experimental+```+(position: { y: number; z?: number; }, plane: "xz" | "xy"): number+```+## planetPlugin — const @experimental```PlanetPlugindiff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 1752c0059..bdd26444a 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: 115 public · 159 beta · 1946 experimental · 3 deprecated+Symbols: 115 public · 159 beta · 1949 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -10377,6 +10377,12 @@ toActivate: string[]toDeactivate: string[]```+## StreamPlane — enum @experimental+```+Ground = 0+Screen = 1+```+## StreamPolicy — type @experimental```'unload' | 'sleep'@@ -10390,6 +10396,7 @@ ComponentDef<StreamedWorldData>## StreamedWorldData — interface @experimental```cellSize: number+plane: StreamPlane```## StudioPreviewReport — interface @experimental@@ -12944,6 +12951,7 @@ static prototype: WorldGenscellSize: numbercells: WorldCell[]persistentRefs: number[]+plane: "xz" | "xy" | undefinedscene: stringversion: number```@@ -12955,6 +12963,7 @@ cells: PartitionedCell[]errors: string[]persistent: SceneDatapersistentRefs: number[]+plane: "xz" | "xy"warnings: string[]```@@ -13017,6 +13026,7 @@ loadCount: numberloadingCells: string[]persistentEntities: numberpersistentHandles: number[]+plane: "xz" | "xy"prefetchCells: string[]prefetchHits: numberprefetchMisses: number@@ -15164,6 +15174,11 @@ Logger(world: World, entity: Entity, init?: WidgetInteractionInit): void```+## manifestPlane — function @experimental+```+(manifest: { plane?: "xz" | "xy"; } | null): "xz" | "xy"+```+## markThemed — function @experimental```(world: World, entity: Entity, style: ThemeStyleData): void@@ -15524,6 +15539,11 @@ ParticlePlugin(app: App, entity: Entity, view?: Entity): PlanarReflectionStatus```+## planeSecond — function @experimental+```+(position: { y: number; z?: number; }, plane: "xz" | "xy"): number+```+## planetPlugin — const @experimental```PlanetPlugindiff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex d5c240bda..e3feaf7c1 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: 115 public · 159 beta · 1937 experimental · 3 deprecated+Symbols: 115 public · 159 beta · 1940 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -10090,6 +10090,12 @@ toActivate: string[]toDeactivate: string[]```+## StreamPlane — enum @experimental+```+Ground = 0+Screen = 1+```+## StreamPolicy — type @experimental```'unload' | 'sleep'@@ -10103,6 +10109,7 @@ ComponentDef<StreamedWorldData>## StreamedWorldData — interface @experimental```cellSize: number+plane: StreamPlane```## StudioPreviewReport — interface @experimental@@ -12676,6 +12683,7 @@ static prototype: WorldGenscellSize: numbercells: WorldCell[]persistentRefs: number[]+plane: "xz" | "xy" | undefinedscene: stringversion: number```@@ -12687,6 +12695,7 @@ cells: PartitionedCell[]errors: string[]persistent: SceneDatapersistentRefs: number[]+plane: "xz" | "xy"warnings: string[]```@@ -12749,6 +12758,7 @@ loadCount: numberloadingCells: string[]persistentEntities: numberpersistentHandles: number[]+plane: "xz" | "xy"prefetchCells: string[]prefetchHits: numberprefetchMisses: number@@ -14891,6 +14901,11 @@ Logger(world: World, entity: Entity, init?: WidgetInteractionInit): void```+## manifestPlane — function @experimental+```+(manifest: { plane?: "xz" | "xy"; } | null): "xz" | "xy"+```+## markThemed — function @experimental```(world: World, entity: Entity, style: ThemeStyleData): void@@ -15251,6 +15266,11 @@ ParticlePlugin(app: App, entity: Entity, view?: Entity): PlanarReflectionStatus```+## planeSecond — function @experimental+```+(position: { y: number; z?: number; }, plane: "xz" | "xy"): number+```+## planetPlugin — const @experimental```PlanetPlugindiff --git a/sdk/src/core-content.ts b/sdk/src/core-content.tsindex 9b4294188..0c8fc7acb 100644--- a/sdk/src/core-content.ts+++ b/sdk/src/core-content.ts@@ -312,6 +312,7 @@ export { sceneManagerPlugin } from './scene/scenePlugin';export {StreamedWorld,+ StreamPlane,WorldPersistent,WorldStreamingSource,WorldStreamer,@@ -320,6 +321,8 @@ export {distanceToCell,cellAt,cellSquare,+ manifestPlane,+ planeSecond,worldResidencyPlugin,worldResidencySystem,worldResidencyReport,diff --git a/sdk/src/residency/cells.ts b/sdk/src/residency/cells.tsindex c302f3f82..35d681757 100644--- a/sdk/src/residency/cells.ts+++ b/sdk/src/residency/cells.ts@@ -43,6 +43,11 @@ export interface WorldManifest {scene: string;/** Edge of one grid square, world units. */cellSize: number;+ /**+ * The world plane the cells lie on: `'xz'` (the default, and what a manifest cooked before this field has) or `'xy'` for a 2D world. A cell's+ * `z` and `minZ`/`maxZ` are the SECOND axis of that plane, so on `'xy'` they are world y.+ */+ plane?: 'xz' | 'xy';/*** Authored ids in the persistent world that a cell holds a hard reference to.* Only these are kept resolvable — a table of every row would be a cost the@@ -62,6 +67,16 @@ export interface ResidencySource {prefetchRadius: number;}+/** The plane a manifest's cells lie on, a manifest cooked before the field existing as the ground. @experimental */+export function manifestPlane(manifest: { plane?: 'xz' | 'xy' } | null): 'xz' | 'xy' {+ return manifest?.plane === 'xy' ? 'xy' : 'xz';+}++/** The second coordinate of a world position on a plane: z on the ground, y on the screen. @experimental */+export function planeSecond(position: { y: number; z?: number }, plane: 'xz' | 'xy'): number {+ return plane === 'xy' ? position.y : position.z ?? 0;+}+/** What residency should be, and the moves that get there. @experimental */export interface ResidencyDecision {/** Every cell that should exist after this tick, in manifest order. */@@ -80,8 +95,8 @@ export interface ResidencyDecision {/*** The cell a world position falls in — the one rule, with two callers that must* not drift: the cook assigns every top-level root by it, and the editor draws- * its grid from it. The y axis is not consulted, because a world is partitioned- * on the ground plane.+ * its grid from it. `z` is the position's SECOND coordinate on the plane the+ * world is cut on: world z on the ground, world y on the screen plane.*/export function cellAt(x: number, z: number, cellSize: number): { x: number; z: number } {return { x: Math.floor(x / cellSize), z: Math.floor(z / cellSize) };diff --git a/sdk/src/residency/components.ts b/sdk/src/residency/components.tsindex 16412829a..50a1996ef 100644--- a/sdk/src/residency/components.ts+++ b/sdk/src/residency/components.ts@@ -15,13 +15,23 @@import { defineComponent, defineTag, type ComponentDef } from '../ecs/component';+/** The plane a streamed world is cut on. @experimental */+export enum StreamPlane {+ /** A 3D world's ground: cells along world x and z, and y does not partition. */+ Ground = 0,+ /** A 2D world's screen plane: cells along world x and y, and z (depth, layering) does not partition. */+ Screen = 1,+}+/** The fields of the `StreamedWorld` component. @experimental */export interface StreamedWorldData {/**- * Edge of one square cell in world units, on the XZ plane. Y does not- * partition: a cell is a vertical column, so a tower's floors are one place.+ * Edge of one square cell in world units, on the plane below. The axis that is not on the plane does not+ * partition: on the ground a cell is a vertical column, so a tower's floors are one place.*/cellSize: number;+ /** The plane the cells lie on: the ground (x, z) of a 3D world, or the screen (x, y) of a 2D one. */+ plane: StreamPlane;}/**@@ -35,10 +45,11 @@ export interface StreamedWorldData {*/export const StreamedWorld: ComponentDef<StreamedWorldData> = defineComponent<StreamedWorldData>('StreamedWorld',- { cellSize: 1000 },+ { cellSize: 1000, plane: StreamPlane.Ground },{fields: {- cellSize: { min: 1, unit: 'wu', tooltip: 'Edge of one cell on the XZ plane.' },+ cellSize: { min: 1, unit: 'wu', tooltip: 'Edge of one cell on the plane.' },+ plane: { enum: [{ label: 'Ground (x, z)', value: StreamPlane.Ground }, { label: 'Screen (x, y)', value: StreamPlane.Screen }], tooltip: 'Which two world axes the cells are cut along: a 3D world is cut on the ground, a 2D world on the screen plane.' },},},);diff --git a/sdk/src/residency/cutWorld.ts b/sdk/src/residency/cutWorld.tsindex 2830c9982..972959d82 100644--- a/sdk/src/residency/cutWorld.ts+++ b/sdk/src/residency/cutWorld.ts@@ -83,6 +83,7 @@ export function cutWorld(version: 1,scene: sceneName,cellSize: partition.cellSize,+ ...(partition.plane === 'xy' ? { plane: 'xy' as const } : {}),persistentRefs: partition.persistentRefs,cells,},diff --git a/sdk/src/residency/index.ts b/sdk/src/residency/index.tsindex 20236a05a..6d7ae15ce 100644--- a/sdk/src/residency/index.ts+++ b/sdk/src/residency/index.ts@@ -6,11 +6,11 @@*/export {- StreamedWorld, WorldPersistent, WorldStreamingSource,+ StreamedWorld, StreamPlane, WorldPersistent, WorldStreamingSource,type StreamedWorldData, type WorldStreamingSourceData,} from './components';export {- desiredResidency, distanceToCell, cellAt, cellSquare,+ desiredResidency, distanceToCell, cellAt, cellSquare, manifestPlane, planeSecond,type WorldCell, type WorldManifest, type ResidencySource, type ResidencyDecision,} from './cells';export {diff --git a/sdk/src/residency/partitionWorld.ts b/sdk/src/residency/partitionWorld.tsindex e8b682666..2028a3470 100644--- a/sdk/src/residency/partitionWorld.ts+++ b/sdk/src/residency/partitionWorld.ts@@ -25,7 +25,8 @@*/import { isPrefabEntry } from '../scene/sceneEntry';-import { cellAt, cellSquare } from './cells';+import { cellAt, cellSquare, planeSecond } from './cells';+import { StreamPlane } from './components';import type { SceneData, SceneEntityData, SceneComponentData } from '../scene/scene';import type { SceneEntry } from '../scene/sceneEntry';import type { PrefabInstanceEntry } from '../prefab/sceneInstance';@@ -61,6 +62,8 @@ export interface PartitionedCell {export interface WorldPartition {cellSize: number;+ /** The plane the cells lie on. */+ plane: 'xz' | 'xy';/** The entry scene as it now ships: everything residency never removes. */persistent: SceneData;cells: PartitionedCell[];@@ -202,10 +205,12 @@ export function partitionWorld(): WorldPartition | null {const entries = (scene.entities ?? []) as unknown as SceneEntry[];let cellSize = 0;+ let plane: 'xz' | 'xy' = 'xz';for (const entry of entries) {if (!hasComponent(entry, 'StreamedWorld')) continue;const declaration = componentData(entry, 'StreamedWorld');cellSize = typeof declaration?.cellSize === 'number' ? declaration.cellSize : 0;+ if (declaration?.plane === StreamPlane.Screen) plane = 'xy';break;}if (cellSize <= 0) {@@ -213,7 +218,7 @@ export function partitionWorld(// scene with no declaration at all is simply not a streamed world.return entries.some((entry) => hasComponent(entry, 'StreamedWorld'))? {- cellSize: 0, persistent: scene, cells: [], persistentRefs: [],+ cellSize: 0, plane, persistent: scene, cells: [], persistentRefs: [],errors: [`StreamedWorld in "${sceneName}" declares no positive cellSize`],warnings: [],}@@ -252,7 +257,7 @@ export function partitionWorld(&& !hasComponent(entry, 'StreamedWorld')&& (isPrefabEntry(entry) || componentData(entry, 'Transform') !== null);const rootPosition = localPosition(entry, options, errors);- const cell = streamed ? cellAt(rootPosition.x, rootPosition.z, cellSize) : null;+ const cell = streamed ? cellAt(rootPosition.x, planeSecond(rootPosition, plane), cellSize) : null;const subtree: number[] = [];const stack: Array<{ id: number; position: Vec3; rotation: [number, number, number, number]; scale: Vec3 }> = [@@ -348,7 +353,8 @@ export function partitionWorld(for (const id of ids) {const at = worldPosition.get(id)!;minX = Math.min(minX, at.x); maxX = Math.max(maxX, at.x);- minZ = Math.min(minZ, at.z); maxZ = Math.max(maxZ, at.z);+ const second = planeSecond(at, plane);+ minZ = Math.min(minZ, second); maxZ = Math.max(maxZ, second);}const name = `${sceneName}.cell_${x}_${z}`;cells.push({@@ -361,6 +367,7 @@ export function partitionWorld(return {cellSize,+ plane,persistent: documentOf(persistentIds, scene.name),cells,persistentRefs: [...persistentRefs].sort((a, b) => a - b),diff --git a/sdk/src/residency/report.ts b/sdk/src/residency/report.tsindex 0a95300d1..6a1ef1ce8 100644--- a/sdk/src/residency/report.ts+++ b/sdk/src/residency/report.ts@@ -19,6 +19,7 @@ import { SceneManager } from '../scene/sceneManager';import { WorldStreaming, type CellDelivery } from './WorldStreamer';import type { RenderReadinessStamp } from '../render/renderReadiness';import { stableEntityId } from './identity';+import { manifestPlane } from './cells';import { renderableComponents } from '../ecs/component';/** @experimental */@@ -36,6 +37,8 @@ export interface WorldResidencyReport {cells: Array<{ name: string; x: number; z: number }>;/** Edge of one grid square, world units — what the coordinates above scale by. */cellSize: number;+ /** The plane the cells lie on: a cell's z is world z on 'xz' (the ground) and world y on 'xy' (a 2D world's screen). */+ plane: 'xz' | 'xy';sourceCount: number;desiredCells: string[];/** Cells any source is close enough to speculate about. */@@ -90,7 +93,7 @@ export interface WorldResidencyReport {}const EMPTY: WorldResidencyReport = {- streamed: false, cellCount: 0, cells: [], cellSize: 0, sourceCount: 0,+ streamed: false, cellCount: 0, cells: [], cellSize: 0, plane: 'xz', sourceCount: 0,desiredCells: [], prefetchCells: [], residentCells: [], preparedCells: [],preparedWithRenderClaim: [], renderClaims: {},loadingCells: [], unloadingCells: [],@@ -146,6 +149,7 @@ export function worldResidencyReport(app: App): WorldResidencyReport {cellCount: status.cellCount,cells: manifest.cells.map((cell) => ({ name: cell.name, x: cell.x, z: cell.z })),cellSize: manifest.cellSize,+ plane: manifestPlane(manifest),sourceCount: status.sourceCount,desiredCells: status.desiredCells,prefetchCells: status.prefetchCells,diff --git a/sdk/src/residency/residencyPlugin.ts b/sdk/src/residency/residencyPlugin.tsindex 233ce0f2f..b4a6d1940 100644--- a/sdk/src/residency/residencyPlugin.ts+++ b/sdk/src/residency/residencyPlugin.ts@@ -9,7 +9,7 @@import type { App, Plugin } from '../app/app';import { SceneManager } from '../scene/sceneManager';import { WorldStreaming, WorldStreamer } from './WorldStreamer';-import type { ResidencySource } from './cells';+import { manifestPlane, planeSecond, type ResidencySource } from './cells';import { WorldStreamingSource, type WorldStreamingSourceData } from './components';import { defineSystem, Schedule, GetWorld } from '../ecs/system';import { Res } from '../ecs/resource';@@ -31,6 +31,7 @@ export const worldResidencySystem = defineSystem(// A source parented to a rig has no position of its own, and the ask is// about where it IS. Composition is a no-op unless something invalidated it.world.ensureTransformsComposed();+ const plane = manifestPlane(streamer.manifest);const sources: ResidencySource[] = [];for (const entity of world.getEntitiesWithComponents([WorldStreamingSource, Transform])) {const source = world.get(entity, WorldStreamingSource) as WorldStreamingSourceData;@@ -39,7 +40,7 @@ export const worldResidencySystem = defineSystem(const at = transform.worldPosition ?? transform.position;sources.push({x: at.x,- z: at.z ?? 0,+ z: planeSecond(at, plane),loadRadius: source.loadRadius,unloadRadius: source.unloadRadius,prefetchRadius: source.prefetchRadius,diff --git a/sdk/tests/partition-world.test.ts b/sdk/tests/partition-world.test.tsindex 5a68b153d..19c2efffa 100644--- a/sdk/tests/partition-world.test.ts+++ b/sdk/tests/partition-world.test.ts@@ -11,6 +11,9 @@*/import { describe, it, expect } from 'vitest';import { partitionWorld, type PartitionOptions } from '../src/residency/partitionWorld';+import { cutWorld } from '../src/residency/cutWorld';+import { StreamPlane } from '../src/residency/components';+import { desiredResidency, manifestPlane, planeSecond } from '../src/residency/cells';import type { SceneData } from '../src/scene/scene';const SIZE = 1000;@@ -186,3 +189,52 @@ describe('partitionWorld', () => {expect(partition.errors.join('\n')).toContain('no positive cellSize');});});++describe('a world cut on the screen plane', () => {+ const screen: Component = { type: 'StreamedWorld', data: { cellSize: SIZE, plane: StreamPlane.Screen } };+ const world = (): SceneData => scene(+ entity(0, 'World', null, { components: [screen] }),+ // A 2D scene lies at z 0 (or a layering depth): only x and y tell the places apart.+ entity(1, 'Near', [500, 500, 0]),+ entity(2, 'East', [1500, 500, 0]),+ entity(3, 'North', [500, 1500, 5]),+ entity(4, 'Far', [500, -1500, 9]),+ );++ it('cuts along x and y, so a scene at z 0 is a grid and not one row', () => {+ const partition = cut(world())!;+ expect(partition.plane).toBe('xy');+ expect(partition.cells.map((c) => [c.x, c.z]).sort()).toEqual([[0, -2], [0, 0], [0, 1], [1, 0]]);+ // The box covers world y, not z: the North entity at y 1500 is inside cell (0, 1).+ const north = partition.cells.find((c) => c.x === 0 && c.z === 1)!;+ expect(north.minZ).toBeLessThanOrEqual(1000);+ expect(north.maxZ).toBeGreaterThanOrEqual(1500);+ });++ it('still cuts the ground by x and z when the world does not say otherwise', () => {+ const partition = cut(scene(+ entity(0, 'World', null, { components: [declaration] }),+ entity(1, 'A', [500, 500, 0]),+ entity(2, 'B', [500, 500, 1500]),+ ))!;+ expect(partition.plane).toBe('xz');+ expect(partition.cells.map((c) => [c.x, c.z])).toEqual([[0, 0], [0, 1]]);+ });++ it('writes the plane into the manifest only for a screen world, and an old manifest reads as the ground', () => {+ expect(cutWorld(world(), 'main', options)!.manifest.plane).toBe('xy');+ const ground = cutWorld(scene(entity(0, 'World', null, { components: [declaration] }), entity(1, 'A', [1, 1, 1])), 'main', options)!;+ expect(ground.manifest.plane).toBeUndefined();+ expect(manifestPlane(ground.manifest)).toBe('xz');+ expect(manifestPlane(null)).toBe('xz');+ });++ it('asks for the cells round a source by its y: a source walking up a 2D world brings in the cells above it', () => {+ const manifest = cutWorld(world(), 'main', options)!.manifest;+ const plane = manifestPlane(manifest);+ const at = { x: 500, y: 1400, z: 0 };+ const sources = [{ x: at.x, z: planeSecond(at, plane), loadRadius: 300, unloadRadius: 400, prefetchRadius: 300 }];+ const wanted = desiredResidency(manifest.cells, sources, new Set()).target;+ expect(wanted).toEqual(['main.cell_0_1']);+ });+});