Skip to content

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.

feat(residency): the partition rule is shared, and the editor draws it

esengined347c5d84f58
diff --git a/desktop b/desktop
index a16344545..28d74bc82 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit a163445450117dbb533d29bd4a31fe94adebc4d4
+Subproject commit 28d74bc828c8027abc4fd0f12ea45fe7f8111441
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index 93491c3c8..5f181036f 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -3,10 +3,10 @@
"counts": {
"public": 113,
"beta": 91,
- "experimental": 1794,
+ "experimental": 1796,
"deprecated": 3
},
- "total": 1998,
+ "total": 2000,
"subsystems": [
{
"id": "ecs",
diff --git a/pipeline/src/world/partitionWorld.ts b/pipeline/src/world/partitionWorld.ts
index ce5879e20..790320b36 100644
--- a/pipeline/src/world/partitionWorld.ts
+++ b/pipeline/src/world/partitionWorld.ts
@@ -19,7 +19,7 @@
* fields hold entity references, and where a prefab's root sits.
*/
-import { isPrefabEntry } from 'esengine';
+import { isPrefabEntry, cellAt, cellSquare } from 'esengine';
import type {
SceneData, SceneEntityData, SceneComponentData, SceneEntry, PrefabInstanceEntry,
} from 'esengine';
@@ -246,9 +246,7 @@ export function partitionWorld(
&& !hasComponent(entry, 'StreamedWorld')
&& (isPrefabEntry(entry) || componentData(entry, 'Transform') !== null);
const rootPosition = localPosition(entry, options, errors);
- const cell = streamed
- ? { x: Math.floor(rootPosition.x / cellSize), z: Math.floor(rootPosition.z / cellSize) }
- : null;
+ const cell = streamed ? cellAt(rootPosition.x, rootPosition.z, cellSize) : null;
const subtree: number[] = [];
const stack: Array<{ id: number; position: Vec3; rotation: [number, number, number, number]; scale: Vec3 }> = [
@@ -337,10 +335,7 @@ export function partitionWorld(
const ids: number[] = [];
for (const root of cellKeys.get(key)!) ids.push(...members.get(root)!);
ids.sort((a, b) => order.get(a)! - order.get(b)!);
- let minX = x * cellSize;
- let minZ = z * cellSize;
- let maxX = minX + cellSize;
- let maxZ = minZ + cellSize;
+ let { minX, minZ, maxX, maxZ } = cellSquare(x, z, cellSize);
// The grid square unioned with where the content actually is: a prop
// hanging over the edge is part of the place the box stands for, and a
// box that stops short of it pops the prop in at the boundary.
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 8941673b5..b30d3a8a2 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: 113 public · 84 beta · 1630 experimental · 3 deprecated
+Symbols: 113 public · 84 beta · 1632 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -10617,6 +10617,16 @@ BtPlugin
(manifest: AddressableManifest): Catalog | undefined
```
+## cellAt — function @experimental
+```
+(x: number, z: number, cellSize: number): { x: number; z: number; }
+```
+
+## cellSquare — function @experimental
+```
+(cellX: number, cellZ: number, cellSize: number): { minX: number; minZ: number; maxX: number; maxZ: number; }
+```
+
## censusProbeIds — function @experimental
```
(): string[]
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 4fc007042..c044e981e 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: 113 public · 89 beta · 1649 experimental · 3 deprecated
+Symbols: 113 public · 89 beta · 1651 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -10825,6 +10825,16 @@ BtPlugin
(manifest: AddressableManifest): Catalog | undefined
```
+## cellAt — function @experimental
+```
+(x: number, z: number, cellSize: number): { x: number; z: number; }
+```
+
+## cellSquare — function @experimental
+```
+(cellX: number, cellZ: number, cellSize: number): { minX: number; minZ: number; maxX: number; maxZ: number; }
+```
+
## censusProbeIds — function @experimental
```
(): string[]
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 9c3b529fc..116f1b7f1 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: 113 public · 86 beta · 1629 experimental · 3 deprecated
+Symbols: 113 public · 86 beta · 1631 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -10612,6 +10612,16 @@ BtPlugin
(manifest: AddressableManifest): Catalog | undefined
```
+## cellAt — function @experimental
+```
+(x: number, z: number, cellSize: number): { x: number; z: number; }
+```
+
+## cellSquare — function @experimental
+```
+(cellX: number, cellZ: number, cellSize: number): { minX: number; minZ: number; maxX: number; maxZ: number; }
+```
+
## censusProbeIds — function @experimental
```
(): string[]
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 7dff7c0a8..5b53810a9 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: 113 public · 84 beta · 1651 experimental · 3 deprecated
+Symbols: 113 public · 84 beta · 1653 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -10864,6 +10864,16 @@ BtPlugin
(manifest: AddressableManifest): Catalog | undefined
```
+## cellAt — function @experimental
+```
+(x: number, z: number, cellSize: number): { x: number; z: number; }
+```
+
+## cellSquare — function @experimental
+```
+(cellX: number, cellZ: number, cellSize: number): { minX: number; minZ: number; maxX: number; maxZ: number; }
+```
+
## censusProbeIds — function @experimental
```
(): string[]
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index adfaafad4..096fb1c1e 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: 113 public · 84 beta · 1641 experimental · 3 deprecated
+Symbols: 113 public · 84 beta · 1643 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -10640,6 +10640,16 @@ BtPlugin
(manifest: AddressableManifest): Catalog | undefined
```
+## cellAt — function @experimental
+```
+(x: number, z: number, cellSize: number): { x: number; z: number; }
+```
+
+## cellSquare — function @experimental
+```
+(cellX: number, cellZ: number, cellSize: number): { minX: number; minZ: number; maxX: number; maxZ: number; }
+```
+
## censusProbeIds — function @experimental
```
(): string[]
diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.ts
index 2f79c124b..5a8102744 100644
--- a/sdk/src/core-content.ts
+++ b/sdk/src/core-content.ts
@@ -238,6 +238,8 @@ export {
WorldStreaming,
desiredResidency,
distanceToCell,
+ cellAt,
+ cellSquare,
worldResidencyPlugin,
worldResidencySystem,
worldResidencyReport,
diff --git a/sdk/src/residency/cells.ts b/sdk/src/residency/cells.ts
index 77a90cde9..c302f3f82 100644
--- a/sdk/src/residency/cells.ts
+++ b/sdk/src/residency/cells.ts
@@ -77,6 +77,31 @@ export interface ResidencyDecision {
toUnload: string[];
}
+/**
+ * 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.
+ */
+export function cellAt(x: number, z: number, cellSize: number): { x: number; z: number } {
+ return { x: Math.floor(x / cellSize), z: Math.floor(z / cellSize) };
+}
+
+/**
+ * The grid square one cell coordinate stands for.
+ *
+ * NOT the same as {@link WorldCell}'s box: a cooked cell's box is this square
+ * unioned with where its content actually reached, so it is usually larger. This
+ * is the partition; that is the partition plus its overhang.
+ */
+export function cellSquare(cellX: number, cellZ: number, cellSize: number): {
+ minX: number; minZ: number; maxX: number; maxZ: number;
+} {
+ const minX = cellX * cellSize;
+ const minZ = cellZ * cellSize;
+ return { minX, minZ, maxX: minX + cellSize, maxZ: minZ + cellSize };
+}
+
/**
* Ground-plane distance from a point to a cell's box; zero inside it.
*
diff --git a/sdk/src/residency/index.ts b/sdk/src/residency/index.ts
index d2599486b..189169be8 100644
--- a/sdk/src/residency/index.ts
+++ b/sdk/src/residency/index.ts
@@ -10,7 +10,7 @@ export {
type StreamedWorldData, type WorldStreamingSourceData,
} from './components';
export {
- desiredResidency, distanceToCell,
+ desiredResidency, distanceToCell, cellAt, cellSquare,
type WorldCell, type WorldManifest, type ResidencySource, type ResidencyDecision,
} from './cells';
export {
diff --git a/tools/check-gizmo-coverage.mjs b/tools/check-gizmo-coverage.mjs
index 13a2b21c4..e4ed8b487 100644
--- a/tools/check-gizmo-coverage.mjs
+++ b/tools/check-gizmo-coverage.mjs
@@ -88,6 +88,10 @@ const DISPOSITION = {
'PostProcessVolume.size': 'extent',
'ShadowCaster2D.size': 'extent',
'TilemapLayer.cellSize': 'extent',
+ 'StreamedWorld.cellSize': 'extent',
+ 'WorldStreamingSource.prefetchRadius': 'extent',
+ 'WorldStreamingSource.loadRadius': 'extent',
+ 'WorldStreamingSource.unloadRadius': 'extent',
// The component's own drawing is the picture; an outline round it would trace
// what is already on screen.
@@ -141,12 +145,8 @@ const DISPOSITION = {
'AudioSource.maxDistance': ['owed', 'the sphere past which a 3D source is inaudible'],
'Hunter.attackRange': ['owed', 'the reach it closes to before swinging — MeleeAttack.radius is drawn, this twin is not'],
'Perceiver.range': ['owed', 'how far it can see; the cone it sees through is not drawn either'],
- 'StreamedWorld.cellSize': ['owed', 'the grid the whole world is partitioned on, visible nowhere'],
'ThirdPersonCamera.distance': ['owed', 'the boom length — where the camera actually ends up'],
'ThirdPersonCamera.obstructionRadius': ['owed', 'the probe swept along the boom'],
- 'WorldStreamingSource.prefetchRadius': ['owed', 'cells this close are prepared, and nothing on screen says where that is'],
- 'WorldStreamingSource.loadRadius': ['owed', 'cells this close are brought in, and nothing on screen says where that is'],
- 'WorldStreamingSource.unloadRadius': ['owed', 'resident cells are kept until past this, shown nowhere'],
};
const components = JSON.parse(readFileSync(SNAPSHOT, 'utf8')).components;