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(logic): gameplay you can draw, and a corpus that draws some
esengine6e7a9cc97a7f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bd361c1a8..3036795ea 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,38 @@ published separately; it ships inside the editor.## [Unreleased]+### Added++- **Gameplay you can draw.** A `.esgraph` is logic as a picture: an event lights+ the white wire, the wire runs one node after another, and the coloured wires+ carry values between them. It is the entry non-programmers have in every other+ engine, and the one Estella did not have.++ The vocabulary is not new, which is the whole point. A node that DOES+ something is an `aiRegistry` action and a node that ANSWERS something is the+ generalisation of a condition — so one `registerAction` in your project shows+ up in a state machine's hook, a behaviour tree's leaf, an event wire AND the+ graph palette, with the pins it declares. `registerValue` is the same door for+ a name that computes: declare what it takes and what it hands back, and the+ editor draws the node. There is no privileged built-in set to imitate; the+ engine's own maths, comparisons and `property.get` come through that door too.++ What the interpreter promises is what the picture shows: a sequence finishes+ pin 0's whole chain before pin 1 starts; one wire carries one value (a pure+ node is evaluated once per activation of the node reading it, and asked again+ on the next, which is how a `while` condition can become false); a node whose+ input wire leads to something this build could not make does not run at all;+ and a graph that loops forever spends a step budget, stops that instance, and+ names the node. The play realm is the editor's own process — "the author will+ not draw that" is not a safety story.++ A `.esgraph` IS the runtime definition. Nothing compiles it, so the graph the+ editor runs and the graph the package ships are the same bytes, and a graph is+ attached to an entity the way an FSM is: a `ScriptGraphAgent` naming it.+ `examples/script-graph-demo` is two squares that move because of what they+ were drawn to do, one of them through a value node the project registered+ itself.+### Fixed- **Run works from wherever you are standing.** The running game's frame isdiff --git a/desktop b/desktopindex 2f28c2029..16aef840f 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 2f28c2029d795c8fc0af54e79dc01b85a126b0ed+Subproject commit 16aef840f29a9b93ea6182e6640645943f4bfb05diff --git a/examples/script-graph-demo/.gitignore b/examples/script-graph-demo/.gitignorenew file mode 100644index 000000000..359472ac2--- /dev/null+++ b/examples/script-graph-demo/.gitignore@@ -0,0 +1,7 @@+node_modules/+dist/+.vscode/+.idea/+.DS_Store+Thumbs.db+.esengine/cache/diff --git a/examples/script-graph-demo/assets/logic/bounce.esgraph b/examples/script-graph-demo/assets/logic/bounce.esgraphnew file mode 100644index 000000000..d6b9c3a16--- /dev/null+++ b/examples/script-graph-demo/assets/logic/bounce.esgraph@@ -0,0 +1,42 @@+{+ "version": "1.0",+ "name": "Bounce",+ "variables": [+ { "name": "x", "type": "number", "default": -220 },+ { "name": "dir", "type": "number", "default": 1 }+ ],+ "nodes": [+ { "id": "update", "kind": "event.update", "x": 40, "y": 60 },+ { "id": "getX", "kind": "var.get", "x": 40, "y": 200, "literals": { "name": "x" } },+ { "id": "getDir", "kind": "var.get", "x": 40, "y": 290, "literals": { "name": "dir" } },+ { "id": "speed", "kind": "call", "ref": "math.multiply", "x": 240, "y": 290, "literals": { "b": 260 } },+ { "id": "step", "kind": "call", "ref": "math.multiply", "x": 430, "y": 290 },+ { "id": "moved", "kind": "call", "ref": "math.add", "x": 620, "y": 200 },+ { "id": "setX", "kind": "var.set", "x": 300, "y": 60, "literals": { "name": "x" } },+ { "id": "write", "kind": "call", "ref": "property.set", "x": 500, "y": 60,+ "literals": { "path": "Transform.position.x" } },+ { "id": "past", "kind": "call", "ref": "compare.greater", "x": 620, "y": 420, "literals": { "b": 220 } },+ { "id": "absX", "kind": "call", "ref": "math.abs", "x": 430, "y": 420 },+ { "id": "turn", "kind": "flow.branch", "x": 760, "y": 60 },+ { "id": "flip", "kind": "call", "ref": "math.multiply", "x": 900, "y": 300, "literals": { "b": -1 } },+ { "id": "setDir", "kind": "var.set", "x": 940, "y": 60, "literals": { "name": "dir" } }+ ],+ "edges": [+ { "id": "e1", "from": "update", "fromPort": "then", "to": "setX", "toPort": "" },+ { "id": "e2", "from": "getDir", "fromPort": "value", "to": "speed", "toPort": "a" },+ { "id": "e3", "from": "speed", "fromPort": "result", "to": "step", "toPort": "a" },+ { "id": "e4", "from": "update", "fromPort": "dt", "to": "step", "toPort": "b" },+ { "id": "e5", "from": "getX", "fromPort": "value", "to": "moved", "toPort": "a" },+ { "id": "e6", "from": "step", "fromPort": "result", "to": "moved", "toPort": "b" },+ { "id": "e7", "from": "moved", "fromPort": "result", "to": "setX", "toPort": "value" },+ { "id": "e8", "from": "setX", "fromPort": "then", "to": "write", "toPort": "" },+ { "id": "e9", "from": "getX", "fromPort": "value", "to": "write", "toPort": "value" },+ { "id": "e10", "from": "write", "fromPort": "then", "to": "turn", "toPort": "" },+ { "id": "e11", "from": "getX", "fromPort": "value", "to": "absX", "toPort": "a" },+ { "id": "e12", "from": "absX", "fromPort": "result", "to": "past", "toPort": "a" },+ { "id": "e13", "from": "past", "fromPort": "result", "to": "turn", "toPort": "cond" },+ { "id": "e14", "from": "turn", "fromPort": "true", "to": "setDir", "toPort": "" },+ { "id": "e15", "from": "getDir", "fromPort": "value", "to": "flip", "toPort": "a" },+ { "id": "e16", "from": "flip", "fromPort": "result", "to": "setDir", "toPort": "value" }+ ]+}diff --git a/examples/script-graph-demo/assets/logic/bounce.esgraph.meta b/examples/script-graph-demo/assets/logic/bounce.esgraph.metanew file mode 100644index 000000000..6160afd42--- /dev/null+++ b/examples/script-graph-demo/assets/logic/bounce.esgraph.meta@@ -0,0 +1,6 @@+{+ "uuid": "5a1d0b10-2c44-4a8e-9f21-7c6b1d3e4a01",+ "version": "2.0",+ "type": "scriptgraph",+ "importer": {}+}diff --git a/examples/script-graph-demo/assets/logic/wave.esgraph b/examples/script-graph-demo/assets/logic/wave.esgraphnew file mode 100644index 000000000..f57f2423b--- /dev/null+++ b/examples/script-graph-demo/assets/logic/wave.esgraph@@ -0,0 +1,149 @@+{+ "version": "1.0",+ "name": "Wave",+ "variables": [+ {+ "name": "elapsed",+ "type": "number",+ "default": 0+ }+ ],+ "nodes": [+ {+ "id": "update",+ "kind": "event.update",+ "x": 40,+ "y": 60+ },+ {+ "id": "getT",+ "kind": "var.get",+ "x": 40,+ "y": 210,+ "literals": {+ "name": "elapsed"+ }+ },+ {+ "id": "rate",+ "kind": "call",+ "ref": "math.multiply",+ "x": 240,+ "y": 330,+ "literals": {+ "b": 110+ }+ },+ {+ "id": "advance",+ "kind": "call",+ "ref": "math.add",+ "x": 240,+ "y": 210+ },+ {+ "id": "setT",+ "kind": "var.set",+ "x": 430,+ "y": 60,+ "literals": {+ "name": "elapsed"+ }+ },+ {+ "id": "wave",+ "kind": "call",+ "ref": "demo.pingPong",+ "x": 430,+ "y": 260,+ "literals": {+ "range": 140+ }+ },+ {+ "id": "lift",+ "kind": "call",+ "ref": "math.add",+ "x": 660,+ "y": 260,+ "literals": {+ "b": -70+ }+ },+ {+ "id": "write",+ "kind": "call",+ "ref": "property.set",+ "x": 660,+ "y": 60,+ "literals": {+ "path": "Transform.position.y"+ }+ }+ ],+ "edges": [+ {+ "id": "e1",+ "from": "update",+ "fromPort": "then",+ "to": "setT",+ "toPort": ""+ },+ {+ "id": "e2",+ "from": "getT",+ "fromPort": "value",+ "to": "advance",+ "toPort": "a"+ },+ {+ "id": "e3",+ "from": "update",+ "fromPort": "dt",+ "to": "rate",+ "toPort": "a"+ },+ {+ "id": "e4",+ "from": "advance",+ "fromPort": "result",+ "to": "setT",+ "toPort": "value"+ },+ {+ "id": "e5",+ "from": "getT",+ "fromPort": "value",+ "to": "wave",+ "toPort": "t"+ },+ {+ "id": "e6",+ "from": "wave",+ "fromPort": "value",+ "to": "lift",+ "toPort": "a"+ },+ {+ "id": "e7",+ "from": "lift",+ "fromPort": "result",+ "to": "write",+ "toPort": "value"+ },+ {+ "id": "e8",+ "from": "setT",+ "fromPort": "then",+ "to": "write",+ "toPort": ""+ },+ {+ "id": "e3b",+ "from": "rate",+ "fromPort": "result",+ "to": "advance",+ "toPort": "b"+ }+ ]+}\ No newline at end of filediff --git a/examples/script-graph-demo/assets/logic/wave.esgraph.meta b/examples/script-graph-demo/assets/logic/wave.esgraph.metanew file mode 100644index 000000000..af7828b0f--- /dev/null+++ b/examples/script-graph-demo/assets/logic/wave.esgraph.meta@@ -0,0 +1,6 @@+{+ "uuid": "5a1d0b10-2c44-4a8e-9f21-7c6b1d3e4a02",+ "version": "2.0",+ "type": "scriptgraph",+ "importer": {}+}diff --git a/examples/script-graph-demo/assets/scenes/main.esscene b/examples/script-graph-demo/assets/scenes/main.esscenenew file mode 100644index 000000000..5fbaa3bcc--- /dev/null+++ b/examples/script-graph-demo/assets/scenes/main.esscene@@ -0,0 +1,41 @@+{+ "version": 4,+ "name": "Main",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 10 } } },+ { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 300, "isActive": true, "priority": 0 } }+ ],+ "visible": true+ },+ {+ "id": 1,+ "name": "Bouncer",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": -220, "y": 90, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 72, "y": 72 }, "color": { "r": 0.42, "g": 0.72, "b": 0.62, "a": 1 } } },+ { "type": "ScriptGraphAgent", "data": { "graph": "assets/logic/bounce.esgraph" } }+ ],+ "visible": true+ },+ {+ "id": 2,+ "name": "Waver",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": -70, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 72, "y": 72 }, "color": { "r": 0.75, "g": 0.57, "b": 0.48, "a": 1 } } },+ { "type": "ScriptGraphAgent", "data": { "graph": "assets/logic/wave.esgraph" } }+ ],+ "visible": true+ }+ ]+}diff --git a/examples/script-graph-demo/assets/scenes/main.esscene.meta b/examples/script-graph-demo/assets/scenes/main.esscene.metanew file mode 100644index 000000000..1a7b07ffd--- /dev/null+++ b/examples/script-graph-demo/assets/scenes/main.esscene.meta@@ -0,0 +1,8 @@+{+ "uuid": "5a1d0b10-2c44-4a8e-9f21-7c6b1d3e4a00",+ "version": "2.0",+ "type": "scene",+ "importer": {+ "autoMigrate": true+ }+}diff --git a/examples/script-graph-demo/project.esproject b/examples/script-graph-demo/project.esprojectnew file mode 100644index 000000000..1301f2539--- /dev/null+++ b/examples/script-graph-demo/project.esproject@@ -0,0 +1,13 @@+{+ "formatVersion": "1",+ "name": "Script Graph Demo",+ "description": "Gameplay authored as a graph: events, an exec wire, and data wires between named verbs.",+ "tag": "Scripting",+ "version": "0.1.0",+ "defaultScene": "assets/scenes/main.esscene",+ "designResolution": {+ "width": 800,+ "height": 600+ },+ "spineVersion": "none"+}diff --git a/examples/script-graph-demo/src/main.ts b/examples/script-graph-demo/src/main.tsnew file mode 100644index 000000000..7262ed736--- /dev/null+++ b/examples/script-graph-demo/src/main.ts@@ -0,0 +1,37 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file main.ts+ * @brief One registered value node — the half of a script graph that is code.+ *+ * A graph is structure; the verbs it calls are names. The engine ships a+ * vocabulary (maths, comparison, `property.get`/`set`, …) and a project extends+ * it through the same door: `registerValue` for a name that answers a question,+ * `registerAction` for one that does something. Either shows up in the editor's+ * palette with the pins it declares, so nothing about a built-in node is+ * privileged.+ */+import { registerValue } from 'esengine';++/**+ * A triangle wave: `t` folded into `0 → range → 0`. The engine has no such node+ * and should not — this is the demo's own idea of motion, and one function is+ * the whole of teaching the graph about it.+ */+registerValue('demo.pingPong', {+ params: [+ { name: 't', type: 'number', tooltip: 'Seconds elapsed' },+ { name: 'range', type: 'number', tooltip: 'Peak value' },+ ],+ outputs: [{ name: 'value', type: 'number' }],+ // Pure: it reads nothing and writes nothing, so the graph may pull it+ // whenever the node reading it runs.+ touches: {},+ evaluate: (_ctx, _bb, params, out) => {+ const range = Number(params.range ?? 0);+ if (range <= 0) { out.value = 0; return; }+ const span = range * 2;+ const wrapped = Math.abs(Number(params.t ?? 0)) % span;+ out.value = wrapped <= range ? wrapped : span - wrapped;+ },+});diff --git a/examples/script-graph-demo/tsconfig.json b/examples/script-graph-demo/tsconfig.jsonnew file mode 100644index 000000000..1f11ff310--- /dev/null+++ b/examples/script-graph-demo/tsconfig.json@@ -0,0 +1,20 @@+{+ "compilerOptions": {+ "target": "ES2020",+ "module": "ESNext",+ "moduleResolution": "bundler",+ "strict": true,+ "esModuleInterop": true,+ "skipLibCheck": true,+ "forceConsistentCasingInFileNames": true,+ "declaration": false,+ "outDir": "./dist",+ "rootDir": ".",+ "paths": {+ "esengine": ["./.esengine/sdk/index.d.ts"],+ "esengine/wasm": ["./.esengine/sdk/wasm.d.ts"]+ }+ },+ "include": ["src/**/*"],+ "exclude": ["node_modules"]+}diff --git a/sdk/src/logic/ScriptGraphPlugin.ts b/sdk/src/logic/ScriptGraphPlugin.tsindex 9378c8a04..6dcaf69ea 100644--- a/sdk/src/logic/ScriptGraphPlugin.ts+++ b/sdk/src/logic/ScriptGraphPlugin.ts@@ -40,6 +40,8 @@ interface AgentState {run: ScriptRunState | null;graphKey: string | null;compiled: CompiledScriptGraph | null;+ /** Refs this agent asked for and nothing had, reported once each. */+ missing: Set<string>;}/** The slice of `World` the step needs — lets tests inject a fake. */@@ -56,7 +58,7 @@ type MutableAiContext = { -readonly [K in keyof AiContext]: AiContext[K] };export function agentGraphBlackboard(states: Map<Entity, AgentState>, entity: Entity): Blackboard {let st = states.get(entity);if (!st) {- st = { bb: new Blackboard(), run: null, graphKey: null, compiled: null };+ st = { bb: new Blackboard(), run: null, graphKey: null, compiled: null, missing: new Set() };states.set(entity, st);}return st.bb;@@ -106,14 +108,25 @@ export function stepScriptGraphs(present.add(entity);const agent = world.get(entity, ScriptGraphAgent);if (!agent.graph) continue;- const compiled = resolveGraph?.(agent.graph) ?? getScriptGraph(agent.graph);- if (!compiled) continue;let st = states.get(entity);if (!st) {- st = { bb: new Blackboard(), run: null, graphKey: null, compiled: null };+ st = { bb: new Blackboard(), run: null, graphKey: null, compiled: null, missing: new Set() };states.set(entity, st);}++ const compiled = resolveGraph?.(agent.graph) ?? getScriptGraph(agent.graph);+ // A ref nothing has is the loudest thing this system can find: the+ // entity carries a graph, and NOT running it looks exactly like running+ // one that does nothing.+ if (!compiled) {+ if (!st.missing.has(agent.graph)) {+ st.missing.add(agent.graph);+ onProblem?.(entity, `graph "${agent.graph}" is not registered — nothing runs`);+ }+ continue;+ }+ st.missing.delete(agent.graph);if (st.run === null || st.graphKey !== agent.graph) {st.run = createScriptRunState(compiled);st.graphKey = agent.graph;diff --git a/sdk/src/logic/ScriptGraphRunner.ts b/sdk/src/logic/ScriptGraphRunner.tsindex 8f29c3f7d..ce35d0278 100644Binary files a/sdk/src/logic/ScriptGraphRunner.ts and b/sdk/src/logic/ScriptGraphRunner.ts differdiff --git a/sdk/tests/script-graph-runner.test.ts b/sdk/tests/script-graph-runner.test.tsindex d5323e90b..71bd7a588 100644--- a/sdk/tests/script-graph-runner.test.ts+++ b/sdk/tests/script-graph-runner.test.ts@@ -141,6 +141,24 @@ describe('exec flows depth-first', () => {expect(r.log).toEqual(['start', 'update', 'update']);});+ it('publishes the frame delta on the update entry', () => {+ const { reg } = registry();+ const g = graphOf([+ node('upd', 'event.update'),+ node('scale', 'call', { ref: 'test.add', literals: { b: 0 } }),+ node('say', 'call', { ref: 'test.say' }),+ ], [+ edge('upd', 'then', 'say', ''),+ edge('upd', 'dt', 'scale', 'a'),+ edge('scale', 'sum', 'say', 'text'),+ ]);+ const r = run(g, reg);+ r.tick(0.25);+ // Not 0: an entry that declares a port and produces nothing is a graph+ // whose every node runs and whose world never moves.+ expect(r.log).toEqual(['0.25']);+ });+it('runs event.destroy only on teardown', () => {const { reg } = registry();const g = graphOf([diff --git a/tools/check-corpus-authoring.mjs b/tools/check-corpus-authoring.mjsindex f0c0e2955..5dc24449a 100644--- a/tools/check-corpus-authoring.mjs+++ b/tools/check-corpus-authoring.mjs@@ -73,6 +73,7 @@ const NOT_INSTANCE_FORMATS = {'.eslocale': 'translated strings','.esbt': 'a behaviour tree','.esfsm': 'a state machine',+ '.esgraph': 'a script graph: events, an exec wire, and data wires between named verbs','.esmesh': 'an import result, regenerated from the model beside it','.inputmap': 'input actions and their bindings','.tmj': 'a Tiled map; the engine derives RuntimeOnly entities from it',@@ -120,7 +121,6 @@ const DISPOSITION = {// — owed: a creator-facing component nothing in the shipped corpus authors.// Each reason names where the coverage belongs. —- ScriptGraphAgent: ['owed', 'the script-graph editor is not landed yet, so no example can hold a `.esgraph` an author made; the coverage belongs in an example whose logic is a graph rather than a script'],};diff --git a/tools/goldenProjects.mjs b/tools/goldenProjects.mjsindex 08813d069..7948e007b 100644--- a/tools/goldenProjects.mjs+++ b/tools/goldenProjects.mjs@@ -51,7 +51,7 @@ export const EVIDENCE_FORMATS = ['.ts', '.esproject', '.esscene', '.esprefab','.esanimator', '.estimeline', '.esanim', '.esavatar','.esmaterial', '.esshader', '.esenv',- '.estileset', '.tmj', '.eslocale', '.esbt', '.inputmap',+ '.estileset', '.tmj', '.eslocale', '.esbt', '.esgraph', '.inputmap','.json',];@@ -356,6 +356,7 @@ export const CAPABILITIES = ['hot-update', 'rollback', 'subpackage','networking','persistence', 'save-versioning',+ 'script-graph',// What a game needs and no sample carried end to end. Each holds a gap below// until the phase covering it lands, so the gate prints how much of a game the// corpus still cannot certify. See docs/REARCH_CELESTIAL_HEIGHTS.md.@@ -374,6 +375,9 @@ export const EVIDENCE = {input: /\b(Input|defineInputMap|isKeyDown|InputState)\b/,animation: /\b(SpriteAnimator|Animator|spriteAnim|Flipbook|TimelinePlayer|AnimClip)\b/,ecs: /\b(defineComponent|defineSystem)\b/,+ // The component that RUNS one. A `.esgraph` on disk that no scene+ // attaches is a picture of gameplay, not gameplay.+ 'script-graph': /\bScriptGraphAgent\b/,'third-person': /\b(ThirdPersonController|ThirdPersonCamera)\b/,particles: /\bParticleEmitter\b/,'lighting-2d': /\b(Light2D|ShadowCaster2D)\b/,@@ -668,6 +672,13 @@ export const GOLDEN = [tier: 'nightly',interactGap: 'a showcase that cycles its own animations; nothing to press',},+ {+ id: 'script-graph-demo',+ certifies: ['script-graph'],+ targets: ['web', 'desktop'],+ tier: 'nightly',+ interactGap: 'both squares are graph-driven on a clock; no input path yet',+ },{id: 'save-load',certifies: ['persistence', 'save-versioning'],diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 030b2a39b..5865217f5 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,9 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'feat(logic): gameplay you can draw, and a corpus that draws some':+ { note: 'Gameplay you can draw.' },+'fix(play): Run brings the realm up from wherever the author is standing':{ note: 'Run works from wherever you are standing.' },