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(net): esengine/session exports the seeded generator

yhh4f63284839d5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2ad93a420..7256232dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,9 +16,11 @@ published separately; it ships inside the editor.
### Added
+- **An Offset side the layout drops is dimmed, with the reason in its tooltip.** In the inspector, a UI node whose Offset has both a start side and a size set already has this axis fixed, so the far side does nothing; that field is dimmed, and its tooltip says which two settings decide the axis and that setting one of them to auto brings the side back.
+- **Every render-graph pass has its own GPU time in the profiler, and the scene pass can be split by shader.** The profiler reads a GPU time for each pass of the frame on WebGL2 and WebGPU, not one number for the frame. With the profiler on and `module.esGpuDetail` set, each run of draws that use one shader is its own timed segment of the scene pass (WebGL2). `docs/TERRAIN_WATER_GPU_COST.md` says what each part of the Terrain & Water example costs and why.
- **Optional tools a project switches on, fetched and checked by the engine.** A project names a tool in `project.esproject` (`tools.luban.enabled`); until it does, the engine does not look for it, mention it or download it. Luban, the industry's configuration tool, turns the Excel tables a game's designers keep into JSON and the TypeScript that reads it, with references between tables checked (a site that produces an item that does not exist fails with the table, the record and the field). It is a .NET program, so the engine also fetches the .NET runtime it runs on. When either is missing, `estella tools install luban` shows exactly what it would download (name, version, licence, size, and where from) and asks before it does; `--yes` agrees in advance for CI. Each tool is pinned in `external-tools.manifest.json` to one vendor file, and a release publishes those files, repackaged as `.zip`, beside an index naming each one's size and SHA-256 and the vendor file it was made from: the engine takes them from the release mirror first and the release itself second, refuses a file that does not match, and refuses an index built from a different vendor file than it pins, so an engine version always runs the tool versions it was built against. There is no fallback to the vendor's own site. `estella luban gen` writes the tables (only the files that changed, and it removes what a deleted table used to produce), `estella luban check` fails when they are out of date, and an export of a project that has Luban on rebuilds them first. Windows, macOS (both architectures) and Linux (both architectures).
- **Protobuf as a second optional tool: .proto files become TypeScript types and a binary codec.** `tools.protobuf.enabled` in `project.esproject` (folders `proto` and `src/proto` unless the project says otherwise) makes the engine fetch the pinned `protoc` the same way it fetches Luban, asking first, and turn the project's `.proto` files into TypeScript: an interface and an `encode`/`decode` pair per message, written against one small `_runtime.ts` beside them, so the game carries no protobuf library. proto3 is supported, with scalars, enums, nested messages, `repeated`, `optional`, `oneof` and `map`; 64-bit integers are numbers and a value past 2^53 throws instead of rounding, and proto2 is refused by name. The output is checked against `protoc` itself, in both directions, byte for byte. `estella proto gen` writes only the files that changed, `estella proto check` fails when they are stale, and an export of a project with Protobuf on regenerates them first. A session can carry it (next entry).
-- **A session can speak protobuf, with the JSON wire kept for debugging.** `ClientSession({ wire: 'pb' })` asks for it in the hello and `SessionHost({ wire })` decides: `'json'` (the default, nothing changes), `'pb'` (a client that asks gets binary frames, and one that asks for JSON still gets text, which is how a session is read in a debugger) or `'pb-only'` (a client that asks for JSON is turned away and JSON frames are dropped afterwards). A message from a `.proto` file is a contract type with `proto(Order)`, or `protoAs(Order, { to, from })` to keep the game's own types on either side of it: the generated code brings its binary codec, a checked JSON form for the debugging wire, and a `shape` that goes into the contract fingerprint, so changing the `.proto` changes it. On the binary wire every control message is one fixed envelope on binary channel 255, which is now reserved (0-254 stay the game's); the frame limit, the rate limit and retry-safe requests apply to it as before, and a retried request is answered from its stored result on either wire. Types written with `s` keep working on both wires.
+- **A session can speak protobuf, with the JSON wire kept for debugging.** `ClientSession({ wire: 'pb' })` asks for it in the hello and `SessionHost({ wire })` decides: `'json'` (the default, nothing changes), `'pb'` (a client that asks gets binary frames, and one that asks for JSON still gets text, which is how a session is read in a debugger) or `'pb-only'` (a client that asks for JSON is turned away and JSON frames are dropped afterwards). A message from a `.proto` file is a contract type with `proto(Order)`, or `protoAs(Order, { to, from })` to keep the game's own types on either side of it: the generated code brings its binary codec, a checked JSON form for the debugging wire, and a `shape` that goes into the contract fingerprint, so changing the `.proto` changes it. On the binary wire every control message is one fixed envelope on binary channel 255, which is now reserved (0-254 stay the game's); the frame limit, the rate limit and retry-safe requests apply to it as before, and a retried request is answered from its stored result on either wire. Types written with `s` keep working on both wires. `esengine/session` also exports `createRng`, so rules shared by a server and its clients draw the same numbers from one import.
- **A text field can accept only digits.** `TextInput.inputFilter` (`TextInputFilter.Digits`) keeps a field to 0-9 for a count or a price: a letter typed or pasted never reaches `value`, and the caret stays where the kept characters put it. A script that cleaned the value itself each frame lost to the field: while a field is being edited its own editor is the source of `value`, so the cleaned value was overwritten with what was typed and the screen kept showing the letters. The filter runs where the editor's text is read in, beside `maxLength`, so what is on screen and what a script reads are the same. Off by default; a `maxLength` still applies after it.
- **A web build can say which servers its game connects to.** The exported page's Content-Security-Policy let a game talk only to the page it came from, so a game with a server of its own could not reach it: the browser refused the connection and said nothing the game could see. A project now lists the origins in `packaging.platforms.web.connect` (`wss://play.example.com`, `ws://127.0.0.1:*` for any port on a host, or a bare `wss:` for any secure WebSocket) and each becomes a `connect-src` source. An entry is checked rather than pasted in: a path, a wildcard host, a space, a semicolon or a quote fails the export and names the entry, so no entry can end the directive and start another. Web only; a mini-game's server addresses are the platform's own list.
- **A session can be told to redial now, and says why its link ended.** `ClientSession.retryNow()` dials at once instead of waiting out the backoff, for a player who pressed "try again"; it does nothing when the session is ready, already dialling, or closed. `lastClose` is the WebSocket close code of the last link that ended (4003, `SessionCloseCode.unavailable`, is the server saying it is full or going away) until the next one is ready, and `attempts` counts dials since the session was last ready, so a screen can tell "reconnecting" from "the server is full" and say which attempt this is.
@@ -62,6 +64,8 @@ published separately; it ships inside the editor.
### Fixed
+- **A Text spawned in Update is ordered in the frame it appears.** The Text render nodes were only made in PreUpdate, so a Text spawned later in the frame reached the order pass with no UIVisual and no order, and was drawn at the base layer, under every panel, for its first frame. A second pass now makes them in PostUpdate, before the order is assigned.
+- **Transform stays on top of the inspector.** A component can name the sections it ranks first, and a Transform it did not name was pushed below them; Transform now leads whatever order a component gives.
- **A small caster no longer drops out of a wide shadow map.** A light's soft shadow first looks for what blocks a point over a disc of 24 texels, with sixteen taps spread over it, none within four texels of the point: a caster narrower than the gaps between them (about a dozen texels) could stand right over the point and be missed, so with a sun whose `shadowExtent` is large (a texel of 30 units, a bush two of them wide) its shadow was speckled and then gone. The point's own texel and the four a step and a half round it are asked first now. A frame of the Terrain & Water example costs 0.2 to 0.4 ms more where it is lit, and the shadows of its bushes, stones and flowers are there.
- **A material's vertex hook reads its own textures when it casts a shadow.** The program a caster is drawn with into a shadow map had its texture samplers left on unit 0, so a hook that reads a texture (the terrain's height pages) read another texture there, and the terrain cast the shadow of heights that were not its own. The samplers are set on the units the material declares them on, as the program it is drawn with in colour has them.
diff --git a/sdk/etc/session.api.md b/sdk/etc/session.api.md
index b3b5cf731..b3a8d3f2e 100644
--- a/sdk/etc/session.api.md
+++ b/sdk/etc/session.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/session
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 0 public · 0 beta · 57 experimental · 0 deprecated
+Symbols: 0 public · 0 beta · 61 experimental · 0 deprecated
## AcceptWebSocketOptions — interface @experimental
```
@@ -249,6 +249,23 @@ idempotencyKey: string | undefined
timeoutMs: number | undefined
```
+## Rng — interface @experimental
+```
+chance: (p: number) => boolean
+float: () => number
+fork: (label: string | number) => Rng
+int: (min: number, max: number) => number
+nextU32: () => number
+pick: <T>(items: readonly T[]) => T
+shuffle: <T>(items: readonly T[]) => T[]
+weighted: <T>(items: readonly T[], weight: (item: T) => number) => T
+```
+
+## RngSeed — type @experimental
+```
+number | string | readonly (number | string)[]
+```
+
## SESSION_HELLO — const @experimental
```
"session:hello"
@@ -395,11 +412,21 @@ terminate: (() => void) | undefined
<Ctx extends SessionContext>(host: SessionHost<Ctx>, socket: WebSocketLike, options?: AcceptWebSocketOptions): void
```
+## createRng — function @experimental
+```
+(seed: RngSeed): Rng
+```
+
## defineContract — function @experimental
```
<R extends RequestDefs, E extends EventDefs = Record<never, never>>(def: { requests: R; events?: E; }): Contract<R, E>
```
+## hashSeed — function @experimental
+```
+(seed: RngSeed): number
+```
+
## jsonCodec — const @experimental
```
PayloadCodec<unknown>
diff --git a/sdk/src/net/session/index.ts b/sdk/src/net/session/index.ts
index 6a9c58abc..aadf5871d 100644
--- a/sdk/src/net/session/index.ts
+++ b/sdk/src/net/session/index.ts
@@ -68,3 +68,5 @@ export {
type ContractImpl,
type RequestDef,
} from './contract';
+// The seeded generator rules code shares between server and client: the same seed draws the same numbers on both.
+export { createRng, hashSeed, type Rng, type RngSeed } from '../../math/random';
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 3262c347b..3fbb995a1 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -3030,10 +3030,24 @@ export const NOTED = {
{"note":"A session can speak protobuf, with the JSON wire kept for debugging."},
'feat(net): a protobuf message can be the wire form of a type the game already has':
{"internal":"A follow-up inside the session protobuf feature, which has not shipped yet."},
+ 'feat(net): esengine/session exports the seeded generator':
+ {"internal":"A follow-up inside the session protobuf feature, which has not shipped yet."},
'fix(tools): a host that cannot read the engine version says so instead of asking the mirror for v0.0.0':
{"internal":"A fix inside the optional tools feature, which has not shipped yet."},
"perf(sdk): a blank mini-game package no longer carries terrain and water":
- {"note":"A blank mini-game package no longer carries terrain and water."},
+ {"note":"A blank mini-game package no longer carries terrain, water and timelines."},
+ "perf(sdk): a blank mini-game package no longer carries timelines":
+ {"note":"A blank mini-game package no longer carries terrain, water and timelines."},
+ 'fix(text): a Text spawned in Update is ordered in the frame it appears, not drawn under its panels for one frame':
+ {"note":"A Text spawned in Update is ordered in the frame it appears."},
+ 'perf(render): the profiler can split the scene pass into a segment per shader, and the cost doc says what is in it':
+ {"note":"Every render-graph pass has its own GPU time in the profiler"},
+ 'perf(render): each render-graph pass has its own GPU time, on WebGL2 and WebGPU, read through the profiler':
+ {"note":"Every render-graph pass has its own GPU time in the profiler"},
+ "fix(inspector): Transform stays on top when a component's section order does not list it":
+ {"note":"Transform stays on top of the inspector."},
+ 'feat(inspector): an Offset side the layout drops is dimmed, with the reason in its tooltip':
+ {"note":"An Offset side the layout drops is dimmed, with the reason in its tooltip."},
"perf(ecs): one stable sort for every component type, 239KB off the engine wasm":
{"note":"The engine's wasm is 239KB smaller, with no change to what it does."},
"perf(render): a mesh draw finds its cached program without searching shader source":
@@ -3041,9 +3055,9 @@ export const NOTED = {
"perf(render): writing one material uniform sends one value, and the float-target check is asked once":
{"note":"Writing one material uniform sends that one value"},
"perf(render): the GL device skips state sets and uniform-buffer binds the context already holds":
- {"note":"The GL device skips state sets the context already holds"},
+ {"note":"The GL device no longer sets state the context already holds"},
"perf(render): instanced meshes that share a material draw together and merge":
- {"note":"Instanced meshes that share a material draw together and merge"},
+ {"note":"Instanced meshes that share a material now draw together"},
"perf(wasm): the module no longer carries a C++ stream library":
- {"note":"The web module is 144 KB smaller without the C++ stream library"},
+ {"note":"The web module is 144 KB smaller"},
};