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
docs(playable): the ad-network guide, and playable stops claiming its own runtime build
esengine0b4dfe849ec1
diff --git a/desktop/electron/exportPlayable.ts b/desktop/electron/exportPlayable.tsindex 7d74dabed..6507e10af 100644--- a/desktop/electron/exportPlayable.ts+++ b/desktop/electron/exportPlayable.ts@@ -2,17 +2,19 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team/*** @file Playable-ad export (REARCH_EXPORT E3). Produces ONE self-contained- * `index.html` (no external requests — ad networks require single-file):- * - the SINGLE_FILE engine glue (esengine.single.js, global ESEngineModule- * with the wasm embedded as base64) inlined as a <script>;+ * `index.html` (single-file, no fetches — what ad networks require):+ * - the shipped WEB engine glue (esengine.js) inlined as a global, run by+ * the host as a blob module, with esengine.wasm inlined as base64 and fed+ * through instantiateWasm — so no separate single-file engine build;* - assets as base64 data URLs + scenes inlined as <script> globals* (keyed by the scene's @uuid: refs — EmbeddedAssetProvider resolves them);- * - the playable host + esengine + project scripts esbuilt to ONE IIFE.+ * - the playable host + esengine + project scripts esbuilt to ONE IIFE;+ * - whatever the chosen ad network's profile injects (playableAdProfile.ts).* Boots the SAME shipping runtime via initPlayableRuntime (play == ship).*- * Correct-by-construction against initPlayableRuntime + the SINGLE_FILE glue- * contract (no playable simulator here — runtime is validated by the user in- * a browser / ad preview). Pure Node (esbuild + fs); IPC wiring in main.ts.+ * Correct-by-construction against initPlayableRuntime (no playable simulator+ * here — runtime is validated in a browser / ad preview). Pure Node (esbuild+ * + fs); IPC wiring in main.ts.*/import { loadEsbuild } from './esbuildRuntime';import { writeFile, mkdir, readFile, stat, rm } from 'node:fs/promises';diff --git a/desktop/src/playableHost.ts b/desktop/src/playableHost.tsindex 316554f6d..5a605a274 100644--- a/desktop/src/playableHost.ts+++ b/desktop/src/playableHost.ts@@ -3,11 +3,12 @@/*** @file playableHost.ts — the exported playable ad's host (single-HTML build).* esbuilt to an IIFE by exportPlayable with esengine + the project scripts- * INLINED. The engine runs from the SINGLE_FILE glue (esengine.single.js —- * a global `ESEngineModule` factory with the wasm embedded as base64), which- * is a sibling inline <script>; assets + scenes are inlined globals. Boots- * the SAME shipping runtime via initPlayableRuntime (play == ship). Nothing- * is fetched — the whole game is one self-contained .html (ad-network ready).+ * INLINED. The engine is the shipped WEB glue, handed over as the inline+ * `__ENGINE_GLUE__` global and evaluated as a blob module (it is ESM), with+ * the wasm arriving base64 in `__ENGINE_WASM__`; assets + scenes are inlined+ * globals too. Boots the SAME shipping runtime via initPlayableRuntime+ * (play == ship). Nothing is fetched — the whole game is one self-contained+ * .html (ad-network ready).*/import { createWebApp, setEditorMode, setPlayMode, initPlayableRuntime, createEmbeddedSideModuleHost, parseThemeOverrides } from 'esengine';import type { ESEngineModule as EngineModule, SceneData, EmbeddedSideModuleRegistry } from 'esengine';diff --git a/docs/astro/src/content/docs/guides/build-export.mdx b/docs/astro/src/content/docs/guides/build-export.mdxindex 683f53807..e06e3eb8a 100644--- a/docs/astro/src/content/docs/guides/build-export.mdx+++ b/docs/astro/src/content/docs/guides/build-export.mdx@@ -68,20 +68,79 @@ and opens it in your browser.| **Web** | A static, self-contained web build. | `dist-web/` | **Preview over http**, or upload the folder to any static host. || **Desktop** | An Electron app source tree. | `dist-desktop/` | `cd dist-desktop && npm install && npm start` — or `npm run dist` for a native `.dmg` / `.exe` / AppImage installer. || **WeChat** | A WeChat MiniGame package. | `dist-wechat/` | Open the folder in WeChat DevTools and set your AppID. See [WeChat MiniGame](/docs/guides/wechat/). |-| **Playable** | One self-contained `index.html` with everything inlined — no external requests, as ad networks require. | `dist-playable/` | **Preview over http** (its real surface is an ad-network iframe). Note a full engine usually exceeds ad-network size limits. |+| **Playable** | One self-contained `index.html` with everything inlined — no external requests, as ad networks require. | `dist-playable/` | **Preview over http** (its real surface is an ad-network iframe). Pick the [ad network](#playable-ad-networks) so the CTA and the size check match where it ships. |++## Playable ad networks++Every network takes the same single HTML file but disagrees on three things: how big+it may be, what must sit in `<head>`, and which function sends the player to the+store. Pick the network in **Project Settings → Packaging → Playable → Ad network**+and the export handles all three.++Your game code never names a network. Call the CTA once:++```ts+import { playableCta } from 'esengine';++// on your end-card button, after the win — wherever the call to action is+playableCta();+```++The export installs the bridge `playableCta()` dispatches through. With no network+selected it is a no-op, so the same scene still runs in the editor and on the web.++| Network | Limit | Click-through | Notes |+|---|---|---|---|+| **Generic** | 2MB | — | No network API. The cap is the strictest we know of, since an unnamed target could be any of them. |+| **Meta** (Facebook / Instagram) | 2MB for `index.html` | `FbPlayableAd.onCTAClick()` | Meta's 5MB figure is the total for a ZIP bundle; a single-file playable is capped by the `index.html` rule. Forbids any HTTP request. |+| **Google Ads** (App campaigns) | 5MB | `ExitApi.exit()` | Its exit API is a Google-hosted script, which the docs require as a literal `<script>` in `<head>` — the export writes it for you. Google uploads a **ZIP**, so compress the `index.html` before uploading. |+| **MRAID network** (generic) | 5MB | `mraid.open()` | For any MRAID host. `mraid` is injected by the webview, so nothing goes in `<head>`. |+| **Unity Ads** | 5MB | `mraid.open()` | Expects the playable to wait for MRAID's `viewableChange` before starting. |+| **AppLovin** | 5MB | `mraid.open()` | Requires every resource embedded — which a single-file playable already is. |++Limits move, so each one is reported against the network it came from: an oversized+export names the cap it used and where that number is published, rather than a bare+number to trust.++### A network we don't ship++Define it yourself — the built-in networks are written against this exact contract,+so nothing is out of reach. **Build → New platform** scaffolds one (pick *Playable ad+network*), or write `.esengine/platforms/<id>.mjs` by hand:++```js+export default {+ id: 'acme-ads',+ kind: 'playable',+ label: 'Acme Ads',++ // The size this network accepts, and where that number is published — the export+ // quotes the note in its warning.+ maxBytes: 5 * 1024 * 1024,+ limitNote: 'Acme docs, Creative specs § playable',++ // Optional: markup for <head> (an orientation meta tag, the network's SDK script).+ emitHead: (ctx) => `<meta name="ad.orientation" content="${ctx.orientation}">`,++ // Installs the bridge playableCta() dispatches through. Runs before the game.+ emitBridge: () => `window.__ESTELLA_PLAYABLE__={cta:function(){AcmeSDK.openStore();}};`,+};+```++It then appears in the Ad network list beside the built-in ones, and packages through+the same pipeline.## Runtime prerequisites-Web and Desktop reuse the engine runtime that ships with the editor, so they export-with no setup. **WeChat** and **Playable** each need their own engine runtime built-once, because they use a different WebAssembly loader / single-file packaging:+Web, Desktop and **Playable** all reuse the engine runtime that ships with the+editor, so they export with no setup — a playable inlines that same web runtime+(glue as a blob module, wasm as base64) rather than needing a build of its own.+**WeChat** is the exception: its WebAssembly loader differs, so its runtime is built+once:```bash# only before the first WeChat exportnode build-tools/cli.js build -t wechat--# only before the first Playable export-node build-tools/cli.js build -t playable```The Package Project dialog reminds you when a target's runtime is missing, and a@@ -168,19 +227,18 @@ See [The Editor](/docs/guides/editor/) for the settings UI.## The build CLI (advanced)The editor packages your **game**. The `build-tools/cli.js` command builds the-**engine and SDK** themselves — you only need it to produce the WeChat / Playable-runtimes above, or when working on the engine. Common commands:+**engine and SDK** themselves — you only need it to produce the WeChat runtime above,+or when working on the engine. Common commands:```bashnode build-tools/cli.js build -t web # build the engine (web target)node build-tools/cli.js build -t wechat # …the WeChat runtime-node build-tools/cli.js build -t playable # …the single-file runtimenode build-tools/cli.js sdk # build the SDK onlynode build-tools/cli.js watch # rebuild on change (engine dev)```<Aside type="note">- Most game developers never run the build CLI beyond the one-time WeChat / Playable+ Most game developers never run the build CLI beyond the one-time WeChatruntime builds — day-to-day work happens in the editor and the SDK.</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/build-export.mdx b/docs/astro/src/content/docs/zh-cn/guides/build-export.mdxindex f6355acce..925d0e741 100644--- a/docs/astro/src/content/docs/zh-cn/guides/build-export.mdx+++ b/docs/astro/src/content/docs/zh-cn/guides/build-export.mdx@@ -59,19 +59,72 @@ import { Aside, Steps } from '@astrojs/starlight/components';| **Web** | 一个静态、自包含的 Web 构建。 | `dist-web/` | **Preview over http**,或把文件夹上传到任意静态托管。 || **桌面** | 一棵 Electron 应用源码树。 | `dist-desktop/` | `cd dist-desktop && npm install && npm start`——或 `npm run dist` 出原生 `.dmg` / `.exe` / AppImage 安装包。 || **微信** | 一个微信小游戏包。 | `dist-wechat/` | 在微信开发者工具里打开该文件夹并设置你的 AppID。见 [微信小游戏](/docs/zh-cn/guides/wechat/)。 |-| **Playable** | 一个自包含的 `index.html`,一切内联——无外部请求(广告网络的要求)。 | `dist-playable/` | **Preview over http**(它的真实宿主是广告网络的 iframe)。注意完整引擎通常超出广告网络的体积限制。 |+| **Playable** | 一个自包含的 `index.html`,一切内联——无外部请求(广告平台的要求)。 | `dist-playable/` | **Preview over http**(它的真实宿主是广告平台的 iframe)。先选好[广告平台](#试玩广告平台),CTA 与体积检查才对得上投放目标。 |++## 试玩广告平台++各家平台收的都是同一个单文件 HTML,但在三件事上不一致:体积上限、`<head>` 里必须放什么、+以及用哪个函数把玩家送去商店。在 **项目设置 → 打包 → 试玩广告 → 广告平台** 选好平台,+导出会把这三件事都处理掉。++游戏代码里不出现任何平台名字,只调一次 CTA:++```ts+import { playableCta } from 'esengine';++// 结束卡的按钮、通关之后——凡是"号召点击"的地方+playableCta();+```++导出会注入 `playableCta()` 要分发到的桥接层。未选平台时它是空操作,所以同一个场景在编辑器里+和网页上照样能跑。++| 平台 | 上限 | 点击跳转 | 说明 |+|---|---|---|---|+| **通用** | 2MB | — | 不接任何平台接口。上限取我们已知里最严的一档——毕竟未指名的目标可能是其中任何一家。 |+| **Meta**(Facebook / Instagram) | `index.html` 2MB | `FbPlayableAd.onCTAClick()` | Meta 的 5MB 是 ZIP 包的总量;单文件试玩受 `index.html` 那条约束。禁止任何 HTTP 请求。 |+| **Google Ads**(应用广告系列) | 5MB | `ExitApi.exit()` | 它的退出接口是 Google 托管的脚本,官方要求以字面 `<script>` 写在 `<head>` 里——导出会帮你写好。Google 上传 **ZIP**,所以要先把 `index.html` 压缩。 |+| **MRAID 平台**(通用) | 5MB | `mraid.open()` | 适用于任何 MRAID 宿主。`mraid` 由宿主 webview 注入,`<head>` 无需任何内容。 |+| **Unity Ads** | 5MB | `mraid.open()` | 要求试玩包等到 MRAID 的 `viewableChange` 之后再开始。 |+| **AppLovin** | 5MB | `mraid.open()` | 要求所有资源内嵌——单文件试玩本来就是。 |++上限会变,所以每条警告都指名它用的是哪一家的上限、以及这个数字出自哪里,而不是丢一个+让你盲信的数字。++### 我们没内置的平台++自己定义就行——内置的那几家写的就是这份契约,没有做不到的事。**构建 → 新建平台** 可以+生成脚手架(类型选*试玩广告平台*),也可以手写 `.esengine/platforms/<id>.mjs`:++```js+export default {+ id: 'acme-ads',+ kind: 'playable',+ label: 'Acme Ads',++ // 这家接受的体积,以及这个数字出自哪里——导出的警告会引用这条说明。+ maxBytes: 5 * 1024 * 1024,+ limitNote: 'Acme 文档,创意规格 § playable',++ // 可选:注入 <head>(方向 meta、平台自己的 SDK 脚本)。+ emitHead: (ctx) => `<meta name="ad.orientation" content="${ctx.orientation}">`,++ // 注入 playableCta() 要分发到的桥接层,在游戏代码之前执行。+ emitBridge: () => `window.__ESTELLA_PLAYABLE__={cta:function(){AcmeSDK.openStore();}};`,+};+```++它随后就会和内置平台并列出现在"广告平台"列表里,并走同一条导出管线。## 运行时前置条件-Web 和桌面复用随编辑器附带的引擎运行时,所以导出无需准备。**微信**和 **Playable** 各需先构建一次-自己的引擎运行时,因为它们用不同的 WebAssembly 加载器 / 单文件打包方式:+Web、桌面与 **Playable** 都复用随编辑器附带的引擎运行时,所以导出无需准备——试玩包内联的+就是同一份 web 运行时(glue 作为 blob 模块、wasm 以 base64 传入),不需要单独构建。**微信**是+例外:它的 WebAssembly 加载器不同,运行时需先构建一次:```bash# 仅在首次微信导出前node build-tools/cli.js build -t wechat--# 仅在首次 Playable 导出前-node build-tools/cli.js build -t playable```当某个目标的运行时缺失时,打包项目对话框会提醒你,而微信导出会**直接失败**并给出确切的@@ -137,12 +190,11 @@ node build-tools/cli.js build -t playable## 构建 CLI(进阶)编辑器打包你的**游戏**。而 `build-tools/cli.js` 命令构建的是**引擎和 SDK 本身**——你只在要产出上面-的微信 / Playable 运行时、或开发引擎时才需要它。常用命令:+的微信运行时、或开发引擎时才需要它。常用命令:```bashnode build-tools/cli.js build -t web # 构建引擎(web 目标)node build-tools/cli.js build -t wechat # …微信运行时-node build-tools/cli.js build -t playable # …单文件运行时node build-tools/cli.js sdk # 只构建 SDKnode build-tools/cli.js watch # 改动即重建(引擎开发)```